Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static function move($coords, Ship $myShip, $mines){
- e('move');
- // from a position to get to
- // see what's best to do
- //set orientation
- $myPos = $myShip->coords;
- $dirHorizontal = 'NONE'; // left, right or none
- if($coords[0] > $myPos[0])
- $dirHorizontal = 'RIGHT';
- else if($coords[0] < $myPos[0])
- $dirHorizontal = 'LEFT';
- $dirVertical = 'NONE'; // top, bottom or none
- if($coords[1] > $myPos[1])
- $dirVertical = 'BOTTOM';
- else if($coords[1] < $myPos[1])
- $dirVertical = 'TOP';
- $dir = "$dirHorizontal $dirVertical";
- $orientation = [0];
- if($dir == "NONE BOTTOM")
- $orientation = [4, 5];
- elseif($dir == "NONE TOP")
- $orientation = [1, 2];
- elseif($dir == "LEFT BOTTOM")
- $orientation = [4];
- elseif($dir == "LEFT TOP")
- $orientation = [2];
- elseif($dir == "LEFT NONE")
- $orientation = [3];
- elseif($dir == "RIGHT BOTTOM")
- $orientation = [5];
- elseif($dir == "RIGHT TOP")
- $orientation = [1];
- elseif($dir == "RIGHT NONE")
- $orientation = [0];
- $mines = array_map(function($mine){
- return $mine->coords;
- }, $mines);
- $leftTurn = [1, 2, 3, 4, 5, 0];
- if(in_array($myShip->orientation, $orientation)){ //if our orientation is correct
- //check next case
- $nextCase = Utils::FuturePos($myShip->coords, $myShip->orientation, false, 1);
- if(!in_array($nextCase, $mines)){ //no mine where we go
- if($myShip->speed === 0)
- self::faster();
- else
- self::wait();
- }
- else{
- self::rotate();
- }
- }
- else{ // set our orientation right
- ('set orientation');
- //leftway
- $left = 1;
- $currentOrientation = $myShip->orientation;
- while($leftTurn[$currentOrientation] != $orientation){
- $left++;
- if($left > 3) break;
- $currentOrientation = ($currentOrientation+1) % 6;
- }
- if($left <= 3)
- self::rotate('LEFT');
- else
- self::rotate();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement