Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

🎮 Mastermind Game

Python Version License

A classic color-based code-breaking game built in Python with intelligent feedback system

AboutInstallationHow to PlayFeatures


🎯 About

Mastermind is an interactive command-line game where players attempt to crack a secret 4-color code within 10 guesses. The game provides strategic feedback after each guess, indicating correct positions and correct colors in wrong positions. Built with Python's random module and featuring robust input validation.

✨ Features

Gameplay

  • 🎨 6 Color Options - Red, Orange, Yellow, Green, Blue, Purple
  • 🔢 4-Color Code - Random code generation each game
  • 🎯 10 Attempts - Strategic guessing with limited tries
  • 💡 Smart Feedback - Clues for correct colors and positions
  • 🔄 Replay Option - Play multiple rounds seamlessly

Technical

  • Input Validation - Handles invalid entries gracefully
  • 🛡️ Error Handling - Try-except blocks for robustness
  • 🎲 Seeded Random - Reproducible results for testing
  • 📊 Pattern Matching - Advanced guess evaluation algorithm
  • 🧩 Modular Design - Clean function-based architecture

🚀 Installation

Prerequisites

# Requires Python 3.6 or later
python --version

Quick Start

Clone & Run:

# Clone the repository
git clone https://github.com/yourusername/mastermind-game.git
cd mastermind-game

# Run the game
python mastermind.py

Or download and run directly:

python mastermind.py

🎮 How to Play

Game Rules

  1. Objective: Guess the secret 4-color code within 10 attempts
  2. Color Options: Choose from 6 colors (numbered 0-5)
  3. Feedback System:
    • 2 = Correct color in correct position
    • 1 = Correct color in wrong position
  4. Win Condition: Get all four colors in the correct positions [2, 2, 2, 2]

Example Gameplay

The secret code has been chosen. You have 10 tries to guess the code.
-----------------------------
Make a guess of four colors:
0 - red
1 - orange
2 - yellow
3 - green
4 - blue
5 - purple
-----------------------------
Guess color: 0
Guess color: 1
Guess color: 2
Guess color: 3
-----------------------------
Your guess is:
['red', 'orange', 'yellow', 'green']

Your clue is: [1, 2]
You have 9 guesses left

Understanding Clues

Clue Meaning Example
[2, 2, 2, 2] All correct - You win! Code: [red, blue, green, yellow]
Guess: [red, blue, green, yellow]
[2, 2, 1, 1] 2 correct positions, 2 correct colors wrong positions Code: [red, blue, green, yellow]
Guess: [red, blue, yellow, green]
[1, 1, 1] 3 correct colors, all in wrong positions Code: [red, blue, green, yellow]
Guess: [blue, yellow, red, orange]
[] No correct colors Code: [red, blue, green, yellow]
Guess: [orange, purple, orange, purple]

🔧 Technical Implementation

Architecture

┌──────────────────────────────┐
│      Main Game Loop          │
├──────────────────────────────┤
│  generateCode()              │  → Creates random 4-color codegetGuess()                  │  → Gets player input with validationCheckGuess(guess, code)     │  → Evaluates guess & returns cluesmain(seedValue)             │  → Controls game flow & replay logic
└──────────────────────────────┘

Key Functions

🔵 generateCode()

# Generates a random 4-color code
# Uses random.randint() for index selection
# Returns: List of 4 color strings

🔵 getGuess()

# Prompts player for 4 color choices (0-5)
# Validates input with try-except blocks
# Handles both invalid numbers and non-numeric input
# Returns: List of 4 color strings

**🔵 CheckGuess(guess, co

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages