Class AstarStrategy

java.lang.Object
com.edu.xmum.CST210.AlgorithmStrategy.AstarStrategy
All Implemented Interfaces:
IFindPathStrategy

public class AstarStrategy extends Object implements IFindPathStrategy
Implementation of the A* algorithm for pathfinding in a maze. This class uses the A* algorithm to find the shortest path from the starting position to the goal position.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Inner class representing a node in the A* algorithm.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    findPath(IMazeModel mazeModel, List<int[]> path, boolean[][] visited, int x, int y, int goalX, int goalY)
    Finds a path using the A* algorithm.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AstarStrategy

      public AstarStrategy()
  • Method Details

    • findPath

      public boolean findPath(IMazeModel mazeModel, List<int[]> path, boolean[][] visited, int x, int y, int goalX, int goalY)
      Finds a path using the A* algorithm.
      Specified by:
      findPath in interface IFindPathStrategy
      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.