Skip to content

Instantly share code, notes, and snippets.

@jazzychad
Created February 3, 2012 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jazzychad/1727711 to your computer and use it in GitHub Desktop.
Save jazzychad/1727711 to your computer and use it in GitHub Desktop.
ELO implementation for PicAFight
# 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