Beispiel #1
0
    def send_play_request(self):
        for i in range(5):
            current_trick_cards = [self.trick_cards.get((i + j) % 5, "") for j in range(0, 5)]
            hand_sizes = [len(self.hands[(i + j) % 5]) for j in range(1, 5)]
            trick_card_history = [(i, lead, trick) for lead, trick in self.tricks_record]

            card_validity = []
            joker_suit_info = None
            for j in range(len(self.hands[i])):
                validity, joker_suits = is_card_valid(
                    current_trick_cards, trick_card_history, self.winning_bid[-1], self.hands[i], j
                )
                card_validity.append(validity)
                joker_suit_info = joker_suit_info or joker_suits

            if joker_suit_info:
                joker_suit_info = list(joker_suit_info)

            if card_validity:
                assert any(card_validity), f"{current_trick_cards}, {self.winning_bid}, {self.hands[i]}"

            bidding_player_name = self.player_names[(self.lead_player + len(self.trick_cards)) % 5]
            if i == (self.lead_player + len(self.trick_cards)) % 5:
                emit(
                    "play request",
                    (current_trick_cards, hand_sizes, card_validity, joker_suit_info, (i - self.lead_player) % 5),
                    room=self.player_sids[i],
                )
            else:
                emit("play status", (current_trick_cards, bidding_player_name, hand_sizes, (i - self.lead_player) % 5), room=self.player_sids[i])
def test_joker_nt_nothing_played():
    trick_cards = ["", "", "", "", ""]
    hand_cards = [
        "joker", "spade_ace", "heart_3", "heart_jack", "club_9", "club_king",
        "spade_jack"
    ]
    previous_tricks = []
    assert is_card_valid(trick_cards, previous_tricks, "n", hand_cards,
                         0) == (True, {"h", "d", "c", "s"})
def test_card_validity():
    trick_cards = ["diamond_6", "", "", "diamond_9", "diamond_5"]
    hand_cards = [
        "spade_7", "spade_ace", "heart_3", "heart_jack", "club_9", "club_king",
        "spade_jack"
    ]

    for i in range(len(hand_cards)):
        assert is_card_valid(trick_cards, None, "c", hand_cards,
                             i) == (True, None)
def test_nothing_played():
    for i in range(10):
        for suit in "scdhn":
            validity, joker_suits = is_card_valid(["", "", "", ""], [], suit,
                                                  test_cards, i)
            assert validity == True
            if test_cards[i] == "joker" and suit == "n":
                assert joker_suits == {"h", "d", "c", "s"}
            else:
                assert joker_suits is None
def test_joker_nt_hearts_finished():
    trick_cards = ["", "", "", "", ""]
    hand_cards = [
        "joker", "spade_ace", "spade_3", "club_9", "club_king", "spade_jack"
    ]
    previous_tricks = [
        (0, 0, ["heart_jack", "heart_2", "heart_6", "heart_7", "heart_8"])
    ]
    assert is_card_valid(trick_cards, previous_tricks, "n", hand_cards,
                         0) == (True, {"h", "d", "c", "s"})
def test_joker_nt_void_suit():
    # Spades already played, and hearts is void
    trick_cards = ["", "", "", "", ""]
    hand_cards = [
        "joker", "spade_ace", "spade_3", "club_9", "club_king", "spade_jack"
    ]
    previous_tricks = [
        (1, 0, ["heart_jack", "spade_2", "heart_6", "heart_7", "heart_8"])
    ]
    assert is_card_valid(trick_cards, previous_tricks, "n", hand_cards,
                         0) == (True, {"d", "c"})
def test_follow_suit():
    valid_indices = {0, 1, 3, 5, 7}
    for i in range(len(test_cards)):
        assert is_card_valid(["", "", "", "heart_7"], None, "h", test_cards,
                             i) == (i in valid_indices, None)