1

If I had a 2D environment in which I could move in four directions, but in addition to those directions, I could dash in a direction until I hit a wall, how would I calculate an admissible heuristic for this? Whether a move or dash, each would have a G-cost of 1, so dashing and walking are weighted equally. Should I even use A*? If in some scenario, dashing a number of times would get you to your destination faster than moving, even if at some point you are farther away from your destination after dashing, what kind of pathfinding would be able to calculate an optimal path?

Andrew
  • 63
  • 7
  • 1
    yes you can use A*, just consider the dash-able places as neighbours when adding them to the open set – BeyelerStudios Jan 15 '16 at 15:48
  • Andrew, can you explain how A* works? I do not know the algorithm by name. – Lajos Arpad Jan 15 '16 at 15:56
  • 2
    @LajosArpad [A* or A-Star](https://en.wikipedia.org/wiki/A*_search_algorithm) is a common (maybe the most common?) general pathfinding algorithm. – Mike Harris Jan 15 '16 at 16:03
  • @BeyelerStudios However, if a dash ends you up farther away than the destination, it would have a higher estimated distance and most likely would not be considered since its F-cost would be high, even though it might be a more optimal path. – Andrew Jan 15 '16 at 16:12
  • yeah the heuristic is going to be painful (as usual), like, try to incorporate the total possible dashable distance (in any direction) into the f-score – BeyelerStudios Jan 15 '16 at 16:23
  • @BeyelerStudios if I underestimate my heuristic cost, will I still find the most optimal path? It will just take longer right? Is it true that only overestimating the h-cost can yield a suboptimal path? – Andrew Jan 15 '16 at 16:56
  • check this [answer](http://stackoverflow.com/a/1012852/3426025) – BeyelerStudios Jan 16 '16 at 15:06

1 Answers1

0

Heuristic: A heuristic is admissible if it never over-estimates the cost of reaching the goal. Since you use the four cardinal directions, an admissible heuristic would be to take the manhattan distance (L1-Norm) between the start and destination, call it dist. Then divide dist by the number of tiles in a single dash. There's no way you'll overestimate using this this heuristic.

Computing Optimal Path: You can use A-Star to compute an optimal path provided you use an admissible heuristic. The key is that your node.getNeighbors() method return the neighbors adjacent to the current node i.e. to the (N)orth, (S)outh, (E)ast, and (W)est, and also those that are reachable by a dash beginning from the current node (i.e. dashDist-tiles to the N/S/E/W). The method might look something like this:

public List<Node> getNeighbors(){
    List<Node> neighbors = new LinkedList<Node>();
    neighbors.addAll(this.getAdjacentNeighbors());
    neighbors.addAll(this.getDashableNeighbors());
    return neighbors;
}

private List<Node> getAdjacentNeighbors(){
    //implement code to get the adjacent neighbors
}

private List<Node> getDashableNeighbors(){
    //implement code to get the neighbors 1-dash away
}

One other consideration: I assume a dash happens in a straight line... In that case, I suggest looking into the JumpPointSearch algorithm. It takes advantage of symmetries in the world to reduce the number of nodes in the open set.

Austin
  • 8,018
  • 2
  • 31
  • 37