@@ -0,0 +1,1775 @@
+##%0A# elo.py%0A# provides implementation of ELO algorithm to determine%0A# change in fitness given a malicious act of nature.%0A##%0A%0A%0AK_FACTOR = 50 # weighting factor. The larger the more significant a match%0A# %5E in chess it's usually 15-16 for grandmasters and 32 for weak players%0ABETA = 400%0A%0Aclass ResultType:%0A    WIN = 1%0A    LOSE = 2%0A    DRAW = 3%0A%0A'''%0AReturns a tuple (newELOYou, newELOThem)%0Aexample usage:%0A(2100NewElo, 2000NewElo) = get_elos_for_result(2100, 2000, ResultType.LOSE)%0A'''%0Adef get_elos_for_result(eloYou, eloOpponent, result):%0A    # get expected values%0A    expectedYou = 1. / (1.+10.**(float(eloOpponent - eloYou)/BETA))%0A    expectedThem = 1 - expectedYou # 1. / (1+10**((eloYou - eloOpponent)/BETA))%0A%0A    # actual scores%0A    if result == ResultType.WIN:%0A        actualYou = 1%0A    elif result == ResultType.LOSE:%0A        actualYou = 0%0A    else:%0A        actualYou = 0.5%0A    actualThem = 1. - actualYou%0A%0A    newELOYou = eloYou + K_FACTOR * (actualYou - expectedYou)%0A    newELOOpponent = eloOpponent + K_FACTOR * (actualThem - expectedThem)%0A    return (newELOYou, newELOOpponent)%0A%0A%0A'''%0ATest to make sure elo calculated correctly given constants%0A'''%0Adef test_elos():%0A    def eloTuplesEqual(tupleA, tupleB):%0A        return abs(tupleA%5B0%5D - tupleB%5B0%5D) %3C= 1 and abs(tupleA%5B1%5D - tupleB%5B1%5D) %3C= 1%0A    assert eloTuplesEqual(get_elos_for_result(1200, 1200, ResultType.DRAW), (1200, 1200))%0A    assert eloTuplesEqual(get_elos_for_result(800, 1400, ResultType.DRAW), (823, 1377))%0A    assert eloTuplesEqual(get_elos_for_result(200, 2000, ResultType.WIN), (249, 1951))%0A    assert eloTuplesEqual(get_elos_for_result(2100, 2000, ResultType.WIN), (2117, 1983))%0A    assert eloTuplesEqual(get_elos_for_result(2100, 2000, ResultType.LOSE), (2067, 2033))%0A    print %22tests pass%22%0A%0A%0A#test_elos()

Add ELO algorithm code, with small tests.