Project Detail

Blackjack

A Day 11 project from the 100 Days of Code bootcamp, built in two versions to show architectural growth. The original follows the course spec closely in ~75 lines of procedural Python. The advanced version is a complete rebuild with a four-file modular architecture, a 4-deck shoe, a chip-based betting system, casino-style side bets (split, double down, insurance), three difficulty modes, an animated terminal UI with ASCII card art, and a session statistics screen. Both versions launch from a shared root menu and share a single ASCII logo asset.

Software game python OOP CLI terminal terminal-ux dataclasses

Quick Facts

Tech:
Python 3.10+ dataclasses enum typing tty termios random subprocess

Overview

Problem

The Day 11 course brief produces a minimal working game — cards dealt, hit or stand, result printed — but nothing that feels like a real product or demonstrates meaningful Python depth. There is no sense of stakes without chips, no replay incentive, no visual feedback beyond raw score printouts, and no architectural separation between game logic and output. A single flat file with hardcoded print statements is not a portfolio piece, and it doesn't exercise the Python features introduced across the first eleven days of the course in any cohesive way.

Solution

Two versions were built and shipped side by side so the contrast is visible. The original implements the course spec as written. The advanced version enforces a strict four-file separation: config.py holds every constant, blackjack.py contains pure game logic with zero I/O using dataclasses and enums, display.py owns all terminal rendering and animations, and main.py orchestrates the round loop. Chip accounting uses a pre-deduction model — the bet is removed upfront and chip_delta returns what to add back — which keeps split-hand accounting clean. A finite 4-deck shoe with automatic reshuffle replaces the course's infinite random sampling, more closely modelling real casino play.

Challenges

The hardest problem was building card-flip and dealer-reveal animations without clearing the screen — the game board needed to remain visible while the animation played in a side panel. This required ANSI cursor-up escape codes to overwrite specific terminal lines in place rather than re-rendering the full screen on each frame. The split flow presented a second challenge: two independent interactive hand loops share a single dealer turn, and double-downs inside each split hand alter their individual bets separately. Getting chip accounting to remain correct across all combinations of split, double, bust, and insurance required pinning the pre-deduction model consistently throughout rather than patching it per-case. Raw single-keypress input via tty/termios also required careful terminal state restoration to avoid corrupting the shell after exit.

Results / Metrics

The project demonstrates clean separation of concerns, Python dataclasses and enums used for domain modelling, and raw terminal UI techniques rarely seen in beginner-level Python work. The advanced version is genuinely playable with casino-accurate rules across all three difficulty modes. Placing both versions in the same repository makes architectural growth explicit — from 75 procedural lines to a modular system with animations, side bets, and session statistics. The pure-logic isolation in blackjack.py means unit tests could be added with no refactoring required, which would be the first improvement in a future iteration.

Screenshots

Click to enlarge.

Click to enlarge.

Videos