Created
February 3, 2012 04:11
-
-
Save jazzychad/1727711 to your computer and use it in GitHub Desktop.
ELO implementation for PicAFight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ELO implementation for PicAFight | |
# using ELO formula from http://en.wikipedia.org/wiki/Elo_rating_system#Mathematical_details and a K value of 32 | |
# all contestants start with ELO rating of 1500 | |
ra = pic1.elo | |
rb = pic2.elo | |
qa = 10**((ra + 0.0)/400.0) + 0.0 | |
qb = 10**((rb + 0.0)/400.0) + 0.0 | |
ea = qa / (qa + qb) | |
eb = qb / (qa + qb) | |
# a win is worth 1 point, a loss is worth 0 points | |
sa = 1 - (params[:win]).to_i | |
sb = params[:win].to_i | |
ka = 32 | |
kb = 32 | |
radelta = ka * (sa - ea) | |
rbdelta = kb * (sb - eb) | |
ra = ra + radelta | |
rb = rb + rbdelta | |
# store new ELO value back | |
pic1.elo = ra.to_i | |
pic2.elo = rb.to_i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment