Skip to content

Commit

Permalink
elo algo
Browse files Browse the repository at this point in the history
  • Loading branch information
c7h committed Aug 16, 2014
1 parent ff4e460 commit a830458
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions elo.py
Original file line number Diff line number Diff line change
@@ -0,0 1,55 @@
'''
Created on 16.08.2014
@author: christoph
'''

K = 10

class Elo(object):

def match(self, p1, p2):
algo_func=self.__match_algo_strict
return algo_func(p1, p2)

@staticmethod
def __match_algo_strict(winner, looser):
#elo algorithm - simple modifications
r1 = max(min(looser.score - winner.score, 400), -400)
r2 = max(min(winner.score - looser.score, 400), -400)
e1 = 1.0 / (1 10**(r1 / 400))
e2 = 1.0 / (1 10**(r2 / 400))

s1 = 1
s2 = 0

winner.score = winner.score K*(s1-e1)
looser.score = looser.score K*(s2-e2)

#increase wincounter
winner.wins =1

#increase matchcounter
winner.matches =1
looser.matches =1

return winner, looser

def __match_algo_experimental(self, winner, looser):
#elo algorithm - simple modifications
r1 = max(min(looser.score - winner.score, 400), -400)
r2 = max(min(winner.score - looser.score, 400), -400)
e1 = 1.0 / (1 10**(r1 / 400))
e2 = 1.0 / (1 10**(r2 / 400))


winner.set_score(winner.score K*e2)
looser.set_score(looser.score-K*e2)

#increase wincounter
winner.wins =1

#increase matchcounter
winner.matches =1
looser.matches =1

0 comments on commit a830458

Please sign in to comment.