Class Node<T>

java.lang.Object
puzzle.solver.Node<T>
Type Parameters:
T - represents the moves that can be applied to the states

public class Node<T> extends Object
Represents the nodes of a search graph.
  • Constructor Details

    • Node

      public Node(State<T> state)
      Creates a Node without a parent, i.e., a root node.
      Parameters:
      state - the state represented by the node
    • Node

      public Node(State<T> state, Node<T> parent, T move)
      Creates a Node with a parent node.
      Parameters:
      state - the state represented by the node
      parent - the parent of the node
      move - the move that created the state from the parent node
  • Method Details

    • getState

      public State<T> getState()
      Returns the state represented by the node.
      Returns:
      the state represented by the node
    • getParent

      public Optional<Node<T>> getParent()
      Returns the parent of the node.
      Returns:
      an Optional describing the parent of the node, or an empty optional if the node does not have a parent
    • getMove

      public Optional<T> getMove()
      Returns the move that created the state from the state of the parent node.
      Returns:
      an Optional describing the move that created the state from the parent node, or an empty Optional if the node does not have a parent
    • hasNextChild

      public boolean hasNextChild()
      Returns whether the node has at least one child node to be created with the nextChild() method.
      Returns:
      whether the node has at least one child node to be created with the nextChild() method
    • nextChild

      public Optional<Node<T>> nextChild()
      Creates and returns the next child of the node by applying a legal move to the state represented by the node. The move applied to the state is removed from the set of legal moves.
      Returns:
      an Optional describing the next child of the node, or an empty Optional if there are no more children
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object