Class EasyAlgorithm


public class EasyAlgorithm extends MastermindAlgorithm
An implementation of the MastermindAlgorithm class that provides a simple algorithm for solving the Mastermind game, by randomly choosing codes that have not guessed before.
  • Constructor Details Link icon

    • EasyAlgorithm Link icon

      public EasyAlgorithm()
      Constructs a new instance of the `EasyAlgorithm` class. This constructor initializes the algorithm by instantiating a HashMap to store all previous guesses that the algorithm made.
  • Method Details Link icon

    • guess Link icon

      public Code guess()
      This simple guess algorithm generates a random guess that has not been made before.

      The algorithm generates a random guess by selecting a random color for each of the four positions in the code. If the generated guess has already been made, the algorithm generates a new guess until a unique guess is found.

      Specified by:
      guess in class MastermindAlgorithm
      Returns:
      The initial guess to be made by the algorithm.
    • guess Link icon

      public Tuple2<Status,Code> guess(Response response)
      Determines the next guess for the Mastermind game.

      The algorithm generates a random guess by selecting a random color for each of the four positions in the code. If the generated guess has already been made, the algorithm generates a new guess until a unique guess is found.

      Specified by:
      guess in class MastermindAlgorithm
      Parameters:
      response - The response to the previous guess made by the algorithm.
      Returns:
      A tuple containing the status of the game and the next guess to be made by the algorithm.
      Throws:
      IllegalCallerException - If this method is invoked for the initial guess.