Search code examples
calgorithmpath-finding

A star algorithm, but in four directions only


I've been reading about path-finding algorithms and I'm currently looking for one that works just like the A* but where the agent cannot move diagonally. Do the nodes still expand diagonally or is it some other way? Perhaps it's not related to A* at all? Also please consider the following image where it shows that the triangle is our agent, the brown rectangle is an obstacle between the grid squares and the arrow is just to make it clear that you can still walk through squares that have obstacles on their "borders", when not face to face to that obstacle. What kind of algorithm would you advise me as a base to a path-finding problem with these characteristics? Forgive me if something like this was posted already, I couldn't find it.

enter image description here


Solution

  • A* is a search algorithm in a graph, given a starting location and a set of target nodes, it finds a path - based on the graph's vertices and edges.

    If you want your agent to be unable to move diagonally, all you need to do is design your graph such that there is no edge between diagonal vertices.

    I assume you are using a next:V->2^V function to get all positions your agent can be next step. If it is the case, just make sure diagonals are not returned from this function.