Beispiel #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")
def test_straight(hand, expected):
    if expected:
        assert poker_rules.hand_strength(hand) == PokerHand.STRAIGHT
    else:
        assert poker_rules.hand_strength(hand) != PokerHand.STRAIGHT
def test_flush(hand, expected):
    if expected:
        assert poker_rules.hand_strength(hand) == PokerHand.FLUSH
    else:
        assert poker_rules.hand_strength(hand) != PokerHand.FLUSH
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
def test_quads(hand, expected):
    if expected:
        assert poker_rules.hand_strength(hand) == PokerHand.QUADS
    else:
        assert poker_rules.hand_strength(hand) != PokerHand.QUADS
def test_hand_strength(hand, strength):
    assert poker_rules.hand_strength(hand) == strength
def test_pair(hand, expected):
    if expected:
        assert poker_rules.hand_strength(hand) == PokerHand.PAIR
    else:
        assert poker_rules.hand_strength(hand) != PokerHand.PAIR
def test_trips(hand, expected):
    if expected:
        assert poker_rules.hand_strength(hand) == PokerHand.TRIPS
    else:
        assert poker_rules.hand_strength(hand) != PokerHand.TRIPS