Created
March 1, 2011 15:04
-
-
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
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
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