Exemple #1
0
def build_hand(hand):
    """Converts the individual card values to a List of Cards"""
    encoded = hand[1:6]
    output = list()

    for code in encoded:
        output.append(Card(code, hand[0]))

    return output
Exemple #2
0
    def get_non_trump_led_suit_ranks(self, trump, led_suit):
        """

        :param trump: str - [C|S|D|H]
        :param led_suit: str - [C|S|D|H]
        :return:
        """
        if led_suit in [trump, suit.d_bower_suits[trump]]:
            lst_extra = [
                Card(**dict(zip(['card_rank', 'card_suit'], x)))
                for x in itertools.product(self.non_bowers, led_suit)
            ]
        else:
            lst_extra = [
                Card(**dict(zip(['card_rank', 'card_suit'], x)))
                for x in itertools.product(self.ranks, led_suit)
            ]
        return lst_extra
Exemple #3
0
def test_get_card_ranks_by_trump_and_led_bower_led_pass():
    low_rank = 9
    d = Deck(low_rank=low_rank)

    card = Card("J", "C")
    rez = d.get_card_ranks_by_trump_and_led("S", card)
    assert [repr(x) for x in rez] == ["J♠", "J♣", "A♠", "K♠", "Q♠", "10♠", "9♠"]

    card = Card("J", "S")
    rez = d.get_card_ranks_by_trump_and_led("C", card)
    assert [repr(x) for x in rez] == ["J♣", "J♠", "A♣", "K♣", "Q♣", "10♣", "9♣"]

    card = Card("J", "D")
    rez = d.get_card_ranks_by_trump_and_led("H", card)
    assert [repr(x) for x in rez] == ["J♥", "J♦", "A♥", "K♥", "Q♥", "10♥", "9♥"]

    card = Card("J", "H")
    rez = d.get_card_ranks_by_trump_and_led("D", card)
    assert [repr(x) for x in rez] == ["J♦", "J♥", "A♦", "K♦", "Q♦", "10♦", "9♦"]
Exemple #4
0
 def get_card_ranks_by_trump_and_led(self, trump, led_card):
     """
     :param trump: [S|H|D|C]
     :param led_card: Card
     :return: list of card ranks for the hand
     """
     led_suit = led_card.suit
     lst_extra = []
     if trump is not None:
         left_bower = Card(card_rank="J",
                           card_suit=suit.d_bower_suits[trump])
         right_bower = Card(card_rank="J", card_suit=trump)
         lst_out = [right_bower, left_bower] + \
                   [Card(**dict(zip(['card_rank', 'card_suit'], x)))
                    for x in itertools.product(self.non_bowers, trump)]
         if not (led_suit == trump or led_card == left_bower):
             lst_extra = self.get_non_trump_led_suit_ranks(trump, led_suit)
     else:
         lst_out = list(itertools.product(self.ranks, led_suit))
     lst_out += lst_extra
     return lst_out
Exemple #5
0
def test_trick_with_trump_led(hand_fixture):
t = Trick()
d = Deck()
p0 = Player(name='matthew', player_id=0)
p1 = Player(name='sean', player_id=1)
p2 = Player(name='sean', player_id=2)
p3 = Player(name='sean', player_id=3)
h = Hand(players=[p0, p1, p2, p3], deal_style=[3, 2, 3, 2], deck=d)
t.add_card(player=p0, card=p0.cards[0], hand=h)
t.add_card(player=p1, card=p1.cards[0], hand=h)
t.add_card(player=p2, card=p2.cards[0], hand=h)
t.add_card(player=p3, card=p3.cards[0], hand=h)

    t.add_card()
    t.cards = [Card("10", "S"), Card("10", "H"), Card("10", "D"), Card("10", "C")]
    t.led_suit = "S"
    t.led_rank = "10"
    t.players = [Player(name="Player {}".format(x), player_id=x) for x in [3, 0, 1, 2]]
    hand_fixture.set_trump("H")
    rez = t.score(hand=hand_fixture)
    print(rez)
Exemple #6
0
def test_get_card_ranks_by_trump_and_led_non_bower_led_pass():
    low_rank = 9
    d = Deck(low_rank=low_rank)
    card = Card("A", "S")
    rez = d.get_card_ranks_by_trump_and_led("S", card)
    assert [repr(x) for x in rez] == ["J♠", "J♣", "A♠", "K♠", "Q♠", "10♠", "9♠"]

    # when non-bower suit is led, J should be in the rankings
    # for the non-trump and non-bower suit

    card = Card("A", "D")
    rez = d.get_card_ranks_by_trump_and_led("S", card)
    assert [repr(x) for x in rez] == ["J♠", "J♣", "A♠", "K♠", "Q♠", "10♠", "9♠",
                   "A♦", "K♦", "Q♦", "J♦", "10♦", "9♦"]

    card = Card("A", "H")
    rez = d.get_card_ranks_by_trump_and_led("S", card)
    assert [repr(x) for x in rez] == ["J♠", "J♣", "A♠", "K♠", "Q♠", "10♠", "9♠",
                   "A♥", "K♥", "Q♥", "J♥", "10♥", "9♥"]

    card = Card("A", "C")
    rez = d.get_card_ranks_by_trump_and_led("S", card)
    assert [repr(x) for x in rez] == ["J♠", "J♣", "A♠", "K♠", "Q♠", "10♠", "9♠",
                   "A♣", "K♣", "Q♣", "10♣", "9♣"]
