Exemple #1
0
 /**
  * @param MoveInterface $move
  *
  * @return GameState
  */
 private function createStateFromMove(MoveInterface $move)
 {
     if (!$move->getFrom()) {
         return null;
     }
     $gameState = new GameState();
     $gameState->setFrom($move->getFrom());
     $gameState->setTo($move->getTo());
     $gameState->setPiece($move->getPiece());
     $gameState->setCapture($move->getCapture());
     $gameState->setMoveType($move->getType());
     return $gameState;
 }
 /**
  * @param PersistableGameStateInterface $persistableGameState
  *
  * @return GameState
  */
 protected function createFromPersistableState(PersistableGameStateInterface $persistableGameState)
 {
     $gameState = new GameState();
     if ($pieceData = $persistableGameState->getPiece()) {
         $piece = PieceFactory::create($pieceData['type'], $pieceData['color'], array_key_exists('id', $pieceData) ? $pieceData['id'] : null);
         $gameState->setPiece($piece);
         $gameState->setColor($persistableGameState->getColor());
         $gameState->setFrom($persistableGameState->getFrom());
         $gameState->setTo($persistableGameState->getTo());
         $gameState->setMoveType($persistableGameState->getMoveType());
         if ($captureData = $persistableGameState->getCapture()) {
             $capturingPiece = PieceFactory::create($captureData['capturing_type'], $captureData['capturing_color'], $captureData['capturing_id']);
             $capturedPiece = PieceFactory::create($captureData['captured_type'], $captureData['captured_color'], $captureData['captured_id']);
             $capture = new Capture($capturingPiece, $capturedPiece, $captureData['position']);
             $gameState->setCapture($capture);
         }
     }
     return $gameState;
 }
 /**
  * @param GameState $gameState
  *
  * @return array
  */
 private function getExpectedGameStateArray(GameState $gameState)
 {
     $state = [];
     $state['id'] = $gameState->getId();
     if ($gameState->getPiece()) {
         $state['color'] = $gameState->getColor();
         $state['from'] = $gameState->getFrom();
         $state['to'] = $gameState->getTo();
         $state['piece'] = $this->getExpectedPieceArray($gameState->getPiece());
         $state['move_type'] = $gameState->getMoveType();
         $state['capture'] = $this->getExpectedCaptureArray($gameState->getCapture());
     }
     return $state;
 }