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; }
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()); }
/** * @param string $asciiBoard * * @return Game */ protected function createGameFromAsciiBoard($asciiBoard) { $board = BoardDecorator::fromAscii($asciiBoard); $game = GameFactory::create(PlayerFactory::createWhite(), PlayerFactory::createBlack(), $board); return $game; }