Created
July 31, 2023 09:55
-
-
Save ianfab/993ac3a9d83cb644b97fdaf081c6b586 to your computer and use it in GitHub Desktop.
simple shogi elo calculator based on http://fesashogi.eu/index.php?mid=5&listid=elosystem
This file contains hidden or 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
K_FACTORS = ( | |
(720, 40), | |
(1040, 36), | |
(1280, 32), | |
(1560, 28), | |
(1920, 24), | |
(2240, 20), | |
(9999, 16), | |
) | |
def get_elo(tr, games, results): | |
for r, kr in K_FACTORS: | |
if tr < r: | |
k = kr | |
break | |
else: | |
raise ValueError("Invalid rating") | |
change = 0 | |
for or_, res in results: | |
ev = 1 / (1 + 10**((or_ - tr) / 400)) | |
change += k * max(res - ev, (or_ - tr) / 160 if res == 1 else -ev) | |
if games < 100: | |
change += max(1800 - tr, 0) / 200 | |
return round(tr + change) | |
def main(): | |
myelo = int(input("Player Elo: ")) | |
mygames = int(input("Player games: ")) | |
results = [] | |
try: | |
while True: | |
oppelo = int(input("Opponent Elo: ")) | |
result = int(input("Result: ")) | |
results.append((oppelo, result)) | |
except ValueError: | |
pass | |
print("New Elo: {}".format(get_elo(myelo, mygames, results))) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ported to JS for this html web page https://amshogi.github.io/rangos/rating-calc.html