Package mastermind.core.solvers
Class MastermindSolver
java.lang.Object
mastermind.core.solvers.MastermindSolver
- Direct Known Subclasses:
HumanSolver
,MastermindAlgorithm
The ultimate base class, all solvers are derived from this class.
It defines a few utility methods that are common to all solvers.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Retrieves the number of attempts made by the solver.protected boolean
Whether the solver guesses the code withinMastermind.MAX_GUESSES
.protected boolean
Whether the guess the solver will make is its first ever guess
-
Constructor Details
-
MastermindSolver
public MastermindSolver()Default constructor.
-
-
Method Details
-
getAttempts
public int getAttempts()Retrieves the number of attempts made by the solver.- Returns:
- the current number of attempts
-
hasExceededMaxGuesses
protected boolean hasExceededMaxGuesses()Whether the solver guesses the code withinMastermind.MAX_GUESSES
.To ensure
hasExceededMaxGuesses
checks the losing status correctly, the method must be called by bothMastermindAlgorithm.guess()
andMastermindAlgorithm.guess(Response)
.- Returns:
- true if the solver fails to guess the code, and false otherwise
-
isInitialGuess
protected boolean isInitialGuess()Whether the guess the solver will make is its first ever guess- Returns:
- true if the solver will make its first guess, false otherwise
-