Skip to content

Commit

Permalink
Fixed ELO
Browse files Browse the repository at this point in the history
  • Loading branch information
waplet committed Apr 7, 2018
1 parent d83fd1a commit 5244f41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
18 changes: 8 additions & 10 deletions bot/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,18 +451,16 @@ private function updateTemporaryElo($game, $teamAWon)
$gamePlayers[] = $this->getUser($game['player_' . $i]);
}

error_log(print_r($gamePlayers, true));

// We need to check each player with each 2 they played
// 1 - 3; 1 - 4, 2 - 3; 2 - 4, 3 - 1; 3 - 2; 4 - 1; 4 - 2;
$this->updateUserElo($gamePlayers[0]['id'], EloManager::getElo($gamePlayers[0]['current_elo'], $gamePlayers[2]['current_elo'], $teamAWon));
$this->updateUserElo($gamePlayers[0]['id'], EloManager::getElo($gamePlayers[0]['current_elo'], $gamePlayers[2]['current_elo'], $teamAWon));
$this->updateUserElo($gamePlayers[1]['id'], EloManager::getElo($gamePlayers[1]['current_elo'], $gamePlayers[3]['current_elo'], $teamAWon));
$this->updateUserElo($gamePlayers[1]['id'], EloManager::getElo($gamePlayers[1]['current_elo'], $gamePlayers[3]['current_elo'], $teamAWon));
$this->updateUserElo($gamePlayers[2]['id'], EloManager::getElo($gamePlayers[2]['current_elo'], $gamePlayers[0]['current_elo'], !$teamAWon));
$this->updateUserElo($gamePlayers[2]['id'], EloManager::getElo($gamePlayers[2]['current_elo'], $gamePlayers[0]['current_elo'], !$teamAWon));
$this->updateUserElo($gamePlayers[3]['id'], EloManager::getElo($gamePlayers[3]['current_elo'], $gamePlayers[1]['current_elo'], !$teamAWon));
$this->updateUserElo($gamePlayers[3]['id'], EloManager::getElo($gamePlayers[3]['current_elo'], $gamePlayers[1]['current_elo'], !$teamAWon));
$this->updateUserElo($gamePlayers[0]['id'], EloManager::getTempElo($gamePlayers[0]['current_elo'], $gamePlayers[2]['current_elo'], $teamAWon));
$this->updateUserElo($gamePlayers[0]['id'], EloManager::getTempElo($gamePlayers[0]['current_elo'], $gamePlayers[2]['current_elo'], $teamAWon));
$this->updateUserElo($gamePlayers[1]['id'], EloManager::getTempElo($gamePlayers[1]['current_elo'], $gamePlayers[3]['current_elo'], $teamAWon));
$this->updateUserElo($gamePlayers[1]['id'], EloManager::getTempElo($gamePlayers[1]['current_elo'], $gamePlayers[3]['current_elo'], $teamAWon));
$this->updateUserElo($gamePlayers[2]['id'], EloManager::getTempElo($gamePlayers[2]['current_elo'], $gamePlayers[0]['current_elo'], !$teamAWon));
$this->updateUserElo($gamePlayers[2]['id'], EloManager::getTempElo($gamePlayers[2]['current_elo'], $gamePlayers[0]['current_elo'], !$teamAWon));
$this->updateUserElo($gamePlayers[3]['id'], EloManager::getTempElo($gamePlayers[3]['current_elo'], $gamePlayers[1]['current_elo'], !$teamAWon));
$this->updateUserElo($gamePlayers[3]['id'], EloManager::getTempElo($gamePlayers[3]['current_elo'], $gamePlayers[1]['current_elo'], !$teamAWon));
}

}
9 changes: 5 additions & 4 deletions bot/EloManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class EloManager
* K-Factor
* @var int
*/
const K = 32;
const K = 16; // Default is 32, but as we account for 2 games, we divide by 2

/**
* @param int $rankingA current ranking of A team
Expand All @@ -27,10 +27,11 @@ public static function getElo($rankingA, $rankingB, $aWon)
$aWon ? $ratingB : $ratingA
);

return (int)($ratingA + self::K * ($S - $E));
return (int)(($aWon ? $rankingA : $rankingB) + self::K * ($S - $E));
}

/**
* Temp Elo is just a diff from current Elo to new elo
* @param int $rankingA current ranking of A team
* @param int $rankingB current ranking of B team
* @param bool $aWon
Expand All @@ -39,8 +40,8 @@ public static function getElo($rankingA, $rankingB, $aWon)
public static function getTempElo($rankingA, $rankingB, $aWon)
{
return $aWon
? $rankingA - self::getElo($rankingA, $rankingB, true)
: $rankingB - self::getElo($rankingA, $rankingB, false);
? self::getElo($rankingA, $rankingB, true) - $rankingA
: self::getElo($rankingA, $rankingB, false) - $rankingB;
}

/**
Expand Down

0 comments on commit 5244f41

Please sign in to comment.