rwitz commited on
Commit
b27fe1c
·
verified ·
1 Parent(s): 30ab522

Update elo.py

Browse files
Files changed (1) hide show
  1. elo.py +18 -0
elo.py CHANGED
@@ -1,5 +1,7 @@
1
  import pandas as pd
2
 
 
 
3
  def update_elo_ratings(ratings_dict, winner, loser):
4
  # Check if the ratings_dict is empty
5
  if not ratings_dict:
@@ -26,6 +28,22 @@ def update_elo_ratings(ratings_dict, winner, loser):
26
  return 20
27
  else:
28
  return 10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  # Update games played
31
  ratings_df.loc[ratings_df['bot_name'] == winner, 'games_played'] += 1
 
1
  import pandas as pd
2
 
3
+ import math
4
+
5
  def update_elo_ratings(ratings_dict, winner, loser):
6
  # Check if the ratings_dict is empty
7
  if not ratings_dict:
 
28
  return 20
29
  else:
30
  return 10
31
+ def elo(winner_rating, loser_rating, k_factor_winner=32, k_factor_loser=32):
32
+ # Calculate the expected scores for each player
33
+ winner_expected = 1 / (1 + 10 ** ((loser_rating - winner_rating) / 400))
34
+ loser_expected = 1 / (1 + 10 ** ((winner_rating - loser_rating) / 400))
35
+
36
+ # Calculate the new ratings for each player
37
+ winner_new_rating = winner_rating + k_factor_winner * (1 - winner_expected)
38
+ loser_new_rating = loser_rating + k_factor_loser * (0 - loser_expected)
39
+
40
+ return winner_new_rating, loser_new_rating
41
+
42
+ # ...
43
+
44
+ # Calculate new ratings
45
+ winner_new_rating, loser_new_rating = elo(winner_old_rating, loser_old_rating, k_factor_winner=winner_k_factor, k_factor_loser=loser_k_factor)
46
+
47
 
48
  # Update games played
49
  ratings_df.loc[ratings_df['bot_name'] == winner, 'games_played'] += 1