Search code examples
searchxnaa-star

A* Search Algorithm gets stuck


I am trying to implement an A* Search algorithm. For now I am just trying to find a good path through an environment littered with walls. The walls are randomly generated, and in some cases my path gets "stuck". If the search encounters a wall in front of it, and to all of its sides (except the one that led it into this mess), it stops. Is there something I can do to prevent this? I am using a "as the crow flies" point system for my H value, which ignores the walls and just estimates how far it will take to get to the destination. This sometimes leads it into this trap.

Thanks.


Solution

  • Underestimating the distance is 'proper' for A*.

    But it sounds like you have a depth/breadth problem.

    When evaluating options from a given position, you should add them to a list of options to check and sort them by score. There should be no reason why you would check the options available from a given position immediately after you've evaluated that position - i.e. all options from each position should go into the same list. This way, when you hit a dead end, it simply does not generate further options and you proceed by taking the next highest scored option off the list and evaluating that.