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
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Representing a bi-directional "portal" between areas. -
Field Summary
Modifier and TypeFieldDescription(package private) boolean
Portals between areas. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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.void
addObstacle(Pair<Integer,NodeId> o)
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.connectedLowPortal(int A)
Return the low-portal of the previous area, to which we will travel from to teleport to A.Return a path from the start node to either a frontier-node or an unexplored node (the implementation decides this).Return a path between "from", to "to".Return frontier-nodes.boolean
hasbeenSeen(Pair<Integer,NodeId> ndx)
Check is the given node is marked as "has been seen".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).boolean
isBlocking(Pair<Integer,NodeId> o)
Return the state of this obstacle.lowPortal(int A)
Return the low-portal of the given area A.void
markAsSeen(Pair<Integer,NodeId> ndx)
Mark the given node as "has been seen".void
removeObstacle(Pair<Integer,NodeId> o)
void
setBlockingState(Pair<Integer,NodeId> o, boolean isBlocking)
Set the the state of this obstacle to blocking or unblocking.void
When true then the pathfinder will consider all nodes in the graph to have been seen.void
setPortal(int areaFrom, int areaTo, boolean isOpen)
Set the portal between area a1 and a2 to open or close.toString()
boolean
When true then the pathfinder will consider all nodes in the graph to have been seen.void
Clear the marking of "has been seen".Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface eu.iv4xr.framework.extensions.pathfinding.CanDealWithDynamicObstacle
toggleBlockingOff, toggleBlockingOn
Methods inherited from interface eu.iv4xr.framework.extensions.pathfinding.Pathfinder2
isReachableFrom
Methods inherited from interface eu.iv4xr.framework.extensions.pathfinding.XPathfinder
explore, markAsSeen
-
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
-
lowPortal
Return the low-portal of the given area A. -
connectedHighPortal
Return the high-portal of the next area, to which we will travel to if we take the A's low-portal. -
highPortal
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
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
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 interfacePathfinder2<NodeId>
-
addObstacle
- Specified by:
addObstacle
in interfaceCanDealWithDynamicObstacle<NodeId>
-
removeObstacle
- Specified by:
removeObstacle
in interfaceCanDealWithDynamicObstacle<NodeId>
-
setBlockingState
Description copied from interface:CanDealWithDynamicObstacle
Set the the state of this obstacle to blocking or unblocking.- Specified by:
setBlockingState
in interfaceCanDealWithDynamicObstacle<NodeId>
isBlocking
- If true then the obstacle will be set to its blocking state, and else non-blocking.
-
markAsSeen
Description copied from interface:XPathfinder
Mark the given node as "has been seen".- Specified by:
markAsSeen
in interfaceXPathfinder<NodeId>
-
hasbeenSeen
Description copied from interface:XPathfinder
Check is the given node is marked as "has been seen".- Specified by:
hasbeenSeen
in interfaceXPathfinder<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 interfaceXPathfinder<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 interfaceXPathfinder<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 interfaceXPathfinder<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 interfaceXPathfinder<NodeId>
-
setPerfectMemoryPathfinding
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 interfaceXPathfinder<NodeId>
-
isBlocking
Description copied from interface:CanDealWithDynamicObstacle
Return the state of this obstacle. True means that it is in the blocking state.- Specified by:
isBlocking
in interfaceCanDealWithDynamicObstacle<NodeId>
-
toString