forked from neery1218/PythonOFCSimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsims.py
186 lines (158 loc) · 4.88 KB
/
sims.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
from ofc_hand import OfcHand
from deck import parse_cards
from deck import parse_card
from hand_ev_estimator import Decision
from hand_ev_estimator import find_optimal_decision
from hand_ev_estimator import Placement
from ofc_scoring import Row
def _create_ofc_hand(top, middle, bottom):
ofc_hand = OfcHand()
if top:
for c in parse_cards(top.split(" ")):
ofc_hand.add_top(c)
if middle:
for c in parse_cards(middle.split(" ")):
ofc_hand.add_middle(c)
if bottom:
for c in parse_cards(bottom.split(" ")):
ofc_hand.add_bottom(c)
return ofc_hand
def decision_finder(our_hand, their_hand, dead_cards, candidate_decisions, num_epochs):
# parse decisions
decisions = []
for d in candidate_decisions:
arr = d.split(" ")
placements = []
dead_cards_d = [c for c in dead_cards]
for c, action in zip(arr[0::2], arr[1::2]):
card = parse_card(c)
if action == "top":
placements.append(Placement(card=card, row=Row.TOP))
elif action == "mid":
placements.append(Placement(card=card, row=Row.MIDDLE))
elif action == "bot":
placements.append(Placement(card=card, row=Row.BOTTOM))
elif action == "dead":
dead_cards_d.append(card)
else:
raise AssertionError("wtf")
decisions.append(Decision(placements=placements, dead_cards=dead_cards_d))
return find_optimal_decision(
our_hand=our_hand,
their_hand=their_hand,
decisions=decisions,
num_epochs=num_epochs,
)
def conflicting_draw_flush_q():
# 2d Kc Ac
our_hand = _create_ofc_hand(
"Qs",
"Ts Tc 9s 2d",
"Kh Jh 8h 6h"
)
their_hand = _create_ofc_hand(
"Qd 5d",
"Ad 7s 7d 4d 4s",
"Ac 8c 5c 2c"
)
dead_cards = parse_cards(["8d", "3c"])
candidate_decisions = [
"Qc top 9d mid 2h dead",
"Qc top 2h bot 9d dead",
"2h bot 9d mid Qc dead",
]
placements_to_ev = decision_finder(
our_hand=our_hand,
their_hand=their_hand,
dead_cards=dead_cards,
candidate_decisions=candidate_decisions,
num_epochs=10000
)
for placements, ev in placements_to_ev.items():
s = "{} {} {} {}".format(placements[0].card, placements[0].row, placements[1].card, placements[1].row)
print("{} : {}".format(s, ev))
def pair_or_q_top(): # TODO: not enough compute power
# 2d Kc Ac
our_hand = _create_ofc_hand(
None,
"9h 8c",
"Ah Ad 5d",
)
their_hand = _create_ofc_hand(
"Ks",
"7c 2c",
"6s 6c",
)
dead_cards = []
candidate_decisions = [
"Qh top 3h mid 3c dead",
"3h mid 3c mid Qh dead",
]
placements_to_ev = decision_finder(
our_hand=our_hand,
their_hand=their_hand,
dead_cards=dead_cards,
candidate_decisions=candidate_decisions,
num_epochs=10000
)
for placements, ev in placements_to_ev.items():
s = "{} {} {} {}".format(placements[0].card, placements[0].row, placements[1].card, placements[1].row)
print("{} : {}".format(s, ev))
def T_top_or_mid():
# 2d Kc Ac
our_hand = _create_ofc_hand(
None,
"9c 9d",
"Ac Ad 3s 3h 3d"
)
their_hand = _create_ofc_hand(
"Qc",
"Kd 4d",
"Ts 9s 8h 2s",
)
dead_cards = parse_cards(["6c"])
candidate_decisions = [
"Th mid 5d mid 2h dead",
"Th top 5d mid 2h dead"
]
placements_to_ev = decision_finder(
our_hand=our_hand,
their_hand=their_hand,
dead_cards=dead_cards,
candidate_decisions=candidate_decisions,
num_epochs=100
)
for placements, ev in placements_to_ev.items():
s = "{} {} {} {}".format(placements[0].card, placements[0].row, placements[1].card, placements[1].row)
print("{} : {}".format(s, ev))
def three_outer_mid_or_ace():
our_hand = _create_ofc_hand(
"Ks Kd Qh",
"8c 4s",
"Jd 7s 7c 7d"
)
their_hand = _create_ofc_hand(
"Qc Qd 4c",
"Td 9s 6s Ac",
"Ah Jh 9h 3h"
)
dead_cards = parse_cards(["Th", "6c"])
candidate_decisions = [
"7h bot As mid 5c dead",
"7h bot 5c mid As dead"
]
placements_to_ev = decision_finder(
our_hand=our_hand,
their_hand=their_hand,
dead_cards=dead_cards,
candidate_decisions=candidate_decisions,
num_epochs=10000
)
for placements, ev in placements_to_ev.items():
s = "{} {} {} {}".format(placements[0].card, placements[0].row, placements[1].card, placements[1].row)
print("{} : {}".format(s, ev))
if __name__ == '__main__':
#conflicting_draw_flush_q()
# pair_or_q_top()
#T_top_or_mid()
three_outer_mid_or_ace()