The aim of the mastermind game is to guess a code given appropriate clues.
The code is a 4-digit number, drawn from 1 to 6. The code can be any number in the range 1111 to 6666.
The computer interrogates the user for a guess of a hidden code (that is generated by the computer).
The computer should return the correct clues to each guess.
The clues returned are evaluated as follows:
If the user has a correct number in the right position the guess scores a ‘bull’.
If the user has a correct guess in the wrong position the guess scores a ‘cow.
If one gets 4 bulls then one has got the correct code.
A bull should not be ‘double-counted’ as a cow.
Suppose the (hidden) code was 3141 and the user guesses
1234 clue/score := 3 cows
as 1234 includes 3 of the numbers in the code but they are all in the wrong position.
2345 clue/score := 1 bull (the 4), 1 cow (the 3)
Suppose code is 6446 (generated by the computer)
Guess Clue-score 1234 1 cow 2345 1 bull 3256 1 bull
The user keeps guessing until they either get it or give up.