Example #1
0
 /**
  * @param Game $game
  * @return bool
  */
 public function fixResult(Game $game) : bool
 {
     $this->chessGameService->setPgn($game->getPgn());
     switch ($this->chessGameService->gameOver()) {
         case 'W':
             $game->setResultWhite(1)->setResultBlack(0);
             return true;
         case 'B':
             $game->setResultWhite(0)->setResultBlack(1);
             return true;
         case 'D':
             $game->setResultWhite(0.5)->setResultBlack(0.5);
             return true;
         default:
             return false;
     }
 }
Example #2
0
 /**
  * @param GameFixResultInterface $request
  * @param Game $game
  */
 private function fixResultIfTimeOver(GameFixResultInterface $request, Game $game)
 {
     $gameService = $this->container->get("core.service.chess.game");
     $gameService->setPgn($game->getPgn());
     if ($request->getTimeWhite() !== null && $game->getTimeWhite() <= 100) {
         switch ($gameService->isInsufficientMaterialBlack()) {
             case false:
                 $game->setResultWhite(0)->setResultBlack(1);
                 $this->changeGameStatus($game, GameStatus::END);
                 break;
             case true:
                 $game->setResultWhite(0.5)->setResultBlack(0.5);
                 $this->changeGameStatus($game, GameStatus::END);
                 break;
         }
     } elseif ($request->getTimeBlack() !== null && $game->getTimeBlack() <= 100) {
         switch ($gameService->isInsufficientMaterialWhite()) {
             case false:
                 $game->setResultWhite(1)->setResultBlack(0);
                 $this->changeGameStatus($game, GameStatus::END);
                 break;
             case true:
                 $game->setResultWhite(0.5)->setResultBlack(0.5);
                 $this->changeGameStatus($game, GameStatus::END);
                 break;
         }
     }
 }