Example #1
0
def test_rules_full_house():
    cards = [
        poker.Card("C", 14),
        poker.Card("D", 14),
        poker.Card("S", 8),
        poker.Card("H", 14),
        poker.Card("D", 8),
    ]
    ruleset = poker.Rules(big_blind=10)
    house, rest, string = ruleset.x_of_a_kind(cards)

    assert all([house == cards, rest == [], string == "Full House"])
Example #2
0
def test_rules_high_card():
    cards = [
        poker.Card("C", 14),
        poker.Card("C", 5),
        poker.Card("S", 10),
        poker.Card("H", 2),
        poker.Card("D", 8),
    ]
    ruleset = poker.Rules(big_blind=10)
    high_card = ruleset.high_card(cards)

    assert high_card == cards[0]
Example #3
0
def test_shuffle_cardstack():
    cards = [
        poker.Card(suit, rank) for suit in ["C", "D", "H", "S"]
        for rank in [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
    ]
    shuffled_stack = poker.Cardstack()
    assert cards != shuffled_stack.cards
Example #4
0
def test_rules_two_pair():
    cards = [
        poker.Card("C", 14),
        poker.Card("D", 14),
        poker.Card("S", 8),
        poker.Card("H", 10),
        poker.Card("D", 8),
    ]
    ruleset = poker.Rules(big_blind=10)
    twopair, rest, string = ruleset.x_of_a_kind(cards)

    assert all([
        twopair == [cards[0], cards[1], cards[2], cards[4]],
        rest == [cards[3]],
        string == "Two Pair",
    ])
Example #5
0
def test_rules_four_of_a_kind():
    cards = [
        poker.Card("C", 14),
        poker.Card("D", 14),
        poker.Card("S", 14),
        poker.Card("H", 14),
        poker.Card("D", 8),
    ]
    ruleset = poker.Rules(big_blind=10)
    fours, rest, string = ruleset.x_of_a_kind(cards)

    assert all([
        fours == [cards[0], cards[1], cards[2], cards[3]],
        rest == [cards[4]],
        string == "Four of a Kind",
    ])
Example #6
0
def test_rules_three_of_a_kind():
    cards = [
        poker.Card("C", 14),
        poker.Card("C", 5),
        poker.Card("S", 14),
        poker.Card("H", 14),
        poker.Card("D", 8),
    ]
    ruleset = poker.Rules(big_blind=10)
    threes, rest, string = ruleset.x_of_a_kind(cards)

    assert all([
        threes == [cards[0], cards[2], cards[3]],
        rest == [cards[1], cards[4]],
        string == "Three of a Kind",
    ])
Example #7
0
 def c(cards, suits):
     """args - [(x, y), ...] where
         x is the value of the card
         y is the suit of the card
     """
     suit = {0: "♠", 1: "♥", 2: "♦", 3: "♣"}
     for c, s in zip(cards, suits):
         s = suit[s]
         self.deck.add(poker.Card(c, s))
Example #8
0
def test_straight():
    cards = [
        poker.Card("H", 2),
        poker.Card("H", 14),
        poker.Card("S", 11),
        poker.Card("H", 12),
        poker.Card("S", 5),
        poker.Card("H", 10),
        poker.Card("C", 13),
    ]
    ruleset = poker.Rules(big_blind=10)
    straight, string = ruleset.straight(cards)

    assert all([
        straight == [cards[1], cards[6], cards[3], cards[2], cards[5]],
        string == "Straight! Ace to Ten",
    ])
Example #9
0
def test_flush():
    cards = [
        poker.Card("H", 2),
        poker.Card("H", 14),
        poker.Card("S", 8),
        poker.Card("H", 7),
        poker.Card("H", 9),
        poker.Card("H", 11),
        poker.Card("H", 8),
    ]
    ruleset = poker.Rules(big_blind=10)
    flush, string = ruleset.flush(cards)

    assert all([
        flush == [cards[1], cards[5], cards[4], cards[6], cards[3]],
        string == "Flush! Ace high",
    ])
Example #10
0
def finish_hands(dest_cardpool_index):
    suit = cardpool_list[dest_cardpool_index].cards[-1].suit
    for i in range(13):
        cardpool_list[dest_cardpool_index].cards.pop()
    if len(cardpool_list[dest_cardpool_index].cards) > 0:
        cardpool_list[dest_cardpool_index].cards[-1].show = True
    tail_pos = get_card_pos(dest_cardpool_index,
                            len(cardpool_list[dest_cardpool_index].cards))
    height = 12 * CARDDISTANCE + CARDHEIGHT
    hand_rect = pygame.Rect(tail_pos[0], tail_pos[1], CARDWIDTH, height)
    pygame.draw.rect(windowSurface, BACKGROUNDCOLOR, hand_rect)
    global FINISHED_HANDS
    FINISHED_HANDS += 1
    draw_cardpool(dest_cardpool_index)
    King = poker.Card(suit, 13)
    King.show = True
    left = SIDEDISTANCE + FINISHED_HANDS * CARDDISTANCE
    top = WINDOWHEIGHT - TOPDISTANCE - CARDHEIGHT
    display_card(King, left, top, windowSurface)
Example #11
0
def test_rank_numbers():
    cards = [
        poker.Card(suit, rank) for suit in ["C"]
        for rank in [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
    ]
    assert [card.rank_str for card in cards] == [
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "Ten",
        "Jack",
        "Queen",
        "King",
        "Ace",
    ]
Example #12
0
File: test.py Project: correl/euler
 def test_valid_face_card(self):
     card = poker.Card('QH')
     self.assertEqual(card.value, 12)
Example #13
0
File: test.py Project: correl/euler
 def test_valid_number_card(self):
     card = poker.Card('9D')
     self.assertEqual(card.value, 9)
Example #14
0
File: test.py Project: correl/euler
 def test_compare(self):
     cards = ['QH', '9D', 'JS']
     cards_sorted = sorted([poker.Card(c) for c in cards], reverse=True)
     self.assertEqual([c.value for c in cards_sorted], [12, 11, 9])