Flat Earth Fish
awake and eager
    Home - Game Design - Personal - Contact

How to solve Mastermind in 5 guesses or less

<Back

This is an analysis of playing the classic game Mastermind with for four pegs from a pool of six or fewer possible colors

Terminology:
“color match” refers to either black or white result pegs
“location match” refers to black pegs
“color set” refers to which colors are used in the final solution.  If one color is used more than once, it will only be referenced once in the color set.

Guess 1:
Guess all different colors, preferably in a logical, familiar sequence.
For example: blue, green, red, yellow

Guess 2:
Shift the sequence once to the left.
For example: green, red, yellow, orange
special note: if Guess 1 returned 1 or 0 color matches, it may be better to shift twice for Guess 2

Guess 3:
Shift the sequence once more to the left:
For example: red, yellow, orange, pink

Guess 4:
Now, after the three guesses you should only concern yourself with finding which colors are being used (the color set).  Make two piles of pegs in front of you.  One pile is the “used at least once pile” the other pile is the “not used at all pile”.  In most cases, you can narrow down the set of colors used to two possibilities.  Most likely you will be in a worst-case situation something like this:

I know there is one Pink and, either there is both Red and Yellow or there is an Orange, Blue and only one of either Red or Yellow.
So your two possible sets are:

  • Pink, Red, Yellow
  • Pink, Orange, Blue, (Red or Yellow)

In the first case one of the three colors is used twice.

At this point you must plan your 4th guess so that it settles which situation is true.  In the above example, I might guess the colors: Pink, Orange, Blue, Yellow.  If the solution is the first possibility, I will get two color matches.  If the solution is the second possibility, I will get three or four color matches (and thus also determine if it the unknown color is Red or Yellow).  We actually had three possible color sets, but with one guess, I will eliminate all but one possibility.
When making your 4th guess you must also consider where you put the colors of your guess.  Make sure each color covers locations it has not already occupied in previous guesses.  Your fourth guess will need to pinpoint the locations of the colors.  In most cases, you do not have to trouble yourself much about setting this up as it will be relatively easy to resolve once you have determined the color set.

Guess 5:
Assuming you have not already been able to solve the puzzle and that you have not ignored a low-yield guess #1, you should now have enough information to deduce which colors are being used and what their arrangement is.  Cross reference your previous four guesses and, using your color set knowledge, deduce the color locations.
It is possible to solve every Mastermind puzzle within 5 guesses and in 90% of the puzzles you should only need to devote any serious thought to the fourth guess.
The other 10% of situations can be spotted early enough to adjust the guessing strategy.

Home - Game Design - Personal - Contact