Mastermind

You can rate the game:
1.0 (1)

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 code in the classic game can be cracked in at most 5 guesses with optimal play.

How to play

  • The computer secretly chooses a 4-color code. Pick a mode first:
    • Easy: 6 colors, 10 guesses.
    • Medium (the default): 6 colors, 8 guesses.
    • Hard: 8 colors, 8 guesses.
    • Duplicates allowed: 6 colors, 10 guesses, and colors CAN repeat in the code (the classic rules).
  • In Easy, Medium and Hard the code uses 4 different colors. Your guesses may repeat colors in any mode.
  • For each guess, pick a color from the palette (or press 1-8), click a slot to place it, then Submit (or press Enter). Clear (or Backspace) empties the 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 = all guesses used without solving, and the code is revealed. Your wins and fewest-guess solve are saved in your browser.

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 which colors are in the code and roughly how many of each.
  • Use the no-repeat rule. In Easy and Medium, the code holds 4 of the 6 colors, so only 2 are missing. A first guess of 4 different colors already tells you a lot.
  • 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 in the classic game, with an average of about 4.5.

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 in each of 4 positions = 6^4 = 1296 possible codes (the Duplicates mode). Without repeats there are 360 codes with 6 colors and 1,680 with 8. Each guess partitions these into feedback classes; the best partition has roughly even-sized classes.
  • Memorize the optimal opening. 1122 (or any analog) is Knuth’s minimax opener for the classic repeats-allowed game. It’s a strong start in Duplicates mode.

Mastermind variants

  • Classic Mastermind (4 pegs, 6 colors): the original.
  • Super Mastermind (5 pegs, 8 colors): harder, with far more possible codes.
  • Grand Mastermind: pegs vary by both color and shape.
  • Mastermind44: a version for up to four players.
  • Word games: Jotto and Wordle apply the same feedback idea to words.
  • 8 colors, 4 pegs: our Hard mode, a step up from the classic 6.

Mastermind history

  • 1970 — Meirowitz creates Mastermind. Initially rejected by major game companies; Invicta Plastics in the UK eventually licenses it.
  • 1970s commercial success. A worldwide hit; tens of millions of copies have been sold since.
  • 1976 — Knuth’s optimal algorithm. Published in The Journal of Recreational Mathematics. Proves 5-guess upper bound.
  • 1980s — computer versions: Mastermind clones are common on home computers.
  • 2021 — Wordle. The same family of feedback guessing, alongside the older Bulls and Cows and Jotto, reaches a huge new audience.

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 swapped digits for 6 colors with repeats; Jotto (1955) had already applied the idea to 5-letter words. Wordle is essentially Jotto with positional feedback.

Common mistakes

  • Random first guess. In Duplicates mode, 4 different colors gives less information than a 2-2 guess. In the no-repeat modes, 4 different colors is a fine start.
  • 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 your second-to-last guess, you should have narrowed it to a handful of codes. In Medium and Hard, guess 8 is your last.

FAQ

  • Q: Can colors repeat in the code? A: Only in Duplicates allowed mode, where the code can have 4 of the same color, or all different (1296 possible codes). Easy, Medium and Hard codes use 4 different colors.
  • Q: What’s the maximum guesses needed with optimal play? A: 5 for the classic 6-color, repeats-allowed game (Knuth, 1976).
  • 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.

🔌 Connect any AI assistant to dinogame.gg — we run an MCP server: https://dinogame.gg/mcp