Exemplo n.º 1
0
 /**
  * @return Game
  */
 private function createGame()
 {
     $whitePlayer = PlayerFactory::create(Color::WHITE, 'White', true);
     $blackPlayer = PlayerFactory::create(Color::BLACK, 'Black', true);
     $board = BoardFactory::create();
     $gameState = $this->createGameState();
     $gameState->setFrom(SquareInterface::POSITION_E2);
     $gameState->setTo(SquareInterface::POSITION_E4);
     $gameState->setColor(Color::WHITE);
     $gameState->setMoveType(MoveInterface::TYPE_NORMAL);
     $gameState->setPiece(PieceFactory::create(PieceInterface::TYPE_PAWN, Color::WHITE));
     $game = new Game($whitePlayer, $blackPlayer, $board);
     $game->addState($gameState);
     return $game;
 }
Exemplo n.º 2
0
 /**
  * @param PersistableGameInterface $persistableGame
  *
  * @return Game
  */
 protected function createFromPersistable(PersistableGameInterface $persistableGame)
 {
     $whitePlayer = new Player(Color::WHITE, $persistableGame->getWhitePlayerName(), $persistableGame->isWhitePlayerHuman());
     $blackPlayer = new Player(Color::BLACK, $persistableGame->getBlackPlayerName(), $persistableGame->isBlackPlayerHuman());
     $squares = [];
     if (null !== ($lastState = $persistableGame->getLastState())) {
         foreach ($lastState->getSquares() as $squareData) {
             $squares[] = SquareFactory::create($squareData['position'], $squareData['piece']);
         }
     }
     $board = BoardFactory::create($squares);
     $game = new Game($whitePlayer, $blackPlayer, $board, $persistableGame->getUid());
     foreach ($persistableGame->getStates() as $persistableGameState) {
         $game->addState($this->createFromPersistableState($persistableGameState));
     }
     $game->setFinished($persistableGame->hasFinished());
     $game->setFinishedReason($persistableGame->getFinishedReason());
     if ($lastState !== null) {
         $game->setCurrentColor($lastState->getColor() === Color::WHITE ? Color::BLACK : Color::WHITE);
     }
     return $game;
 }