def show_game_winners(initial_players, winners_names): """Display winner(s) of the game and ending chips of each player. Args: initial_players (list): all players who began the game winners_names (list): name of poker winner(s) """ # Sort player by chips remaining players = sorted(initial_players, key=lambda player: player.chips, reverse=True) clear_screen() for i in range(len(players)): player_name = f'{players[i].name:<12}' chips = f'Chips:{players[i].chips:>6}' print(f"{player_name:>44}{chips:>18}") print('\n' * 5) if len(winners_names) == 1: winners_str = winners_names[0] elif len(winners_names) == 2: winners_str = f'{winners_names[0]} and {winners_names[1]}' else: winners_str = '' for i in range(len(winners_names)): if i == len(winners_names) - 1: winners_str += f'and {winners_names[i]}' else: winners_str += f'{winners_names[i]}, ' print(f' >>> {winners_str} won the game!') print(big_text.game_over) print('\n')
def prompt_for_name() -> str: """Prompts user for their name.""" clear_screen() print(big_text.welcome) print('\n' * 4) name = '' while not name.strip(): name = input('What is your name? ') return name
def prompt_for_number_computer_players() -> int: clear_screen() print(big_text.settings) print('\n' * 4) error_message = '\nMust choose between 1 to 5 computer players.' num_computer_players = 0 while num_computer_players < 1 or num_computer_players > 5: try: num_computer_players = int( input('How many computer players? (up to 5) ')) if num_computer_players < 1 or num_computer_players > 5: print(error_message) except ValueError: print(error_message) return num_computer_players
def prompt_for_starting_chips() -> int: clear_screen() print(big_text.settings) print('\n' * 4) error_message = '\nMust choose between 100 and 999,999 chips.' starting_chips = 0 while starting_chips < 100 or starting_chips > 999999: try: chips = input( 'How many chips to start with? (between 100 and 999,999) ') starting_chips = int(chips.replace(',', '')) if starting_chips < 100 or starting_chips > 999999: print(error_message) except ValueError: print(error_message) return starting_chips
def show_table(initial_players: list[Player], table: Table, time: float = 0): """Update display with player's stats, community, blinds, and pot. Parameters: initial_players (list): all players who began the game table (__main__.Table): the poker table time (float): amount of time to pause the game """ clear_screen() show_player_stats(initial_players) print('\n') show_community(table.community) print() show_blinds(table) show_pots(table.pots) print('\n\n') sleep(time)
def prompt_for_big_blind(min_blind: int, max_blind: int) -> int: clear_screen() print(big_text.settings) print('\n' * 3) print('Last question!') error_message = f'\nBig Blind amount must be between {min_blind:,} - {max_blind:,}, ' \ f'or game will be too long or too short. ' big_blind = 0 while big_blind < min_blind or big_blind > max_blind: try: blind = input( f'How much should the Big Blind amount be? (between {min_blind:,} and {max_blind:,}) ' ) big_blind = int(blind.replace(',', '')) if big_blind < min_blind or big_blind > max_blind: print(error_message) except ValueError: print(error_message) return big_blind
def show_showdown_results(initial_players, table, hand_winners, showdown_players, pot_num): """Update display and show the winner of a particular pot in the showdown. Parameters: initial_players (list): all players who began the game table (__main__.Table): the poker table hand_winners (list): players who won the pot showdown_players (list): all players who participated in the showdown pot_num (int): which pot is currently being displayed """ clear_screen() show_player_stats(initial_players, isShowDown=True) print('\n') show_community(table.community) show_pots(table.pots) print('\n\n\n') show_pot_winners(hand_winners, showdown_players, pot_num) print() input("Press any key to continue....")