Class LayeredAreasNavigation<NodeId,​Nav extends XPathfinder<NodeId> & CanDealWithDynamicObstacle<NodeId>>

java.lang.Object
eu.iv4xr.framework.extensions.pathfinding.LayeredAreasNavigation<NodeId,​Nav>
Type Parameters:
NodeId -
Nav -
All Implemented Interfaces:
CanDealWithDynamicObstacle<Pair<Integer,​NodeId>>, Pathfinder2<Pair<Integer,​NodeId>>, XPathfinder<Pair<Integer,​NodeId>>

public class LayeredAreasNavigation<NodeId,​Nav extends XPathfinder<NodeId> & CanDealWithDynamicObstacle<NodeId>> extends Object implements XPathfinder<Pair<Integer,​NodeId>>, CanDealWithDynamicObstacle<Pair<Integer,​NodeId>>
Support navigation over multiple areas, linearly stacked in layers. The areas are numbered starting from 0. Each area is connected to the area before it through a portal, and to the area next to it with another portal. The first and last areas only have one portal.
Author:
Wish
  • Field Details

    • areas

    • portals

      Portals between areas. If P is the i-th Portal in the list, this P connects area i to i+1. P.lowPortal is a node in area i, and P.highPortal is a node in area i+1. From P.lowPortal we can travel to P.highPortal (which is in area i+1).

      Note that if there are n areas, we will only have n-1 portals, as the last area have no next-area to connect to.

    • perfect_memory_pathfinding

      boolean perfect_memory_pathfinding
  • Constructor Details

    • LayeredAreasNavigation

      public LayeredAreasNavigation()
  • Method Details

    • addNextArea

      public void addNextArea(Nav area, NodeId portalLow, NodeId portalHigh, boolean isOpen)
      Add a new area with index a, where a is the current number of areas we have. The new area is connected to the area a-1 through the given pair of portals, where portalLow is in the area a-1 and portalHigh is in the area a.

      Note that for the first area added, the specified portals are ignored (so they can just be null) because we don't have a previous portal yet.

      Parameters:
      isOpen - indicate whether the added portal is set to be open or close.
    • lowPortal

      public NodeId lowPortal(int A)
      Return the low-portal of the given area A.
    • connectedHighPortal

      public NodeId connectedHighPortal(int A)
      Return the high-portal of the next area, to which we will travel to if we take the A's low-portal.
    • highPortal

      public NodeId highPortal(int A)
      Return the high-portal of the given area A (this is the portal we travel to from the low-portal of the area previous to A).
    • connectedLowPortal

      public NodeId connectedLowPortal(int A)
      Return the low-portal of the previous area, to which we will travel from to teleport to A.
    • setPortal

      public void setPortal(int areaFrom, int areaTo, boolean isOpen)
      Set the portal between area a1 and a2 to open or close.
      Parameters:
      isOpen - If true will open the portal, else close it.
    • findPath

      public List<Pair<Integer,​NodeId>> findPath(Pair<Integer,​NodeId> from, Pair<Integer,​NodeId> to)
      Description copied from interface: Pathfinder2
      Return a path between "from", to "to". The path is represented as a list, whose first element is the node "from", and its last element is "to". The method returns null if no path can be found between them.
      Specified by:
      findPath in interface Pathfinder2<NodeId>
    • addObstacle

      public void addObstacle(Pair<Integer,​NodeId> o)
      Specified by:
      addObstacle in interface CanDealWithDynamicObstacle<NodeId>
    • removeObstacle

      public void removeObstacle(Pair<Integer,​NodeId> o)
      Specified by:
      removeObstacle in interface CanDealWithDynamicObstacle<NodeId>
    • setBlockingState

      public void setBlockingState(Pair<Integer,​NodeId> o, boolean isBlocking)
      Description copied from interface: CanDealWithDynamicObstacle
      Set the the state of this obstacle to blocking or unblocking.
      Specified by:
      setBlockingState in interface CanDealWithDynamicObstacle<NodeId>
      isBlocking - If true then the obstacle will be set to its blocking state, and else non-blocking.
    • markAsSeen

      public void markAsSeen(Pair<Integer,​NodeId> ndx)
      Description copied from interface: XPathfinder
      Mark the given node as "has been seen".
      Specified by:
      markAsSeen in interface XPathfinder<NodeId>
    • hasbeenSeen

      public boolean hasbeenSeen(Pair<Integer,​NodeId> ndx)
      Description copied from interface: XPathfinder
      Check is the given node is marked as "has been seen".
      Specified by:
      hasbeenSeen in interface XPathfinder<NodeId>
    • getFrontier

      public List<Pair<Integer,​NodeId>> getFrontier()
      Description copied from interface: XPathfinder
      Return frontier-nodes. A frontier is a seen node, with at least one neighbor which has not been seen yet (unexplored).
      Specified by:
      getFrontier in interface XPathfinder<NodeId>
    • explore

      public List<Pair<Integer,​NodeId>> explore(Pair<Integer,​NodeId> startNode, Pair<Integer,​NodeId> heuristicNode)
      Description copied from interface: XPathfinder
      Return a path from the start node to either a frontier-node or an unexplored node (the implementation decides this). A frontier node is a node with at least one unexplored neighbor. Such a path should only traverse though explored nodes, except the last node which could be an unexplored node. It is up to the implementation to guarantee (or at least make effort for it) that the returned path is navigable. To help chosing which frontier or unexplored node to explore to, a 'heuristic node' is also given. The chosen exploration target is expected to be the closest one, among candidate targets, to the given heuristic node.
      Specified by:
      explore in interface XPathfinder<NodeId>
    • wipeOutMemory

      public void wipeOutMemory()
      Description copied from interface: XPathfinder
      Clear the marking of "has been seen". So, after this all nodes are again considered as has not been seen.
      Specified by:
      wipeOutMemory in interface XPathfinder<NodeId>
    • usingPerfectMemoryPathfinding

      public boolean usingPerfectMemoryPathfinding()
      Description copied from interface: XPathfinder
      When true then the pathfinder will consider all nodes in the graph to have been seen.
      Specified by:
      usingPerfectMemoryPathfinding in interface XPathfinder<NodeId>
    • setPerfectMemoryPathfinding

      public void setPerfectMemoryPathfinding(Boolean flag)
      Description copied from interface: XPathfinder
      When true then the pathfinder will consider all nodes in the graph to have been seen.
      Specified by:
      setPerfectMemoryPathfinding in interface XPathfinder<NodeId>
    • isBlocking

      public boolean isBlocking(Pair<Integer,​NodeId> o)
      Description copied from interface: CanDealWithDynamicObstacle
      Return the state of this obstacle. True means that it is in the blocking state.
      Specified by:
      isBlocking in interface CanDealWithDynamicObstacle<NodeId>
    • toString

      public String toString()
      Overrides:
      toString in class Object