2

I'm trying to find a solution for pathfinding with multiple objects on a 2D grid. To my understanding, algorithms like A* can not be used in a case like this (to get an efficient solution).

The exemple below shows a case where a simple algorithm for multiple objects might fail:

Object A is going to destination B
Object C is going to destination D
 ┏------┓
 |D    A|
 ┗-┓  ┏-┛
   |  | 
 ┏-┛  ┗-┓ 
 |C    B|
 ┗------┛

The path is to narrow for both of the objects to go through at the same time, so the algorithm should be able to somehow decide which one goes through first. It should do this without sacrificing efficiency. Meaning that if it is possible to move multiple objects at once the algorithm should do so, to get the least amount of iterations.

The example below shows a case where the algorithm should only take one iteration to solve the problem:

Object A is going to destination B
Object C is going to destination D
┏------┓
|C    A|
|D    B|
┗------┛

Because there is no reason for object A and C to not go at the same time the algorithm should move them both, and they should both get to their destinatin in one iteration.

Is there a commonly used algorithm for this sort of problem, or are there any other ways to solve it? Thanks in advance.

Linus
  • 55
  • 3
  • A possible approach is to have multiple A* searches, one for each source-destination pair. The multiple A* searches run simultaneously and the path is recalculated after every move. All searches share the 2D grid. Each location on this grid can have 4 states: empty, wall, occupied (by a player), temporary-occupied (by a moving player). Note: I never implemented such search, so you nay want to wait for experience-backed proposals. – c0der Nov 13 '21 at 07:03

0 Answers0