1package com.runehive.game.world.pathfinding.path.impl;
3import com.runehive.game.world.Interactable;
4import com.runehive.game.world.entity.mob.Direction;
5import com.runehive.game.world.entity.mob.Mob;
6import com.runehive.game.world.pathfinding.distance.Distance;
7import com.runehive.game.world.pathfinding.path.Path;
8import com.runehive.game.world.pathfinding.path.PathFinder;
9import com.runehive.game.world.position.Position;
10import com.runehive.game.world.region.Region;
31 private final Deque<Position>
shortest =
new ArrayDeque<>(100);
52 return new Path(
null);
66 return new Path(
null);
82 return new Path(
null);
92 nodes.put(target, end);
99 boolean found =
false;
115 next =
position.transform(direction.getFaceLocation());
117 Node node =
nodes.computeIfAbsent(next, Node::new);
125 if (end.hasParent()) {
145 return new Path(
null);
153 }
else if (other.
isOpen() && !
open.contains(other)) {
186final class Node implements Comparable<Node> {
300 return Integer.compare(
cost, other.
cost);
311 public final boolean equals(Object obj) {
312 if (
this == obj)
return true;
313 if (!(obj instanceof
Node))
return false;
332 final int prime = 31;
334 result = prime * result +
position.getX();
335 result = prime * result +
position.getY();
336 result = prime * result +
position.getHeight();
339 result = prime * result + p.
getX();
340 result = prime * result + p.
getY();
343 result = prime * result +
cost;
An algorithm used to find a path between two Positions.
boolean traversable(Position current, int size, Direction... directions)
Returns whether or not a Position walking one step in any of the specified Directions would lead to i...
Represents a single path in the path finding system.
void compare(Node active, Node other)
Path find(Interactable destination)
A default method to find a path for the specified Mob.
final Map< Position, Node > nodes
Node getCheapest(Queue< Node > nodes)
Gets the cheapest open Node from the Queue.
Path find(Mob source, Position target, int targetWidth, int targetLength)
Performs the path finding calculations to find the path using the A* algorithm.
final Distance heuristic
The Heuristic used by this PathFinder.
final Deque< Position > shortest
final Queue< Node > sorted
Path find(Position destination)
A default method to find a path for the specified Mob.
AStarPathFinder(Mob character, Distance heuristic)
Constructs a new AStarPathFinder with the specified traversal tool.mapviewer.
A Entity representing a weighted Position.
Node getParent()
Gets the parent Entity of this Entity.
Node(Position position)
Creates the Entity with the specified Position and cost.
Node(Position position, int cost)
Creates the Entity with the specified Position and cost.
boolean isOpen()
Returns whether or not this Node is openShop.
int cost
The cost of this Entity.
int getCost()
Gets the cost of this Entity.
int compareTo(Node other)
Compares the Entity's cost with another.
Position getPosition()
Gets the Position this Entity represents.
final Position position
The Position of this Entity.
void close()
Closes this Entity.
boolean open
Whether or not this Entity is openShop.
final boolean equals(Object obj)
Gets the condition if the Entity equals another object.
final int hashCode()
Gets the node's hash code.
void setCost(int cost)
Sets the cost of this Entity.
Node parent
The parent Entity of this Entity.
void setParent(Node parent)
Sets the parent Entity of this Entity.
boolean hasParent()
Returns whether or not this Entity has a parent Entity.
Represents a single tile on the game world.
int getHeight()
Gets the height coordinate, or height.
int getY()
Gets the absolute y coordinate.
int getX()
Gets the absolute x coordinate.
boolean equals(Object obj)
double getDistance(Position other)
Gets the distance between this location and another location.
Represents a single region.
Represents the enumerated directions an entity can walk or face.
static Direction[] valid()
static Direction getOppositeDirection(Direction direction)
An object implementing Interactable has uses.
An interface to calculate the distance between two nodes in a Position.