本文整理匯總了Python中rvr.poker.cards.Card類的典型用法代碼示例。如果您正苦於以下問題:Python Card類的具體用法?Python Card怎麽用?Python Card使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Card類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_compare
def test_compare(self):
"""
Test BestHandEval7 compare
"""
hand1 = BestHandEval7(Card.many_from_text("AsTdTs5sAc5cQd"))
hand2 = BestHandEval7(Card.many_from_text("AsTdTs5sAc5cJd"))
self.assertTrue(hand1 > hand2) # Q kicker beats J kicker
示例2: do_test_re_deal
def do_test_re_deal(self, action, dealt, key, board, result, re_dealt,
iterations=1, delta=0.0):
"""
Worker function for testing re_deal
"""
# pylint:disable=R0913,R0914
action2 = ActionDetails(HandRange(action[0]),
HandRange(action[1]),
HandRange(action[2]), 2)
board2 = Card.many_from_text(board)
re_dealt2 = [(HandRange(text).generate_options(board2), ratio)
for text, ratio in re_dealt]
counts = [0 for _ in re_dealt2]
for _ndx in xrange(iterations):
dealt2 = {k: Card.many_from_text(val) for k, val in dealt.items()}
_te, fpct, _pp, _ap = re_deal(action2, dealt2, key, board2, False,
True)
continue_ratio = 1.0 - fpct
self.assertEqual(continue_ratio, result,
msg="Expected continue ratio %0.3f but got %0.3f" %
(result, continue_ratio))
for ndx, (options, ratio) in enumerate(re_dealt2):
if (frozenset(dealt2[key]), 1) in options:
counts[ndx] += 1
break
else:
self.fail("dealt[key]=%r not in expected re_dealt2 ranges: %r" %
(dealt2[key], re_dealt2))
for ndx, val in enumerate(counts):
expected = re_dealt[ndx][1] * iterations
self.assertAlmostEqual(val, expected, delta=delta,
msg=("Expected count %0.0f but got count %0.0f" + \
" for re_dealt item %s") % (expected, val, re_dealt[ndx][0]))
示例3: test_cmp_options
def test_cmp_options(self):
"""
Test _cmp_options
"""
cqh = Card.from_text("Qh")
ckh = Card.from_text("Kh")
cah = Card.from_text("Ah")
cks = Card.from_text("Ks")
ckc = Card.from_text("Kc")
kh_qh = set([ckh, cqh])
ah_kh = set([ckh, cah])
ks_kh = set([ckh, cks])
kh_kc = set([ckh, ckc])
self.assertEqual(-1, _cmp_options(kh_qh, ah_kh))
self.assertEqual(-1, _cmp_options(kh_qh, ks_kh))
self.assertEqual(-1, _cmp_options(kh_qh, kh_kc))
self.assertEqual(1, _cmp_options(ah_kh, kh_qh))
self.assertEqual(1, _cmp_options(ah_kh, ks_kh))
self.assertEqual(1, _cmp_options(ah_kh, kh_kc))
self.assertEqual(1, _cmp_options(ks_kh, kh_qh))
self.assertEqual(-1, _cmp_options(ks_kh, ah_kh))
self.assertEqual(1, _cmp_options(ks_kh, kh_kc))
self.assertEqual(1, _cmp_options(kh_kc, kh_qh))
self.assertEqual(-1, _cmp_options(kh_kc, ah_kh))
self.assertEqual(-1, _cmp_options(kh_kc, ks_kh))
示例4: test_create_afei_two_folders_raise
def test_create_afei_two_folders_raise(self):
""" Test _create_afei for a raise against two players"""
# raise from 10 to 30 on an original pot of 10
# unprofitable bluff
fea = FoldEquityAccumulator(
gameid=0,
order=0,
street=RIVER,
board=[],
bettor=0,
range_action=None,
raise_total=30,
pot_before_bet=20,
bet_cost=30,
pot_if_called=70,
potential_folders=[])
fold_range = HandRange("KK")
nonfold_range = HandRange("AA")
fea.folds.append((1, fold_range, nonfold_range)) # folds 2/3
fold_range = HandRange("QQ")
nonfold_range = HandRange("KK+")
fea.folds.append((1, fold_range, nonfold_range)) # folds 1/4
afei = fea._create_afei(combo=Card.many_from_text("AsQh"), is_agg=True)
self.assertAlmostEqual(afei.fold_ratio, 1.0 / 6.0)
self.assertAlmostEqual(afei.immediate_result,
1.0 / 6.0 * 20.0 + (5.0 / 6.0) * (-30)) # -21.66...
self.assertAlmostEqual(afei.semibluff_ev, None)
self.assertAlmostEqual(afei.semibluff_equity, None)
示例5: test_description
def test_description(self):
"""
Test BestHandEval7 to string
"""
cards = Card.many_from_text("AsTdTs5sAc5cQd")
hand = BestHandEval7(cards)
self.assertEqual(str(hand), "two pair, Aces and Tens")
示例6: test_hand_vs_range_monte_carlo
def test_hand_vs_range_monte_carlo(self):
hand = Card.many_from_text("AsAd")
villain = HandRange("AA,A3o,32s")
board = []
equity = py_hand_vs_range_monte_carlo(
hand, villain, board, 10000000)
self.assertAlmostEqual(equity, 0.85337, delta=0.002)
示例7: test_create_afei_one_folder_reraise
def test_create_afei_one_folder_reraise(self):
""" Test _create_afei for a reraise against one player"""
# raise from 30 to 50 on an original pot of 10
# unprofitable bluff
fea = FoldEquityAccumulator(
gameid=0,
order=0,
street=PREFLOP,
board=[],
bettor=0,
range_action=None,
raise_total=50,
pot_before_bet=50,
bet_cost=40,
pot_if_called=110,
potential_folders=[])
fold_range = HandRange("QQ")
nonfold_range = HandRange("AA-KK")
fea.folds.append((1, fold_range, nonfold_range))
afei = fea._create_afei(combo=Card.many_from_text("KsQh"), is_agg=True)
self.assertAlmostEqual(afei.fold_ratio, 1.0 / 4.0)
self.assertAlmostEqual(afei.immediate_result,
1.0 / 4.0 * 50.0 + (3.0 / 4.0) * (-40.0)) # -17.5
self.assertAlmostEqual(afei.semibluff_ev, 4.0 / 3.0 * 17.5)
self.assertAlmostEqual(afei.semibluff_equity, 4.0 / 3.0 * 17.5 / 110.0)
示例8: test_create_afei_two_folders_bet
def test_create_afei_two_folders_bet(self):
""" Test _create_afei for a bet against two players"""
# bet 10 on a pot of 10
# profitable bluff
fea = FoldEquityAccumulator(
gameid=0,
order=0,
street=RIVER,
board=[],
bettor=0,
range_action=None,
raise_total=10,
pot_before_bet=10,
bet_cost=10,
pot_if_called=30,
potential_folders=[])
fold_range = HandRange("KK")
nonfold_range = HandRange("AA")
fea.folds.append((1, fold_range, nonfold_range))
fold_range = HandRange("KK")
nonfold_range = HandRange("AA")
fea.folds.append((1, fold_range, nonfold_range))
afei = fea._create_afei(combo=Card.many_from_text("AsQh"), is_agg=True)
self.assertAlmostEqual(afei.fold_ratio, 4.0 / 9.0)
self.assertAlmostEqual(afei.immediate_result,
4.0 / 9.0 * 10.0 + (5.0 / 9.0) * (-10))
self.assertEqual(afei.semibluff_ev, None)
self.assertEqual(afei.semibluff_equity, None)
示例9: test_create_afei_one_folder_raise
def test_create_afei_one_folder_raise(self):
""" Test _create_afei for a raise against one player"""
# raise from 10 to 30 on an original pot of 10
# profitable bluff
fea = FoldEquityAccumulator(
gameid=0,
order=0,
street=PREFLOP,
board=[],
bettor=0,
range_action=None,
raise_total=30,
pot_before_bet=20,
bet_cost=30,
pot_if_called=70,
potential_folders=[])
fold_range = HandRange("KK-JJ")
nonfold_range = HandRange("AA")
fea.folds.append((1, fold_range, nonfold_range))
afei = fea._create_afei(combo=Card.many_from_text("KsQh"), is_agg=True)
self.assertAlmostEqual(afei.fold_ratio, 2.0 / 3.0)
self.assertAlmostEqual(afei.immediate_result,
2.0 / 3.0 * 20.0 + (1.0 / 3.0) * (-30.0)) # 3.33...
self.assertAlmostEqual(afei.semibluff_ev, -10.0)
self.assertAlmostEqual(afei.semibluff_equity, -10.0 / 70.0)
示例10: inject_range_sizes
def inject_range_sizes(players, board_raw):
"""
Inject a range size into each situation player
"""
for player in players:
player.range_size = len(HandRange(player.range_raw).generate_options(
Card.many_from_text(board_raw)))
示例11: test_create_afei_two_fodlers_reraise
def test_create_afei_two_fodlers_reraise(self):
""" Test _create_afei for a reraise against two players"""
# raise from 30 to 50 on an original pot of 10
# profitable bluff
fea = FoldEquityAccumulator(
gameid=0,
order=0,
street=RIVER,
board=[],
bettor=0,
range_action=None,
raise_total=50,
pot_before_bet=50,
bet_cost=50,
pot_if_called=120, # assumes called by the raiser, not the bettor
potential_folders=[])
fold_range = HandRange("KK")
nonfold_range = HandRange("AA")
fea.folds.append((1, fold_range, nonfold_range)) # folds 2/3
fold_range = HandRange("KK-JJ")
nonfold_range = HandRange("AA")
fea.folds.append((1, fold_range, nonfold_range)) # folds 5/6
afei = fea._create_afei(combo=Card.many_from_text("AsQh"), is_agg=True)
self.assertAlmostEqual(afei.fold_ratio, 10.0 / 18.0)
self.assertAlmostEqual(afei.immediate_result,
10.0 / 18.0 * 50.0 + 8.0 / 18.0 * (-50.0)) # 5.55...
self.assertAlmostEqual(afei.semibluff_ev, None)
self.assertAlmostEqual(afei.semibluff_equity, None)
示例12: generate_options_unweighted
def generate_options_unweighted(self, board=None):
"""
just hand, no weight
error if weights are not all the same
"""
excluded_cards = board or []
excluded_mnemonics = [card.to_mnemonic() for card in excluded_cards]
# it's really nice for this to be a list, for self.polarise_weights
options = []
first_weight = None
for part, weight in self.subranges:
if first_weight == None:
first_weight = weight
elif weight != first_weight:
raise ValueError("range is not evenly weighted")
option_mnemonics = hands_in_subrange(part) # list of e.g. "AhKh"
not_excluded = lambda hand: (hand[0:2] not in excluded_mnemonics
and hand[2:4] not in excluded_mnemonics)
option_mnemonics = [o for o in option_mnemonics if not_excluded(o)]
hands = [frozenset(Card.many_from_text(txt))
for txt in option_mnemonics]
options.extend(hands)
if self.is_strict:
return options
else:
return list(set(options))
示例13: test_all_hands_vs_range
def test_all_hands_vs_range(self):
hero = HandRange("AsAd,3h2c")
villain = HandRange("AA,A3o,32s")
board = []
equity_map = py_all_hands_vs_range(hero, villain, board, 10000000)
self.assertEqual(len(equity_map), 2)
hand1 = frozenset(Card.many_from_text("AsAd"))
hand2 = frozenset(Card.many_from_text("3h2c"))
self.assertAlmostEqual(equity_map[hand1], 0.85337, delta=0.002)
self.assertAlmostEqual(equity_map[hand2], 0.22865, delta=0.002)
# Hero has an impossible hand in his range.
hero = HandRange("JsJc,QsJs")
villain = HandRange("JJ")
board = Card.many_from_text("KhJd8c")
equity_map = py_all_hands_vs_range(hero, villain, board, 10000000)
hand = frozenset(Card.many_from_text("QsJs"))
self.assertAlmostEqual(equity_map[hand], 0.03687, delta=0.0002)
self.assertEqual(len(equity_map), 1)
示例14: safe_board_form
def safe_board_form(field_name):
"""
Pull a board (list of Card) from request form field <field_name>.
If there is a problem, return an empty list.
"""
value = request.form.get(field_name, '', type=str)
try:
return Card.many_from_text(value)
except ValueError:
return []
示例15: safe_board
def safe_board(arg_name):
"""
Pull a board (list of Card) from request arg <arg_name>.
If there is a problem, return an empty list.
"""
value = request.args.get(arg_name, '', type=str)
try:
return Card.many_from_text(value)
except ValueError:
return []