Class PathfindingContext
java.lang.Object
com.edu.xmum.CST210.AlgorithmStrategy.PathfindingContext
Context class for pathfinding strategy.
This class is used to select and execute different pathfinding algorithms.
-
Constructor Summary
ConstructorsConstructorDescriptionPathfindingContext(IFindPathStrategy strategy) Constructor to set the pathfinding strategy. -
Method Summary
Modifier and TypeMethodDescriptionbooleanfindPath(IMazeModel mazeModel, List<int[]> path, boolean[][] visited, int x, int y, int goalX, int goalY) Finds a path from the starting position to the goal position using the selected strategy.
-
Constructor Details
-
PathfindingContext
Constructor to set the pathfinding strategy.- Parameters:
strategy- The pathfinding strategy to be used.
-
-
Method Details
-
findPath
public boolean findPath(IMazeModel mazeModel, List<int[]> path, boolean[][] visited, int x, int y, int goalX, int goalY) Finds a path from the starting position to the goal position using the selected strategy.- Parameters:
mazeModel- The maze model containing the maze structure.path- A list to store the path found from start to goal.visited- A 2D boolean array to keep track of visited positions in the maze.x- The x-coordinate of the current position.y- The y-coordinate of the current position.goalX- The x-coordinate of the goal position.goalY- The y-coordinate of the goal position.- Returns:
- True if a path is found, false otherwise.
-