Introduction Mastermind - Rules of the Game
Homepage
  Fore note: this game requires JavaScript and DynamicHTML. Please make sure your browser has JavaScript enabled.

1. Summary
2. How to play
3. Rules
4. Examples
5. High scores
6. Notes
7. The colour game

1. Summary

The goal of Mastermind is to discover a combination of of coloured pegs selected by the computer at random.

At each turn, the player chooses a combination of coloured pegs and the computer returns one black dot for each peg on the right position and one white dot for each peg present in the combination in a different position.

Then the player chooses a different combination, adding pegs of other colours, switching the order of the coloured pegs, or both.

The game continues until the combination is found or the maximum number of turns is reached.

This implementation of Mastermind offers three levels of increasing difficulty. From level I to level III, the number of pegs and the number of possible colours increase and also the maximum number of turns.

Table 1: game features on each level
  number of pegs number of colours number of turns
level I 4 6 8
level II 5 7 10
level III 6 8 12

1. Summary
2. How to play
3. Rules
4. Examples
5. High scores
6. Notes
7. The colour game

2. How to play

2.1. The game board

An example of the level I board is shown on the right.

The board shows the key pegs on the top; these will be hidden until the end of the game.

The game progresses from top to bottom, one turn on each row. In this example, the two rows under the key show the first and second turns and the next row shows the undefined pegs for the third turn.

The column on the right shows the results for each turn.

example, level I
   
   
   
   
   

2.2. The game sequence

Each turn is composed of five steps:

  1. To select one coloured peg, the player clicks one of the circles and chooses the desired colour from the table of colours. When a colour is selected (clicked), the circle is replaced by a peg of the desired colour.
  2. In case of mistake, it is possible to choose a different colour, selecting the wrong peg and choosing a new colour.
  3. The process is repeated until all the circles are filled with coloured pegs. At this moment, the symbol appears on the right column.
  4. When the player is satisfied with the proposed combination, the player clicks on the symbol. Otherwise, one can correct the peg sequence until the desired combination is attained. Only then the turn is validated, by clicking on .
  5. The computer evaluates the combination and returns an answer: one black dot for each peg that coincides with the peg on the secret key and one white dot for each peg contained in the secret key in a different position. The order of the dots is arbitrary.

If the player hits the key - the number of the black dots is equal to the number of pegs -, the game ends. The key is revealed on top and a green flagis shown on the right.

If the combination is not correct and there are empty turns to play, a new row with the symbols appears below the last one.

If the maximum number of turns is reached before the key is discovered, the player looses. The key is revealed on top and a red flagis shown on the right.

At any instant during the game, if the player clicks an invalid point a yellow warning flagappears on the top right corner of the board.

The command "Quit the game" terminates the game at any moment, revealing the key.

The command "jogar de novo . play again . jouer à nouveau" starts a new game at the same level. To choose a different level, one should return to the Introduction. To choose a different game one should return to the homepage.

 
1. Summary
2. How to play
3. Rules
4. Examples
5. High scores
6. Notes
7. The colour game

3. Rules

The key is a combination of N coloured pegs, chosen from a set of possible colours P, with or without repetition.

Each turn is formed by a combination of N coloured pegs, chosen from a set of possible colours P, with or without repetition.

On Table 1 the values for N and P are shown for the three levels of the game.

After each turn, the computer compares the proposed combination with the key:

  1. For each position on the player's turn, from 1 to N, the peg on the turn is compared with the peg in the key at the same position. In case they match, the computer puts a black mark on the right column.
  2. For each position on the current turn - from 1 to N - that has not been matched before (thus, it does not correspond to a black or white mark), a peg with the same colour in any other position of the key is searched. If a correspondence with a previously unmatched peg in the key is found, the computer indicates such occurrence with a white mark.
  3. The order of black and white marks on the right column is arbitrary.
 
1. Summary
2. How to play
3. Rules
4. Examples
5. High scores
6. Notes
7. The colour game

