Class BreadthFirstSearch<T>

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

public class BreadthFirstSearch<T> extends Object
Implements the breadth-first search (BFS) algorithm to solve puzzles.
  • Constructor Details

    • BreadthFirstSearch

      public BreadthFirstSearch()
  • Method Details

    • solve

      public Optional<Node<T>> solve(State<T> state)
      Searches for the shortest solution for the puzzle starting from the state provided.
      Parameters:
      state - the initial state
      Returns:
      an Optional describing the shortest solution for the puzzle, or an empty Optional if no solution is found
    • solveAndPrintSolution

      public Optional<Node<T>> solveAndPrintSolution(State<T> state)
      Searches for the shortest solution for the puzzle starting from the state provided, and it also prints the solution to the standard output.
      Parameters:
      state - the initial state
      Returns:
      an Optional describing the shortest solution for the puzzle, or an empty Optional if no solution is found