Skip to content

Instantly share code, notes, and snippets.

@tuvokki
Created February 26, 2014 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuvokki/9226002 to your computer and use it in GitHub Desktop.
Save tuvokki/9226002 to your computer and use it in GitHub Desktop.
/**
* This method will calculate the change in a player's
* Elo rating after playing a single game against another player.
* The value K is the maximum change in rating.
**/
function calculateELORatingChange(elo1, elo2, k)
{
var percentage = 1 / ( 1 + Math.pow( 10, (elo2 - elo1) / 400 ) );
return {
win: Math.round( k * ( 1 - percentage ) ),
draw: Math.round( k * ( .5 - percentage ) ),
loss: Math.round( k * ( 0 - percentage ) ),
percent: Math.round( percentage * 100 )
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment