Skip to content

Instantly share code, notes, and snippets.

@Ads20000
Last active February 13, 2018 00:01
Show Gist options
  • Save Ads20000/9a8f9f46b647f0fdd4888216c24fc941 to your computer and use it in GitHub Desktop.
Save Ads20000/9a8f9f46b647f0fdd4888216c24fc941 to your computer and use it in GitHub Desktop.
Calculate elo update
// Modify the values below, then hit Display in Firefox's Scratchpad
// https://github.com/Zarel/Pokemon-Showdown/blob/dde05fab18626afad1b666dd0c0875dde5d221e6/ladders.js#L176
elo = 1000;
foeElo = 2000;
score = 0;
// The K factor determines how much your Elo changes when you win or
// lose games. Larger K means more change.
// In the "original" Elo, K is constant, but it's common for K to
// get smaller as your rating goes up
K = 50;
// dynamic K-scaling (optional)
if (elo < 1200) {
if (score < 0.5) {
K = 10 + (elo - 1000) * 40 / 200;
} else if (score > 0.5) {
K = 90 - (elo - 1000) * 40 / 200;
}
} else if (elo > 1350) {
K = 40;
} else if (elo > 1600) {
K = 32;
}
// main Elo formula
E = 1 / (1 + Math.pow(10, (foeElo - elo) / 400));
elo += K * (score - E);
if (elo < 1000) elo = 1000;
// Elo decay
// http://www.smogon.com/forums/threads/ask-a-simple-question-get-a-simple-answer-ps-edition-please-read-before-posting-a-thread.3520646/page-52#post-6927913
// On Pokemon Showdown
// If elo < 1400, or more than 5 battles played during the day, then no decay
// If 1-5 battles played during the day, the rating decays 1 point for every 100 points above 1400 elo (0 + intval(($elo-1400)/100) [PHP]
// If 0 battles played during the day, the rating decays by 1 point, plus 1 for every 50 points above 1400 elo (1 + intval(($elo-1400)/50) [PHP]
// For EUPS, given that we only have at least one tournament per week, the above is too punishing (would make it extremely difficult to get far above 1400 elo), as such, the following will be applied:
// If elo <= 1400, or a battle is played during the termtime week, or if it is not a termtime week, then no decay
// If none of the above conditions are met, and a battle has been played the previous week (and that week is termtime), then the rating decays 1 point for every 100 points above 1400 elo (0 + intval(($elo-1400)/100) [PHP]
// If none of the above conditions are met, and no battles have been played in two or more consecutive weeks (and the weeks are both in termtime), then the rating decays by 1 point, plus 1 for every 50 points above 1400 elo (1 + intval(($elo-1400)/50) [PHP]
// Decay is applied Sunday 23:59 GMT for the previous week (the Tournament Secretary will update the Championship elo table ASAP after this point)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment