MM Phase I

Make sure you know the rules of the game. You could play online with one of several Mastermind web sites.

Representation

There are two logical representations to use for your game state (code). In each, each of the six colored peg available for use in the code is represented by one of the numbers 1 through 6. For the computer’s use, 0 through 5 are marginally better.

  • List of integers: [1,5,3,3]
  • Single integer, base ten: 1533
  • Single integer, base six: 0422. Note that in this representation it makes more sense to use digits 0 through 5 so every base six number 0000 through 5555 represents a valid code.

I recommend the last method because its convenient for enumerating the possibilities easier and even storing results for every code.

Phase I Tasks

  • Implement a scoring function. It should return a tuple (exact, approximate) with the number of “black pegs” and “white pegs” in the response to a guess.

      def score(secret: int, guess: int) -> (int, int);
          pass
    
  • Implement a “complete guesser” that works for binary codes (codes with only two colors). One way to do this is to use the first guess to determine how many black pegs are in the code, and then guess every possible combination with that many pegs.

Architecture

In my Solver class, I use the following interface:

  • Constructor: input is how many slots and how many colors are being used. (In a standard game, these are 4 and 6, respectively.) In the constructor I create an instance variable containing every possible configuration.
  • generate_guess() -> int: Return the next code to guess.
  • register_feedback(guess: int, exact: int, approximate: int): Inform the solver how many were exactly and approximately correct. Updates the internal state of the solver so that this information will be used on the next guess.