The Game of Mastermind

Background and Introduction

The Basic Idea of the Game of Mastermind

Mastermind is a game of skill, in which two players engage in a battle of wits and logic. One of the players is called the Codemaker, and this player chooses, then hides, a secret code, which the other player, who is called the Codebreaker, must attempt to discover. A move in the game of Mastermind consists of the following two steps:

  1. The Codebreaker supplies a guess for the secret code hidden by the Codemaker.
  2. The Codemaker then scores the Codebreaker's guess against the hidden secret code, and provides the Codebreaker with this score, as feedback to the Codebreaker to be used in preparing the next guess.

The idea is that each successive score will give the Codebreaker more information about the hidden secret code, so that successive guesses become more and more "educated", until the identity of the secret code is determined. Generally, the Codebreaker is limited to a fixed number of guesses. There may be a penalty if the Codebreaker fails to guess the secret code before this fixed number of guesses is exceeded and/or a bonus if the correct guess is made within a certain (small) number of guesses. There may also be a penalty (and perhaps a forfeit of, or a replay of, the game) if the Codemaker is found to have given the wrong information by scoring incorrectly.

There are many variations of the game. A standard one is to conduct a match, in which the players agree in advance to exchange the roles of Codemaker and Codebreaker for a given (even) number of games. The winner is the player with the smaller total number of guesses, or the larger total number if each point—that is, each guess made—is "awarded" to the Codemaker, rather than "charged" to the Codebreaker. In such a match, if there is a game in which the Codebreaker fails to guess the secret code within the maximum number of guesses permitted, the number of points for that game might be counted as one more than the maximum number of guesses allowed (as one simple example of a possible penalty scheme).

Coding, Guessing and Scoring in the Original Mastermind Board Game

In the original Mastermind board game, the necessary equipment included the following:

  1. A decoding board, containing ten rows of holes for the coding pegs and scoring pegs (or key pegs, as the scoring pegs are also called). Each of these rows contains four large holes for the coding pegs, and four smaller holes, adjacent to the larger holes, for the scoring pegs. The board also has a special row at one end, which contains just four of the larger holes. The secret code is placed in this row.
  2. A shield that either sits on, or plugs into, the decoding board, in front of the special row, and thus hides the Codemaker's secret code from the Codebreaker's view.
  3. A quantity of colored coding pegs, each of which fits into any hole of the larger size. There are six different colors, excluding both black and white, and a dozen or so pegs of each of the six colors.
  4. About forty or fifty smaller scoring pegs, divided equally between black and white. Each of these pegs will fit into any hole of the smaller size.

The Codemaker sits at the end of the board containing the special row, and begins by choosing colored pegs for the secret code and placing them in the holes of the special row, behind the shield, in any order. The pegs may be all of the same color, all different, or any combination in between. The Codebreaker then chooses colored pegs for the first guess and inserts these pegs into the first of the guess rows at the Codebreaker's end of the board. The Codemaker compares the guess with the hidden secret code and indicates to the Codebreaker the "score" for that guess by inserting the appropriate number of black and/or white pegs into the smaller holes adjacent to the guess row.

To provide the score for the current guess supplied by the Codebreaker, the Codemaker compares that guess with the hidden secret code, and determines the following two values:

  1. The number of pegs that match in both color and position in the two codes (this is called the number of exact matches)
  2. The number of pegs in the two codes that match only in color but not in position (this is called the number of color matches only)

Note that in determining these two values, the Codemaker must be careful not to count any peg more than once.

The Codemaker then inserts into the smaller holes opposite the current guess row (the row into which the Codebreaker has most recently placed a guess) a number of black pegs equal to the number of exact matches, and a number of white pegs equal to the number of color matches only. There is nothing about the placement of the black and white scoring pegs to indicate which of the guess pegs correspond to which of the secret code pegs. In other words, the positioning of the scoring pegs has no significance, only the number of each color. If neither a black peg nor a white peg is placed in one of the smaller holes, this means that the Codebreaker has used a color not found in the secret code. And, by extension, if no black or white pegs are placed, this means that the secret code contains none of the colors chosen by the Codebreaker.

The number of black pegs, together with the number of white pegs, form the score used by the Codebreaker to assist in making the subsequent guesses, which proceed similarly until the Codebreaker either guesses the secret code, or runs out of guesses. Once played, all pegs remain in place until the end of the current game.

Both players must exercise a certain amount of care, the Codebreaker in guessing, and the Codemaker in scoring.