コード例 #1
0
def royalties(row, row_pos):
    if row_pos == Row.BOTTOM:
        return bottom_to_royalties.get(hand_strength(row), 0)
    elif row_pos == Row.MIDDLE:
        return middle_to_royalties.get(hand_strength(row), 0)
    elif row_pos == Row.TOP:  # top
        strength = hand_strength(row)
        if strength == PokerHand.TRIPS:
            return 8 + 7.5 + row[0].rank.value
        elif strength == PokerHand.PAIR:
            pair_rank = row[0].rank.value if row[0].rank == row[
                2].rank else row[1].rank.value
            if pair_rank in [12, 13, 14]:  # fantasy land bonus
                pair_rank += 7.5
            if pair_rank in [2, 3, 4, 5]:
                return 0
            else:
                return pair_rank - 5
        elif strength == PokerHand.HIGH_CARD:
            return 0
        else:
            raise Exception("unexpected hand strength in top row")
    else:
        raise Exception("invalid row pos")
コード例 #2
0
def test_straight(hand, expected):
    if expected:
        assert poker_rules.hand_strength(hand) == PokerHand.STRAIGHT
    else:
        assert poker_rules.hand_strength(hand) != PokerHand.STRAIGHT
コード例 #3
0
def test_flush(hand, expected):
    if expected:
        assert poker_rules.hand_strength(hand) == PokerHand.FLUSH
    else:
        assert poker_rules.hand_strength(hand) != PokerHand.FLUSH
コード例 #4
0
def test_full_house(hand, expected):
    if expected:
        assert poker_rules.hand_strength(hand) == PokerHand.FULL_HOUSE
    else:
        assert poker_rules.hand_strength(hand) != PokerHand.FULL_HOUSE
コード例 #5
0
def test_quads(hand, expected):
    if expected:
        assert poker_rules.hand_strength(hand) == PokerHand.QUADS
    else:
        assert poker_rules.hand_strength(hand) != PokerHand.QUADS
コード例 #6
0
def test_hand_strength(hand, strength):
    assert poker_rules.hand_strength(hand) == strength
コード例 #7
0
def test_pair(hand, expected):
    if expected:
        assert poker_rules.hand_strength(hand) == PokerHand.PAIR
    else:
        assert poker_rules.hand_strength(hand) != PokerHand.PAIR
コード例 #8
0
def test_trips(hand, expected):
    if expected:
        assert poker_rules.hand_strength(hand) == PokerHand.TRIPS
    else:
        assert poker_rules.hand_strength(hand) != PokerHand.TRIPS