Mastermind
For your next project, you will implement the game of Mastermind. The
rules of the game of Mastermind can be found
here.
Mastermind is a single player game, where the computer picks a random
code of four colors, and the user tries to guess the code. After
each guess, the computer tells the player how many guesses were the
correct color in the correct location, and how many guesses were the
correct color in the incorrect location. For each correct color
in the correct location, the computer gives the player a black token,
and for each correct color in the incorrect location, the computer
gives the player a white token. For example, if the secret code
was:
Blue Black
Blue Red
And the player guessed:
Blue Red Red Yellow
Then the computer would respond with:
Black White
Since one color (blue) was in the correct location, and one color (red)
was correct, but in the wrong location.
Likewise, if the secret code was:
Yellow Yellow Blue Green
and he player guessed
Red Black
Yellow
Blue
Then the computer would respond
White White
Since no color is in the correct location, but two colors (yellow and
blue) are correct, but in the wrong locations.
The player has up to eight guesses to try to figure out the secret code.
Part I
For part I of the assignment, you will create a command-line version of
Mastermind. The computer will prompt the user for a guess
and then print the result. Play continues until the secret
code is guessed, or the maximum number of guesses is
reached. When the game is finished, an appropriate message
should be printed out
- The input should be a string of characters for the colors ((R)ed,
(Y)ellow, (G)reen, (B)lue, blac(K), (W)hite) -- so RYYG is an
acceptable input. The input should be case insensitive, and
should allow for (but not require) spaces between the colors.
So Ry y B
is also an acceptable input.
- Error checking should be done on the input -- if the input is not
valid, the user should be allowed to try again, until a valid guess is
entered.
BEFORE YOU START CODING, you need to design your project. That
is, what classes are you going to have, what methods are going to be in
each class, and what dependancies there are -- that is, which classes
will call other classes methods.
Also for Part I, you need to design the interface for the GUI.
Give a sketch of what the window will look like for your MasterMind
GUI, and describe how to interact with the GUI. I need to approve
your GUI before you implement it (of course, you could go ahead and
implement it before my approval, but you may have some wasted effort if
your design is not approved.
Note that the GUI is harder than the command line version -- you may
want to finish up the command line version early, so you have more time
to work on the GUI.
Part II
For part II, you need to add a GUI to your Mastermind game, and
implement it as an applet. You have a fairly large amount of
leeway here -- as a minimum, you need to:
- Display all of the past guesses, with the responses
- Enter a guess, using a textbook, or, even better, some kind of
button interface.
- Allow the player to restart the game
You can create a board that looks like the the official board
(wikipedia
link). You can have the player click on buttons to determine
the move, or (if you are really ambitious), drag pieces onto the
playing field to implement the moves. You need to have your
design approved for Part I.
Submission
All file(s) required for your project should be in the folder
https://www.cs.usfca.edu/svn/<username>/cs112/Project7/