public function testGetStartingPosition() { $this->assertNull($this->boardWalker->getStartingPosition(), 'Starting position should not be set yet'); $this->boardWalker->start(SquareInterface::POSITION_D5)->forward(1); $this->assertEquals(SquareInterface::POSITION_D5, $this->boardWalker->getStartingPosition(), 'Starting position should still be the same after calling forward()'); $this->assertNotEquals($this->boardWalker->getPosition(), $this->boardWalker->getStartingPosition(), 'Current position and starting position should not match at this point'); $this->boardWalker->restart(); $this->assertEquals(SquareInterface::POSITION_D5, $this->boardWalker->getStartingPosition(), 'Starting position should still be the same after restart()'); }
/** * {@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)); }