Instantly share code, notes, and snippets.

# andr3w321/sim-elo.py Created Apr 22, 2016

 import math import random def alt_win_probability(p1, p2): diff = p1 - p2 p = 1 - 1 / (1 + math.exp(0.00583 * diff - 0.0505)) return p def win_probability(p1, p2): diff = p1 - p2 p = 1 - 1 / (1 + 10 ** (diff / 400.0)) return p def rate_1vs1(p1, p2, k=20, drawn=False): rp1 = 10 ** (p1/400) rp2 = 10 ** (p2/400) exp_p1 = rp1 / float(rp1 + rp2) exp_p2 = rp2 / float(rp1 + rp2) if drawn == True: s1 = 0.5 s2 = 0.5 else: s1 = 1 s2 = 0 new_p1 = p1 + k * (s1 - exp_p1) new_p2 = p2 + k * (s2 - exp_p2) return new_p1, new_p2 def run_sim(starta, startb): ayes, bees = [], [] for i in range(1, 1000): a, b = starta, startb for j in range(0, 1000): if random.random() <= win_probability(starta, startb): a, b = rate_1vs1(a, b) else: b, a = rate_1vs1(b, a) ayes.append(a) bees.append(b) print sum(ayes) / len(ayes), sum(bees) / len(bees) return sum(ayes) / len(ayes) x = [] for i in range(0, 10): x.append(run_sim(1550,1450)) print sum(x) / len(x)
to join this conversation on GitHub. Already have an account? Sign in to comment