Last active
March 24, 2017 03:53
-
-
Save safoyeth/736836b593d274e847d74c44c883574c to your computer and use it in GitHub Desktop.
This is simple script to calculate Elo rating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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