-
Notifications
You must be signed in to change notification settings - Fork 70
/
pokergames.py
126 lines (109 loc) · 3.82 KB
/
pokergames.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
from pokertrees import *
def kuhn_eval(hc, board):
return hc[0].rank
def half_street_kuhn_rules():
players = 2
deck = [Card(14,1),Card(13,1),Card(12,1)]
ante = 1
blinds = None
rounds = [RoundInfo(holecards=1,boardcards=0,betsize=1,maxbets=[1,0])]
return GameRules(players, deck, rounds, ante, blinds, handeval=kuhn_eval, infoset_format=leduc_format)
def half_street_kuhn_gametree():
rules = half_street_kuhn_rules()
tree = GameTree(rules)
tree.build()
return tree
def half_street_kuhn_publictree():
rules = half_street_kuhn_rules()
tree = PublicTree(rules)
tree.build()
return tree
def kuhn_rules():
players = 2
deck = [Card(14,1),Card(13,1),Card(12,1)]
ante = 1
blinds = None
rounds = [RoundInfo(holecards=1,boardcards=0,betsize=1,maxbets=[1,1])]
return GameRules(players, deck, rounds, ante, blinds, handeval=kuhn_eval, infoset_format=leduc_format)
def kuhn_gametree():
rules = kuhn_rules()
tree = GameTree(rules)
tree.build()
return tree
def kuhn_publictree():
rules = kuhn_rules()
tree = PublicTree(rules)
tree.build()
return tree
def leduc_format(player, holecards, board, bet_history):
cards = holecards[0].RANK_TO_STRING[holecards[0].rank]
if len(board) > 0:
cards += board[0].RANK_TO_STRING[board[0].rank]
return "{0}:{1}:".format(cards, bet_history)
def leduc_eval(hc,board):
hand = hc + board
if hand[0].rank == hand[1].rank:
return 15*14+hand[0].rank
return max(hand[0].rank, hand[1].rank) * 14 + min(hand[0].rank, hand[1].rank)
def leduc_rules():
players = 2
deck = [Card(13,1),Card(13,2),Card(12,1),Card(12,2),Card(11,1),Card(11,2)]
ante = 1
blinds = None
rounds = [RoundInfo(holecards=1,boardcards=0,betsize=2,maxbets=[2,2]),RoundInfo(holecards=0,boardcards=1,betsize=4,maxbets=[2,2])]
return GameRules(players, deck, rounds, ante, blinds, handeval=leduc_eval, infoset_format=leduc_format)
def leduc_gametree():
rules = leduc_rules()
tree = GameTree(rules)
tree.build()
return tree
def leduc_publictree():
rules = leduc_rules()
tree = PublicTree(rules)
tree.build()
return tree
def royal_format(player, holecards, board, bet_history):
cards = holecards[0].RANK_TO_STRING[holecards[0].rank]
for i in range(len(board)):
cards += board[i].RANK_TO_STRING[board[i].rank]
if board[i].suit == holecards[0].suit:
cards += 's'
else:
cards += 'o'
return "{0}:{1}:".format(cards, bet_history)
def royal_eval(hc,board):
hand = hc + board
# Flush
if hand[0].suit == hand[1].suit and hand[0].suit == hand[2].suit:
return 10000 + hc[0].rank
# Straight
ranks = [h.rank for h in hand]
if Card.RANK_QUEEN in ranks and Card.RANK_KING in ranks:
if Card.RANK_ACE in ranks:
return 1000 + Card.RANK_ACE
if Card.RANK_JACK in ranks:
return 1000 + Card.RANK_JACK
# Holecard used in a pair
if hand[0].rank == hand[1].rank or hand[0].rank == hand[2].rank:
return 100+hand[0].rank
return hand[0].rank
def royal_rules():
players = 2
deck = [Card(14,1),Card(14,2),Card(13,1),Card(13,2),Card(12,1),Card(12,2),Card(11,1),Card(11,2)]
ante = 1
blinds = None
preflop = RoundInfo(holecards=1,boardcards=0,betsize=2,maxbets=[2,2])
flop = RoundInfo(holecards=0,boardcards=1,betsize=4,maxbets=[2,2])
turn = RoundInfo(holecards=0,boardcards=1,betsize=4,maxbets=[2,2])
rounds = [preflop,flop,turn]
return GameRules(players, deck, rounds, ante, blinds, handeval=royal_eval, infoset_format=royal_format)
def royal_gametree():
rules = royal_rules()
tree = GameTree(rules)
tree.build()
return tree
def royal_publictree():
rules = royal_rules()
tree = PublicTree(rules)
tree.build()
return tree