Skip to content

Instantly share code, notes, and snippets.

@ianfab
Created July 31, 2023 09:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianfab/993ac3a9d83cb644b97fdaf081c6b586 to your computer and use it in GitHub Desktop.
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
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()
@Little-Mage
Copy link

ported to JS for this html web page https://amshogi.github.io/rangos/rango-calc.html

@ianfab
Copy link
Author

ianfab commented Mar 6, 2024

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment