<jupyter_start><jupyter_text>Blackjack Output Visualizations<jupyter_code>import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

plt.style.use('seaborn-dark')<jupyter_output><empty_output><jupyter_text>The Blackjack simulator is a command line application. It allows one to specify the type of game to play, and how my games to run the simulation on. When complete, it writes the results to a CSV file called `{GameType}.csv`.<jupyter_code>!python blackjack.py --help<jupyter_output>usage: blackjack.py [-h] [--games GAMES_TO_PLAY]
                    [--game-type {FixedPolicyGame,QLearningPolicyGame,OptimizedPolicyGame}]

Plays games of Blackjack

options:
  -h, --help            show this help message and exit
  --games GAMES_TO_PLAY
                        The number of games to play. Default 1000.
  --game-type {FixedPolicyGame,QLearningPolicyGame,OptimizedPolicyGame}
                        The type of game to play. Default: FixedPolicyGame<jupyter_text>Fixed Policy Game My initial fixed policy has the player hitting until they could bust (e.g. hit under 12).<jupyter_code>!python blackjack.py --game-type FixedPolicyGame --games 1000
fixed_game_df = pd.read_csv('FixedPolicyGame.csv')
fixed_game_df.head()
sns.countplot(x=fixed_game_df['winner'], order=fixed_game_df['winner'].value_counts().index)
plt.title('Winner Counts of Initial Fixed Game', fontsize=15)
sns.displot(data=fixed_game_df, x='dealer_score', col='winner', hue='winner', col_order=fixed_game_df['winner'].value_counts().index)<jupyter_output><empty_output><jupyter_text>Observations:* The dealer won more often with scores closer to 21.* The dealer lost most often with a score around 16 and the loss rate trailed off in both directions. This can be explained by the higher win percentage as the score got higher and a greater chance of hitting on lower scores.<jupyter_code>sns.displot(data=fixed_game_df, x='player_score', col='winner', hue='winner')<jupyter_output><empty_output><jupyter_text>Observations:* The player won more often when their score approached 21.* The player lost most often when staying on 14 as the fixed policy dictated.  Q-Lerarning Policy Game<jupyter_code>!python blackjack.py --game-type QLearningPolicyGame --games 1000<jupyter_output>Playing 1000 games of type QLearningPolicyGame...

Results after 1000 games of type QLearningPolicyGame:
	Dealer won: 674
	Player won: 326
state: 2 - best action: Action.STAND
state: 3 - best action: Action.STAND
state: 4 - best action: Action.HIT
state: 5 - best action: Action.HIT
state: 6 - best action: Action.HIT
state: 7 - best action: Action.HIT
state: 8 - best action: Action.HIT
state: 9 - best action: Action.HIT
state: 10 - best action: Action.HIT
state: 11 - best action: Action.HIT
state: 12 - best action: Action.HIT
state: 13 - best action: Action.HIT
state: 14 - best action: Action.HIT
state: 15 - best action: Action.HIT
state: 16 - best action: Action.HIT
state: 17 - best action: Action.STAND
state: 18 - best action: Action.STAND
state: 19 - best action: Action.STAND
state: 20 - best action: Action.STAND
state: 21 - best action: Action.STAND<jupyter_text>The q-learning algorithm determined it was best to hit until 17 (given the dealer rules). Next, I implement an optimized policy based on this and observe the results after another 1000 games.  Optimized Policy Game<jupyter_code>!python blackjack.py --game-type OptimizedPolicyGame --games 1000
optimized_game_df = pd.read_csv('OptimizedPolicyGame.csv')
optimized_game_df.head()
sns.countplot(x=optimized_game_df['winner'], order=optimized_game_df['winner'].value_counts().index)
plt.title('Winner Counts of Optimized Game', fontsize=15)
order = optimized_game_df['winner'].value_counts().index
sns.displot(data=optimized_game_df, x='dealer_score', col='winner', hue='winner', col_order=order, hue_order=order)
sns.displot(data=optimized_game_df, x='player_score', col='winner', hue='winner', col_order=order, hue_order=order)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09870064967516241, 'fraction_numerical': 0.02048975512243878, 'mean_word_length': 5.21583850931677, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '476486', 'license': 'Unlicense', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1233, 'n_words': 404, 'path': 'blackjack.ipynb', 'repo_name': 'jstrassburg/cs6330-project-1-reinforcement-learning', 'size': '4002'}