Esempio n. 1
0
 def check_for_payout(self, player: Player) -> bool:
     """
     This function checks to see if a single player (not a dealer) has gotten blackjack or busted.
     If they have, then return out_of_game=True for 'removal from dealt-in players logic'
     """
     out_of_game: bool = False
     (is_blackjack, payout_rate) = BlackJack.is_blackjack(player)
     if is_blackjack:
         # Dealer pays out to the player
         # assume rounding down is house cut
         payout_value: int = int(payout_rate * player.pot.stack_value)
         n_payout_chips: Dict[str, int] = ChipStack.get_chips_from_amount(
             payout_value, denom_pref='high')
         self.dealer.payout_chips(player.pot, n_payout_chips)
         # Remove player from dealt_in list
         self.dealt_in_players.remove(player.name)
         print('{0} has gotten blackjack and wins ${1}'.format(
             player.name, payout_value))
         out_of_game = True
     elif BlackJack.is_bust(player):
         # Player pays out to dealer
         player.payout_all(self.dealer.pot)
         # Remove player from dealt_in list
         self.dealt_in_players.remove(player.name)
         print('{0} has busted and loses ${1}'.format(
             player.name, player.pot.stack_value))
         out_of_game = True
     return out_of_game
Esempio n. 2
0
    def check_for_payouts(self, end_of_hand: bool = False) -> None:
        """
        This function checks to see all players have gotten blackjack or busted.
        If they have, then they are removed from the dealt-in players list and payouts go accordingly.
        Additionally, if its the end of the hand, the scores vs. the dealer are checked and paid put
        """
        max_dealer_hand_value: int = max(BlackJack.get_hand_value(self.dealer))
        dealer_busted: bool = True if max_dealer_hand_value > 21 else False
        for player_name in self.dealt_in_players:
            if end_of_hand:
                # This will be used later for checking payouts at the end of a hand
                max_player_hand_value: int = max(
                    BlackJack.get_hand_value(self.players[player_name]))

            out_of_game = self.check_for_payout(self.players[player_name])
            if out_of_game:
                continue  # don't continue to check other conditions

            if end_of_hand and (max_player_hand_value > max_dealer_hand_value
                                or dealer_busted):
                # Dealer pays out to the player
                # assume rounding down is house cut
                payout_value: int = int(
                    1.5 * self.players[player_name].pot.stack_value)
                n_payout_chips: Dict[str,
                                     int] = ChipStack.get_chips_from_amount(
                                         payout_value, denom_pref='high')
                self.dealer.payout_chips(self.players[player_name].pot,
                                         n_payout_chips)
                # Remove player from dealt_in list
                self.dealt_in_players.remove(player_name)
                # Print the results
                self.players[player_name].view_hand(self.dealer,
                                                    all_visible=True)
                if dealer_busted:
                    print('Dealer busts so {0} wins ${1}'.format(
                        player_name, payout_value))
                else:
                    print('{0} beat the dealer and wins ${1}'.format(
                        player_name, payout_value))
            elif end_of_hand and not dealer_busted and (max_player_hand_value <
                                                        max_dealer_hand_value):
                # Player pays out to dealer
                self.players[player_name].payout_all(self.dealer.pot)
                # Remove player from dealt_in list
                self.dealt_in_players.remove(player_name)
                # Print the results
                self.players[player_name].view_hand(self.dealer,
                                                    all_visible=True)
                print(
                    'Dealer did not bust and beats {0}\'s hand. {0} loses ${1}'
                    .format(player_name, self.players[player_name].bet_value))
            elif end_of_hand and not dealer_busted and (
                    max_player_hand_value == max_dealer_hand_value):
                # Player does not lose their money, but doesn't get paid out.
                self.players[player_name].payout_all(
                    self.players[player_name].pot)  # return the money from pot
                # Remove player from dealt_in list
                self.dealt_in_players.remove(player_name)
                print('Dealer ties {0}\'s hand. {0} is returned ${1}'.format(
                    player_name, self.players[player_name].bet_value))