I wrote a small simulator to understand the Elo rating system. I can create players, matches and tournaments, and I want to be able to predict the match ending depending on the rating of each player and some randomness. At the beginning the ratings are all around the same values (say 600) and it appears to stay between 400 and 1600. This is what I've tried :
p1
and p2
are instances of Player
, rating
is an integer attribute.
def random_win(self):
q = float(self.p2.rating)/float(self.p1.rating)
if q>2:
self.win_2()
elif q<0.5:
self.win_1()
else:
d = float(self.p2.rating)-float(self.p1.rating)
lim = max(self.p1.rating, self.p2.rating)/2
r = random.randint(-lim, lim)
if r > d:
self.win_1()
else:
self.win_2()
I'd like to know if there are some "official" ways of doing this, this custom one works quite fine but I think it can be improved or at least simplified. Any ideas ? The best would be to get something closer the World Chess Ratings.
Once the wins and losses calculated and stored into the Player
as a list attribute, I calculate the new rating for each player using this algorithm.