Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function configureWalker(BoardWalker $walker, GameInterface $game)
 {
     $pawnMoves = $game->getMovesByPiece($game->getBoard()->getSquare($walker->getStartingPosition())->getPiece()->getId());
     if (empty($pawnMoves)) {
         if ($game->getCurrentColor() === Color::WHITE && $walker->getRow() == 2 || $game->getCurrentColor() === Color::BLACK && $walker->getRow() == 7) {
             $newPosition = $walker->peek(BoardWalker::DIRECTION_FORWARD, 1);
             // allowed to make two steps forward
             if ($newPosition && !$game->getBoard()->getSquare($newPosition)->getPiece()) {
                 $newPosition = $walker->peek(BoardWalker::DIRECTION_FORWARD, 2);
                 if ($newPosition && !$game->getBoard()->getSquare($newPosition)->getPiece()) {
                     // temporary check because walker does not seem to consider obstructing pieces of own color
                     $walker->jump(BoardWalker::DIRECTION_FORWARD, 2)->restart();
                 }
             }
         }
     }
     $walker->forward(1, false)->restart();
     $forwardLeftCapture = $walker->peek(BoardWalker::DIRECTION_FORWARDLEFT, 1, null, false, true);
     $forwardRightCapture = $walker->peek(BoardWalker::DIRECTION_FORWARDRIGHT, 1, null, false, true);
     if ($forwardLeftCapture !== null) {
         $walker->forwardLeft(1)->restart();
     }
     if ($forwardRightCapture !== null) {
         $walker->forwardRight(1)->restart();
     }
     $this->walkEnPassant($walker, $game->getLastMove(false));
 }
Пример #2
0
 public function testGetRow()
 {
     $this->boardWalker->start(SquareInterface::POSITION_D5);
     $this->assertEquals(5, $this->boardWalker->getRow());
     $this->boardWalker->forward(1);
     $this->assertEquals(6, $this->boardWalker->getRow());
     $this->boardWalker->start(SquareInterface::POSITION_D5)->left(1);
     $this->assertEquals(5, $this->boardWalker->getRow());
     $this->boardWalker->start(SquareInterface::POSITION_D5)->backward(1);
     $this->assertEquals(4, $this->boardWalker->getRow());
     $this->boardWalker->start(SquareInterface::POSITION_D5)->right(1);
     $this->assertEquals(5, $this->boardWalker->getRow());
 }