Balmoral Software

The Mastermind game is based on an unknown sequence of symbols, numbers, colors or letters that you try to guess. Each attempt to find the hidden answer involves making a guess sequence of the same length from the allowed alphabet of choices, and obtaining a score back that indicates how close your guess is to the secret code. The number of possible codes increases rapidly with longer sequences or alphabets.

Balmoral Software's Mastermind Solver provides solutions to a wide variety of games from the intermediate scores. Given enough guesses (or "moves"), the solver will finish a Mastermind game every time. However, it is structured to find the solution in the fewest number of guesses. Code lengths of 3, 4 or 5 may be specified from alphabets of up to 8 or 10 symbols. An alphabet can be a sequence of numbers starting with 1 or a list of user-specified case-sensitive letters. The latter style may be useful if the alphabet elements are icons or other images that can be represented by single letters; for example, in the computer games here and here.


The usual scoring system, known as Mastermind scoring, awards 10 points for every symbol of the guess code that is found in the same position as in the secret code, plus 1 point for every other symbol of the guess sequence that is found in the secret code, but in an incorrect position. Some variants of the game use a simpler scoring system known as Perfect-match scoring, in which one point is awarded only for each correct symbol that is also in the correct position. Perfect-match scoring is equivalent to the tens digit obtained with Mastermind scoring. If Perfect-match scoring is used instead of Mastermind scoring, the average and maximum number of guesses are about 35-45% higher due to less information being returned to the player.

Repeated symbols

Most Mastermind-style games allow the alphabet symbols to be repeated in a code if desired; however, other versions of the game require all code symbols to be distinct. Games with no repeated symbols may be somewhat easier to solve due to fewer possibilities to consider. If repeated symbols are not allowed, the average number of guesses per game is reduced slightly and the maximum number of guesses is usually about 1 less. The solver supports alphabets of up to 8 symbols that can be repeated, or up to 10 symbols that are not repeated.

Game Parameters

The code length, alphabet size, scoring type and choice of repeated symbols are all game parameters in the solver that can be selected by the player. Preset buttons are provided for some standard games:

GameCode lengthAlphabet sizeScoring typeRepeated symbolsNumber of codes
Super Mastermind58MastermindAllowed32,768
Bulls & Cows410MastermindNot allowed5,040
Jotto variant59Perfect matchNot allowed15,120

The solution procedure used by the Mastermind Solver is either a modified Simple algorithm [1] or the Max Parts algorithm [2], depending on the size of the game. Smaller games take advantage of the fewer moves needed by the more efficient Max Parts algorithm, whereas larger games use a simpler algorithm that doesn't slow down the solver in calculating the next guess. The number of remaining feasible codes is shown for each move in the game. In terms of the number of guesses needed to win a particular type of game, the average and worst-case performance of the solver is shown on the game screen. The optimal starting guess is provided.


[1] Ehud Shapiro, Playing Mastermind Logically, SIGART Newsletter, Vol. 85, pp. 28-29 (1983).
[2] Barteld Kooi, Yet Another Mastermind Strategy, International Computer Games Association (ICGA), 28(1):13-20, 2005.

Home Copyright © 2023 Balmoral Software ( All rights reserved.
Mastermind and Super Mastermind games are copyright © 1971 Invicta, Ltd.
(remove the obvious part)