4. Examples

The illustration of the game is based on Level I examples but the translation to other levels is straightforward.

In addition to the illustration of the rules, a crude explanation of a possible reasoning is offered.

The sorting of pegs is from left to right: first peg on the left, forth peg on the right.

 

 

4.1. Example of rule application and deduction of the hidden key

Let's assume the following hidden key:

Let's assume the first two turns are as illustrated on the right.

Given the key and the turns chosen by the player the computer determines the following:

  1. On the first turn there is a match on the second position. Notice that the match on the same position (black mark) overrides a match on different positions (white mark).
  2. On the second turn, the second peg of the key matches the third or fourth peg of the turn - in either case is a white mark match. In addition, the third peg in the key matches the first or second peg in the player's turn (white mark).

The analysis the two turns returns:

  1. On the first turn one concludes there is exactly one red peg .
  2. On the second turn one concludes that two or the proposed pegs are present in the key, albeit at different positions. Notice this result suits three hypotheses : two red pegs, two green pegs or one red peg and one green peg.
    Combining this analysis with the first turn, one concludes that only the third hypothesis is possible. Moreover, one concludes that the red peg lies on the first or second positions (on the left), while the green peg must lie on the third or fourth positions (on the right).

Let's assume the third and fourth turns are played as illustrated on the right.

Given the key and the turns played, the computer determines the following:

  1. On the third turn, there is a match between the second peg in the key and the first peg in the turn (white mark). There is also a match between the first peg of the key - or fourth peg, it's immaterial - and the second peg of the turn (white mark).
  2. On the fourth turn there is a match between the second peg of the key and the second peg of the turn (black mark), a match of the first or fourth peg of the key with the third peg of the turn (white mark) and a match between the third peg of the key and the fourth peg of the turn (white mark).

The analysis the two turns returns:

  1. On the third turn, one concludes that the red peg still is on wrong position, which, in combination with the second turn, yields the conclusion that the red peg must lie in the second position of the key.
    Moreover, one concludes there might be red pegs or yellow pegs , but not both. In either case, there might be one or two pegs.
  2. On the fourth turn, one concludes that only the red peg is on the right position. Combining the second and fourth turns, one deduces the green peg is necessarily on the third position of the key.
    Moreover, there are yellow pegs or turquoise pegs , but not both. In the first case, one or two pegs may exist; in the latter case, there would be a turquoise peg and a blue peg .

Let's assume the fifth and sixth turns are played as illustrated on the right.

Given the key and the turns played, the computer determines the following:

  1. On the fifth turn there are matches on the second, third and fourth positions of the key and the turn (three black marks).
  2. On the sixth turn the four pegs of the turn are matched with the corresponding four pegs of the key and the game concludes with successfully.

The analysis of the two turns, combined with the previous four turns returns:

  1. On the fifth turn, one confirms that the red peg and the green peg are correctly placed. One concludes that one yellow peg or a pink peg might exist but not both.
  2. On the sixth turn, the key was deduced.
    Although it might elude the inexperienced player, this was the only possible combination after the fifth turn: on the fourth turn one had concluded that one or two yellow pegs could exist, or, alternatively, there were a blue peg and a turquoise peg . Thus, if one were to reject the existence of yellow pegs, it was necessary to admit the admit that presence of one blue peg, one turquoise peg and one pink peg, in a total of five pegs, which is impossible. Therefore, yellow must exist and take the two available positions, since it can not coexist with pink.

4.2. Example with deduction of the key

The table on the right shows another example of deduction. The secret key is revealed on the top line.

