Ejemplo n.º 1
0
 /**
  * Calculate a single player new elo
  *
  * @param User $user
  * @param int $opponentElo
  * @param int $win
  * @return int
  */
 protected function calculateUserElo(User $user, $opponentElo, $win)
 {
     $score = $this->calculateScore($win);
     $expected = $this->calculateExpected($user->getElo(), $opponentElo);
     $kFactor = $this->nbRatedGamesToKfactor($user->getNbRatedGames());
     $difference = 2 * $kFactor * ($score - $expected);
     return round($user->getElo() + $difference);
 }
Ejemplo n.º 2
0
 /**
  * Get the rank of the user starting from 1 (better)
  *
  * @return int
  **/
 public function getUserRank(User $user)
 {
     return $this->createQueryBuilder()->field('elo')->gt($user->getElo())->getQuery()->count() + 1;
 }
Ejemplo n.º 3
0
 /**
  * Sets: Optional registered user who owns the hook
  *
  * @param User user
  */
 public function setUser(User $user)
 {
     $this->user = $user;
     $this->username = $user->getUsername();
     $this->elo = $user->getElo();
     $this->engine = $user->isEngine();
 }
Ejemplo n.º 4
0
 /**
  * Get the rank of the user starting from 1 (better)
  *
  * @return int
  **/
 public function getUserRank(User $user)
 {
     return $this->createEnabledQueryBuilder()->field('elo')->gt($user->getElo())->hint(array('elo' => -1))->getQuery()->count() + 1;
 }