Mastermind (board game)


Mastermind or Master Mind is a code-breaking game for two players. The modern game with pegs was invented in 1970 by Mordecai Meirowitz, an Israeli postmaster and telecommunications expert. It resembles an earlier pencil and paper game called Bulls and Cows that may date back a century or more.

Gameplay and rules

The game is played using:
The two players decide in advance how many games they will play, which must be an even number. One player becomes the codemaker, the other the codebreaker. The codemaker chooses a pattern of four code pegs. Duplicates and blanks are allowed depending on player choice, so the player could even choose four code pegs of the same color or four blanks. In the instance that blanks are not elected to be a part of the game, the codebreaker may not use blanks in order to establish the final code. The chosen pattern is placed in the four holes covered by the shield, visible to the codemaker but not to the codebreaker.
The codebreaker tries to guess the pattern, in both order and color, within eight to twelve turns. Each guess is made by placing a row of code pegs on the decoding board. Once placed, the codemaker provides feedback by placing from zero to four key pegs in the small holes of the row with the guess. A colored or black key peg is placed for each code peg from the guess which is correct in both color and position. A white key peg indicates the existence of a correct color code peg placed in the wrong position.
If there are duplicate colours in the guess, they cannot all be awarded a key peg unless they correspond to the same number of duplicate colours in the hidden code. For example, if the hidden code is white-white-black-black and the player guesses white-white-white-black, the codemaker will award two colored key pegs for the two correct whites, nothing for the third white as there is not a third white in the code, and a colored key peg for the black. No indication is given of the fact that the code also includes a second black.
Once feedback is provided, another guess is made; guesses and feedback continue to alternate until either the codebreaker guesses correctly, or twelve incorrect guesses are made.
Traditionally, players can only earn points when playing as the codemaker. The codemaker gets one point for each guess the codebreaker makes. An extra point is earned by the codemaker if the codebreaker is unable to guess the exact pattern within the given number of turns. The winner is the one who has the most points after the agreed-upon number of games are played.
Other rules may be specified.

History

The game is based on an older, paper based game called Bulls and Cows. A computer adaptation of it was run on Cambridge University’s Titan computer system, where it was called 'MOO'. This version was written by Frank King. There was also another version for the TSS/8 time sharing system, written by J.S. Felton and finally a version for the Multics system at MIT by Jerrold Grochow.
The modern game with pegs was invented in 1970 by Mordecai Meirowitz, an Israeli postmaster and telecommunications expert. Meirowitz presented the idea to many major toy companies but, after showing it at the Nuremberg International Toy Fair, it was picked up by a plastics company, Invicta Plastics, based near Leicester, UK. Invicta purchased all the rights to the game and the founder, Edward Jones-Fenleigh, refined the game further. It was released in 1971–2.
Since 1971, the rights to Mastermind have been held by Invicta Plastics. They originally manufactured it themselves, though they have since licensed its manufacture to Hasbro worldwide, with the exception of Pressman Toys and Orda Industries who have the manufacturing rights to the United States and Israel, respectively.
Starting in 1973, the game box featured a photograph of a well-dressed, distinguished-looking man seated in the foreground, with a woman standing behind him. The two amateur models reunited in June 2003 to pose for another publicity photo.

Algorithms and strategies

Before asking for a best strategy of the codebreaker one has to define what is the meaning of "best": The minimal number of moves can be analyzed under the conditions of worst and average case and in the sense of a minimax value of a zero-sum game in game theory.

Best strategies with four pegs and six colors

With four pegs and six colours, there are 64 = 1296 different patterns.

Worst case: Five-guess algorithm

In 1977, Donald Knuth demonstrated that the codebreaker can solve the pattern in five moves or fewer, using an algorithm that progressively reduces the number of possible patterns.
The algorithm works as follows:
  1. Create the set S of 1296 possible codes
  2. Start with initial guess 1122
  3. Play the guess to get a response of coloured and white pegs.
  4. If the response is four colored pegs, the game is won, the algorithm terminates.
  5. Otherwise, remove from S any code that would not give the same response if it were the code.
  6. Apply minimax technique to find a next guess as follows: For each possible guess, that is, any unused code of the 1296 not just those in S, calculate how many possibilities in S would be eliminated for each possible colored/white peg score. The score of a guess is the minimum number of possibilities it might eliminate from S. A single pass through S for each unused code of the 1296 will provide a hit count for each coloured/white peg score found; the coloured/white peg score with the highest hit count will eliminate the fewest possibilities; calculate the score of a guess by using "minimum eliminated" = "count of elements in S" - "highest hit count". From the set of guesses with the maximum score, select one as the next guess, choosing a member of S whenever possible.
  7. Repeat from step 3.

    Average case

