In grid turn-based roguelike game, how can I detect the following scenarios:

  • other actor is following observing actor
  • other actor is intentionally moving to block its path

Path blocking can happen if for example player intentionally stops right in front of actor and then when actor moves to avoid player, player moves in front and that keeps repeating as long as player does it. I managed to detect that situation in hackish way and I would like to know if there is a better method for solving things like this.

  • \$\begingroup\$ "I managed to detect that situation in hackish" what did your detection approach look like in this case? \$\endgroup\$
    – DMGregory
    Commented Dec 2, 2018 at 16:03
  • \$\begingroup\$ I track number of previous position and if count of unique points in list of last positions is 2 I know it is repeating. \$\endgroup\$ Commented Dec 2, 2018 at 18:26

1 Answer 1


I'd recommend thinking of this as hypothesis testing. Form a hypothesis about the agent's goal, then check whether observations are consistent with that hypothesis.

For example, if we hypothesize that a character is trying to block our movement, then the next time we plan a route around them we suppose that within a given time horizon they'll try to move into our planned path. If they do, that's a point for this hypothesis. If they don't, that's a strike against it.

If we hypothesize that a character is following us, then we can model a pursuit behaviour (either a naive follow or an intercept course) and score how closely the character's subsequent moves follow this predicted behaviour.

After several iterations, the hypothesis may reach a sufficient threshold of confidence that we accept as fact, and change our behaviour accordingly.

We can reduce false positives by also scoring alternative hypotheses: maybe the character isn't following me, but pathing toward some attractive feature near me, for example.

If you want to get really crafty, this lets us conduct an experiment: deliberately change our movement to deviate from the path toward that attractive feature: does the character continue pathing toward the feature, or do they change course along a pursuit path to our new trajectory? This gives strong evidence to break a tie between the chasing and null hypotheses. ;)

  • \$\begingroup\$ Thats exactly what I was looking for. \$\endgroup\$ Commented Dec 3, 2018 at 1:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .