Exemplo n.º 1
0
 public function start(Game $game)
 {
     $game->start();
     if ($game->getInvited()->getIsAi()) {
         return array();
     }
     $messages = array();
     $messages[] = ucfirst($game->getCreator()->getColor()) . ' creates the game';
     $messages[] = ucfirst($game->getInvited()->getColor()) . ' joins the game';
     if ($game->hasClock()) {
         $messages[] = 'Clock: ' . $game->getClock()->getName();
     }
     if ($game->getIsRated()) {
         $messages[] = 'This game is rated';
     }
     return $messages;
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 public function expandGame(Game $game)
 {
     return sprintf('game(%s,%s,%s,%s,%d,%s)', $game->getVariantName(), $game->getClockName(), $game->getIsRated() ? 'rated' : 'casual', $game->getIsPlayable() ? 'playable' : $game->getStatusMessage(), $game->getTurns(), $this->generator->generate('lichess_game', array('id' => $game->getId()), true));
 }
Exemplo n.º 4
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));
 }