Esempio n. 1
0
 /**
  * Decide whether or not to open a trial for this game
  *
  * @return null
  **/
 public function study(Game $game)
 {
     if (!$game->getIsRated()) {
         return;
     }
     if ($game->getFullmoveNumber() < 10) {
         return;
     }
     if (!($winner = $game->getWinner())) {
         return;
     }
     $blurFactor = $this->calculateBlurFactor($winner);
     $timePerMove = $this->calculateTimePerMove($game);
     $score = $this->trialScoreCalculator->calculateScore($blurFactor, $timePerMove);
     if ($score < 75) {
         return;
     }
     $trial = new Trial();
     $trial->setGame($game);
     $trial->setUser($winner->getUser());
     $trial->setScore($score);
     $this->objectManager->persist($trial);
 }
Esempio n. 2
0
 /**
  * @depends testGameCreationStandard
  */
 public function testGameGetWinner(Document\Game $game)
 {
     $this->assertNull($game->getWinner());
     $game->setWinner($game->getPlayer('white'));
     $this->assertSame($game->getPlayer('white'), $game->getWinner());
 }
Esempio n. 3
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));
 }