def _create_ofc_hand(top, middle, bottom): ofc_hand = OfcHand() for c in parse_cards(top.split(" ")): ofc_hand.add_top(c) for c in parse_cards(middle.split(" ")): ofc_hand.add_middle(c) for c in parse_cards(bottom.split(" ")): ofc_hand.add_bottom(c) return ofc_hand
def test_no_foul(): ofc_hand = OfcHand() for c in parse_cards(["2c", "2d", "2h"]): ofc_hand.add_top(c) for c in parse_cards(["6h", "6d", "6c", "6s", "As"]): ofc_hand.add_middle(c) for c in parse_cards(["8h", "8d", "8c", "8s", "9s"]): ofc_hand.add_bottom(c) assert not ofc_hand.foul
def test_ofc_hand_golden(): ofc_hand = OfcHand() for c in parse_cards(["2c", "2d", "2h"]): ofc_hand.add_top(c) for c in parse_cards(["6h", "6d", "6c", "6s", "As"]): ofc_hand.add_middle(c) for c in parse_cards(["8h", "8d", "8c", "8s", "9s"]): ofc_hand.add_bottom(c) assert ofc_hand.completed
def test_add_card_too_many(): row = OfcRow(3) for c in parse_cards(["2c", "2d", "2h"]): row.add_card(c) with pytest.raises(AssertionError): row.add_card(Card(Rank.ACE, Suit.DIAMONDS))
def three_outer_mid_or_ace(): our_hand = _create_ofc_hand("Ks Kd Qh", "8c 4s", "Jd 7s 7c 7d") their_hand = _create_ofc_hand("Qc Qd 4c", "Td 9s 6s Ac", "Ah Jh 9h 3h") dead_cards = parse_cards(["Th", "6c"]) candidate_decisions = ["7h bot As mid 5c dead", "7h bot 5c mid As dead"] placements_to_ev = decision_finder(our_hand=our_hand, their_hand=their_hand, dead_cards=dead_cards, candidate_decisions=candidate_decisions, num_epochs=10000) for placements, ev in placements_to_ev.items(): s = "{} {} {} {}".format(placements[0].card, placements[0].row, placements[1].card, placements[1].row) print("{} : {}".format(s, ev))
def conflicting_draw_flush_q(): # 2d Kc Ac our_hand = _create_ofc_hand("Qs", "Ts Tc 9s 2d", "Kh Jh 8h 6h") their_hand = _create_ofc_hand("Qd 5d", "Ad 7s 7d 4d 4s", "Ac 8c 5c 2c") dead_cards = parse_cards(["8d", "3c"]) candidate_decisions = [ "Qc top 9d mid 2h dead", "Qc top 2h bot 9d dead", "2h bot 9d mid Qc dead", ] placements_to_ev = decision_finder(our_hand=our_hand, their_hand=their_hand, dead_cards=dead_cards, candidate_decisions=candidate_decisions, num_epochs=10000) for placements, ev in placements_to_ev.items(): s = "{} {} {} {}".format(placements[0].card, placements[0].row, placements[1].card, placements[1].row) print("{} : {}".format(s, ev))
def T_top_or_mid(): # 2d Kc Ac our_hand = _create_ofc_hand(None, "9c 9d", "Ac Ad 3s 3h 3d") their_hand = _create_ofc_hand( "Qc", "Kd 4d", "Ts 9s 8h 2s", ) dead_cards = parse_cards(["6c"]) candidate_decisions = ["Th mid 5d mid 2h dead", "Th top 5d mid 2h dead"] placements_to_ev = decision_finder(our_hand=our_hand, their_hand=their_hand, dead_cards=dead_cards, candidate_decisions=candidate_decisions, num_epochs=100) for placements, ev in placements_to_ev.items(): s = "{} {} {} {}".format(placements[0].card, placements[0].row, placements[1].card, placements[1].row) print("{} : {}".format(s, ev))
import pytest from deck import parse_cards import ofc_scoring @pytest.mark.parametrize( "hand,royalties", [ (parse_cards(["2c", "2d"]), 0), # pair (parse_cards(["2c", "2d", "8s", "3h", "3s"]), 0), # two pair (parse_cards(["2c", "2d", "2s", "4d"]), 0), # trips (parse_cards(["5c", "6d", "7c", "8d", "9c"]), 2), # straight (parse_cards(["6d", "5d", "Ad", "Kd", "7d"]), 4), # flush (parse_cards(["5c", "5d", "5s", "Ah", "Ac"]), 6), # full house (parse_cards(["2c", "2d", "2s", "2h", "3s"]), 10), # quads (parse_cards(["Ad", "2d", "3d", "4d", "5d"]), 15), # straight flush (parse_cards(["Ad", "Kd", "Qd", "Jd", "Td"]), 25), # royal flush ]) def test_bottom(hand, royalties): assert ofc_scoring.royalties(hand, ofc_scoring.Row.BOTTOM) == royalties @pytest.mark.parametrize( "hand,royalties", [ (parse_cards(["2c", "2d"]), 0), # pair (parse_cards(["2c", "2d", "8s", "3h", "3s"]), 0), # two pair (parse_cards(["2c", "2d", "2s", "4d"]), 2), # trips (parse_cards(["5c", "6d", "7c", "8d", "9c"]), 4), # straight (parse_cards(["6d", "5d", "Ad", "Kd", "7d"]), 8), # flush (parse_cards(["5c", "5d", "5s", "Ah", "Ac"]), 12), # full house
def test_add_card_golden(): row = OfcRow(3) for c in parse_cards(["2c", "2d", "2h"]): row.add_card(c) assert row.completed
assert row.completed def test_add_card_too_many(): row = OfcRow(3) for c in parse_cards(["2c", "2d", "2h"]): row.add_card(c) with pytest.raises(AssertionError): row.add_card(Card(Rank.ACE, Suit.DIAMONDS)) @pytest.mark.parametrize("row_1, row_2, expected_lt, expected_le", [ ( parse_cards(["Ad", "Kd", "Qd", "Jd", "Td"]), parse_cards(["9d", "Kd", "Qd", "Jd", "Td"]), False, False, ), ( parse_cards(["9d", "Kd", "Qd", "Jd", "Td"]), parse_cards(["Ad", "Kd", "Qd", "Jd", "Td"]), True, True, ), ( parse_cards(["Ad", "Kd", "Qd", "Jd", "Td"]), parse_cards(["Ad", "Kd", "Qd", "Jd", "Td"]), False, True, ), ( # other is higher straight flush parse_cards(["9d", "8d", "Qd", "Jd", "Td"]),
import pytest from deck import parse_cards import poker_rules from poker_rules import PokerHand @pytest.mark.parametrize( "hand,expected", [ (parse_cards(["Ad", "Kd", "Qd", "Jd", "Td"]), True), (parse_cards(["Ad", "2d", "3d", "4d", "5d" ]), False), # straight flush but not royal ]) def test_royal_flush(hand, expected): if expected: assert poker_rules.hand_strength(hand) == PokerHand.ROYAL_FLUSH else: assert poker_rules.hand_strength(hand) != PokerHand.ROYAL_FLUSH @pytest.mark.parametrize( "hand,expected", [ (parse_cards(["Ad", "2d", "3d", "4d", "5d"]), True), (parse_cards(["2d", "6d", "4d", "5d", "3d"]), True), (parse_cards(["Ad", "6d", "4d", "5d", "3d"]), False), (parse_cards(["Ac", "2d", "3c", "4d", "5c"]), False), # straight (parse_cards(["6d", "5d", "Ad", "Kd", "7d"]), False), # flush ]) def test_straight_flush(hand, expected): if expected: