/** * Executes instructions. * * @throws ImpossibleMoveException * @throws UnknownInstructionException */ public function executeInstructions() { foreach ($this->instructions as $instruction) { if (in_array($instruction, $this->allowedActions)) { if (!$this->plateau->isMovePossible($this->xPosition, $this->yPosition, $this->orientation)) { throw new ImpossibleMoveException('Move is not possible - new position is out of the grid.'); } list($newXCoordinate, $newYCoordinate) = $this->plateau->move($this->xPosition, $this->yPosition, $this->orientation); $this->xPosition = $newXCoordinate; $this->yPosition = $newYCoordinate; } elseif (in_array($instruction, $this->allowedTurnDirections)) { $this->orientation = $this->plateau->turn($this->orientation, $instruction); } else { throw new UnknownInstructionException('Unknown instruction.'); } } }
/** * @expectedException Exception */ public function testIsMovePossibleException() { $plateau = new Plateau(5, 5); $plateau->isMovePossible(1, 10, Plateau::NORTH); }