libgdx / gdx-ai

Artificial Intelligence framework for games based on libGDX or not. Features: Steering Behaviors, Formation Motion, Pathfinding, Behavior Trees and Finite State Machines
Apache License 2.0
1.18k stars 241 forks source link

Added normal AStarPathFinder #111

Closed mquickmann closed 4 years ago

mquickmann commented 4 years ago

Adopted the IndexAStarPathFinder and made it more felxible, so you don't have to know a predefined zone and the normal one uses an ObjectMap instead of a fixed array that limits the search to a zone. The AStarPathFinder needs just an instance of Graph and not an instance of IndexedGraph anymore.

Pro: You don't have to predefine / calculate a zone anymore and it has the behavior of a normal AStar. Con: Just a bit (in nano second range) slower than the indexed one, but as fast as possible.

So this is the PathFinder with the normal and general A*-algorithm.

Other differences: The AStarPathFinder uses .equals() instead of == wich is more general an can be defined by the Node itself to ensure a more general node matching. This ensures that nodes don't need to have the same Object reference (Object.equals(Object) uses also ==).

Also added a toString() to the Metrics-class in AStarPathFinder, left the indexed's nested Metrics-class as is.

Works as intended. But be careful, it searches as long as it don't reach the goal or if it runs out of connections/nodes -> the zone is limited by the connections wich is semantically correct.

Greez