Playing Mastermind with GoldSim


This model shows an implementation of the classic game Mastermind. If you are not familiar with this game, see the following Wikipedia article for a description: Mastermind (board game). The GoldSim implementation of the game makes use of some of GoldSim's most interesting features including: (1) advanced dashboard capabilities such as dynamic hiding/showing of controls, (2) Script elements and (3) a Looping Container.

"Mastermind". Licensed under CC BY-SA 2.0 via Wikimedia Commons.

In the GoldSim version of the game, each realization is a game and each time step in a realization allows the codebreaker one guess. The duration of the simulation is 12 days with 1-day time steps, giving the codebreaker 12 guesses. Be sure to step the model to day 1 to register your first guess. NOTE that in order to play the game, you must uncheck the 'Begin simulation immediately on entering Run Mode' option in the 'General' tab of the Model Options dialog. Also, note that the model file is intended to be used with GoldSim version 11.1.3 or later.

Both the code-making and the code-breaking can be done by a human player or by GoldSim. Before play begins, these options are specified using dashboard drop-lists. If the player-specified option is selected for either, a set of sliders is dynamically shown or enabled to allow the code and the guesses to be specified.

During the course of play, GoldSim tracks the guesses. The right-most column of the dashboard shows a history of all guesses and the 'score' each guess received. The 'score' is two numbers that indicate (as described in the Wikipedia article) the number of 'pegs' that are correct in color and position and the number of 'pegs' that are correct in color only. A toggle button ('Show Hint') can be used to show/hide a computer-generated guess (randomly selected from the remaining possible solutions using a Looping Container) in the left-most column. Another toggle button ('Show # of Possible Choices') shows a count of 'codes' that are still possible based on the history of guesses and the corresponding 'scores'. If you either run out of guesses or you give up, another toggle button ('Show Code') allows you to see the code.

The algorithm that GoldSim uses to make its guesses or to provide hints is quite simple and is based on the 'Five-guess algorithm' described in the Wikipedia article. When you make a guess and 'register' the guess by clicking the time step button on the run controller, a Script element 'scores' the guess. Another Script element then iterates over all possible codes (initially 1296 i.e. 6^4) and eliminates all codes that do not give that 'score' when compared against the current guess. Then, to generate the next hint, GoldSim randomly selects a code from among the remaining possible codes. A Looping Container is used to repeatedly sample a number between 1 and 1296 until a code is found that has not already been eliminated.

At the bottom of the 'Guess' column (the middle column), you can always see the number of guesses you've used in the current game. You can also look at a distribution result element (by clicking the 'All Results' button) to see the results for all realizations (i.e. games).


Making Better Decisions In An Uncertain World