Coordinate currentCoordinate = new Coordinate(current.x, current.y);
Enumeration<Coordinate> enumeration = Utility.getNeighborCoordinatesEnumeration(realm, currentCoordinate);
while (enumeration.hasMoreElements()) {
Coordinate coordinate = enumeration.nextElement();
if (isValidLocation(unit, coordinate, ignoreOtherPlayers)) {
Tile tile = realm.getTile(coordinate);
float nextStepCost = current.cost + tile.getMovementCost();
Node neighbour = nodes[coordinate.getAbscissa()][coordinate.getOrdinate()];
if (nextStepCost < neighbour.cost) {
if (open.contains(neighbour)) {
open.remove(neighbour);
}
if (closed.contains(neighbour)) {
closed.remove(neighbour);
}
}
if (!open.contains(neighbour) && !(closed.contains(neighbour))) {
neighbour.cost = nextStepCost;
neighbour.heuristic = tile.getMovementCost();
maxDepth = Math.max(maxDepth, neighbour.setParent(current));
open.add(neighbour);
Collections.<Node>sort(open);
}
}