CardSharp
A Python framework for simulating and analyzing card games. Currently supports Blackjack, War, High Card, Baccarat, Dragon Tiger, and Durak.
Installation
git clone https://github.com/mmichie/cardsharp.git
cd cardsharp
uv sync
Usage
Simulation
# Run 10,000 blackjack games with visualization
uv run python cardsharp/blackjack/blackjack.py --simulate --num_games 10000 --vis
# Compare strategies (Basic, Counting, Aggressive, Martingale)
uv run python cardsharp/blackjack/blackjack.py --analysis --num_games 5000
# Performance profiling
uv run python cardsharp/blackjack/blackjack.py --simulate --profile --num_games 1000
Interactive Play
# Console blackjack
uv run python cardsharp/blackjack/blackjack.py --console
# Full CLI game with options
uv run python examples/cli_blackjack.py --players 3 --bankroll 500 --rounds 5
Examples
uv run python examples/async_api_demo.py # Async API with event-driven flow
uv run python examples/blackjack_engine_demo.py # Engine with immutable state
uv run python examples/adapter_demo.py # Platform adapter system
uv run python examples/modern_blackjack_ui.py # Streamlit web UI
See examples/ for the full set of demos.
Architecture
CardSharp uses an event-driven architecture with immutable state transitions:
- Events -- Components communicate through pub/sub (
cardsharp/events/) - Immutable State -- Game state transitions via pure functions (
cardsharp/state/) - Engines -- Game logic per game type (
cardsharp/engine/,cardsharp/blackjack/, etc.) - Adapters -- Platform-specific rendering and input (
cardsharp/adapters/) - APIs -- High-level sync/async interfaces (
cardsharp/api/)
Testing
uv run pytest # Run all tests
uv run pytest --cov=cardsharp # With coverage
uv run pytest tests/api/test_event_cleanup.py -v # Specific module
uv run pytest -n auto # Parallel
License
MIT
Release files for cardsharp 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cardsharp-0.6.0.tar.gz | 418.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cardsharp-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 660.3 kB
Release files / cardsharp-0.6.0.tar.gz
| Download URL | cardsharp-0.6.0.tar.gz |
|---|---|
| Size | 418.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
659c5300719b065c469b96b4201457c6fe8c94ae1a792ae63400b9affb5ea07b
|
|
BLAKE2b-256 checksum How to use checksums |
fea489bae8934a732710944fa433ce8d46d9a1d521a27ff55d476a893842fafc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / cardsharp-0.6.0-py3-none-any.whl
| Download URL | cardsharp-0.6.0-py3-none-any.whl |
|---|---|
| Size | 241.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cfe27ea8d382da072c5beb8d07627a03804cb8c0f3867b38b5c7e5ee834fb244
|
|
BLAKE2b-256 checksum How to use checksums |
087a3ff0f33bc6f2c87cd14109bad713ea160fd8d60db0f0820c6e6ff31c5bb7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|