Author Topic: monsters surround player tech demo  (Read 6540 times)

oohara

  • Newcomer
  • Posts: 5
  • Karma: +0/-0
    • View Profile
    • Email
monsters surround player tech demo
« on: February 05, 2013, 09:45:36 AM »
I wrote a monster decision-making (monster AI) tech demo:
http://www.interq.or.jp/libra/oohara/surround/index.html
Only the source code is available.  Compile it with gcc and ncurses.

Monsters usually chase the player by following the shortest path
to the current position of the player.  If only one monster can be
in a grid, this is not the best.  To take advantage of numbers,
the destination of monsters should be the adjacent grids of
the player character, not the current position.

The tech demo assumes that:
  + the monsters want to kill the player at any cost
  + hitting the player is always a good thing
  + there is no ranged attack; the only attack is a bump into something
  + the monsters know the map of the dungeon
  + the monsters always know where the player is
  + the monsters know what others are doing

The decision-making code is called just after the player action is done.
It uses the current best action of monsters to improve the decision of
other monsters.

If a monster is adjacent to the player, it attacks the player.
Otherwise, it decides its next action in 3 steps:
  (1) see where it wants to go and find the path
  (2) make sure monsters near the player are not blocked
  (3) cancel the move if a monster near the player is alone

Path-finding in the first step is done with a Dijkstra map.
The first step uses 9 Dijkstra maps.  One map is for a direct chase:
  + the destination is the current position of the player
  + only the wall grids are considered blocked
The other maps are for an indirect chase:
  + the destination is one of the 8 adjacent grids of the player
  + the adjacent grids other than the destination are considered blocked
  + grids with a monster are considered blocked
A monster chooses a Dijkstra map with a non-wall destination and moves to
the best grid according to the map.

The second and third steps handle monsters which engage this turn.
Engaging means that a monster which is not adjacent to the player
gets adjacent.  In the second step, each monster counts the number of
the adjacent grids of the player which are also adjacent to the monster.
This is the number of choices of the monster in this turn.  The monster
with least choices decides the action first.  The third step cancels
engaging if only one monster is adjacent to the player after the move.

Quendus

  • Rogueliker
  • ***
  • Posts: 447
  • Karma: +0/-0
  • $@ \in \{1,W\} \times \{1,H\}$
    • View Profile
    • Klein Roguelikes
Re: monsters surround player tech demo
« Reply #1 on: February 05, 2013, 02:34:30 PM »
I like the way the monsters wait for backup and then synchronously attack the player. Encircled/Surrounded has a monster with similar behaviour - I might try adapting this algorithm for use there.

Nymphaea

  • Rogueliker
  • ***
  • Posts: 74
  • Karma: +0/-0
  • Maria Fox
    • View Profile
    • Nymphaea.ca
Re: monsters surround player tech demo
« Reply #2 on: February 05, 2013, 03:47:45 PM »
I don't have time to compile and test it right now, but from your description, I like the idea. I'm definitely going to use the idea of targeting the 8 empty squares instead of the player when I get to AI. Also helps with teamwork, monsters could purposely move out of doorways to allow others through to their target square, or run away in a hallway to ambush the player in a room. Adding range would be interesting too, having ranged monsters avoid being within the 8 squares so melee allies can use them.

Gmontford

  • Newcomer
  • Posts: 2
  • Karma: +0/-0
    • View Profile
    • Email
Re: monsters surround player tech demo
« Reply #3 on: February 17, 2013, 05:33:19 AM »
I like the way the monsters wait for backup and then synchronously attack the player. Encircled/Surrounded has a monster with similar behaviour - I might try adapting this algorithm for use there.

Exactly the same one I'm about to point out. It's like a monster gang attack.