Ejemplo n.º 1
0
 public function parseGameString($notations, $whitePlayer = null, $blackPlayer = null)
 {
     $notations = trim($notations);
     $whitePlayer = $whitePlayer ?: PlayerFactory::createWhite();
     $blackPlayer = $blackPlayer ?: PlayerFactory::createBlack();
     $board = BoardFactory::create();
     $game = GameFactory::create($whitePlayer, $blackPlayer, $board);
     $movePairs = preg_split('/(\\d+)\\. /', $notations);
     $movePairs = array_filter(array_map('trim', $movePairs));
     $parsed = [];
     foreach ($movePairs as $pairData) {
         list($whiteNotation, $blackNotation) = explode(' ', $pairData);
         if ($whiteNotation !== '0-1') {
             try {
                 $whiteParsed = $this->parse($whiteNotation, $game, Color::WHITE);
                 $game->doMove($this->createMoveFromParsed($whiteParsed));
                 $game->finishTurn($this->moveCalculator);
                 $parsed[] = $whiteParsed;
             } catch (\Exception $e) {
                 throw new \RuntimeException(sprintf('Failed to parse notation for white: %s', $whiteNotation), null, $e);
             }
         }
         if ($blackNotation !== '1-0') {
             try {
                 $blackParsed = $this->parse($blackNotation, $game, Color::BLACK);
                 $game->doMove($this->createMoveFromParsed($blackParsed));
                 $game->finishTurn($this->moveCalculator);
                 $parsed[] = $blackParsed;
             } catch (\Exception $e) {
                 throw new \RuntimeException(sprintf('Failed to parse notation for black: %s', $blackNotation), null, $e);
             }
         }
     }
     return $game;
 }
Ejemplo n.º 2
0
 protected function getGame($id, $storageType)
 {
     /*
     $adapterRegistry = new StorageAdapterRegistry();
     $adapterRegistry->register(new OrmAdapter($managerRegistry, Game::class, GameState::class), 'orm');
     $storageHelper = new StorageHelper($adapterRegistry, $storageType);
     
     return $storageHelper->loadGame($id);
     */
     return GameFactory::create(PlayerFactory::createWhite(), PlayerFactory::createBlack());
 }
Ejemplo n.º 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;
 }