Tirsvad 387b9a2ed4
TirSystem/git-workflows: Release / release (push) Skipped
TirSystem/git-workflows: Sync GitHub mirror metadata / sync-metadata (push) Successful in 18s
TirSystem/git-workflows: Publish wiki / publish-wiki (push) Successful in 46s
CI / check (push) Successful in 52s
TirSystem/git-workflows: Publish accepted milestones / publish (push) Successful in 44s
TirSystem/git-workflows: Validate / validate (push) Successful in 41s
TirSystem/git-workflows: OpenGrep / opengrep (push) Successful in 2m10s
Merge pull request 'Bring the project to the framework baseline (MIL-004)' (#29) from mil-004-baseline into main
2026-11-15 13:42:41 +01:00
2026-11-15 20:39:44 +08:00
2026-10-07 16:39:27 +02:00

Turtle Race

A turtle race game in Python: bet on the colour of one of six turtles and watch them race across the screen.

📚 Table of Contents

🧭 Overview

This game is the day-19 assignment of Udemy's 100 Days of Code: The Complete Python Pro Bootcamp, built with the standard library only (turtle, random) and kept readable so that other course participants can run it and compare solutions.

Project layout

.
├── .editorconfig              editor settings of the framework baseline
├── .env.example               placeholders for the tokens of the framework scripts
├── .github/workflows/ci.yml   continuous integration
├── docs/                      project documents (business case, plan, milestones, reviews, wiki)
├── src/turtle_race/           the game
│   ├── __init__.py
│   ├── __main__.py            entry point of python -m turtle_race
│   ├── bet.py                 asking for the bet and normalising the answer
│   ├── constants.py           every constant of the game
│   ├── game.py                setting up the race, running it, starting the game
│   ├── protocols.py           narrow views of the screen, the turtle and random
│   ├── race.py                the rules: random distance, finish line, winner
│   ├── result.py              the messages that tell how the race went
│   └── starting_line.py       starting positions and the turtles on them
├── tests/                     pytest tests (fakes of the screen and turtle included)
├── Doxyfile                   source documentation settings
├── pyproject.toml             project configuration, dependencies, tool settings
└── README.md

The names of the lectures are kept where they exist: screen, user_bet, all_turtles, new_turtle and is_race_on, and the y_positions of the starting line are starting_y_positions(). The numbers of the lectures (500 by 400, -230, 230, 0 to 10) are in constants.py.

📋 Requirements

  • Python 3.13 or newer, including tkinter (the turtle module needs it).
  • Git, to clone the repository.
  • No runtime dependencies. The development tools (pytest, ruff, mypy) are installed with the dev extra, see Setup.
  • Optional: Doxygen to build the source documentation.

🛠️ Setup

Create a local virtual environment named .venv in the project folder, upgrade pip inside it, and install the project in editable mode with the development tools. Do this once after cloning; activate the environment again in every new terminal. Leave it with deactivate.

Windows powershell

Install Python 3.13 from python.org (keep "tcl/tk and IDLE" ticked) or with winget install Python.Python.3.13.

git clone https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/019-turtle-race.git
cd 019-turtle-race
py -3.13 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

If PowerShell refuses to run the activation script, allow it for this window only with Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned.

Linux debian

Debian 13 (trixie) or newer ships Python 3.13. Debian 12 ships Python 3.11, which is too old: install Python 3.13 separately (for example with pyenv or uv).

sudo apt update
sudo apt install git python3 python3-venv python3-tk
git clone https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/019-turtle-race.git
cd 019-turtle-race
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

MacOS

Install Python 3.13 with its Tk support, for example with Homebrew:

brew install git python@3.13 python-tk@3.13
git clone https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/019-turtle-race.git
cd 019-turtle-race
python3.13 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

▶️ Run

With the virtual environment active:

python -m turtle_race

The game opens a 500 by 400 screen and asks for your bet: type the colour of the turtle you think wins (red, orange, yellow, green, blue or purple; blanks and letter case do not matter). The six turtles line up on the starting line and race. In every round each turtle moves a random distance of 0 to 10 steps, and the first turtle to pass the finish line (x = 230) wins. The terminal then tells you who won and whether your bet was right:

You've won! The orange turtle is the winner!
You've lost! The orange turtle is the winner!

If you cancel the prompt, or type a colour that is not in the list, no race starts and the terminal tells you so. Click the screen to close it.

Build the source documentation

The source carries Doxygen comments and the Doxyfile is in the project root. Install Doxygen, for example with winget install DimitriVanHeesch.Doxygen (Windows), sudo apt install doxygen (Debian) or brew install doxygen (MacOS), then run it from the project root:

doxygen Doxyfile

Open build/doxygen/index.html in a browser. A warning, such as an undocumented public item, makes the build fail.

🧪 Tests

The tests need no display and no network. With the virtual environment active:

pytest

The same checks that the continuous integration runs, for code style and types:

ruff check .
ruff format --check .
mypy

Continuous integration

.github/workflows/ci.yml runs on every push to main and on every pull request. It sets up Python 3.13, runs python -m pip install --upgrade pip and python -m pip install -e ".[dev]", then ruff check, ruff format --check, mypy and pytest. The workflow format is understood by both GitHub Actions and Gitea Actions; the host needs a runner for it to execute.

📄 License

GNU Affero General Public License v3.0. See LICENSE.

📎 Appendix: Project documents

The documents a newcomer needs, in reading order.

Document What it tells you
Business Case Why the project exists, its scope and success criteria
Stakeholder Analysis Who is involved; the stakeholder IDs used for owners and reviewers
Project Plan The milestones and their schedule
Dictionary The terms of the documents and the names in the code
Milestones One document per milestone: Go/No-Go criteria and tasks
Artifact registry Where each artifact type lives, the next version, the PO language and domain
Traceability matrix How the artifacts link and when each was last reviewed

S
Description
Turtle race game in Python (turtle graphics): bet on a colour and watch the turtles race. Day 19 of Udemy's 100 Days of Code: The Complete Python Pro Bootcamp.
Readme AGPL-3.0
442 KiB
0 Stars 1 Watchers 0 Forks
Languages
Python 100%