I am working on finding the A * path for a top-down grid game. The problem that I encountered is probably the easiest to understand in the image below. Asterisks are players / NPCs. A yellow asterisk is the current NPC that wants to go to X. Red asterisks are NPCs, which in this case are obstacles. The yellow cells are the walls, the white cells are the floor. While the entire path to the goal is really inaccessible, I still want to get the path to the next best location (in this case, spot number 8).
I can easily overcome obstacles, but I donβt know how to do it, as I describe. If I stop him as soon as he gets into an obstacle, he will not work properly, stopping at 3. If I go to the tile in the closed list with the smallest distance from the final target, if the final target is on the other side of the wall, as an example, she can ruin things also very badly.
Any suggestions? I feel that something is not so obvious with me, so please forgive the idiocy here.

Thanks Tim
source share