CPSC 120 -- Assignment #3
Phase 1 due Friday Nov. 10
MasterMind ® is a code-breaking game invented in the early 1970s by Mordechai Meirovitz. The object of the game is to guess a sequence of four colors that has been selected by the computer. For this assignment, you will create JAVA classes that implement a Mastermind board, a Mastermind player and a program that plays the game.
Phase 2 due Friday Nov 17
You will need to create the following files:
MMPlayer.java This code is responsible for modeling a Mastermind player. It should have the following characteristics:
MMBoard.java This code is responsible for modeling a Mastermind board. It should have the following characteristics:
- A player should have a name, a number of games played and number of guesses made.
- The player should be able to play a game and report on his or her game-playing statistics.
- There are two major features of a MasterMind board: the colors that are available to make up the code, the code, and the length of the code. When initialized, a board should generate the code using the colors Red, Green, Blue and Yellow. The length of the code should be specified by the client program.
- Encapsulation of data is essential; we don't want a client to be able to simply ask to see the code (that defeats the point of the game!) Accessors should be provided to get the valid colors and the size of the board.
- A player interacts with the board by attempting to guess the code. The Board should provide some feedback about a guess to the would-be code breaker. Specifically, it tells the player how many colors are correct and how many colors are in the correct position.
- Several "helper" methods will prove useful to do things like check to see if a guess is in a valid format (i.e. Purple is not a valid color), or count the number of colors in a given code sequence.
MasterMind.java This is the main program that unites the players with the boards. It consists of a menu with 5 options (in a loop that lets the user keep choosing options until he/she chooses the quit option):
- Create a new player
- Play a standard game (codes of length 4)
- Play a hard game (codes of length 6)
- Print the player statistics (number of games and average number of guesses per game)
Download the files MasterMind.java,
MMPlayer.java from the course web page.
These java files contain the shell for each of the classes described on the previous page.
- All of the method signatures and instance data needed for this assignment are provided. If you believe that it is necessary to write additional methods (even private methods), please contact your instructor immediately.
- The stub code provided to you has numerous comments that should be helpful in figuring out the logic required for completing this assignment.
* It is important to work incrementally when coding your solution - rather than trying to code it all at once. A good order for you to pursue is outlined below:
- The first thing that you want to do is get the shell for your main program doing something. In MasterMind.java, you should add the code to display a menu. A good strategy is to print the menu in its final form and then write the code to respond to it incrementally. Initially, when a menu option is selected, it can just print out the option that was selected. When you are ready to implement that option, simply replace the print statement with the necessary code.
- Once you have your menu up and going, the next thing to work on is establishing a MasterMind board. To do this, you will need to write code for the MMBoard constructor and the getColor helper method. You should verify that you can successfully create a board of different sizes from your menu. (For testing purposes you should verify the contents of the board by printing it (temporarily) in the constructor.)
- The next step is to create a player that can use the board. Once you have written the constructor and the two other methods of the MMPlayer class, you should revisit MasterMind.java to instantiate a player object and use it to play your board.
- Next you should add the logic to actually process the guesses. This means writing the body of tryGuess in the Board class. The private methods countColor and validGuess should prove useful.
- Finally, you should go through your program to fill in any details that may have been omitted along the way (i.e. good prompts, nicely formatted output, and good documentation). You should take special care to remove any print statements that were included for debugging purposes and some of the comments that were instructions to you (leave in or modify comments that explain what is going on).
Phase I of this assignment is to complete steps 1 and 2 above. Phase II of this assignment is to complete steps 3-5 above.
Academic Integrity Reminder!!! Programming assignments are to be your own work (this includes Phase I of this assignment). You may get help on the specifics of the assignment from no one except the instructor. You may not show your program to anyone or look at anyone else's program or share ideas with anyone about how to write the program.
Hand in by Nov 17: A printed copy of your program files Tar all the files in your project subdirectory (the .class, .html, and .java files) and email the .tgz file to email@example.com with a subject of cpsc120 project3.