Mastermind
Controls
- Pick a colour from the palette, then click pegs to set your guess.
- Click Submit to score the guess.
- White peg = right colour right spot. Grey peg = right colour wrong spot.
Mastermind is the 1970 code-breaking board game by Mordechai Meirowitz, an Israeli telecommunications expert. One player creates a secret code of 4 colored pegs (chosen from 6 colors with repetition allowed); the other player has up to 10 guesses to break it. Each guess receives feedback: a black peg for each correct color in the correct position, a white peg for each correct color in the wrong position. Mathematically deep — Donald Knuth proved that any Mastermind code can be cracked in at most 5 guesses with optimal play.
How to play
- The computer secretly chooses a 4-color code from 6 available colors. Colors CAN repeat.
- You have 10 guesses to break the code.
- For each guess, you place 4 colored pegs in a row.
- Feedback shows:
- Black pegs — number of pegs in the correct color AND correct position.
- White pegs — number of pegs of correct color but wrong position.
- No peg — color not in the code at all.
- Note: each peg in your guess is matched to at most one peg in the code (no double-counting).
- Win = 4 black pegs (all positions correct). Lose = 10 guesses used without solving.
Beginner strategy
- Use 2-2 color split for first guess. Try a guess like Red-Red-Blue-Blue. The feedback tells you exactly how many Reds AND Blues are in the code.
- Don’t repeat colors in early guesses that didn’t get black/white feedback. If Red-Red got 0 pegs, Red isn’t in the code.
- Track confirmed positions. When black pegs increase, you know one of YOUR pegs is exactly right.
- Eliminate colors systematically. Guess 1: AABB. Guess 2: CCDD. Guess 3: EEFF. After 3 guesses, you know exactly which 4 of the 6 colors are in the code (and approximately how many of each).
- Don’t guess randomly. Each guess should refine your knowledge, not exhaust possibilities.
Intermediate strategy: the Knuth algorithm
Donald Knuth’s 1976 algorithm guarantees solving Mastermind in at most 5 guesses. His optimal first guess is one that minimizes the worst-case number of remaining possibilities after feedback. The starting guess: 1122 (two of one color, two of another). All subsequent guesses are chosen to minimize maximum remaining possibilities given the worst feedback.
- First guess: 1122 (Red-Red-Blue-Blue or equivalent).
- Track all consistent possibilities. After feedback, list all codes that COULD have produced that feedback.
- Choose next guess to minimize worst case. The guess that, in the worst case after feedback, leaves the smallest list of possibilities. Often this is NOT the most “likely” answer.
- Result: Knuth proved 5 guesses always suffice. Human play averaging 4 guesses is achievable with practice.
Advanced strategy
- Information theory framing. Each guess provides up to 14 different feedback combinations (color count + position count combinations). The guess that maximizes expected information gain is optimal.
- Probabilistic vs minimax. Knuth’s minimax minimizes worst-case. An expectation-based approach minimizes average guesses but may have worse worst-cases.
- Adaptive vs static. Static algorithms compute the full strategy tree in advance. Adaptive algorithms compute the next guess on the fly. Knuth’s is essentially static.
- The 1296 possibility count. 6 colors × 4 positions = 6^4 = 1296 possible codes. Each guess partitions these into feedback classes; the best partition has roughly even-sized classes.
- Memorize the optimal opening. 1122 (or any analog) is the proven optimal opener. Use it every game.
Mastermind variants
- Classic Mastermind (4 pegs, 6 colors): the original.
- Super Mastermind (4 pegs, 8 colors): harder. Worst case extends.
- Grand Mastermind (5 pegs, 6 colors).
- Word Mastermind / Word Master: code is a 5-letter word; precursor to Wordle (Bulls and Cows / Jotto).
- Royal Mastermind (multiple guesses simultaneously): for competitive play.
- Mastermind 44 (4 pegs, 4 colors, repeats allowed): faster, fewer possibilities.
Mastermind history
- 1970 — Meirowitz creates Mastermind. Initially rejected by major game companies; Invicta Plastics in the UK eventually licenses it.
- 1970s commercial success. 50+ million copies sold. Most popular new board game of the decade.
- 1976 — Knuth’s optimal algorithm. Published in The Journal of Recreational Mathematics. Proves 5-guess upper bound.
- 1980s — computer versions: Mastermind ships on virtually every home computer of the 80s.
- 2010s — Wordle ancestry. Mastermind’s color-feedback mechanic directly inspires Bulls and Cows, Jotto, and ultimately Wordle.
Bulls and Cows (the ancestor)
Bulls and Cows is the older pencil-and-paper game from which Mastermind descends. Players try to guess a 4-digit number (digits 0-9, no repeats). Feedback uses “bulls” (correct digit, correct position) and “cows” (correct digit, wrong position). Mastermind generalized to 6 colors with repeats; later, Jotto generalized to 5-letter words. Wordle is essentially Jotto with positional feedback.
Common mistakes
- Random first guess. Most beginner first guesses are 4 different colors. This gives less information than 2-2.
- Ignoring color feedback. If guess 1 (AABB) returned 1 black + 0 white, you know exactly one peg is correct. Don’t waste guess 2 on completely different colors.
- Forgetting position info. Black means BOTH color AND position correct. Track which positions you’ve confirmed.
- Re-using known-wrong colors. If a color got no pegs, never include it again.
- Guessing late. By guess 8, you should have minimized possibilities to under 5. If you haven’t, you weren’t being efficient.
FAQ
- Q: Can colors repeat in the code? A: Yes — the code can have 4 of the same color, or all different. The 1296 possibility count accounts for this.
- Q: What’s the maximum guesses needed with optimal play? A: 5 (Knuth, 1976). Human play averages 4-5 guesses.
- Q: Does the feedback distinguish between left and right pegs? A: No — feedback is just counts (X black, Y white). You don’t know WHICH peg in your guess matches.
- Q: Is Mastermind like Wordle? A: Same family — color-feedback code-cracking. Wordle is essentially Mastermind with 5 positions, 26 “colors” (letters), and the constraint that the answer must be a valid English word.
For other logic-deduction games, try Wordle, Minesweeper, Sudoku, or Hangman.
From the blog
- Indoor Games for Adults: Online Picks for a Rainy DayThe best indoor games for adults to play online on a rainy day — free browser…
- Best Number Games to Play Online FreeThe best number games online to play free — 2048, Sudoku, and math puzzles that sharpen…
- Best Relaxing Games to Play Online When You’re StressedThe best relaxing games online for when you're stressed — calm, low-pressure browser games with no…





