A text-based Blackjack game with ASCII art and smart betting system
Project description
๐ Blackjack Game
A Python implementation of Blackjack (21) featuring ASCII card art, a chip betting system, and Object-Oriented Programming principles.
Features
- Complete Blackjack game logic
- Beautiful ASCII card visualization
- Chip-based betting system (start with 200 chips)
- Automatic screen clearing for better user experience
- Input filtering to prevent paste attempts and ensure clean gameplay
- Blackjack Basic Strategy implemented for Dealer
- Player vs Dealer gameplay
- Clean, modular OOP design
- Fully installable package via pip
- Command-line interface
Installation
Using a virtual environment (recommended)
# Create a virtual environment
python -m venv venv
# Activate the environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install the game from PyPI
pip install gabrielchaves-blackjack
Updating the game
# Upgrade to the latest version
pip install --upgrade gabrielchaves-blackjack
From source (optional)
# Clone or download the repository
cd blackjack
# Install in development mode
pip install -e .
# Or install normally
pip install .
After installation
# Run the game
blackjack
How to Play
- Run the
blackjackcommand after installation - Place your bet - Choose from 1, 5, 10, 25, or 50 chips
- You'll receive 2 cards, the dealer receives 2 (one hidden)
- Choose Hit (take a card) or Stand (keep your current hand)
- Try to get as close to 21 as possible without going over
- The dealer plays automatically (follows Basic Strategy)
- The highest hand wins!
- Win: Get your bet back doubled
- Lose: Lose your bet
- Push: Bet is returned on a tie
- Game continues until you run out of chips or choose to quit
Betting System
- Start with 200 chips
- Betting options: 1, 5, 10, 25, or 50 chips
- Win your bet amount on a win
- Lose your bet amount on a loss
- Bet returned on a push (tie)
- Game ends when you run out of chips
- Option to start a new game with 200 chips
ASCII Visualization
Cards are displayed in beautiful ASCII art:
โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
โA โ โK โ โQ โ
โ โ โ โ โ โ
โ โ โ โ โฅ โ โ โฆ โ
โ โ โ โ โ โ
โ Aโ โ Kโ โ Qโ
โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
The dealer's hidden card appears as:
โโโโโโโโโโโ
โโโโโโโโโโโ
โโโโโโโโโโโ
โโโโโโโโโโโ
โโโโโโโโโโโ
โโโโโโโโโโโ
โโโโโโโโโโโ
Usage as Module
from blackjack import BlackJackGame
# Create and play a game
game = BlackJackGame()
game.play_round()
Card Art Demo
To see cards in ASCII art:
python demo_ascii_cards.py
Architecture
Design Principles
This implementation follows solid OOP principles:
- Encapsulation: Each class manages its own data and behavior
- Single Responsibility: Each class has a clear, focused purpose
- Composition: Game uses Deck, Players use Hands
- Inheritance: Dealer extends Player with specific rules
- Separation of Concerns: Input handling, game logic, and display are separated
Class Structure
- Card: Represents a single playing card (with ASCII art)
- Deck: Manages a 52-card deck (creation, shuffling, dealing)
- Hand: Manages a collection of cards and calculates values
- Player: Represents a player with a hand and chips
- Dealer: Extends Player with specific dealer rules and Basic Strategy
- BlackJackGame: Orchestrates game flow and logic
- CLI: Command-line interface with betting flow
- InputHandler: Filtered input system to prevent paste attempts
Key Implementation Details
Card Values
- Number cards (2-10): Face value
- Face cards (J, Q, K): 10 points
- Aces: 11 points (no soft/hard handling in current version)
Dealer Strategy
The dealer follows Blackjack Basic Strategy:
- Hard hands:
- Hits on 16 or less
- Stands on 17 or more
- Soft hands (with Ace):
- Complex strategy based on up card
- Optimized for realistic gameplay
Input Security
- Paste prevention: All paste attempts (Ctrl+V, Cmd+V, right-click) are blocked
- Character filtering: Only valid single-character inputs accepted
- Clean experience: Invalid inputs are silently ignored
Improvements Implemented
โ ASCII card art: Beautiful, immersive visualization โ Chip betting system: Realistic casino-style betting โ Screen clearing: Clean, professional interface โ Smooth animations: Strategic pauses for better experience โ Emojis: Fun visual feedback โ Input filtering: Prevents cheating and ensures fair play โ Cross-platform compatibility: Works on Windows, Linux, and macOS โ UTF-8 encoding handling: Proper character display across systems
Testing
# Run tests
python -m pytest tests/
๐ Requirements
- Python 3.8+
prompt-toolkitfor enhanced input handling
Game Rules
- Get as close to 21 as possible without going over
- Face cards (J, Q, K) are worth 10 points
- Aces are worth 11 points
- Number cards are worth their face value
- Going over 21 is a "bust" - you lose automatically
- Dealer must hit on 16 or less
- If both player and dealer have the same value, it's a "push" (tie)
License
MIT License
Author
Gabriel Chaves
Version: 1.0.5
Enjoy the game! ๐
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gabrielchaves_blackjack-1.0.5.tar.gz.
File metadata
- Download URL: gabrielchaves_blackjack-1.0.5.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
824f60aadf64bd1f6ef5e1e7919cf43eca4fc59079e3709c6504da7d3cc0a42f
|
|
| MD5 |
6f3dfb9184871f1de046d5c2a818d3df
|
|
| BLAKE2b-256 |
1e566c577e65bad6fdbada3d7b63924aa30329348e2444bce4749ff8aae11590
|
File details
Details for the file gabrielchaves_blackjack-1.0.5-py3-none-any.whl.
File metadata
- Download URL: gabrielchaves_blackjack-1.0.5-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19bff1c3b854b488546a171863ad6adfae8e41d4a6ea2a773dc7d6e5896fba71
|
|
| MD5 |
76ec2c8f39ff66a900451740e1f7bdd6
|
|
| BLAKE2b-256 |
718472d2e98a59a9121463a9b42c56ed6754ab87109a91e69e7b3447f45faf2a
|