Project focuses on a Blackjack game implementation using the Python library Gymnasium. The game environment can be used for reinforcement learning projects.
Currently, there are two versions of the Blackjack environment:
- Blackjack4game-v0 - basic implementation with discrete action space
- Blackjack4game-v1 - implementation featuring betting at the beggining of a game - where an agent can decide what percentage of money to bet (continuous action space)
Blackjack rules
Note: The current implementation does not support SPLIT moves. Besides that, most other standard rules apply. There are still areas for improvement - some of them are marked with #TODO comment in the code.
- Python
configuration file (pyproject.toml)
-
Clone the repository:
git clone https://github.com/jakseluz/blackjack_gym.git cd blackjack_gym -
pip install -e .- (in the project root directory; see the point above)
-
Use the environment in a selected version:
import gymnasium as gym import blackjack_env # version 0 (see README description above) env = gym.make("Blackjack4game-v0", render_mode="terminal") # render_mode="human" if you want to use GUI (or None if neither) # version 1 # env = gym.make("Blackjack4game-v1", render_mode="terminal") # use it like other gymnasium environments;
-
To see how to use the gymnasium environment, see: gymnasium documentation.
-
Check ./notebooks/ directory for the tutorial/ information:
- ./notebooks/main.ipynb file - Blackjack4game-v0 tutorial ./notebooks/bet_example.ipynb file - additional info about Blackjack4game-v1 version
-
More detailed analysis available (in Polish) in
- ./notebooks/report.ipynb
- ./notebooks/report_continuous_env.ipynb
-
Result files used in learning etc. are located in ./results/:
For questions or contributions, please open an issue or submit a pull request!

