Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AI and Deep Learning by (50.2k points)

Suppose that you have a 2D grid of cells, some of which are filled in with walls. Characters can take a step from one square to any square that is one step horizontal or vertical from it but cannot cross walls.

Given a start position and an end position, we can find the shortest path from the start position to the end position by using the A* algorithm with an admissible heuristic. In this current setup, the Manhattan distance would be admissible, since it never overestimates the distance to the destination.

Now suppose that in addition to walls, the world has pairs of teleporters. Stepping onto a teleporter immediately transports a character to the linked teleporter. The existence of teleporters breaks the admissible heuristic given above since it might be possible to get to the destination faster than taking the optimal Manhattan distance walk by using a teleporter to cut down on the distance. For example, consider this linear world with teleporters marked T, start position marked S, and end position marked E:

T.S. . . . . . . . . . . . . E.T

Here, the best route is to walk to the teleporter on the left, then take two steps to the left.

My question is this: what is a good admissible heuristic for A* in a grid world with teleporters?

Thanks!

1 Answer

0 votes
by (108k points)
edited by

Form a graph of the teleporters:

  • You have a node for each teleporter and a node for the end position.
  • You have an edge connecting each node to each other node, forming a fully connected graph.
  • For the edge weights, we will use the Manhattan distance between each node's destination cell (the one you go to when you enter the teleporter) and all the other nodes.
  • Use Dijkstra's algorithm to calculate the shortest distance from each node to the end.

You can now use the minimum distance between a particular position and all the nodes plus the pre-calculated distance from the node to the end as a heuristic function. Dijkstra's algorithm has to run once as a pre-processing step. However, if the number of teleporters is huge then you may not get any benefit over using a simpler heuristic function.

You only need to find the distance to the end point, not the distance between every pair.

Because the function is heuristic, you only have to make sure you never overestimate the actual distance. The distance without the particular walls will never be greater than the distance with the walls.

If you want know about Artificial Intelligence and Deep Learning then you can watch this video:

Become a master of Artificial Intelligence by going through this online AI Course!

Browse Categories

...