Created
June 28, 2017 10:16
-
-
Save wand125/ae4d0b43420500bc4dca8473e8e86fb5 to your computer and use it in GitHub Desktop.
Tournament Rating Simulator
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 math | |
import argparse | |
def calc_win_rate(a,b): | |
return (1.0 / (math.pow(10,(a-b) / -400) + 1)) | |
def calc_win_rate_final(a,b): | |
p = calc_win_rate(a,b) | |
return p * p * p + 3 * p * p * (1-p) | |
def calc_tournament(rating_tree, win_rate_func): | |
def calc_info(r): | |
return [{ 'rating': r, 'probability': 1.0 }] if isinstance(r, int) else calc_tournament(r,calc_win_rate) | |
left = calc_info(rating_tree[0]) | |
right = calc_info(rating_tree[1]) | |
def calc_expected_value(p , opponents): | |
return { 'rating': p['rating'], 'probability': sum([p['probability'] * o['probability'] * win_rate_func(p['rating'], o['rating']) for o in opponents])} | |
return [calc_expected_value(l, right) for l in left] + [calc_expected_value(r, left) for r in right] | |
def __main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--ryuoh', '-r', action='store_true', default=False, | |
help='set flag to ryuoh tournament mode') | |
arg = parser.parse_args() | |
l = eval(input()) | |
print("\n".join(["{0:d}: {1:.2f}%".format(e['rating'],e['probability'] * 100) for e in calc_tournament(l, calc_win_rate_final if arg.ryuoh else calc_win_rate)])) | |
if __name__ == '__main__': | |
__main() |
% python3 rating-simulator.py -r
((1757,(1834,(1749,(1779,1900)))),((1733,1846),((1757,1707),1870)))
1757: 13.86%
1834: 15.93%
1749: 2.21%
1779: 1.62%
1900: 12.49%
1733: 4.42%
1846: 19.83%
1757: 3.33%
1707: 1.31%
1870: 25.01%
竜王戦トーナメントの2回戦以降において
現レーティング(1700)の場合藤井四段の勝率は0.56%
レーティングを1900と推定した場合、勝率12.49%
レーティングの参考値はこちら
http://kishi.a.la9.jp/rating.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
% python3 rating-simulator.py -r
((1757,(1834,(1749,(1779,1700)))),((1733,1846),((1757,1707),1870)))
1757: 15.4952%
1834: 19.1905%
1749: 3.1737%
1779: 2.9708%
1700: 0.5655%
1733: 4.9551%
1846: 21.5168%
1757: 3.7049%
1707: 1.4841%
1870: 26.9433%