Subsequent mathematicians have been finding various algorithms that reduce the average number of turns needed to solve the pattern: in 1993, Kenji Koyama and Tony W. Lai performed an exhaustive depth-first search showing that the optimal method for solving a random code could achieve an average of 5625/1296 = 4.3403 turns to solve, with a worst-case scenario of six turns.

Minimax value of game theory

The minimax value in the sense of game theory is 5600/1290 = 4.341. The minimax strategy of the codemaker consists in a uniformly distributed selection of one of the 1290 patterns with two or more colors.

Genetic algorithm

A new algorithm with an embedded genetic algorithm, where a large set of eligible codes is collected throughout the different generations. The quality of each of these codes is determined based on a comparison with a selection of elements of the eligible set. This algorithm is based on a heuristic that assigns a score to each eligible combination based on its probability of actually being the hidden combination. Since this combination is not known, the score is based on characteristics of the set of eligible solutions or the sample of them found by the evolutionary algorithm.
The algorithm works as follows:
  1. Set i = 1
  2. Play fixed initial guess G1
  3. Get the response X1 and Y1
  4. Repeat while XiP:
  5. # Increment i
  6. # Set Ei = and h = 1
  7. # Initialize population
  8. # Repeat while hmaxgen and |Ei| ≤ maxsize:
  9. ## Generate new population using crossover, mutation, inversion and permutation
  10. ## Calculate fitness
  11. ## Add eligible combinations to Ei
  12. ## Increment h
  13. # Play guess Gi which belongs to Ei
  14. # Get response Xi and Yi

    Complexity and the satisfiability problem

In November 2004, Michiel de Bondt proved that solving a Mastermind board is an NP-complete problem when played with n pegs per row and two colors, by showing how to represent any one-in-three 3SAT problem in it. He also showed the same for Consistent Mastermind.
The Mastermind satisfiability problem is a decision problem that asks, "Given a set of guesses and the number of colored and white pegs scored for each guess, is there at least one secret pattern that generates those exact scores?" In December 2005, Jeff Stuckman and Guo-Qiang Zhang showed in an arXiv article that the Mastermind satisfiability problem is NP-complete.

Variations

Varying the number of colors and the number of holes results in a spectrum of Mastermind games of different levels of difficulty. Another common variation is to support different numbers of players taking on the roles of codemaker and codebreaker. The following are some examples of Mastermind games produced by Invicta, Parker Brothers, Pressman, Hasbro, and other game manufacturers:
GameYearColorsHolesComments
Mastermind197264Original version
Royale Mastermind19725 colors × 5 shapes3
Mastermind44197265For four players
Grand Mastermind19745 colors × 5 shapes4
Super Mastermind 1975 85
Word Mastermind197526 letters4Only valid words may be used as the pattern and guessed each turn.
Mini Mastermind197664Travel-sized version; room for only six guesses
Number Mastermind19766 digits4Uses numbers instead of colors. The codemaker may optionally give, as an extra clue, the sum of the digits.
Electronic Mastermind 197710 digits3, 4, or 5Uses numbers instead of colors. Handheld electronic version. Solo or multiple players vs. the computer. Invicta branded.
Walt Disney Mastermind197853Uses Disney characters instead of colors
Mini Mastermind 198864Travel-sized version; room for only six guesses
Mastermind Challenge199385Both players simultaneously play code maker and code breaker.
Parker Mastermind199384
Mastermind for Kids199663Animal theme
Mastermind Secret Search199726 letters3-6Valid words only; clues are provided letter-by-letter using up/down arrows for earlier/later in the alphabet.
Electronic Hand-Held Mastermind 199764Handheld electronic version. Hasbro.
New Mastermind200484For up to five players
Mini Mastermind200464Travel-sized self-contained version; room for only eight guesses

The difficulty level of any of the above can be increased by treating “empty” as an additional color or decreased by requiring only that the code's colors be guessed, independent of position.
Computer and Internet versions of the game have also been made, sometimes with variations in the number and type of pieces involved and often under different names to avoid trademark infringement. Mastermind can also be played with paper and pencil.
There is a numeral variety of the Mastermind in which a 4-digit number is guessed.
The game was compiled into for the Switch under the name "Hit & Blow".