Exemple #1
0
    def _verify(self):
        super()._verify()

        if not self.game.stage.is_discard_draw_stage():
            raise ValueError('not a draw round')
        elif not all(map(
                partial(contains, self.actor.hole), self.discarded_cards,
        )):
            raise ValueError('hole cards not in actor hole')

        if self.drawn_cards is None:
            if not distinct(self.discarded_cards):
                raise ValueError('duplicates in cards')
        else:
            if not all(map(
                    partial(contains, self.population), self.drawn_cards,
            )):
                raise ValueError('cards not in deck or muck if not enough')
            elif any(map(
                    partial(contains, self.actor.seen), self.drawn_cards,
            )):
                raise ValueError('drawing card previously seen')
            elif not distinct(self.discarded_cards + self.drawn_cards):
                raise ValueError('duplicates in cards')
            elif len(self.discarded_cards) != len(self.drawn_cards):
                raise ValueError('cannot match discarded cards with draws')
Exemple #2
0
def rainbow(cards):
    """Check if all cards have a rainbow texture.

    Cards have a rainbow texture when their suits are all unique to each
    other.

    :param cards: The cards to check.
    :return: ``True`` if the cards have a rainbow texture, else
             ``False``.
    """
    return distinct(map(Card.suit.fget, cards))
Exemple #3
0
    def _verify(self):
        super()._verify()

        if not self.game.stage.is_dealing_stage():
            raise ValueError('not a dealing stage')

        if self.cards is not None:
            if not all(map(partial(contains, self.game.deck), self.cards)):
                raise ValueError('some or one cards not in deck')
            elif not distinct(self.cards):
                raise ValueError('duplicates in cards')
            elif len(self.cards) != self.deal_count:
                raise ValueError(f'number of deals not {self.deal_count}.')
    def verify(self, game):
        if game.nature.can_deal_hole():
            assert game.nature.can_deal_hole(
                sample(
                    game.deck,
                    game.nature.deal_hole_count,
                ))
            assert not game.nature.can_deal_hole(
                sample(
                    game.deck,
                    game.nature.deal_hole_count + 1,
                ))

        if game.nature.can_deal_board():
            assert game.nature.can_deal_board(
                sample(
                    game.deck,
                    game.nature.deal_board_count,
                ))
            assert not game.nature.can_deal_board(
                sample(
                    game.deck,
                    game.nature.deal_board_count + 1,
                ))

        for player in game.players:
            if player.can_fold():
                assert player.bet < max(map(PokerPlayer.bet.fget,
                                            game.players))

            if player.can_bet_raise():
                assert player.can_bet_raise(player.bet_raise_min_amount)
                assert player.can_bet_raise(player.bet_raise_max_amount)
                assert not player.can_bet_raise(player.bet_raise_min_amount -
                                                1)
                assert not player.can_bet_raise(player.bet_raise_max_amount +
                                                1)

            if player.can_discard_draw():
                assert player.can_discard_draw(player.hole)
                assert not game.deck or not player.can_discard_draw(game.deck)

                if len(game.deck) < len(player.hole):
                    population = set(chain(game.deck, game.muck)) \
                                 - set(player.seen)
                    cards = set(player.seen) & set(game.muck)

                    if cards:
                        end = max(len(player.hole) - len(cards), 0)
                        assert not player.can_discard_draw(
                            player.hole,
                            chain(
                                cards,
                                tuple(chain(game.deck, game.muck))[:end],
                            ))
                else:
                    population = game.deck

                    if game.muck:
                        end = max(len(player.hole) - len(game.muck), 0)
                        assert not player.can_discard_draw(
                            player.hole,
                            chain(game.muck, game.deck[:end]),
                        )

                assert player.can_discard_draw(
                    player.hole, sample(
                        tuple(population),
                        len(player.hole),
                    ))
            else:
                assert not player.can_discard_draw(player.hole)

                if len(game.deck) < len(player.hole):
                    population = set(chain(game.deck, game.muck)) \
                                 - set(player.seen)
                else:
                    population = game.deck

                assert not player.can_discard_draw(
                    player.hole, sample(
                        tuple(population),
                        len(player.hole),
                    ))

            if player.can_showdown():
                assert player.can_showdown(False)
                assert player.can_showdown(True)
            else:
                assert not player.can_showdown(False)
                assert not player.can_showdown(True)

            assert set(player.seen) >= set(player.hole)

        assert sum(map(PokerPlayer.total.fget, game.players)) + game.pot \
               == sum(map(PokerPlayer.starting_stack.fget, game.players))
        assert sum(game.side_pots) == game.pot
        assert distinct(
            chain(
                game.deck, game.muck,
                chain.from_iterable(map(
                    PokerPlayer.hole.fget,
                    game.players,
                ))))

        if game.is_terminal():
            assert game.pot == 0
Exemple #5
0
 def _is_valid(cls, cards):
     return distinct(map(Card.rank.fget, cards)) and rainbow(cards)