-
Notifications
You must be signed in to change notification settings - Fork 146
/
poker.py
56 lines (42 loc) · 1.64 KB
/
poker.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
#
# This is an example of how to build poker-type games in Gambit
#
import gambit
import torr
#
# Functions to categorize public histories.
# These all use torr.GenericHistory, which is basically just a list
#
def AtRoot(history): return len(history) == 0
def AliceRaise(history):
return len(history) == 1 and history[0] in [ "Red", "Black" ]
def BobPlay(history):
return (len(history) == 2 and
history[0] in [ "Red", "Black" ] and
history[1] in [ "Raise" ])
def AliceWins(history):
return history[2] == "Pass"
def BobWins(history):
return history[1] == "Fold"
def AliceWinsBig(history):
return history[0] == "Red" and history[2] == "Meet"
def BobWinsBig(history):
return history[0] == "Black" and history[2] == "Meet"
rules = [ { "condition": AtRoot,
"action": torr.ChanceMove([ "Red", "Black" ],
[ gambit.Rational(1,2),
gambit.Rational(1,2) ]) },
{ "condition": AliceRaise,
"action": torr.Move(1, [ "Raise", "Fold" ]) },
{ "condition": BobPlay,
"action": torr.Move(2, [ "Meet", "Pass" ]) },
{ "condition": BobWins,
"action": torr.TerminalPayoff([-1, 1]) },
{ "condition": AliceWins,
"action": torr.TerminalPayoff([1, -1]) },
{ "condition": BobWinsBig,
"action": torr.TerminalPayoff([-2, 2]) },
{ "condition": AliceWinsBig,
"action": torr.TerminalPayoff([2, -2]) } ]
tree = torr.BuildTree([ "Alice", "Bob" ], rules, torr.GenericHistory)
print tree.AsEfgFile()