MasterMind
MasterMind is a board game with two players; in this
case the user choses the secret and the program does the
guessing. Unfortunately, the board is not visualised.
Here is a sample interaction:
examples> ./MasterMind
Welcome to Mastermind!
Choose your secret. Press return when ready.
My guess: Red Blue Blue Red
Answer (two integers): 1 1
My guess: Blue Black Yellow Red
Answer (two integers): 2 0
My guess: Green Black Red Red
Answer (two integers): 0 0
My guess: Blue Blue Yellow White
Answer (two integers): 3 0
My guess: Blue Blue Yellow Blue
Answer (two integers): 3 0
My guess: Blue Blue Yellow Yellow
Answer (two integers): 4 0
Yippee!
Do you want to play again? (y/n) n
examples>
The program is too long to display here. We only note a few things:
- The program makes use of two auxiliary modules
Data.Functional.List and RandomGenerator. The
former is a library module, while the latter is provided in the
examples directory.
- The program complains if the user gives contradictory answers,
asks for the secret and explains the user's mistake.
- There is no error handling: if an answer cannot be parsed as
two integers, the program crashes.