Пример #1
0
    def reset_game(self):
        '''
        creates new game: 0 pot, set players, new deck, clear common cards,
        new dealer
        '''

        self.last_bet = 0

        self.common_cards = []
        # shuffle a new deck
        self.deck = cards.new_deck()

        # new hand
        self.hand_started = False

        self.pot = 0
        for player in self.players:
            player.chips += player.chips_in_hand

        # reset each player
        for player in self.players:
            if not player.left_seat:
                player.new_game()
        if self.game_name == "Man-Mouse":
            self.next_active_player()
Пример #2
0
    def new_game(self, game_name, from_button):
        '''
        creates new game: 0 pot, set players, new deck, clear common cards,
        new dealer
        '''
        if self.pot != 0:
            raise ClientError('WARNING: pot must be empty')

        self.acey_ducey_deals = 0
        self.last_bet = 0
        self.game_name = game_name
        # reset each player
        for player in self.players:
            player.new_game()

        self.common_cards = []
        # shuffle a new deck
        self.deck = cards.new_deck()

        self.discard_mode = False
        # new hand
        self.hand_started = False
        self.wait_for_card = False
        if self.dealer is not None and self.game_name == "Select Game":  # vs. from new game btn
            # pick a new dealer
            self.next_dealer()
        # pick the first active player
        self.active_player = self.next_player_after(self.dealer)
        if from_button:
            self.game_count += 1
Пример #3
0
 def __init__(self):
     self.players = []
     self.deck = cards.new_deck()
     self.pot = 0
     self.hand_started = False
     self.discard_mode = False
     self.dealer = None
     self.active_player = None
     self.common_cards = []
     self.last_bet = 0
     self.game_name = "Select Game"
     self.chips_bet_in_round = 0  # reset when deal all or deal common
     self.show_chip_totals = False
     self.card_back_num = 1
     self.current_game = None
     self.wait_for_card = False
     self.wait_for_bet = False
     self.reshuffled = False
     self.history = []
     self.game_count = 0
     self.connections = []
     self.acey_ducey_deals = 0
     self.message = ""
     self.instructions = "will show instructions for chosen game"
     self.player_id_connections = defaultdict(list)
     self.client_update_event = asyncio.Event()
     self.backup_event = asyncio.Event()
     self.backup_file = Path(tempfile.gettempdir()) / 'card_game_state.json'
Пример #4
0
    def collect_shuffle(self):
        '''collect cards and reshuffle deck
        used for Man-Mouse and Dirty Gertie'''

        for player in self.players:
            player.clear_hand()
            if self.game_name == "Man-Mouse":
                if not player.left_seat:
                    player.in_hand = True  # put everyone that was out back in
                    player.in_man_mouse = False
        self.common_cards = []
        self.deck = cards.new_deck()  # shuffle a new deck
Пример #5
0
    def one_card(self, up):
        '''
        deals one card to one player
        :param up: True if up card, False if down card
        '''
        # don't deal card if acey ducey first card is ace and btn not yet pressed

        self.game_state.wait_for_card = False

        if not self.game_state.wait_for_card and self.player.id == self.game_state.dealer.id:
            self.game_state.hand_started = True
            num_cards_in_hand = len(self.game_state.active_player.hand)

            # don't deal 3rd card unless player bets:
            if self.game_state.game_name == "Acey-Ducey" and\
               self.game_state.active_player.chips_in == 0 and\
               num_cards_in_hand == 2:
                self.game_state.wait_for_bet = True
            else:
                self.game_state.wait_for_bet = False

            if not self.game_state.wait_for_bet:

                self.reset_antes_and_chips_in(True)
                card = self.game_state.draw_card()

                self.game_state.active_player.give_card(PlayerCard(card, up))

                if self.game_state.game_name == "Acey-Ducey":
                    # reshuffle when 1 card left (0  incl. in case mistake in dealing was made)
                    if len(self.game_state.deck) == 0 or len(
                            self.game_state.deck) == 1:
                        # shuffle a new deck
                        self.game_state.deck = cards.new_deck()
                        self.game_state.reshuffled = True
                    else:
                        self.game_state.reshuffled = False

                num_cards_in_hand = len(self.game_state.active_player.hand)

                # acedy-ducey - stop if first ace:
                # woolworths stop if 4, 5, or 10

                # booleans:
                is_first_card = num_cards_in_hand == 1
                is_ace = card[0] == "1"
                is_510_up = card[
                    0] in '5T' and self.game_state.active_player.hand[-1].up
                is_34 = card[0] in '34' and self.game_state.active_player.hand[
                    -1].up
                if (is_first_card and is_ace and self.game_state.game_name == "Acey-Ducey") or\
                   (self.game_state.game_name == "Woolworths" and is_510_up) or\
                   (self.game_state.game_name == "Day Baseball" and is_34):
                    self.game_state.wait_for_card = True
                else:
                    self.game_state.wait_for_card = False

                # go to next player unless it's discard mode or if you just completed a 5-card hand in 5-card draw:
                fifth_card = self.game_state.game_name == "5-Card Draw" and num_cards_in_hand == 5

                not_discard = not self.game_state.discard_mode
                not_midnight = self.game_state.game_name != "Midnight Baseball"
                not_acey = self.game_state.game_name != "Acey-Ducey"

                if (not_discard and not_midnight and not_acey) or fifth_card:
                    self.game_state.next_active_player()

                self.game_state.checkpoint('money_or_card')