/**
  * @param string $gameString
  * @param string $expectedAsciiBoard
  *
  * @dataProvider getGameStringsAndExpectedBoards()
  */
 public function testParseGameString($gameString, $expectedAsciiBoard)
 {
     $actualParsedGame = $this->parser->parseGameString($gameString);
     $expectedAsciiBoard = trim(str_replace('    ', '', $expectedAsciiBoard));
     $actualAsciiBoard = trim(BoardDecorator::toAscii($actualParsedGame->getBoard()));
     $this->assertEquals($expectedAsciiBoard, $actualAsciiBoard);
 }
 /**
  * @param string $asciiBoard
  * @param array  $expectedPossibleMovesByColor
  *
  * @dataProvider getBoardsAndPossibleMoves()
  */
 public function testPossibleMoves($asciiBoard, array $expectedPossibleMovesByColor)
 {
     if (empty($expectedPossibleMovesByColor)) {
         $this->markTestIncomplete('No possible moves provided by testing data');
     }
     $game = $this->createGameFromAsciiBoard($asciiBoard);
     foreach ($expectedPossibleMovesByColor as $colorToMove => $expectedPossibleMoves) {
         $game->setCurrentColor($colorToMove);
         $board = $game->getBoard();
         $actualMovesByColor = $this->getSimplifiedActualMoves($colorToMove, $board);
         foreach ($expectedPossibleMoves as $x => $expectedMove) {
             $found = false;
             $expectedFrom = $expectedMove[0];
             $expectedTo = $expectedMove[1];
             foreach ($actualMovesByColor as $y => $actualMove) {
                 $actualFrom = $actualMove[0];
                 $actualTo = $actualMove[1];
                 if ($expectedFrom == $actualFrom && $expectedTo == $actualTo) {
                     unset($expectedPossibleMoves[$x]);
                     unset($actualMovesByColor[$y]);
                     $found = true;
                 }
             }
             if (null === ($fromPiece = $board->getSquare($expectedFrom)->getPiece())) {
                 throw new \RuntimeException(sprintf('No piece found to move from %s to %s: %s', BoardHelper::positionToLabel($expectedFrom), BoardHelper::positionToLabel($expectedTo), BoardDecorator::toAscii($board)));
             }
             $this->assertTrue($found, sprintf('Expected move for %s (%s from %s to %s) is missing from actual moves', $colorToMove === Color::WHITE ? 'white' : 'black', $fromPiece->getTypeLabel(), BoardHelper::positionToLabel($expectedFrom), BoardHelper::positionToLabel($expectedTo)));
         }
         foreach ($actualMovesByColor as $actualMove) {
             $actualFrom = $actualMove[0];
             $actualTo = $actualMove[1];
             $this->assertTrue(false, sprintf('Actual move for %s (%s from %s to %s) is missing from expected moves', $colorToMove === Color::WHITE ? 'white' : 'black', $board->getSquare($actualFrom)->getPiece()->getTypeLabel(), BoardHelper::positionToLabel($actualFrom), BoardHelper::positionToLabel($actualTo)));
         }
     }
 }
Example #3
0
 /**
  * @param string $asciiBoard
  *
  * @return Game
  */
 protected function createGameFromAsciiBoard($asciiBoard)
 {
     $board = BoardDecorator::fromAscii($asciiBoard);
     $game = GameFactory::create(PlayerFactory::createWhite(), PlayerFactory::createBlack(), $board);
     return $game;
 }
Example #4
0
 /**
  * @param GameInterface $game
  *
  * @return string
  *
  * @todo Add ascii for history, captures, players and clocks
  */
 public static function toAscii(GameInterface $game)
 {
     return BoardDecorator::toAscii($game->getBoard());
 }