Author Topic: Method for ambush AI?  (Read 3190 times)

NON

  • Rogueliker
  • ***
  • Posts: 349
  • Karma: +0/-0
    • View Profile
    • Infra Arcana
    • Email
Method for ambush AI?
« on: November 23, 2012, 03:31:22 PM »
I was doing some idle thinking about making the AI set up ambushes for the player. I wrote up some possible steps for how to achieve this, as a starting point for discussion. It is certainly not intended as a "tutorial" or something.

So,
* Do you think the steps below is a viable way to achieve it? (Implementation, execution speed and result)
* Are there better/simpler ways?

The scenario: There's a group of monsters that due to some AI choice decides they want to set up an ambush (they are aware of the player coming). I assume the game's AI is capable of telling them to go to a specified position and wait there until further notice.

A) Identify suitable position for '1' (pre-ambush position) and '2' (attack position). This step could be a whole point of discussion in itself, but assume we can identify a corridor shape leading into a room.
########
.......#     
.......#     
.......##     
.......21    @
.......##
.......#
.......#
########



B) Run FOV from '1'
########
.......#     
XXXX...#     
XXXXXX.##     
XXXXXXXX1    @
XXXXXX.##
XXXX...#
.......#
########



C) Run FOV from '2'
########
XXXXX..#     
XXXXXX.#     
XXXXXXX##     
XXXXXXX2    @
XXXXXXX##
XXXXXX.#
XXXXX..#
########



D) Find positions reached by FOV '2', but not by '1'
########
XXXXX..#     
....XX.#     
......X##     
.......2     
......X##
....XX.#
XXXXX..#
########


E) If monsters have (prefer) ranged attacks, remove positions in melee range of '2'.
Otherwise (if they prefer melee), remove cells NOT in melee range of '2' (though this example would only leave two such cells).
Sort the remaining cells according to distance from '2'. Start with the furthest cell and place a monster there. For the next position, if it blocks LOS from any previous position, earase it, otherwise place a monster there. Repeat until no more monsters or no more positions (if there are more monsters than positions, it needs to be decided what to do with the remaining monsters)
########
M.M.M..#     
.......#     
.......##     
.......2     
.......##
.......#
M.M.M..#
########
Happy is the tomb where no wizard hath lain and happy the town at night whose wizards are all ashes.

Darren Grey

  • Rogueliker
  • ***
  • Posts: 2027
  • Karma: +0/-0
  • It is pitch black. You are likely to eat someone.
    • View Profile
    • Games of Grey
Re: Method for ambush AI?
« Reply #1 on: November 23, 2012, 04:13:54 PM »
That would work, but you'd need exceptions for when the FOV doesn't fit well or there are no rooms to ambush in, etc.

I'd suggest making a height-map from a floodfill from player's position, or from a certain tactical point.  Make enemies head for the maxima on the map.  Add exception for locations visible from position x, y if possible.

As for execution speed I can't see any problem.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Method for ambush AI?
« Reply #2 on: November 23, 2012, 09:09:34 PM »
Make monsters avoid y location of the player, but approach on x so monsters would rush into corners of the room and near the doorway until player detects them.