Beispiel #1
0
 protected function getPgnResult(Game $game)
 {
     if ($game->getIsFinished()) {
         if ($game->getPlayer('white')->getIsWinner()) {
             return '1-0';
         } elseif ($game->getPlayer('black')->getIsWinner()) {
             return '0-1';
         }
         return '1/2-1/2';
     }
     return '*';
 }
Beispiel #2
0
 protected function updateElo(Game $game)
 {
     // Game can be aborted
     if (!$game->getIsFinished()) {
         return;
     }
     if (!$game->getIsRated()) {
         return;
     }
     // Don't rate games with less than 2 moves
     if ($game->getTurns() < 2) {
         return;
     }
     $white = $game->getPlayer('white');
     $black = $game->getPlayer('black');
     $whiteUser = $white->getUser();
     $blackUser = $black->getUser();
     // Don't rate games when one ore more player is not registered
     if (!$whiteUser || !$blackUser) {
         return;
     }
     if ($winner = $game->getWinner()) {
         $win = $winner->isWhite() ? -1 : 1;
     } else {
         $win = 0;
     }
     list($whiteElo, $blackElo) = $this->calculator->calculate($white->getElo(), $black->getElo(), $win);
     $white->setEloDiff($whiteEloDiff = $whiteElo - $white->getElo());
     $black->setEloDiff($blackEloDiff = $blackElo - $black->getElo());
     $this->eloUpdater->updateElo($whiteUser, $whiteUser->getElo() + $whiteEloDiff, $game);
     $this->eloUpdater->updateElo($blackUser, $blackUser->getElo() + $blackEloDiff, $game);
     $this->logger->notice($game, sprintf('Elo exchanged: %s', $whiteEloDiff));
 }