Stove: Rename range to h_range

range is a resvered word in Python.
This commit is contained in:
Worros 2010-12-03 11:46:15 +08:00
parent b83242622a
commit 9b629a467a

View File

@ -27,7 +27,7 @@ class Stove:
def __init__(self): def __init__(self):
self.hand = None self.hand = None
self.board = None self.board = None
self.range = None self.h_range = None
def set_board_with_list(self, board): def set_board_with_list(self, board):
pass pass
@ -58,7 +58,7 @@ class Stove:
def set_villain_range_string(self, string): def set_villain_range_string(self, string):
# Villain's range # Villain's range
range = Range() h_range = Range()
hands_in_range = string.strip().split(',') hands_in_range = string.strip().split(',')
for h in hands_in_range: for h in hands_in_range:
_h = h.strip() _h = h.strip()
@ -67,11 +67,11 @@ class Stove:
r1 = cc[0] r1 = cc[0]
r2 = cc[1] r2 = cc[1]
vp = Cards(r1, r2) vp = Cards(r1, r2)
range.add(vp) h_range.add(vp)
else: else:
range.expand(expand_hands(_h, self.hand, self.board)) h_range.expand(expand_hands(_h, self.hand, self.board))
self.range = range self.h_range = h_range
class Cards: class Cards:
@ -147,13 +147,13 @@ class SumEV:
self.n_ties += ev.n_ties self.n_ties += ev.n_ties
self.n_losses += ev.n_losses self.n_losses += ev.n_losses
def show(self, hand, range): def show(self, hand, h_range):
win_pct = 100 * (float(self.n_wins) / float(self.n_hands)) win_pct = 100 * (float(self.n_wins) / float(self.n_hands))
lose_pct = 100 * (float(self.n_losses) / float(self.n_hands)) lose_pct = 100 * (float(self.n_losses) / float(self.n_hands))
tie_pct = 100 * (float(self.n_ties) / float(self.n_hands)) tie_pct = 100 * (float(self.n_ties) / float(self.n_hands))
print 'Enumerated %d possible plays.' % self.n_hands print 'Enumerated %d possible plays.' % self.n_hands
print 'Your hand: (%s %s)' % (hand.c1, hand.c2) print 'Your hand: (%s %s)' % (hand.c1, hand.c2)
print 'Against the range: %s\n' % cards_from_range(range) print 'Against the range: %s\n' % cards_from_range(h_range)
print ' Win Lose Tie' print ' Win Lose Tie'
print ' %5.2f%% %5.2f%% %5.2f%%' % (win_pct, lose_pct, tie_pct) print ' %5.2f%% %5.2f%% %5.2f%%' % (win_pct, lose_pct, tie_pct)
@ -182,7 +182,7 @@ def expand_hands(abbrev, hand, board):
else: else:
selection = ANY selection = ANY
range = [] h_range = []
considered = set() considered = set()
for s1 in SUITS: for s1 in SUITS:
c1 = r1 + s1 c1 = r1 + s1
@ -196,8 +196,8 @@ def expand_hands(abbrev, hand, board):
elif selection == OFFSUIT and s1 == s2: elif selection == OFFSUIT and s1 == s2:
continue continue
if c2 not in considered and c2 not in known_cards: if c2 not in considered and c2 not in known_cards:
range.append(Cards(c1, c2)) h_range.append(Cards(c1, c2))
return range return h_range
def parse_args(args, container): def parse_args(args, container):
@ -260,7 +260,7 @@ def odds_for_range(holder):
iters = random.randint(25000, 125000) iters = random.randint(25000, 125000)
else: else:
iters = -1 iters = -1
for h in holder.range.get(): for h in holder.h_range.get():
e = odds_for_hand( e = odds_for_hand(
[holder.hand.c1, holder.hand.c2], [holder.hand.c1, holder.hand.c2],
[h.c1, h.c2], [h.c1, h.c2],
@ -269,7 +269,7 @@ def odds_for_range(holder):
) )
sev.add(e) sev.add(e)
sev.show(holder.hand, holder.range.get()) sev.show(holder.hand, holder.h_range.get())
def usage(me): def usage(me):
print """Texas Hold'Em odds calculator print """Texas Hold'Em odds calculator
@ -281,9 +281,9 @@ Separate cards with space.
Separate hands in range with commas. Separate hands in range with commas.
""" % me """ % me
def cards_from_range(range): def cards_from_range(h_range):
s = '{' s = '{'
for h in range: for h in h_range:
if h.c1 == '__' and h.c2 == '__': if h.c1 == '__' and h.c2 == '__':
s += 'random, ' s += 'random, '
else: else: