Skip to content

Instantly share code, notes, and snippets.

@DanielVF
Created March 1, 2011 15:04
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 DanielVF/849248 to your computer and use it in GitHub Desktop.
Save DanielVF/849248 to your computer and use it in GitHub Desktop.
Written to simulate games using the 'likelihood of superiority' bayesian elo results dump from the conclusion of the 2010 Google AI challenge. -- Daniel Von Fange
import random
"""
Written to simulate games using the 'likelihood of superiority'
bayesian elo results dump from the conclusion of the 2010 Google AI challenge.
-- Daniel Von Fange
"""
# We offset off this to find the scores
LENGTH_OF_NAME_FIELD = 30
class GameSimulator:
def __init__(self, filename):
'''Read in the likelyhood of superiority file'''
f = open(filename,'r')
self.lines = f.readlines()
self.lines = self.lines[1:] #Ignore the first line
f.close()
def get_odds(self,a,b):
'''Odds, expressed from 0 to 1000, that a will beat b'''
if a == b:
return 500
line = a
col = LENGTH_OF_NAME_FIELD + b * 4
return int(self.lines[line][col:col+4])
def game_winner(self,a,b):
'''randomly pick a game winner, based on the probability that a will beat b'''
if self.get_odds(a,b) > random.randint(0,999):
return a
else:
return b
if __name__ == "__main__":
gs = GameSimulator('final-los.txt')
for i in range(100):
a = 2
b = 3
print "#%s vs #%s - winner #%s" % (a,b,gs.game_winner(a,b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment