Skip to content

EliWeiss1/Mastermind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Mastermind (Python)

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

This project explores algorithmic reasoning, constraint satisfaction, and interactive game design.

πŸš€ Features

βœ” Code-Breaker Mode

  • 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

βœ” Code-Maker Mode

  • 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

🧠 Game Logic

Red & White Scoring

  • Red (r): digit correct & in correct position
  • White (w): digit correct but in wrong position

CPU Guess Strategy

In Code-Maker Mode, the CPU:

  1. Generates a random candidate
  2. Checks if it’s consistent with all previous red/white feedback
  3. Rejects impossible codes
  4. Continues until a viable code is found

This acts as a constraint-satisfaction solver.


πŸ•ΉοΈ How to Play

Run the game:

python mastermind.py

Choose a role:

  • cb β†’ play as code-breaker
  • cm β†’ play as code-maker

Giving feedback (Code-Maker Mode)

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

About

Classic Mastermind game with CPU. User can either be code-maker or code-breaker.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages