-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathequity.py
More file actions
executable file
·70 lines (51 loc) · 1.3 KB
/
Copy pathequity.py
File metadata and controls
executable file
·70 lines (51 loc) · 1.3 KB
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
#!/usr/bin/python
import subprocess
import os
import re
import tempfile
import hand
def hand2pql(h):
suits = 'WXYZ'
cards = []
for (r, s) in h.cards:
cards.append('%s%s' % (hand.idxr(r), suits[s]))
return ''.join(cards)
def hands2pql(hands, f):
for i in xrange(len(hands)):
f.write("""
select avg(riverEquity(p1)) as EQ%d from game='omahahi', p1='%s', p2='*';
""" % (i, hand2pql(hands[i])))
def compute_equities(hands):
f = tempfile.NamedTemporaryFile(delete=False)
hands2pql(hands, f)
f.flush()
f.close()
res = subprocess.check_output(
"java -cp ../p3.jar propokertools.cli.RunPQL -mt 10000 -tc 8 -c < %s" % f.name,
shell=True)
os.unlink(f.name)
return parse_equities(hands, res)
def parse_equities(hands, eqs):
r = re.compile('EQ(\d+) = (.+)')
ret = []
for l in eqs:
m = r.match(l)
if m:
(idx, eq) = m.groups()
eq = float(eq)
ret.append(hands[idx], eq)
return ret
if __name__ == '__main__':
import regress
import sys
import cPickle
print "Reading hands..."
hands = regress.read_hands(sys.argv[1])
print "Read %d hands" % len(hands)
print "Computing equities..."
eqs = compute_equities(hands)
print "Pickling..."
pickled = open(sys.argv[2], 'wb')
cPickle.dump(eqs, pickled)
pickled.close()
print "Done!"