-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.py
41 lines (35 loc) · 1.15 KB
/
stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 21 18:13:17 2021
@author: vavilse1
"""
from bots import *
from itertools import combinations
from random import randint
payout = {("C", "C"): (2, 2), ("C", "N"): (-1, 3), ("N", "C"): (3, -1), ("N", "N"): (0, 0)}
def match(bot1, bot2):
bot1.__init__()
bot2.__init__()
score1 = 0
score2 = 0
for _ in range(randint(5,10)):
resp1 = bot1.move()
resp2 = bot2.move()
bot1.append_history(resp2)
bot2.append_history(resp1)
dscores = payout[(resp1, resp2)]
score1 += dscores[0]
score2 += dscores[1]
return (score1, score2)
def statistics(bots_list):
scores = {bot: 0 for bot in bots_list}
for _ in range(10):
for pair in combinations(bots_list, 2):
dscores = match(pair[0], pair[1])
scores[pair[0]] += dscores[0]
scores[pair[1]] += dscores[1]
return scores
def print_statistics(bots_list):
scores = statistics(bots_list)
for k, v in sorted(scores.items(), key = lambda item: item[1], reverse = True):
print(v, k.__class__.__name__, sep = "\t")