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.2k stars 242 forks source link

IndexedAStarPathFinder uses == where .equals() might be better #67

Closed ShardPhoenix closed 8 years ago

ShardPhoenix commented 8 years ago

In IndexedAStarPathFinder#search there is this line:

// Terminate if we reached the goal node
if (current.node == endNode) return true;

This only works if nodes don't change identity. Depending on how the user implements methods such as getConnections, the nodes might change identity while still remaining logically equal (eg if the type N is the user's custom Coordinate class). I ran into this problem myself, but fixed it by caching my coordinate objects (which I should have been doing anyway), but it's potentially confusing for less experienced developers. If there isn't a compelling reason to to do otherwise, it might be better to replace the == with .equals.

davebaol commented 8 years ago

This is kinda related to issue #24. Probably the method isGoal(current.node) would be more general.