Exemple #7
0
 def __init__(self, low_rank=9):
     self.low_low_rank = 7
     self.high_low_rank = 9
     low_rank = int(low_rank)
     if not self.low_low_rank <= low_rank <= self.high_low_rank:
         raise IllegalArgumentError(
             "Low rank of {} not permitted, must be between {} and {}".
             format(low_rank, self.low_low_rank, self.high_low_rank))
     self.suits = list(suit.names.keys())
     # apparently there are variations that play with 8's or 7's as the low card
     # # low_rank will be used to implement this
     self.ranks = ['A', 'K', 'Q', 'J'
                   ] + [str(x) for x in list(range(10, low_rank - 1, -1))]
     self.non_bowers = [x for x in self.ranks if x != "J"]
     self.cards = [
         Card(**dict(zip(['card_rank', 'card_suit'], x)))
         for x in itertools.product(self.ranks, self.suits)
     ]
     random.shuffle(self.cards)
Exemple #8
0
def test_sort_combines_sorts():
    card = Card("9s", "Diamonds")
    assert card.sort_value() == "3263"
Exemple #9
0
def test_sort_left_jack_bower():
    card = Card("Jc", "Spades")
    assert card.sort_bower_value() == 2
Exemple #10
0
def test_suit_sorts_diamonds_fourth():
    card = Card("9d", "Clubs")
    assert card.sort_suit_value() == 4
Exemple #11
0
def test_suit_sorts_hearts_second():
    card = Card("9h", "Clubs")
    assert card.sort_suit_value() == 2
Exemple #12
0
def test_non_trump_card_outputs_sort_of_two():
    card = Card("Ad", "Spades")
    assert card.sort_trump_value() == 2
Exemple #13
0
def test_trump_card_outputs_sort_of_one():
    card = Card("Ad", "Diamonds")
    assert card.sort_trump_value() == 1
Exemple #14
0
def test_init_deck_low_rank_ok_pass(rank, suit):
    d = Deck(low_rank=rank)
    test_card = Card(card_rank=rank, card_suit=suit)
    assert test_card in d.cards
Exemple #15
0
def test_card_invalid_suit_fail():
    bad = Card("A", "Q")
Exemple #16
0
def test_card_accepts_trump_suit_upon_creation():
    card = Card("Ah", "Diamonds")
    assert card.trump_suit == "d"
Exemple #17
0
def test_decode_suit_decodes_all_suits():
    card = Card("Ah", "Diamonds")
    assert decode_suit("Diamonds") == "d"
    assert decode_suit("Clubs") == "c"
    assert decode_suit("Hearts") == "h"
    assert decode_suit("Spades") == "s"
Exemple #18
0
def test_get_card_ranks_by_trump_and_led_no_trump():
    trump = None
    d = Deck(low_rank=9)
    rez = d.get_card_ranks_by_trump_and_led(trump, led_card=Card("9", "C"))
    print(rez)
Exemple #19
0
def test_card_has_value():
    card = Card("9h", "Clubs")
    assert card.value == '9'
Exemple #20
0
def test_ten_card_has_sort_value_of_five():
    card = Card("Th", "Diamonds")
    assert card.sort_card_value() == 5
Exemple #21
0
def test_suit_sorts_clubs_first():
    card = Card("9c", "Hearts")
    assert card.sort_suit_value() == 1
Exemple #22
0
def test_jack_card_has_sort_value_of_four():
    card = Card("Jh", "Diamonds")
    assert card.sort_card_value() == 4
Exemple #23
0
def test_suit_sorts_spades_third():
    card = Card("9s", "Hearts")
    assert card.sort_suit_value() == 3
Exemple #24
0
def test_queen_card_has_sort_value_of_three():
    card = Card("Qh", "Diamonds")
    assert card.sort_card_value() == 3
Exemple #25
0
def test_sort_jack_bauer_errr_right_jack_bower():
    card = Card("Js", "Spades")
    assert card.sort_bower_value() == 1
Exemple #26
0
def test_king_card_has_sort_value_of_two():
    card = Card("Kh", "Diamonds")
    assert card.sort_card_value() == 2
Exemple #27
0
def test_not_jack_bower():
    card = Card("Jh", "Spades")
    assert card.sort_bower_value() == 3
Exemple #28
0
def test_ace_card_has_sort_value_of_one():
    card = Card("Ah", "Diamonds")
    assert card.sort_card_value() == 1
Exemple #29
0
def test_nine_card_has_sort_value_of_six():
    card = Card("9h", "Diamonds")
    assert card.sort_card_value() == 6
Exemple #30
0
def test_card_outputs_encoded_value():
    card = Card("Ah", "Diamonds")
    assert card.output() == "Ah"