Mastermind Game
The computer hides a secret code of colored pegs. You have 10 guesses to crack it: after each guess, a black peg means right color in the right spot and a white peg means right color in the wrong spot.
Guess 1 of 10: pick colors.
Code cracked!
How to use the Mastermind Game
- Choose a mode: Classic (4 pegs, 6 colors) or Hard (5 pegs, 8 colors), and whether the secret may repeat colors.
- Build a guess by clicking colors in the palette, dragging them into the holes, or typing their numbers. Click a hole to select it; click it again to clear it.
- Press Check (or Enter). Each black peg means one peg is the right color in the right position; each white peg means a right color in the wrong position.
- Use the clues to narrow it down. Turn on the counter to see how many codes still fit, or press Hint for a guess that matches every clue so far.
- Crack the code within 10 guesses to win. The secret is revealed at the end either way.
How the feedback is scored
Feedback is worked out in two steps. First, count the pegs that match exactly in color and position: each one gives a black peg. Then, for the remaining pegs, count for every color how many times it appears in both your guess and the secret code and take the smaller number: those give white pegs. A secret peg is never counted twice.
| Secret | Guess | Feedback | Why |
|---|---|---|---|
| Red Blue Green Yellow | Red Green Orange Orange | 1 black, 1 white | Red is in the right spot; green is in the code but in the wrong spot. |
| Red Red Blue Blue | Red Blue Red Orange | 1 black, 2 white | First red is exact; the second red and the blue are in the code but misplaced. |
| Green Green Green Blue | Green Yellow Yellow Yellow | 1 black, 0 white | Only one green in the guess, and it is already counted as black. |
| Purple Orange Yellow Red | Red Purple Orange Yellow | 0 black, 4 white | All four colors are right, but none is in its place. |
Mastermind strategy tips
- Open with two pairs. A guess like Red Red Orange Orange tells you about two colors at once and is the opening of Donald Knuth's strategy, which never needs more than five guesses in the classic game.
- Only play codes that could still be right. Before each guess, check it against every earlier clue. If it would have produced different feedback for any earlier row, it can't be the secret. The "codes still possible" counter and the Hint button do this check for you.
- Watch the totals. Black plus white tells you how many of your colors are in the code. If a guess gets zero pegs, every color in it is out.
- Change one thing at a time when you are close. Swapping two pegs or replacing one color makes it much easier to see what the feedback is telling you.
- Remember duplicates. When duplicates are on, a code like Blue Blue Blue Green is possible, so don't rule out repeated colors too early.
Number of possible codes
| Mode | Duplicates allowed | No duplicates |
|---|---|---|
| Classic: 4 pegs, 6 colors | 64 = 1,296 | 6 × 5 × 4 × 3 = 360 |
| Hard: 5 pegs, 8 colors | 85 = 32,768 | 8 × 7 × 6 × 5 × 4 = 6,720 |
Keyboard: type 1–6 (or 1–8) to place colors, Backspace to remove one, ← → to move between holes and Enter to check. Double-click an earlier guess to copy it into the current row.
Frequently asked questions
How do the black and white pegs work?
After each guess you get one black peg for every peg that has the right color in the right position, and one white peg for every other peg whose color is in the code but in a different position. Each peg in the secret is counted only once, so the total of black and white pegs is never more than the number of pegs.
Does the order of the feedback pegs matter?
No. The feedback pegs are always shown with the black ones first, so they don't tell you which positions are correct. Working that out is the puzzle.
How many possible codes are there?
With 4 pegs and 6 colors and duplicates allowed there are 6^4 = 1,296 possible codes. Without duplicates there are 6 × 5 × 4 × 3 = 360. Hard mode with 5 pegs and 8 colors has 8^5 = 32,768 codes with duplicates, or 6,720 without.
Can every code be solved in 10 guesses?
Yes, easily. In 1977 Donald Knuth showed that any classic 4-peg, 6-color code can be found in at most five guesses with the right strategy. Ten guesses leaves plenty of room for normal play.
What is a good first guess?
For the classic game, a guess with two pairs of colors such as red, red, orange, orange is a strong start; it is the first guess in Knuth's five-guess strategy. After that, try to make guesses that are consistent with all the feedback you have received.
Is this the same as Bulls and Cows?
It is very similar. Bulls and Cows is an older pencil-and-paper game played with digits, where bulls are like black pegs and cows are like white pegs. Mastermind uses colored pegs instead of numbers.
What does the hint do?
The hint fills in your current row with a code that is consistent with every clue you have received so far, chosen at random from the codes that are still possible. Using it doesn't end the game, but it is noted in your result.