Class MastermindSolver

java.lang.Object
mastermind.core.solvers.MastermindSolver
Direct Known Subclasses:
HumanSolver, MastermindAlgorithm

public abstract class MastermindSolver extends Object
The ultimate base class, all solvers are derived from this class.

It defines a few utility methods that are common to all solvers.

  • 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 within Mastermind.MAX_GUESSES.

      To ensure hasExceededMaxGuesses checks the losing status correctly, the method must be called by both MastermindAlgorithm.guess() and MastermindAlgorithm.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