2 # Copyright (C) 2007, 2008 Loic Dachary <loic@dachary.org>
3 # Copyright (C) 2004, 2005, 2006 Mekensleep
6 # 24 rue vieille du temple
8 # licensing@mekensleep.com
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
25 # Loic Dachary <loic@dachary.org>
29 sys
.path
.insert(0, ".")
30 sys
.path
.insert(0, ".libs")
32 from pokereval
import PokerEval
34 iterations_low
= 100000
35 iterations_high
= 200000
37 pokereval
= PokerEval()
39 if pokereval
.best_hand_value("hi", ["Ah", "Ad", "As", "Kh", "Ks" ]) != 101494784:
42 if pokereval
.string2card("2h") != 0:
46 pockets
= [ ["As", "Ad", "Ac", "Tc", "Ts", "2d", "5c" ],
47 ["Js", "Jc", "7s", "8c", "8d", "3c", "3h" ],
49 print "stud7 (1) result = %s\n" % pokereval
.winners(game
= "7stud", pockets
= pockets
, dead
= [], board
= [])
51 pockets
= [[22, 18, 21, 3, 41, 1, 30], [39, 255, 255, 15, 13, 17, 255]]
52 print "stud7 (2) result = %s\n" % pokereval
.winners(game
= "7stud", pockets
= pockets
, dead
= [], board
= [])
54 print [ j
+ i
+ "/%d" % pokereval
.string2card(j
+ i
) for i
in "hdcs" for j
in "23456789TJQKA" ]
55 print "deck = %s\n" % pokereval
.deck()
57 print "result = %s\n" % pokereval
.poker_eval(game
= "holdem", pockets
= [ ["tc", "ac"], ["3h", "ah"], ["8c", "6h"]], dead
= [], board
= ["7h", "3s", "2c"])
58 print "winners = %s\n" % pokereval
.winners(game
= "holdem", pockets
= [ ["tc", "ac"], ["3h", "ah"], ["8c", "6h"]], dead
= [], board
= ["7h", "3s", "2c"])
60 print "result = %s\n" % pokereval
.poker_eval(game
= "holdem", pockets
= [ ["tc", "ac"], ["th", "ah"], ["8c", "6h"]], dead
= [], board
= ["7h", "3s", "2c", "7s", "7d"])
61 print "winners = %s\n" % pokereval
.winners(game
= "holdem", pockets
= [ ["tc", "ac"], ["th", "ah"], ["8c", "6h"]], dead
= [], board
= ["7h", "3s", "2c", "7s", "7d"])
63 print "winners (filthy pockets) = %s\n" % pokereval
.winners(game
= "holdem", pockets
= [ ["tc", "ac", 255], [], [255, 255], ["th", "ah"], ["8c", "6h"]], dead
= [], board
= ["7h", "3s", "2c", "7s", "7d"])
65 print "winners omaha = %s\n" % pokereval
.winners(game
= "omaha", pockets
= [ ["tc", "ac", "ks", "kc" ], ["th", "ah", "qs", "qc" ], ["8c", "6h", "js", "jc" ]], dead
= [], board
= ["7h", "3s", "2c", "7s", "7d"])
66 print "winners omaha8 = %s\n" % pokereval
.winners(game
= "omaha8", pockets
= [ ["tc", "ac", "ks", "kc" ], ["th", "ah", "qs", "qc" ], ["8c", "6h", "js", "jc" ]], dead
= [], board
= ["7h", "3s", "2c", "7s", "7d"])
68 hand
= ["Ac", "As", "Td", "7s", "7h", "3s", "2c"]
69 best_hand
= pokereval
.best_hand("hi", hand
)
70 print "best hand from %s = %s" % ( hand
, pokereval
.best_hand("hi", hand
) )
71 print "best hand from %s = (%s) %s " % (hand
, best_hand
[0], [ pokereval
.card2string(i
) for i
in best_hand
[1:] ])
74 hand
= ["Ah", "Ts", "Kh", "Qs", "Js" ]
75 best_hand
= pokereval
.best_hand("hi", hand
)
76 print "best hand from %s = %s" % ( hand
, pokereval
.best_hand("hi", hand
) )
77 print "best hand from %s = (%s) %s " % (hand
, best_hand
[0], [ pokereval
.card2string(i
) for i
in best_hand
[1:] ])
80 hand
= ["2h", "Kh", "Qh", "Jh", "Th" ]
81 best_hand
= pokereval
.best_hand("hi", hand
)
82 print "best hand from %s = %s" % ( hand
, pokereval
.best_hand("hi", hand
) )
83 print "best hand from %s = (%s) %s " % (hand
, best_hand
[0], [ pokereval
.card2string(i
) for i
in best_hand
[1:] ])
86 hand
= ['2s', '3s', 'Jd', 'Ks', 'As', '4d', '5h', '7d', '9c']
87 best_hand
= pokereval
.best_hand("hi", hand
)
88 print "best hand from %s = %s" % ( hand
, pokereval
.best_hand("hi", hand
) )
89 print "best hand from %s = (%s) %s " % (hand
, best_hand
[0], [ pokereval
.card2string(i
) for i
in best_hand
[1:] ])
92 hand
= ['As', '2s', '4d', '4s', '5c', '5d', '7s']
93 best_hand
= pokereval
.best_hand("low", hand
)
94 print "1/ low hand from %s = %s" % ( hand
, pokereval
.best("low", hand
) )
95 print "best low hand from %s = (%s) %s " % (hand
, best_hand
[0], [ pokereval
.card2string(i
) for i
in best_hand
[1:] ])
98 hand
= ['As', '2s', '4d', '4s', '5c', '5d', '8s']
99 best_hand
= pokereval
.best_hand("low", hand
)
100 print "2/ low hand from %s = %s" % ( hand
, pokereval
.best("low", hand
) )
101 print "best low hand from %s = (%s) %s " % (hand
, best_hand
[0], [ pokereval
.card2string(i
) for i
in best_hand
[1:] ])
104 hand
= ['7d', '6c', '5h', '4d', 'As']
105 best_hand
= pokereval
.best_hand("low", hand
)
106 print "3/ low hand from %s = %s" % ( hand
, pokereval
.best("low", hand
) )
107 print "best low hand from %s = (%s) %s " % (hand
, best_hand
[0], [ pokereval
.card2string(i
) for i
in best_hand
[1:] ])
110 board
= [ 'As', '4d', '5h', '7d', '9c' ]
111 hand
= [ '2s', 'Ts', 'Jd', 'Ks' ]
112 best_hand
= pokereval
.best_hand("low", hand
, board
)
113 print "4/ low hand from %s / %s = %s" % ( hand
, board
, pokereval
.best("low", hand
, board
) )
114 print "best low hand from %s / %s = (%s) %s " % (hand
, board
, best_hand
[0], [ pokereval
.card2string(i
) for i
in best_hand
[1:] ])
117 board
= [ 'As', '4d', '6h', '7d', '3c' ]
118 hand
= [ '2s', '5s', 'Jd', 'Ks' ]
119 best_hand
= pokereval
.best_hand("low", hand
, board
)
120 print "low hand from %s / %s = %s" % ( hand
, board
, pokereval
.best("low", hand
, board
) )
121 print "best low hand from %s / %s = (%s) %s " % (hand
, board
, best_hand
[0], [ pokereval
.card2string(i
) for i
in best_hand
[1:] ])
124 board
= [ 'Jc', '4c', '3c', '5c', '9c' ]
125 hand
= [ '2c', 'Ac', '5h', '9d' ]
126 best_hand
= pokereval
.best_hand("hi", hand
, board
)
127 print "hi hand from %s / %s = %s" % ( hand
, board
, pokereval
.best("hi", hand
, board
) )
128 print "best hi hand from %s / %s = (%s) %s " % (hand
, board
, best_hand
[0], pokereval
.card2string(best_hand
[1:]))
131 board
= [ 'Jd', '9c', 'Jc', 'Tc', '2h' ]
132 hand
= [ '2c', '4c', 'Th', '6s' ]
133 best_hand
= pokereval
.best_hand("low", hand
, board
)
134 print "5/ low hand from %s / %s = %s" % ( hand
, board
, pokereval
.best("low", hand
, board
) )
135 print "best low hand from %s / %s = (%s) %s " % (hand
, board
, best_hand
[0], [ pokereval
.card2string(i
) for i
in best_hand
[1:] ])
138 board
= [ 'Ks', 'Jd', '7s', '4d', 'Js' ]
139 hand
= [ '2d', '6c', 'Ac', '5c' ]
140 best_hand
= pokereval
.best_hand("low", hand
, board
)
141 print "6/ low hand from %s / %s = %s" % ( hand
, board
, pokereval
.best("low", hand
, board
) )
142 print "best low hand from %s / %s = (%s) %s " % (hand
, board
, best_hand
[0], [ pokereval
.card2string(i
) for i
in best_hand
[1:] ])
144 if len(sys
.argv
) > 2:
146 print "f0 result = %s\n" % pokereval
.poker_eval(game
= "holdem", fill_pockets
= 1, pockets
= [ ["As", "3s"], ["__", "__"], ["__", "__"]], dead
= [], board
= ["__", "Qs", "2c", "Ac", "Kc"])
149 print "f1 result = %s\n" % pokereval
.poker_eval(game
= "holdem", fill_pockets
= 1, pockets
= [ ["As", "3s"], ["__", "__"], ["__", "__"]], dead
= [], board
= ["7s", "Qs", "2c", "Ac", "Kc"])
153 print "f2 result = %s\n" % pokereval
.poker_eval(game
= "holdem", fill_pockets
= 1, iterations
= iterations_low
, pockets
= [ ["As", "3s"], ["__", "__"], ["__", "__"]], dead
= [], board
= ["__", "__", "__", "__", "__"])
156 print "f3 result = %s\n" % pokereval
.poker_eval(game
= "holdem", fill_pockets
= 1, iterations
= iterations_high
, pockets
= [ ["As", "Ac"], ["__", "__"], ["__", "__"]], dead
= [], board
= ["__", "__", "__", "__", "__"])
159 print "f4 result = %s\n" % pokereval
.poker_eval(game
= "holdem", fill_pockets
= 1, iterations
= iterations_high
, pockets
= [ ["As", "Ks"], ["__", "__"], ["__", "__"]], dead
= [], board
= ["__", "__", "__", "__", "__"])
162 print "f5 result = %s\n" % pokereval
.poker_eval(game
= "holdem", fill_pockets
= 1, iterations
= iterations_high
, pockets
= [ ["2s", "2c"], ["__", "__"], ["__", "__"]], dead
= [], board
= ["__", "__", "__", "__", "__"])
165 print "f6 result = %s\n" % pokereval
.poker_eval(game
= "holdem", fill_pockets
= 1, iterations
= iterations_high
, pockets
= [ ["Js", "Jc"], ["__", "__"], ["__", "__"]], dead
= [], board
= ["__", "__", "__", "__", "__"])
168 print "f7 result = %s\n" % pokereval
.poker_eval(game
= "omaha", fill_pockets
= 1, iterations
= iterations_high
, pockets
= [ ["Js", "Jc", "7s", "8c"], ["__", "__", "__", "__"], ["__", "__", "__", "__"]], dead
= [], board
= ["__", "__", "__", "__", "__"])
172 print "handval %s = %d " % (hand
, pokereval
.evaln(hand
))
176 print "handval %s = %d " % (hand
, pokereval
.evaln(hand
))