Example #1
0
 /**
  * @param Game $game
  * @return Pgn
  */
 private function buildPgnForSaver(Game $game) : Pgn
 {
     $headers = ['Event' => 'Game #' . $game->getId(), 'Site' => $this->container->getParameter('app_core_site_host'), 'White' => $game->getUserWhite(), 'Black' => $game->getUserBlack(), 'Result' => $game->getResultWhite() == 0.5 ? '1/2-1/2' : $game->getResultWhite() . '-' . $game->getResultBlack(), 'Date' => $game->getTimeLastMove()->format('Y.m.d')];
     if ($game->getTournamentGame()) {
         $headers['Event'] = $game->getTournamentGame()->getTournament()->getName();
         $headers['Round'] = $game->getTournamentGame()->getRound();
     }
     return (new Pgn())->setPgnString($game->getPgn())->setHeaders($headers);
 }
Example #2
0
 /**
  * @param Game $game
  * @param User $user
  * @param int $win
  * @param int $draw
  * @param int $lose
  */
 private function updateWinDrawLose(Game $game, User $user, int &$win, int &$draw, int &$lose)
 {
     if ($game->getUserWhite() == $user) {
         switch ($game->getResultWhite()) {
             case 1:
                 $win++;
                 break;
             case 0.5:
                 $draw++;
                 break;
             case 0:
                 $lose++;
                 break;
         }
     } elseif ($game->getUserBlack() == $user) {
         switch ($game->getResultBlack()) {
             case 1:
                 $win++;
                 break;
             case 0.5:
                 $draw++;
                 break;
             case 0:
                 $lose++;
                 break;
         }
     }
 }
Example #3
0
 /**
  * @param Game $game
  * @return EloGame
  */
 private function getEloGame(Game $game)
 {
     $eloGame = new EloGame();
     $whiteUser = $game->getUserWhite();
     $blackUser = $game->getUserBlack();
     $eloGame->setWhiteElo($whiteUser->getRating())->setBlackElo($blackUser->getRating())->setWhiteGames($whiteUser->getRateGamesCount())->setBlackGames($blackUser->getRateGamesCount())->setWhiteResult($game->getResultWhite())->setBlackResult($game->getResultBlack());
     return $eloGame;
 }