Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path finding Algorithm for changeable environments

I am having trouble adapting the A* algorithm to handle changing environments. As a minimum example, consider this rogue-like map:

######
#!   #
###  #
#S   #
##+###
##F###
######

The goal is to get from S to F, but in order to do so the player must step on ! to open the door. The problem I'm having is that in A* once a grid point is visited it becomes "closed" and cannot be reentered. How can I modify the algorithm to solve this puzzle?

like image 602
John F. Miller Avatar asked Sep 20 '26 04:09

John F. Miller


2 Answers

You can run A* twice:

  1. First find shortest path to the switch (!) where the door is like a wall
  2. Then find shortest path to the end from the switch, where the door is blank tile.

The shortest path will be the combination of these two paths.

like image 171
amit Avatar answered Sep 22 '26 03:09

amit


In your problem, it is not true that in A* when you visit a point (x,y cord) you won't visit again the same point.

The reason is that in your problem, state is position in the grid and for each door its state (open or close). So at the beginning, in your example, the initial state is (3,1,{false}). (false means the door is closed).

When you reach the '!' position, the new state will be (1,1,{true}) so now when you reach the door you will pass the door.

like image 43
barak1412 Avatar answered Sep 22 '26 02:09

barak1412



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!