Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (49 sloc) 2.06 KB
A super basic implementation of the ELO ranking algorithm. The advantage
of this algorithm is that it's very simple and does not require any more information
than an individual match in order to update rankings.
The downside is that ELO doesn't take into account the actual score, just a win/lose.
It updates rankings step-wise, and is expected to be called for each game in succession.
Especially: see
import logging
def update_ranks(game):'Updating rankings based on game %s' % game)'Winner: %s' % game.winner)'Prior ranks: (%s, %s) (%s, %s)' %
(game.player_1.pseudonym, game.player_1.rank, game.player_2.pseudonym, game.player_2.rank))
player_1 = game.player_1
player_2 = game.player_2
expected_1 = expected(player_2.rank, player_1.rank)
expected_2 = expected(player_1.rank, player_2.rank)
if game.winner.key() == game.player_1.key():
score_1 = 1
score_2 = 0
elif game.winner.key() == game.player_2.key():
score_1 = 0
score_2 = 1
raise "No winner. Something went wrong."
update_player_rank(player_1, score_1, expected_1)
update_player_rank(player_2, score_2, expected_2)'Resulting ranks: (%s, %s) (%s, %s)' %
(game.player_1.pseudonym, game.player_1.rank, game.player_2.pseudonym, game.player_2.rank))
def expected(rank_1, rank_2):
return 1 / (1 + 10 ** (float(rank_1 - rank_2) / 400))
def update_player_rank(player, score, expected):'Updating player rank based on score: %s and expected score: %s' % (score, expected))
player.rank += (MAX_INCREASE * (score - expected))
def max_increase(rank):
Determines the maximum possible points that a player can get in any given match
if rank <= 2100:
return 32
if 2100 < rank <= 2400:
return 24
if 2400 < rank:
return 16
Jump to Line
Something went wrong with that request. Please try again.