A fully playable Python implementation of the classic code-breaking game Mastermind, featuring:
- Code-Breaker Mode β You guess the CPUβs secret code
- Code-Maker Mode β The CPU tries to deduce your code using logical pruning
-
CPU generates a secret 4-digit code (digits 1β9, no repeats)
-
Player has 8 guesses
-
Feedback after each guess:
- Red β correct digit in the correct position
- White β correct digit in the wrong position
- You choose a secret code
- CPU generates guesses and filters out impossible ones using past feedback
- Continue giving feedback until the CPU finds the solution
- Red (r): digit correct & in correct position
- White (w): digit correct but in wrong position
In Code-Maker Mode, the CPU:
- Generates a random candidate
- Checks if itβs consistent with all previous red/white feedback
- Rejects impossible codes
- Continues until a viable code is found
This acts as a constraint-satisfaction solver.
python mastermind.pycbβ play as code-breakercmβ play as code-maker
If CPU guesses:
[3, 7, 1, 9]
Respond with something like:
r, r, w
Meaning:
- 2 digits correct & in correct position
- 1 digit correct but wrong position
π€ Author Eli Weiss
GitHub: https://github.com/EliWeiss1 LinkedIn: https://www.linkedin.com/in/eli-weiss-40803a330/ Email: eliisaweiss@gmail.com