Class Response

java.lang.Object
mastermind.core.Response

public class Response extends Object
Represents the response to a guess in the Mastermind game.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Response(Code code, Code guess)
    Constructs a Response object by calculating the number of correctly matched and misplaced elements between the provided code and guess.
    Constructs a Response object using the given Tuple2 containing the counts of correct and misplaced elements.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Compares this Response object to the specified object for equality.
    Returns the Tuple2 object containing the counts of correct and misplaced elements.
    int
    Returns the hash code value for this Response object.
    Returns a string representation of the Response object.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Response

      public Response(Tuple2<Integer,Integer> response)
      Constructs a Response object using the given Tuple2 containing the counts of correct and misplaced elements.
      Parameters:
      response - a Tuple2 object where: - The first element represents the count of correct matches. - The second element represents the count of misplaced elements.
    • Response

      public Response(Code code, Code guess)
      Constructs a Response object by calculating the number of correctly matched and misplaced elements between the provided code and guess.

      The constructor evaluates the following: - Matches where both the position and color are correct. - Matches where the color is correct but the position is incorrect. The results are stored as a Tuple2 consisting of the count of correct matches and the count of misplaced elements.

      Parameters:
      code - the code to be matched, represented as a sequence of colors
      guess - the guessed code, represented as a sequence of colors
  • Method Details

    • getResponse

      public Tuple2<Integer,Integer> getResponse()
      Returns the Tuple2 object containing the counts of correct and misplaced elements.
      Returns:
      a Tuple2 containing two integers: - The first integer represents the count of correct key pegs. - The second integer represents the count of misplaced key pegs.
    • equals

      public boolean equals(Object obj)
      Compares this Response object to the specified object for equality.

      The method first checks if the two objects reference the same memory location; if so, they are considered equal. Next, it checks if the specified object is null or if its class differs from this Response object's class; if either condition is true, they are not considered equal. Finally, it compares the "response" field of the two Response objects for equality.

      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare with this Response instance
      Returns:
      true if the specified object is equal to this Response instance, false otherwise
    • hashCode

      public int hashCode()
      Returns the hash code value for this Response object.

      The hash code is computed based on the underlying `response` field, which is a Tuple2 containing the counts of correct and misplaced matches. This ensures that the hash code is consistent with the definition of equality provided in the `equals` method.

      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this Response object
    • toString

      public String toString()
      Returns a string representation of the Response object.

      The returned string includes the count of correctly placed elements (correct count) and the count of misplaced elements (misplacement count), both extracted from the `response` field, formatted in the following structure:

      "correct count: [value] misplacement count: [value]"

      Overrides:
      toString in class Object
      Returns:
      a string representation of this Response object