graph - Best path algorithm while avoiding moving enemies? -


i have general graph/path-finding question had interview.

suppose trying specific node on 2d graph, , there enemy units transversing graph's nodes, searching you: best way maximize chances of reaching goal without encountering enemy unit?

i curious of best algorithm or general approach handle this.

p.s: know enemy units located

assuming want human in dangerous maze do: go ahead , run away whenever see enemy, here simple idea:

  1. run breadth first search once starting goal on whole graph store distance goal in every node. in step, ignore enemies. of course assuming have distance measure in graph. otherwise counting number of nodes during bfs applications. keep distance of last node goal, let call quantity maxdist.

  2. run "small" breadth first search every enemy towards directions. small, because stop after distance of k, k number of graph nodes want keep away enemies or other suitable metric (this represents "seeing"). similar thing in bfs: store distance towards enemy enemy sits in, denote d_i arbitrary node i. in bfs overwrite distance goal in node i maxdist + k - d_i. notice quantity @ least high maxdist. in step need careful on how update node i when enemy has written (keep larger value).

now, in every timestep pick next node 1 node in neighborhood has closest distance goal. since nodes "close" enemy @ least expensive maxdist, automatically avoiding enemies. , if cornered enemies 2 sides, automatically stay in middle between two, hoping long possible 1 of them turns around.

this might not maximize chances, not if can predictions enemy movement. furthermore behaves "stupid" run towards enemy if can't pass until "sees" it, turn around.

but general approach, might best 1 can do, if cannot see enemies far away , if have no information movement, have map see , goal is.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -