|
||||||||||
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 where 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 n and number of possible values k for each digit. |
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). |
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 solution, where n > 2k
- the number of possible values for each digit, 0 thru k-1, where k > 4.public MMGame()
Method Detail |
public boolean guess(java.lang.String s)
s
- a String containing the user's guess.
public int numComplete()
public int numPartial()
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 |