Esempio n. 1
0
 public function testOmnidirectional()
 {
     $this->boardWalker->start(SquareInterface::POSITION_D5)->omnidirectional(1);
     $this->assertEquals(SquareInterface::POSITION_D5, $this->boardWalker->getPosition(), 'Position should stay the same after calling omnidirectional()');
     $this->assertCount(8, $this->boardWalker->flush(), 'There should be 8 moves returned by flush() after calling omnidirectional(1)');
     $this->boardWalker->omnidirectional(2);
     $this->assertCount(16, $this->boardWalker->flush(), 'There should be 16 moves returned by flush() after calling omnidirectional(2)');
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function configureWalker(BoardWalker $walker, GameInterface $game)
 {
     $walker->omnidirectional(1);
     $kingPosition = BoardHelper::getKingPosition($game->getBoard(), $game->getCurrentColor());
     $kingColumn = BoardHelper::getColumnFromPosition($kingPosition);
     $kingRow = BoardHelper::getRowFromPosition($kingPosition);
     $board = $game->getBoard();
     $king = $board->getSquare($kingPosition)->getPiece();
     $track = $kingPosition === SquareInterface::POSITION_E1;
     // check for possible castle move
     if (empty($game->getMovesByPiece($king->getId()))) {
         // see if one of the rooks did not make any moves
         $rookCriteria = ['piece_type' => PieceInterface::TYPE_ROOK, 'piece_color' => $game->getCurrentColor()];
         foreach ($board->getPiecesBy($rookCriteria) as $rookPosition => $rook) {
             if (empty($game->getMovesByPiece($rook->getId()))) {
                 // see if there are no pieces between the king and this rook
                 $rookColumn = BoardHelper::getColumnFromPosition($rookPosition);
                 $columnDiff = abs($kingColumn - $rookColumn) - 1;
                 $track = $track === true && $columnDiff === 3;
                 if ($columnDiff > 1) {
                     $skip = false;
                     for ($x = 1; $x <= $columnDiff; $x++) {
                         if ($rookColumn > $kingColumn) {
                             $cursor = $rookColumn - $x . $kingRow;
                         } else {
                             $cursor = $rookColumn + $x . $kingRow;
                         }
                         if (null !== ($piece = $board->getSquare($cursor)->getPiece())) {
                             $skip = true;
                             break;
                         }
                     }
                     if ($skip) {
                         continue;
                     }
                     if ($kingColumn > $rookColumn) {
                         if ($game->getCurrentColor() === Color::WHITE) {
                             $walker->jump(BoardWalker::DIRECTION_LEFT, 2);
                         } else {
                             $walker->jump(BoardWalker::DIRECTION_RIGHT, 2);
                         }
                     } else {
                         if ($game->getCurrentColor() === Color::WHITE) {
                             $walker->jump(BoardWalker::DIRECTION_RIGHT, 2);
                         } else {
                             $walker->jump(BoardWalker::DIRECTION_LEFT, 2);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function configureWalker(BoardWalker $walker, GameInterface $game)
 {
     $walker->omnidirectional('*');
 }