예제 #1
0
 /**
  * @return Board
  */
 public static function createEmpty()
 {
     $squares = [];
     foreach (BoardHelper::getAllPositions() as $position) {
         $squares[] = SquareFactory::create($position);
     }
     return new Board($squares);
 }
예제 #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;
 }