Class AStarMachine<N extends AStarNode,P extends Plan>

java.lang.Object
net.citizensnpcs.api.astar.AStarMachine<N,P>

public class AStarMachine<N extends AStarNode,P extends Plan> extends Object
  • Method Details

    • getStateFor

      public AStarMachine<N,P>.AStarState getStateFor(AStarGoal<N> goal, N start)
      Creates an AStarMachine<N extends AStarNode,P extends Plan>.AStarState that can be reused across multiple invocations of {run(AStarState, int).
      Parameters:
      goal - The AStarGoal state
      start - The starting AStarNode
      Returns:
      The created state
      See Also:
    • run

      public P run(AStarMachine<N,P>.AStarState state)
      Runs the AStarMachine<N extends AStarNode,P extends Plan>.AStarState until a plan is found.
      Parameters:
      state - The state to use
      Returns:
      The generated Plan, or null
      See Also:
    • run

      public P run(AStarMachine<N,P>.AStarState state, int maxIterations)
      Runs the machine using the given AStarMachine<N extends AStarNode,P extends Plan>.AStarState's AStarStorage. Can be used to provide a continuation style usage of the A* algorithm.
      Parameters:
      state - The state to use
      maxIterations - The maximum number of iterations
      Returns:
      The generated Plan, or null if not found
    • runFully

      public P runFully(AStarGoal<N> goal, N start)
      Runs the machine until a plan is either found or cannot be generated.
      See Also:
    • runFully

      public P runFully(AStarGoal<N> goal, N start, int iterations)
      Runs the machine fully until the iteration limit has been exceeded. This will use the supplied goal and start to generate neighbours until the goal state has been reached using the A* algorithm.
      Parameters:
      goal - The AStarGoal state
      start - The starting AStarNode
      iterations - The number of iterations to run the machine for
      Returns:
      The generated Plan, or null if it was not found
    • setStorageSupplier

      public void setStorageSupplier(com.google.common.base.Supplier<AStarStorage> newSupplier)
      Sets the Supplier to use to generate instances of AStarStorage for use while searching.
      Parameters:
      newSupplier - The new supplier to use
    • createWithDefaultStorage

      public static <N extends AStarNode, P extends Plan> AStarMachine<N,P> createWithDefaultStorage()
      Creates an AStarMachine using SimpleAStarStorage as the storage backend.
      Returns:
      The created instance
    • createWithStorage

      public static <N extends AStarNode, P extends Plan> AStarMachine<N,P> createWithStorage(com.google.common.base.Supplier<AStarStorage> storageSupplier)
      Creates an AStarMachine that uses the given to create AStarStorage instances.
      Parameters:
      storageSupplier - The storage supplier
      Returns:
      The created instance