An open API service indexing awesome lists of open source software.

https://github.com/alivaezii/mastermindgame

Mastermind Classic Game
https://github.com/alivaezii/mastermindgame

agile-development agile-methodology cicd docker game-development mastermind-game python-3

Last synced: 13 days ago
JSON representation

Mastermind Classic Game

Awesome Lists containing this project

README

          




# ๐ŸŽฎ Mastermind Game (Python)

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)](https://de.wikipedia.org/wiki/Mastermind_(Spiel))

---

## ๐Ÿ›  Tech Stack & Tools











## ๐Ÿš€ Quick Start

### 1. Create and activate environment
```bash
conda env create -f environment.yml
conda activate mastermind
```

### 2. Install the package
```bash
pip install -e .
```

### 3. Play the game

**๐ŸŽจ GUI Mode (Recommended)**
```bash
# Launch the graphical interface
python -m mastermind.gui.app

# Or directly
python src/mastermind/gui/app.py
```

**๐Ÿ’ป Command-Line Mode**
```bash
# 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 12
```

### 4. Run tests
```bash
pytest
```

---

## ๐Ÿณ Docker Support (CLI Only)

This project includes an official Docker image for the **CLI version**
of Mastermind.

[![Docker Image](https://img.shields.io/docker/pulls/alivaezii/mastermindgame?logo=docker)](https://hub.docker.com/repository/docker/alivaezii/mastermindgame)
![Image Size](https://img.shields.io/docker/image-size/alivaezii/mastermindgame/1.0.0)
![Version](https://img.shields.io/badge/version-1.0.0-blue)
![Multi-stage](https://img.shields.io/badge/docker-multistage-blue)
![Build](https://img.shields.io/badge/build-passing-brightgreen)
![Base Image](https://img.shields.io/badge/base-python%3A3.11--slim-blue)
![Interface](https://img.shields.io/badge/interface-CLI--only-lightgrey)
![Security](https://img.shields.io/badge/security-scanned-brightgreen)

### Pull from Docker Hub

``` bash
docker pull alivaezii/mastermindgame:1.0.0

```

### Run the game in Docker

``` bash
docker run --rm -it alivaezii/mastermindgame:1.0.0
```

### Run with custom arguments

``` bash
docker 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 5
```

### Build locally (optional)

``` bash
docker build -t mastermindgame .
```

### Pull from GitHub Container Registry (GHCR)

[![GHCR](https://img.shields.io/badge/GHCR-Container%20Image-2088FF?logo=github&logoColor=white)](https://github.com/users/alivaezii/packages/container/package/mastermindgame)

``` bash
docker pull ghcr.io/alivaezii/mastermindgame:1.0.0
```
### Run the Mastermind CLI from GHCR

``` bash
docker 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.

---

## ๐ŸŽฏ Features

### Dual Interface

**๐ŸŽจ 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

### Game Modes

**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!

### Scoring System

- **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**

### Configurable Rules

- **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`

## ๐ŸŽฎ Mastermind Game: UI Overview

Below is a complete overview of the Mastermind game's graphical interface, showing all major gameplay states:

1. **Start Screen & Settings**
2. **In-Game Screen (Player vs Computer)**
3. **Winning Screen**
4. **Game Over Screen**


Mastermind Game Screenshots

---

## ๐Ÿงช Testing & Code Quality

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](./docs/Quality_Testing_CICD_Policy.md)

---

## ๐Ÿ“‚ Project Structure

```
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
```

---

## ๐Ÿ—๏ธ Architecture

The codebase is organized into clean, testable modules:

- **`engine.py`**: Pure functions for game rules (`Rules`, `validate_guess`, `score`)
- **`game.py`**: `Game` class encapsulating game state and logic, supporting both PvC and PvP modes
- **`scoreboard.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 logic
- **`gui/`**: 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.

---

## ๐Ÿ“– Usage Examples

### Basic Game (PvC)
```bash
mastermind
```

### Player vs Player
```bash
mastermind --mode pvp
```

### Hard Mode (no duplicates, limited attempts)
```bash
mastermind --no-duplicates --max-attempts 5
```

### Custom Alphabet
```bash
mastermind --alphabet RGBYOP --length 6
```

---

## โš™๏ธ Continuous Integration (CI)

All commits and pull requests trigger an automated workflow that performs:

1. Environment setup via **Conda**
2. Auto-formatting using **isort** and **black**
3. Linting with **flake8**
4. Running **pytest** for all unit and CLI tests
5. Enforcing **coverage โ‰ฅ 85%**

If all stages pass, the build turns โœ… green in GitHub Actions.

---

## ๐Ÿค Contributing

1. Fork this repository
2. Create a new branch: `feature/my-feature`
3. Run local quality checks before committing:
```bash
isort . && black . && flake8 . && pytest
```
4. Submit a Pull Request, all CI jobs must pass before merge.

---

## ๐Ÿงฑ Built With
- Python 3.10 / 3.11
- Conda environment management
- pytest + coverage
- black / isort / flake8 / pre-commit
- GitHub Actions for CI/CD automation

---

## ๐Ÿ“ License

### Mastermind Game: Team Information
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 |


---

## ๐Ÿ“˜ Project Documentation

This project includes full Agile documentation, test specifications, retrospectives, architecture diagrams, and development guidelines.

[![Open Wiki](https://img.shields.io/badge/Project%20Wiki-Open-blue?logo=github&style=for-the-badge)](https://github.com/alivaezii/mastermindgame/wiki)

---

### ๐Ÿ’ก Related Documentation

- [Quality Assurance & CI/CD Policy](./docs/Quality_Testing_CICD_Policy.md)
- [Code Quality KPI](./reports)
- [Python โ†” Java Toolchain Comparison](./docs/Python_vs_Java_Tooling.md)