Add Blackjack game: rules, card rendering, game loop and tests #17

Merged
Tirsvad merged 1 commits from mil-002-game-implementation into main 2026-10-04 16:06:12 +02:00
Owner

Summary

  • Implement the playable console game for gateway MIL-002 (Gateway 2 - Game Implementation): python -m blackjack.
  • rules.py holds deal_card, calculate_score (blackjack = 0, aces drop 11 to 1) and compare with an Outcome enum, with no console I/O.
  • display.py renders hands as plain-text rank plus suit emoji (keycap emoji showed as boxes in common terminals), plus scores and outcome messages. art.py holds the course logo.
  • game.py has the game flow: hit/stand, the dealer draws below 17, restart loop with console clear and logo, and a yes/no prompt that asks again on invalid input. read, write and draw are injected so games can be scripted.
  • Constants (ranks, suits, prompts, messages) live in constants.py; the README has run instructions.

Issues

Closes #7
Closes #8
Closes #9
Closes #10
Closes #11
Closes #12
Closes #13
Closes #14

Verification

  • python -m unittest discover -s tests: 35 tests pass. They cover every house rule, the order of the compare checks, each way a game can end, and scripted full sessions with restart.
  • An AST test checks that rules.py never calls input() or print().
  • ruff check, ruff format --check and mypy --strict are clean on src and tests.
  • doxygen Doxyfile ran and I saw no warnings in its output.
  • One real game played through python -m blackjack showed the logo, cards and a result.

Review notes

  • Suits follow a card's position in the hand (♠ ♥ ♦ ♣, repeating) because the game tracks only card values. They have no gameplay effect.
  • A Jack, Queen or King is shown as 10, since the house rules store one value for all four.
  • The dealer does not draw once the player has bust; the result is the same as in the assignment's hint.
  • After merge: check that issues #7 to #14 are closed and close milestone 35.
## Summary - Implement the playable console game for gateway MIL-002 (Gateway 2 - Game Implementation): `python -m blackjack`. - `rules.py` holds `deal_card`, `calculate_score` (blackjack = 0, aces drop 11 to 1) and `compare` with an `Outcome` enum, with no console I/O. - `display.py` renders hands as plain-text rank plus suit emoji (keycap emoji showed as boxes in common terminals), plus scores and outcome messages. `art.py` holds the course logo. - `game.py` has the game flow: hit/stand, the dealer draws below 17, restart loop with console clear and logo, and a yes/no prompt that asks again on invalid input. `read`, `write` and `draw` are injected so games can be scripted. - Constants (ranks, suits, prompts, messages) live in `constants.py`; the README has run instructions. ## Issues Closes #7 Closes #8 Closes #9 Closes #10 Closes #11 Closes #12 Closes #13 Closes #14 ## Verification - `python -m unittest discover -s tests`: 35 tests pass. They cover every house rule, the order of the `compare` checks, each way a game can end, and scripted full sessions with restart. - An AST test checks that `rules.py` never calls `input()` or `print()`. - `ruff check`, `ruff format --check` and `mypy --strict` are clean on `src` and `tests`. - `doxygen Doxyfile` ran and I saw no warnings in its output. - One real game played through `python -m blackjack` showed the logo, cards and a result. ## Review notes - Suits follow a card's position in the hand (♠ ♥ ♦ ♣, repeating) because the game tracks only card values. They have no gameplay effect. - A Jack, Queen or King is shown as `10`, since the house rules store one value for all four. - The dealer does not draw once the player has bust; the result is the same as in the assignment's hint. - After merge: check that issues #7 to #14 are closed and close milestone 35.
Tirsvad added 1 commit 2026-10-04 16:06:06 +02:00
Implement the playable console game for gateway MIL-002.

- rules.py: deal_card, calculate_score (blackjack = 0, aces drop 11 ->
  1)
  and compare with an Outcome enum; no console I/O
- display.py: hand rendering as plain-text rank plus suit emoji (keycap
  emoji rendered as boxes in common terminals), score formatting and
  outcome messages
- art.py: course logo shown at the start of every game
- game.py: play_game (hit/stand, dealer draws below 17), play (restart
  loop, console clear, logo) and ask_yes_no with re-prompt; read, write
  and draw are injected so games can be scripted
- __main__.py: python -m blackjack entry point, exits cleanly on
  Ctrl+C/Ctrl+D
- constants.py: card ranks and suits, prompts and messages
- tests: 32 new unit and scripted end-to-end tests (35 in total)
- README: run instructions for python -m blackjack

Closes #7
Closes #8
Closes #9
Closes #10
Closes #11
Closes #12
Closes #13
Closes #14

Task: MIL-002#1
Task: MIL-002#2
Task: MIL-002#3
Task: MIL-002#4
Task: MIL-002#5
Task: MIL-002#6
Task: MIL-002#7
Task: MIL-002#8
Tirsvad merged commit 06d0386010 into main 2026-10-04 16:06:12 +02:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Tirsvad-Udemy-100_days_of_code/011-black-jack#17