Crack a hidden 4-peg colour code in 10 tries. Read black/white feedback pegs after each guess. Six colours, classic rules, free in browser.
#classic#logic#single-player#brain-teaser
How to play
Pick a colour from the palette, then tap a slot in the active row to place a peg. Tap again with no colour selected to clear a slot. Fill four pegs and press Submit. Dark feedback = right colour right slot; light feedback = right colour wrong slot.
About Mastermind — Classic Code-Breaking Puzzle
Mastermind is a two-player code-breaking puzzle invented by Israeli postmaster and telecommunications expert Mordecai Meirowitz in 1970. The commercial board game — with its iconic black-and-white plastic pegs — sold over fifty million copies in its first decade and became a staple in puzzle and logic curricula around the world.
Classic rules: one player picks a secret sequence of four coloured pegs, the other has up to ten guesses to crack it. After each guess the codemaker gives feedback — a *black* peg for every guess peg that matches both colour and position, a *white* peg for every guess peg whose colour appears in the code but in a different slot. No pegs at all means none of your colours feature.
Mastermind is a celebrated case study in deductive reasoning. Donald Knuth proved in 1977 that a five-guess strategy suffices for the standard 4×6 version, and the modern competitive scene still hunts for optimal openings. In this version the computer plays the codemaker — you get up to ten attempts to break a randomly generated four-peg code.
Tips & strategy
Your first guess sets the tone — try four distinct colours so you maximise the information you collect.
If your first guess returns zero pegs, you have eliminated four colours at once. That's a huge gain — never waste it.
Black peg counts are about positions; white peg counts are about *presence*. Track them separately when you reason.
Change only one or two pegs between guesses when you're zeroing in — too many changes muddy the comparison.
When you know the colours but not the positions, permute systematically: swap two pegs, see how the black count changes.
Don't forget colours can repeat in the secret. If a guess returns more black+white than you have unique colours, doubles are in play.
If you crack the code in five guesses you're playing at Donald Knuth's proven optimum. Sub-five takes luck.
Frequently asked questions
Can the secret code have repeated colours?
Yes. The codemaker may use the same colour multiple times, and our version follows the classic rule. That makes the search space 1,296 codes (6⁴) instead of just 360 unique permutations.
What do the small dark and light pegs mean?
Dark (black) peg = one of your guess pegs is the right colour in the right slot. Light (white) peg = one of your guess pegs is a colour the code uses, but in a different slot. The two never double-count the same peg.
How many guesses do I have?
Ten. If you don't crack the code by the tenth row, the codemaker wins and the secret is revealed.
Is there always a way to win in ten?
Yes. Knuth's 1977 algorithm guarantees a solution in five guesses or fewer for any 4-peg, 6-colour code — so ten is comfortable, even without machine-perfect play.
Does the order of my guess pegs matter when I'm collecting feedback?
Yes. The codemaker scores black pegs by exact position. Swapping the order of two pegs can change the black/white split even if your colour selection is identical.
Who invented Mastermind?
Mordecai Meirowitz, an Israeli postmaster and telecommunications expert, designed Mastermind in 1970. Invicta Plastics published it commercially in 1971 and it became one of the best-selling games of the 1970s.