A complete implementation of the classic Mastermind logic game with both command-line and graphical user interface (GUI) options. Features multiple game modes, scoring system, and persistent leaderboard. Built to demonstrate clean software design, testing, and CI/CD automation principles using Python.
Mastermind Wikipedia (Game)
conda env create -f environment.yml
conda activate mastermindpip install -e .๐จ GUI Mode (Recommended)
# Launch the graphical interface
python -m mastermind.gui.app
# Or directly
python src/mastermind/gui/app.py๐ป Command-Line Mode
# Player vs Computer (default)
mastermind
# Player vs Computer with custom settings
mastermind --mode pvc --max-attempts 10
# Player vs Player mode
mastermind --mode pvp --max-attempts 8
# Custom rules
mastermind --length 5 --alphabet ABCDEF --no-duplicates --max-attempts 12pytestThis project includes an official Docker image for the CLI version of Mastermind.
docker pull alivaezii/mastermindgame:1.0.0
docker run --rm -it alivaezii/mastermindgame:1.0.0docker run --rm -it alivaezii/mastermindgame:1.0.0 --mode pvc --max-attempts 12
docker run --rm -it alivaezii/mastermindgame:1.0.0 --no-duplicates --length 5docker build -t mastermindgame .docker pull ghcr.io/alivaezii/mastermindgame:1.0.0docker run --rm -it ghcr.io/alivaezii/mastermindgame:1.0.0โน Notes
The container includes only the CLI version of Mastermind. The GUI cannot run inside Docker because Tkinter requires access to a local window server.
๐จ Graphical User Interface (GUI)
- Beautiful color-based visual interface using Tkinter
- Interactive color selection with clickable buttons
- Visual feedback with bulls (โ) and cows (โ) indicators
- Scrollable guess history
- High scores leaderboard with professional table layout
- Intuitive navigation between screens
- Modern dark theme with vibrant colors
๐ป Command-Line Interface (CLI)
- Traditional text-based gameplay
- Perfect for terminal enthusiasts
- Lightweight and fast
Player vs Computer (PvC)
- Computer generates a random secret code
- Player tries to guess the code
- Default mode
Player vs Player (PvP)
- Player 1 sets a secret code (hidden input in CLI, visual in GUI)
- Player 2 tries to guess the code
- Great for playing with friends!
- Win: Base score of 100 + bonus for remaining attempts (10 points each)
- Loss: 0 points
- Scores are automatically saved to
scores.json - Top 5 scores displayed after each game
Example Scoring:
- Win in 3/10 attempts: 100 + (7 ร 10) = 170 points
- Win in 10/10 attempts: 100 + (0 ร 10) = 100 points
- Loss: 0 points
- Code length: Default 4, customizable via
--length - Alphabet: Default "012345", customizable via
--alphabet - Duplicates: Allowed by default, disable with
--no-duplicates - Max attempts: Default 10, customizable via
--max-attempts
Below is a complete overview of the Mastermind game's graphical interface, showing all major gameplay states:
- Start Screen & Settings
- In-Game Screen (Player vs Computer)
- Winning Screen
- Game Over Screen
This project follows a lightweight yet strict Testing and Quality Policy:
| Area | Tool | Purpose |
|---|---|---|
| Testing | pytest + pytest-cov |
Unit & CLI tests, min. 85% coverage |
| Formatting | black + isort |
Code formatting & import sorting |
| Linting | flake8 |
Static code analysis |
| Pre-commit | pre-commit |
Auto-runs all checks before pushing |
| CI/CD | GitHub Actions | Multi-version tests (Python 3.10 & 3.11) |
๐ For full details: Quality & CI/CD Policy
mastermindgame/
โ
โโโ src/mastermind/
โ โโโ __init__.py # Package exports
โ โโโ engine.py # Core rules and validation logic
โ โโโ game.py # Game state management
โ โโโ scoreboard.py # Scoring and persistence
โ โโโ cli.py # Command-line interface
โ โโโ gui/ # Graphical user interface (Sprint 3)
โ โโโ __init__.py
โ โโโ app.py # Main GUI application controller
โ โโโ utils.py # Color-symbol mapping utilities
โ โโโ screens/ # All game screens
โ โ โโโ start.py # Game configuration screen
โ โ โโโ secret.py # PvP secret selection
โ โ โโโ gameboard.py # Main gameplay interface
โ โ โโโ gameover.py # Results & scoring
โ โ โโโ highscores.py # Leaderboard display
โ โโโ widgets/ # Reusable UI components
โ โโโ colorpicker.py # Color selection widget
โ โโโ row.py # Guess row display
โ
โโโ tests/
โ โโโ test_engine.py # Engine unit tests
โ โโโ test_game.py # Game class tests
โ โโโ test_scoreboard.py # Scoreboard tests
โ โโโ test_cli.py # CLI integration tests
โ โโโ test_gui_utils.py # GUI utilities tests
โ
โโโ scores.json # Persistent scoreboard (auto-created)
โโโ environment.yml # Conda environment
โโโ pyproject.toml # Project configuration
โโโ .github/workflows/ci.yml # CI/CD pipeline
The codebase is organized into clean, testable modules:
engine.py: Pure functions for game rules (Rules,validate_guess,score)game.py:Gameclass encapsulating game state and logic, supporting both PvC and PvP modesscoreboard.py: Score calculation and JSON persistence (ScoreEntry,calculate_score,save_score,load_scores,top_scores)cli.py: Command-line user interface, completely decoupled from game logicgui/: Graphical user interface (Sprint 3)- MVC Architecture: Clean separation of Model (Game), View (screens/widgets), Controller (app navigation)
- Color Mapping: Translates visual colors to game engine symbols
- Reusable Widgets: ColorPicker and GuessRow components
- No Logic Duplication: GUI calls existing Game and scoreboard functions
This separation makes the codebase easy to extend (e.g., adding a web interface) without modifying core logic.
mastermindmastermind --mode pvpmastermind --no-duplicates --max-attempts 5mastermind --alphabet RGBYOP --length 6All commits and pull requests trigger an automated workflow that performs:
- Environment setup via Conda
- Auto-formatting using isort and black
- Linting with flake8
- Running pytest for all unit and CLI tests
- Enforcing coverage โฅ 85%
If all stages pass, the build turns โ green in GitHub Actions.
- Fork this repository
- Create a new branch:
feature/my-feature - Run local quality checks before committing:
isort . && black . && flake8 . && pytest
- Submit a Pull Request, all CI jobs must pass before merge.
- Python 3.10 / 3.11
- Conda environment management
- pytest + coverage
- black / isort / flake8 / pre-commit
- GitHub Actions for CI/CD automation
Developed by TM26 -Hochschule Campus Wien
MIT License ยฉ 2025
A student software engineering project at Hochschule Campus Wien
Sprint-based development following SCRUM
| Role | Name | Contact |
|---|---|---|
| Product Owner | Laurenz | laurenz.stelzl@stud.hcw.ac.at |
| Scrum Master | Markus | markus.maximus@stud.hcw.ac.at |
| Senior Developer & Tester | Ali | mohammadali.vaezi@stud.hcw.ac.at |
| Python Developer | Adnan | adnan.eminovic@stud.hcw.ac.at |
| Python Developer | Hossein | seyed.meymandi.nezhad@stud.hcw.ac.at |
This project includes full Agile documentation, test specifications, retrospectives, architecture diagrams, and development guidelines.

