Class MMGame

java.lang.Object
  extended byMMGame

public class MMGame
extends java.lang.Object

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

MMGame

public MMGame(int n,
              int k)
Constructor to create game with specified solution length and number of possible values for each digit.

Parameters:
n - the length of the solution
k - the number of possible values for each digit, 0 thru k-1.

MMGame

public 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

public 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.

Parameters:
n - the length of the solution
k - 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

guess

public 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.

Parameters:
s - a String containing the user's guess.
Returns:
true if guess is valid and false otherwise.

numComplete

public 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.

Returns:
number of correct characters in correct position.

numPartial

public 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.

Returns:
number of correct characters in incorrect position.

getSolution

public java.lang.String getSolution()
Access the solution (added for GUI project)

Returns:
solution of the current game

getNumHidden

public int getNumHidden()
Access the length of the hidden solution (n).

Returns:
length of solution

getNumTypes

public int getNumTypes()
Access the size of the solution alphabet (k).

Returns:
size of solution alphabet

isGameOver

public boolean isGameOver()
Find out if game is over (correct solution) or not.

Returns:
true if game is over and false otherwise

getNumGuesses

public int getNumGuesses()
Access the number of user guesses so far this game.

Returns:
number of user guesses