|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object MMGame
Class MMGame provides the evaluation engine for a game of MasterMind. The MMGame object will internally store a hidden code of a given length and made up of an alphabet of a given size. It will accept guesses in the form of strings. If the guess is invalid it will not be processed. Otherwise, it will be accepted. Once a guess is validated, the MMGame object will report on the number of complete matches and the number of partial matches. The object also records the number of valid guesses, and stops accepting guesses once the game is over (a perfect guess is accepted).
Constructor Summary | |
MMGame()
Default constructor to create game with n=4, k=6 (solution is 4 digits long and each digit can have 6 possible values 0-5). |
|
MMGame(int n,
int k)
Constructor to create game with specified solution length and number of possible values for each digit. |
|
MMGame(int n,
int k,
java.lang.String solution,
int guesses)
Constructor, added for GUI project, to create in-progress game with specified solution length and number of possible values for each digit, plus given solution and number of moves. |
Method Summary | |
int |
getNumGuesses()
Access the number of user guesses so far this game. |
int |
getNumHidden()
Access the length of the hidden solution (n). |
int |
getNumTypes()
Access the size of the solution alphabet (k). |
java.lang.String |
getSolution()
Access the solution (added for GUI project) |
boolean |
guess(java.lang.String s)
Stores the specified string as the user's current guess, provided it is a valid guess -- correct length and no invalid characters. |
boolean |
isGameOver()
Find out if game is over (correct solution) or not. |
int |
numComplete()
Given a valid guess, will compute and return the number of characters in the guess that exactly match corresponding characters in the solution. |
int |
numPartial()
Given a valid guess, will compute and return the number of characters in the guess that match characters in the solution but are in the wrong position. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MMGame(int n, int k)
n
- the length of the solutionk
- the number of possible values for each digit, 0 thru k-1.public MMGame()
public MMGame(int n, int k, java.lang.String solution, int guesses)
n
- the length of the solutionk
- the number of possible values for each digit, 0 thru k-1.solution
- the solution of in-progress game, string length is assumed to be correct.guesses
- the number of guesses made in in-progress game.Method Detail |
public boolean guess(java.lang.String s)
s
- a String containing the user's guess.
public int numComplete()
public int numPartial()
public java.lang.String getSolution()
public int getNumHidden()
public int getNumTypes()
public boolean isGameOver()
public int getNumGuesses()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |