Mastermind is a codebreaking for game for two players. One player takes the role of a codemaker and the other, the codebreaker. The codemaker chooses a secret codeword and the codebreaker tries to decypher the codeword using the clues the codemaker leaves behind.
docker run -it $(docker build . -q)- The codemaker chooses a secret codeword, a four digit PIN in which each digit can only be from 0 to 5.
- The codebreaker guesses the codeword.
- The codemaker tells the codebreaker how close the guess was by saying the number of digits in the guess that have the:
- (Black) Correct value and correct position
- (White) Correct value but incorrect position
- (None) Incorrect value and incorrect position
- When the clue is all black, the codebreaker wins.
========Game 1======== Enter secret code: ========Turn 1======== Enter secret code: 1100 Response: black=1, white=0, none=3 ========Turn 2======== Enter secret code: 3320 Response: black=1, white=2, none=1 ========Turn 3======== Enter secret code: 4302 Response: black=3, white=0, none=1 ========Turn 4======== Enter secret code: 2302 Response: black=3, white=0, none=1 ========Turn 5======== Enter secret code: 5302 Response: black=4, white=0, none=0 ========Winner======== Answer: 5302 The computer codebreaker uses Donald Knuth's minimax algorithm, which can break the code in five or fewer moves.