This is a terminal version of the classic boardgame, Mastermind. I played this as a kid with my grandmother and wrote this simple terminal version in 2018 for kicks. This game looks best on a dark terminal background. I might make this configurable in a future commit. The instructions should work on macOS or Linux.
If you're using this code to learn and have any questions, feel free to reach out. You can find my Fosstodon and Website on my GitHub profile.
The game doesn't have any dependencies outside the Python Core Library.
Download and install Python3.12.
https://www.python.org/downloads/
Clone the repo:
git clone https://github.com/dansahagian/mastermind.git
Change into the directory:
cd mastermind
Run the program:
./play
Fork the repo:
https://github.com/dansahagian/mastermind/fork
Clone your fork:
git clone <url-to-your-fork>
Install uv.
Install tools:
uv tool install ruff
uv tool install pre-commit
Initialize environment:
./dev/initialize-env
Run the tests:
uv run pytest .
- You'll be asked how long of a sequence to generate.
- The standard game is 4.
- You'll be asked how many guesses you should be allowed.
- The standard game is 10.
- Your goal is to guess the sequence in that number of guesses.
- The game will ask you for your color sequence one at a time.
- It will ask you to confirm your guess before scoring it.
-
A ✅ means you have the correct color in the correct position.
-
A
⚠️ means you have the correct color in the wrong position. -
The scoring pegs are sorted. They don't correlate to the position of your colors.
In a 4 sequence game:
- 4
⚠️ means you have all the colors, but in the wrong positions. - 2 ✅ and 2
⚠️ means you have all the colors right, but two are in the wrong position.
- 4