Interface PlayerAI

  • All Superinterfaces:
    Constants, java.lang.Runnable
    All Known Implementing Classes:
    PlayerAStarAI, PlayerBreadthFirstAI

    public interface PlayerAI
    extends java.lang.Runnable, Constants
    This interface has Player specific AI code that is shared between AI implementations
    • Method Detail

      • search

        boolean search​(State start,
                       State goal)
        Search for the goal from a starting state
        Parameters:
        start - The start state
        goal - The goal state
        Returns:
        Return true if there is a path or false otherwise
      • addDestination

        void addDestination​(State destination)
        Add a destination to the list of destinations
        Parameters:
        destination - The new destination
      • sortDestinations

        void sortDestinations()
        Sor the destinations based on importance and distance
      • heuristic

        default double heuristic​(State start,
                                 State goal)
        The heuristic to get the distance between the start state and the end state Manhattan Distance Used for 4 direction movements h = abs (current_cell.x – goal.x) + abs (current_cell.y – goal.y) Diagonal Distance Used for 8 direction movements h = max { abs(current_cell.x – goal.x), abs(current_cell.y – goal.y) } Euclidean Distance Used for distance between 2 points h = sqrt ( (current_cell.x – goal.x)2 + (current_cell.y – goal.y)2 )
        Parameters:
        start - The start state
        goal - The goal state
        Returns:
        Returns the distance between the states
      • sortDestinations

        default java.util.List<State> sortDestinations​(java.util.List<State> destinations,
                                                       State initial)
        Sort the destinations based on importance and distance
        Parameters:
        destinations - The destinations to sort
        initial - The initial state of the player
        Returns:
        Returns the new sorted destinations
      • destinationArrived

        default boolean destinationArrived​(Scene scene,
                                           State goal)
        If the player arrived at a a goal this should be called
        Parameters:
        scene - The scene
        goal - The goal
        Returns:
        Returns true if the goal is in a certain state or false if the goal is not truly reachable or usable
      • checkCondition

        default boolean checkCondition​(Scene scene,
                                       State goal)
        Check conditions for the goal, if they are not met don't go after that goal yet
        Parameters:
        scene - The scene
        goal - The goal
        Returns:
        Returns true if the goal is obtainable or false otherwise
      • getOpenSpaceAroundPlayer

        default State.Type getOpenSpaceAroundPlayer​(Scene scene)
        Check if the spaces around the player are ope or not and return one of them randomly
        Parameters:
        scene - The scene
        Returns:
        Returns a random direction to go
      • doAction

        default void doAction​(Scene scene,
                              java.util.List<State.Type> steps)
        Do the player control actions
        Parameters:
        scene - The scene
        steps - The steps to follow