The Blackjack Predictor is an innovative terminal-based application that combines artificial intelligence
with a simulated blackjack game to enhance player decision-making.
By leveraging a deep learning model trained on historical game data,
this application predicts the outcomes of blackjack hands,
providing users with actionable insights based on their current game state.
After inputting their
first card and second card, as well as the dealer card,
the program displays the recommended course of action at the given point in time,
along with the current win/loss probability and a hi-lo count of the cards.
The recommended actions are based on this chart (show chart of blackjack hands),
which describes the three outcomes the program will assign your current hand to: a hard hand,
a soft hand, and a pair.
The project begins with the collection of historical gameplay data from a CSV file (blackjack.csv
). Each record includes details such as player card values, the dealer’s visible card, and the outcome of the game (Win or Loss). The data undergoes a transformation process to create a cleaned dataset (modified_blackjack.csv
), which involves:
tf.data
API to create a streamlined pipeline for efficient loading and preprocessing of the dataset.The features used for the model input include:
This structured approach ensures that the model is trained on relevant features that influence the game outcome. TensorFlow's make_csv_dataset
method is employed to generate batches, facilitating real-time training and inference.
The core of the Blackjack Predictor lies in its deep learning model, designed using TensorFlow and Keras. The model architecture is as follows:
The model utilizes categorical cross-entropy as the loss function, which is appropriate for multi-class classification tasks, and an Adam optimizer is employed to adjust the model weights efficiently during training, enhancing convergence speed.
The model is trained on the processed dataset using TensorFlow’s built-in training routines. Key aspects of training include:
If a pre-trained model exists, it is loaded for predictions. If not, the model undergoes training from scratch.
The Blackjack game integrates the model seamlessly into gameplay mechanics:
The model's predictions deliver insights into winning probabilities and potential game outcomes. For example, if the model predicts a 70% chance of winning, players may be more inclined to continue playing rather than folding. By integrating AI predictions, the Blackjack Predictor not only entertains but also educates users on optimal strategies in blackjack.