The Game

Mastermind (https://en.wikipedia.org/wiki/Mastermind_(board_game)) is an old game. The plastic version that was ubiquitous in every house with children was invented in 1970. I got a board around 1980 as a Christmas gift and solving the game puzzle in BASIC language was one of the first programs that I created around 1984.

The game board contains holes in several rows in four columns. There are plastic pins of six different colors that can be inserted into the holes. Each pin has one color. They are usually red, green, blue, yellow, black, and white. There is a special row that is hidden from one of the players (the guesser).

To play the game, one of the players (hider) has to select four pins from a set of pins. The selected pins should have different colors. The pins are placed in the hidden row one by one, each into a position.

The guesser tries to find out what colors are in which position guessing. Each guess takes place selecting four pins and placing them in a row. The hider tells the guesser how many pins are in correct position and how many have a color that is on the table, but are not in the position where that color is hidden.

A sample play may go like this:

  • The hider hides four pins with color blue, yellow, white, and black.
  • Guesser guesses yellow, blue, green, and red.
  • The hider tells the guesser that there are two colors matching, but none of them is in the position in the hidden row. The hider says this because yellow and blue are in the hidden row but not in the positions as the guesser guessed. They are actually swapped, but this information the hider keeps a secret. All she says is that there are two colors matching, none in the correct position.
  • The next guess is ...

The game finishes when the guesser finds the correct colors in the correct order. The same game, as on the figure, can also be described with textual notation, B for blue, Y for yellow, G for green, W for white, R for red, and b for black (lucky we have upper and lower case letters on the computer).

RGBY 0/0
GRWb 0/2
YBbW 0/2
BYGR 0/4
RGYB 2/2
RGBY 4/0

Guess what! This is the actual output of the program that we develop in this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.135.36