forked from CS3243-AY1819S2-G50/POK-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfr_test.py
72 lines (57 loc) · 1.86 KB
/
cfr_test.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import matplotlib.pyplot as plt
from matplotlib.table import Table
from cfr import CFR
cfr = CFR()
ante = 1.0
bet1 = 2.0
bet2 = 8.0
util = cfr.train(1000, ante, bet1, bet2)
label = ['A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2']
rank_index_map = {'A': 0, 'K': 1, 'Q': 2,
'J': 3, 'T': 4, '9': 5,
'8': 6, '7': 7, '6': 8,
'5': 9, '4': 10, '3': 11, '2': 12}
def get_color(frequency):
if frequency >= 0.9:
return 'green'
elif frequency >= 0.75:
return 'yellowgreen'
elif frequency >= 0.5:
return 'yellow'
elif frequency >= 0.25:
return 'orange'
elif frequency >= 0.05:
return 'orangered'
else:
return 'red'
def create_table(title, frequencies):
fig, ax = plt.subplots()
ax.set_axis_off()
tb = Table(ax, bbox=[0,0,1,1])
nrows, ncols = len(label), len(label)
width, height = 1.0 / ncols, 1.0 / nrows
# Add cells
for hand, val in frequencies.items():
i, j = rank_index_map[hand[0]], rank_index_map[hand[1]]
if len(hand) == 3 and hand[2] == 'o':
i, j = j, i
color = get_color(val)
value_formatted = '{0:.2f}'.format(val)
tb.add_cell(i + 1, j, width, height, text=hand,
loc='center', facecolor=color)
# Row Labels...
for i in range(len(label)):
tb.add_cell(i + 1, -1, width, height, text=label[i], loc='right',
edgecolor='none', facecolor='none')
# Column Labels...
for j in range(len(label)):
tb.add_cell(0, j, width, height/2, text=label[j], loc='center',
edgecolor='none', facecolor='none')
ax.add_table(tb)
plt.title(title)
return fig
print "Player One Expected Value Per Hand: %f" % util
result = cfr.get_strategy()
for decision in sorted(result):
table = create_table(decision, result[decision])
plt.show()