コード例 #1
0
ファイル: game.py プロジェクト: kmorrison/crib
    def do_pegging(self, player_one_has_crib):
        player_idx_to_start = 0
        if player_one_has_crib:
            player_idx_to_start = 1

        all_cards_pegged = set()
        cards_in_pegging_round = []
        gos = [False, False]
        while len(all_cards_pegged) < 8 and not self._game_over():
            peg_card = self.bots[player_idx_to_start].ask_for_next_peg_card(
                list(cards_in_pegging_round),
                list(all_cards_pegged),
            )
            if peg_card is None:
                gos[player_idx_to_start] = True
                if sum(gos) == 2:
                    gos = [False, False]
                    cards_in_pegging_round = []
                    self.scores[player_idx_to_start] += 1
                player_idx_to_start ^= 1
                continue

            # TODO: Check if cheating
            all_cards_pegged.add(peg_card)
            cards_in_pegging_round.append(peg_card)
            # TODO: Score card
            pegging_sum = cribbage.sum_cards_for_pegging(cards_in_pegging_round)
            assert pegging_sum <= 31
            if pegging_sum == 31:
                gos = [False, False]
                cards_in_pegging_round = []
                self.scores[player_idx_to_start] += 2
            player_idx_to_start ^= 1
コード例 #2
0
ファイル: test_ai.py プロジェクト: kmorrison/crib
 def ask_for_next_peg_card(self, cards_in_pegging_round, all_cards_pegged):
     current_sum = cribbage.sum_cards_for_pegging(cards_in_pegging_round)
     cards_not_played = set(self.hand.cards) - set(all_cards_pegged)
     cards_can_play = [card for card in cards_not_played if cribbage.VALUES[card.rank] < (31 - current_sum)]
     if not cards_can_play:
         return None
     return sorted(cards_can_play)[-1]