Project 2

For this assignment, you must implement the game of Mastermind. Below, we'll describe the rules of this game, and then the interface that we expect your program to use.


Rules of the game


The interface of Mastermind on computer

Since we are requiring only a text interface, we must choose characters that represent the colored pegs and the colored markers. The colors of the pegs will be designated by the first letter of the color, like so:

  1. b = Blue
  2. w = White
  3. g = Green
  4. y = Yellow
  5. o = Orange
  6. r = Red

So, a sequence "bbyr" represents a peg sequence of blue, blue, yellow, and then red.

We must also choose characters to represent the markers that the adversary uses to communicate with the player. Your adversary should respond with:

  1. c = Correct (both color and position in the sequence)
  2. m = Misplaced (correct color, wrong position in the sequence)

An example:


The program you have to write

Write a program that plays the game of Mastermind. The computer should randomly select the sequence of four pegs from the possible six colors, and then allow the user as many as 10 guesses. When the game is over (either the adversary or the player has won), the user should be given the option to play again.

A key part of this assignment is to write the program as a group of methods that call one another. Here are some suggestions for methods that you might want to write for this program:

There may be more methods that you choose to write!


What you must submit

You will need to create transcripts of your running program. The script command will record everything you do into a text file. Thus, if you type...

script foo.script

Everything you type from that point onward will be recorded into the file named foo.script. When you want to stop recording, you simply type:

exit

Using this command, you record transcripts of two slightly different versions of your Mastermind program:

  1. A "cheater's" version that immediately reveals the computer's secret color sequence before the user starts to guess. We need this version because without it, we will have a great deal of difficulty in determining whether or not the program is working correctly. For this version, the transcript should record the program's responses to the following entries, in this order:
    1. A guess with no correct colors.
    2. A guess with two colors in the wrong place. (The response should be mm.)
    3. A guess that uses the rightmost color twice, where one use of that color is in the correct location, and the other is in an incorrect location.
    4. One guess that is all the same color, where that color is one of those in the answer.
    5. The correct guess.
  2. A regular version that does not show you the computer's secret color sequence until the game is over. For this version, the transcript should record you simply playing the game (and, assumedly, trying to win.)

Use the cs11-submit command to turn in your Java code, a script of playing the "cheater's" version, and a script of playing the regular version. Submit this work as project-2. Note that you should demonstrate that your program is robust, and that it correctly responds to all kinds of guesses (ones that are incorrect, ones that have both correct and misplaced pegs, and ones that are fully correct.)


The project is due Sunday, 14-Nov-2004, at 11:59 pm

Scott F. Kaplan
Last modified: Thu Nov 4 22:07:11 EST 2004