Skip to content

Instantly share code, notes, and snippets.

@safoyeth
Last active March 24, 2017 03:53
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 safoyeth/736836b593d274e847d74c44c883574c to your computer and use it in GitHub Desktop.
Save safoyeth/736836b593d274e847d74c44c883574c to your computer and use it in GitHub Desktop.
This is simple script to calculate Elo rating
import math
def elo(ra, rb, sa, sb, ka, kb):
'''
you can find the description here https://safoyeth.com/2017/03/04/chessscripts/
ra/rb - current rating. Python 2.x note - values must be float
sa/sb - result (1 for win, 1/2 for draw, 0 for lose)
ka/kb = 10 if ra/rb >= 2400
ka/kb = 20 if ra/rb < 2400
ka/kb = 40 if gamesPlayed < 30 or (age < 18 and ra/rb < 2300)
'''
ea = 1/(1 + math.pow(10, (rb - ra)/400))
eb = 1/(1 + math.pow(10, (ra - rb)/400))
raNew = round((ra + ka * (sa - ea)), 2)
rbNew = round((rb + kb * (sb - eb)), 2)
return raNew, rbNew
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment