Difference between revisions of "Simple way to prevent jams of monsters with A*"

From RogueBasin
Jump to navigation Jump to search
 
Line 1: Line 1:
== Introduction ==
== Introduction ==


This was originally posted on the r.g.r.d. newsgroup, and sparked quite the discussion.
This was originally posted on the r.g.r.d. newsgroup, and sparked quite the discussion. The explanation of the method is simple and can be read on the first post, copied here in its entirety.
 
The explanation of the method is simple and can be read on the first post, copied here in its entirety.




Line 15: Line 13:
== The solution ==
== The solution ==


Here it is. Monsters have a simple counter for how long they've been stopped in the same tile ("idle time"). This should be 0 when moving.
Here it is.


When pathfinding, if a walkable tile has a monster on it, its cost is proportional to the monster's idle time.
'''Monsters have a simple counter for how long they've been stopped in the same tile ("idle time"). This should be 0 when moving.
When pathfinding, if a walkable tile has a monster on it, its cost is proportional to the monster's idle time.'''


That's it!
That's it!
Line 24: Line 23:




== Original thread ==
[http://groups.google.com/group/rec.games.roguelike.development/browse_thread/thread/30eee2a1991f2086 "Getting monsters with A* pathfinding to behave!", on r.g.r.d., first post by Joao Henriques (Jotaf)]
 
"Getting monsters with A* pathfinding to behave!", on r.g.r.d., first post by Jo??o Henriques (Jotaf)
http://groups.google.com/group/rec.games.roguelike.development/browse_thread/thread/30eee2a1991f2086

Revision as of 18:56, 5 April 2009

Introduction

This was originally posted on the r.g.r.d. newsgroup, and sparked quite the discussion. The explanation of the method is simple and can be read on the first post, copied here in its entirety.


The problem

The problem is that monsters blocking the best path make other monsters go around the longest way. Making A* think the monsters are "passable" results in piles of monsters around entrances, when ideally some of them should go around to avoid the "jam".

Most solutions are a bit convoluted; at least the ones I know about. IIRC one of the arguments for the scent-based approach is that it avoids this; but A* is more desirable for other reasons.


The solution

Here it is.

Monsters have a simple counter for how long they've been stopped in the same tile ("idle time"). This should be 0 when moving. When pathfinding, if a walkable tile has a monster on it, its cost is proportional to the monster's idle time.

That's it!

Emergent behavior is that some monsters flowing naturally through the quickest path don't make others go around the longest way; the cost is 0. But as soon as a jam is formed, the idle monsters will make it an undesirable path, and others will try to go for alternatives.


"Getting monsters with A* pathfinding to behave!", on r.g.r.d., first post by Joao Henriques (Jotaf)