# Mastermind

This tool offers some well-known strategies for solving the Mastermind board game like the MinMax, Entropy, ExpectedSize and MaxParts strategies. Mastermind is a simple two-player code-breaking board game. In the game, one player is the codemaker and the other is the codebreaker. The codemaker secretly selects a code consisting of an ordered sequence of four colors (c1,c2,c3,c4), each chosen from a set of six possible colors where repetitions are allowed. Thus, there are 64=1296 possible codes.

The codebreaker then tries to guess the code by repeatedly proposing a guess (g1,g2,g3,g4). After each guess, the codemaker tells the codebreaker two numbers (b,w):

• b is the number of correct colors in the correct positions, i.e., the number of positions j such that cj=gj holds
• w is the number of colors that are part of the code but not in the correct positions, i.e., the number of positions j such that cj≠gj holds, but where cj=gk for some k where gk has not been used in another hit
While b is clearly understood, the definition of w is often difficult to understand. Mathematically, it is can be computed as w=(∑j=0..5 min(num(j,c),num(j,g)))-b where num(j,c) is the number of times color j occurs in the code c.

In the tool below, one can specify the number of colors, the number of places (code length), and a strategy to be used by the codebreaker. Moreover, a code to be broken has to be specified which is, of course, kept secret from the codebreaker. The tool then simulates the game where the codebreaker makes guesses according to the selected strategy to break the code.

 strategy Minimize Maximal Number of Remaining Possibilities Maximize Entropy of Answer Distribution Minimize Expected Number of Remaining Possibilities Maximize Number of Non-Empty Possible Answers #colors #places secret code

The above strategies can also be drawn as trees where each node contains the guess made by the codebreaker (we have additionally added the number of possible codes remaining when making the guess):

References:
• [1] D.E. Knuth: The computer as master mind, Journal on Recreational Mathematics, 9(1):1–6, 1976.
• [2] B. Kooi: Yet another Mastermind strategy, International Computer Games Association (ICGA), 28(1):13–20, 2005.
• [3] K. Koyoma and T. Lai: An optimal Mastermind strategy, Journal of Recreational Mathematics, 25(4):251–256, 1993.
• [4] E. Neuwirth: Some strategies for Mastermind, Zeitschrift für Operations Research (ZOR), 26:257–278, 1982.