One possible line of deduction - among the many possible - is presented, leading towards the correct solution:

  1. On the first turn, one concludes that there is only one turquoise peg or one yellow peg; in either case, on different positions than the selected ones.
  2. On the second turn, one concludes there are no blue pegs or turquoise pegs , therefore, there is one or two yellow pegs on the third and/or fourth positions.
  3. After the third turn, the deduction line is forked in two hypotheses:
    a) if one admits the yellow peg is on the correct position, then, there is only one red peg , necessarily on the fourth position, and one or two green pegs on the first or second positions.
    b) if one admits the yellow peg is on the wrong position, implies that it must lie on the fourth position. Following this reasoning, one of the red pegs is on the correct position and a green peg or a second red peg could exist on the third position.
  4. The fourth turn followed the latter hypothesis, with two red pegs . This hypothesis proved wrong, since the match of the yellow peg on the fourth position has failed (a black mark is missing).
    Thus, the first hypothesis is right, the yellow peg is on the third position and the red peg is on the fourth position. One can still deduce there is one pink peg , necessarily on the second position, and there is a green peg , necessarily on the first position.
  5. This hypothesis is confirmed on the fifth turn, and the game concludes successfully.

4.3. Notes

These examples do not intend to "teach you" how to play Mastermind. The goal is to illustrate the rules used by the computer and introduce new players of the game into the typical deductive processes that apply to the game and highlight its differences from the colour game.

There was also a concern to show a limited set of hypotheses to explore to help new players understand the rules.

Like the colour game, Mastermind depends on chance to some extent but depends much more on the player's deductive skills and experience. A seasoned player recognises the patterns of coloured pegs and corresponding black and white marks and deploys the various possibilities without stating them explicitly peg by beg. It should be emphasised that Mastermind patterns are completely different from the colour game patterns.

1. Summary
2. How to play
3. Rules
4. Examples
5. High scores
6. Notes
7. The colour game

5. High scores

This Mastermind implementation offers the possibility of storing the high scores reached on each computer. To this purpose, a cookie is stored on the computer disk. This option is only available in case you allow the use of cookies.

It must be emphasised that no information is sent to the server where the game is installed. If you're moving to another browser or to another computer, you will start a new table of high scores.

The high score table stores the number of turns to success, the key, your name and the date.

The procedure is straightforward: upon success, the computer checks your result with the scores on the board. If you have reached a better result, you are invited to write your name - or any message - up to 44 characters. In case you do not want to record you score you may "Close" this option.

When a new score is added to the table, it is shown automatically. To check the current high scores at other times, follow the "High score table" link in the "Introduction" page.

The high score table shows the results for each level. From this page it is possible to start a new game on the same level with "jogar de novo . play again . jouer à nouveau", "Reset high scores" on this level or review the tables for the other levels.

1. Summary
2. How to play
3. Rules
4. Examples
5. High scores
6. Notes
7. The colour game

6. Notes

  1. The pages of the game initialise a new game each time they are loaded. Thus, using reload or refresh will yield a new game with a different colour key.
    Likewise, if you move to a new page - these rules, for instance - an then returns to the game, you will find a new game. Therefore, if you want to check another page during a game, I suggest you target it to a new page.
  2. You're advised to wait for the complete loading of the images on the page, especially the black and white marks that show the outcome of each turn, before starting a new turn. This is due to traffic slowdown on the net. These problems are overcome after some games since the images are cached.
  3. Following suggestions of a few players, the number of possible turns for levels I to III increased from 6, 8 and 10 to 8, 10 and 12, respectively. This implementation becomes similar to other Masterminds, such as this Java implementation.
1. Summary
2. How to play
3. Rules
4. Examples
5. High scores
6. Notes
7. The colour game

7. The colour game

The colour game is my personal variation of Mastermind.

The colour game rules are very similar to the Mastermind rules. They differ only in the manner the white pegs (right colour at the wrong location) are computed.

This minor change suffices to change deeply the game algorithms and the deduction patterns. Thus, I advise you not to change too often between the two games to minimise the confusion.

Introduction  
Homepage

I wish you many pleasant moments with the Mastermind game. In case you have any doubts, remarks or suggestions, feel free to contact me. All messages are welcome.

©2001 João Gomes Mota