Class PlayerAStarAI

  • All Implemented Interfaces:
    PlayerAI, Constants, java.lang.Runnable

    public class PlayerAStarAI
    extends AI
    implements PlayerAI, Constants
    The class implements the A* search AI algorithm for the player
    • Constructor Detail

      • PlayerAStarAI

        public PlayerAStarAI​(Scene scene,
                             Player player)
        Initialize the A* algorithm
        Parameters:
        scene - The scene the algorithm is in
        player - The player being controlled by AI
    • Method Detail

      • search

        public boolean search​(State start,
                              State goal)
        Search for a path between the start point and the goal
        Specified by:
        search in interface PlayerAI
        Parameters:
        start - The start point
        goal - The goal
        Returns:
        Returns true if a path to the goal exists or false otherwise
      • removeKeyDestination

        public void removeKeyDestination​(int x,
                                         int y)
        Remove the picked up key from destinations if it is there
        Overrides:
        removeKeyDestination in class AI
        Parameters:
        x - The x coordinate of the key
        y - The y coordinate of the key
      • addDestination

        public void addDestination​(State destination)
        Add a destination to visit
        Specified by:
        addDestination in interface PlayerAI
        Overrides:
        addDestination in class AI
        Parameters:
        destination - The destination to visit
      • run

        public void run()
        Run this in a loop
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class AI
      • sortDestinations

        public void sortDestinations()
        Sort the destinations by importance, if the importance is the same then sort them by distance
        Specified by:
        sortDestinations in interface PlayerAI