Esempio n. 1
0
    def render_table(self):
        """Print out the players and the hands of cards (if they've been dealt)."""
        print(header('TABLE'))

        # Print the dealer's hand. If `hide_dealer` is True, don't factor in the dealer's buried card.
        num_dashes = len(self.dealer.name) + 6
        print(
            f"{'-'*num_dashes}\n   {self.dealer.name.upper()}   \n{'-'*num_dashes}\n"
        )
        if self.dealer.hand:
            print(self.dealer.hand.pretty_format(hide=self.hide_dealer))
        else:
            print('No hand.')

        # Print the gambler's hand(s)
        num_dashes = len(self.gambler.name) + 6
        print(
            f"\n{'-'*num_dashes}\n   {self.gambler.name.upper()}   \n{'-'*num_dashes}\n\nBankroll: {money_format(self.gambler.bankroll)}  |  Auto-Wager: {money_format(self.gambler.auto_wager)}\n"
        )
        if self.gambler.hands:
            for hand in self.gambler.hands:
                print(hand.pretty_format())
                print()
        else:
            print('No hands.')
Esempio n. 2
0
def get_interactive_configuration(default):
    """Get game configuration data for the interactive game mode."""
    if default:
        # Default values
        name = 'Gambler'
        bankroll = 1000.0
        auto_wager = 100.0
        number_of_decks = 3
    else:
        # User-entered values
        print(header('GAME SETUP'))
        name = input("Enter a player name => ")
        bankroll = get_user_input("Enter a bankroll amount => $",
                                  float_response)
        auto_wager = get_user_input("Enter an auto-wager amount => $",
                                    float_response)
        number_of_decks = get_user_input(
            "Enter the number of decks to use => ", int_response)

    # Serialize and return configuration
    return {
        'gambler': {
            'name': name,
            'bankroll': bankroll,
            'auto_wager': auto_wager
        },
        'shoe': {
            'number_of_decks': number_of_decks
        },
        'gameplay': {
            'strategy': UserInputStrategy,
            'verbose': True,
            'max_turns': None
        }
    }
Esempio n. 3
0
    def render_game_over(self):
        """Print out a final summary message once the game has ended."""
        # Show game over message
        print(header('GAME OVER'))

        # Print a final message after the gambler is finished
        if self.gambler.auto_wager == 0 or self.turn == self.max_turns:
            action = f"{self.gambler.name} cashed out with bankroll: {money_format(self.gambler.bankroll)}."
            message = 'Thanks for playing!'
        else:
            action = f"{self.gambler.name} is out of money."
            message = 'Better luck next time!'

        print(f"{action}\n\n{message}")
Esempio n. 4
0
 def render_action(self):
     """Print out the action section that the user interacts with."""
     print(header('ACTION'))
     if self.dealer_playing:
         print('Dealer playing turn...')
Esempio n. 5
0
 def render_activity(self):
     """Print out the activity log for the current turn."""
     print(header('ACTIVITY'))
     for message in self.activity:
         print(message)
Esempio n. 6
0
from blackjack.game_setup import setup_game

if __name__ == '__main__':

    # Command line args
    parser = ArgumentParser()
    parser.add_argument(
        '-d',
        '--default',
        help='Use the default game setup instead of manually configuring',
        action='store_true')
    args = parser.parse_args()

    # Clear the terminal screen.
    clear()

    # Load the game configuration (in this case, the 'interactive' configuration).
    configuration = get_interactive_configuration(args.default)

    # Set up the game using the loaded configuration.
    game = setup_game(configuration)

    # Play the game.
    game.play()

    # Analyze the results of the game.
    print(header('ANALYTICS'))
    analyzer = SingleGameAnalyzer(**game.metric_tracker.serialize_metrics())
    analyzer.print_summary()
    analyzer.create_plots()