A Gentle Introduction to the Game Mastermind

Rules

Mastermind (tm) is a two-player game. One player, whom we'll call the code maker, creates a code that consists of a sequence of n objects chosen from a set of m possibilities. For the sake of this description, let's suppose that the code maker creates a code that consists of a sequence of four colors chosen from a set of four colors.

For example, if the set of possibilities is { Blue, Red, Green, Yellow }, the code maker might create the following code:

Blue - Red - Green - Yellow

Order matters in the code, so the previous code is different than the following:

Red - Blue - Green - Yellow

The second player, whom we'll call the code breaker, tries to determine the sequence in some limited number of guesses. If the second player figures out the code within the allowed number of guesses, she "breaks the code" and wins the game. If she doesn't, then the code maker wins the game.

During play, the code breaker cannot see the code maker's sequence. She makes a guess by proposing a 4-color sequence. The code maker scores the guess by telling the code breaker how many of the guessed values are the right color in the right position and how many are the right color in the wrong position. Given this information, the code breaker tries to deduce how many choices were neither the right color nor in the right place, by a sequence of guesses. The code maker's feedback can be shown graphically as a number of black pegs (for guesses of the right color in the right position) and number of white pegs (for guesses of the right color in the wrong position).

For example, suppose that the code maker chooses the following code:

Red - Blue - Red - Yellow

and the code breaker guesses

Blue - Red - Green - Yellow

The code maker would respond with one black peg and two white pegs. The code breaker has identified the Yellow peg in the correct position to earn the black peg. She has also identified correctly the Blue peg and the Red peg, but in the wrong positions. The code breaker might then guess

Blue - Yellow - Red - Red

The code maker would respond with one black peg and three white pegs. The code breaker has identified the Red peg in slot three and also the Blue, Red, and Yellow pegs in the wrong positions.

Play proceeds until either the code breaker guesses the sequence correctly or uses up the allotted number of guesses without identifying the code. In each case, the code maker gives an appropriate response, including revealing the code if the code breaker didn't identify it.

The following image shows the results of several plays. The first guess is at the bottom of the image.

In this game, the code breaker started by guessing four blue pegs. The code maker responded with one black peg (one peg is the right color in the right position) and no white pegs (no pegs of the right color but wrong position). The last guess was

Red - Yellow - Blue - Red

The code maker responded with one black peg (one peg is the right color in the right position) and three white pegs (three pegs of the right color but wrong position). The code breaker is close!

The Hasbro Version of Mastermind

This game is a variation of several common parlor games, but the name "Mastermind" is the property of Hasbro, Inc. This description of the game is intended to mimic the common parlor game. It is not an official description of Hasbro's game, and neither this description nor the associated programming assignment is endorsed by Hasbro in any way.

While on the topic of Hasbro, you might get a kick out of looking at the instructions included with the company's versions of the game:

My, how the glitziness of marketing has to change over time!

Eugene Wallingford ==== wallingf@cs.uni.edu ==== April 18, 2005