Playing Mastermind/Codebreaker
Mastermind (or CodeBreaker) is a game played by two players: Maker and Breaker. The Maker secretly chooses a code consisting of 4 pegs, each of which is any of the 6 colors. The Breaker tries to determine the secret code by repeatedly guessing a code of the same format. The Maker provides a response based on how close the guess code is to the secret code. This response is two numbers, called Black and White: Black is how many pegs are correct and in the correct position, and White is how many pegs are correct but in the wrong position.
Your goal is to complete two programs: one in which the computer is the Maker and one where the computer is the Breaker.
The colors will represent by numbers from 0 - 5. It is assumed that the response given is a nonnegative interger, where tens digit is the Black and the ones digit is the White; so a response of 21 means tat Black was 2 and While was 1, such as when the secret and guess are 1202 and 1052.
Task 1:
Create a class Code stored in Code.cpp. For this task it needs only to work with the Maker program provided. That is, Code needs
-a constructor taking a string
-a (static) score function called compare
-a (static) function that creates a random code and returns it
-a display function that prints out the code
The code for Maker should not be changed.
Task 2
Create a suitable class CodeList that stores a set/list of Codes. This class will be used by your Breaker program stored in Breaker.cpp. Breaker solves Mastermind by using the "random feasible strategy". That is, each round a guess is chosen at random from the list of all codes that can still be the secret.
It is your choice how you store CodeList and what member function you give to CodeList, but please include the following
-an array of Codes
-an array of booleans signifying whether the corresponding code was still alive
-a constructor that creates a list of all possible codes;
-a member function that returns a random entry in the (live) list
-a filter member function that kills all Codes incompatible with the latest guess and response
Task1 Due 5/21/13 Noon
Task2 Due 5/24/13 Noon