Sunday, January 10, 2010

The Joys of Emergent Behavior - Monsters that work "well" togeather

So today I had a moment where my own AI monsters did something I thought was "clever". I have two monster AIs hacked out so far, the Sprinter and the Ranged. The Sprinter can "rush" when within two moves of the player. This moves them next to the player and immediately attacks, but then takes an an extra turn before it gets to go again. The ranged can use a sling as a ranged attack, requiring a turn to reload between shots. The only "intelligent" AI is the Ranged. If it figures out there are others monsters nearby the AI, it tries to move away if it's inside the minimum range of their weapon (unless they are at melee, then they swap to melee and attack).

So, I ran into a Ranged in the hallway and chased it down. The hallway opened up into a room, with another Ranged and a Sprinter. The Ranged I has caught up to backed off due to nearby help. I chased it again, and the sprinter rushed me, one Ranged hit me and the other moved back again. As I dealt with the sprinter I took another two sling stones to the face, and then turned on one of the Ranged. As I chased it, the other backed away and kept pelting me as the other ran away. In the end I ran out of health and died.

Now, from the code's point of view nothing special happened. Each actor followed it's simple rules. However, from my point of view the buggers seemed smart for a second. The Sprinter tanked me, while the Ranged moved away and nuked me. I was kited by one of the enemies since I didn't have ranged attack while the other killed me. That sounds like something more out of a WoW boss fight than Magecrawl.

It was an amazing to see simple rules you write turn into something that seems "alive" even just for a moment.

1 comment:

Mingos said...

Have you ever played Baldur's Gate? There's a scripted part there where you can, if you wish, describe your party members' behaviour. Distance from the enemy, snipe them or charge them, the HP level at which the character disengages, weapon and spell priorities, etc. It's a very simple script, but if you know how to write it, your party members can start behaving in a pretty "intelligent" manner. I guess same happens in your case. The simple rules are enough to make the monsters seem intelligent. Great work, mate. Looking forward to playing Magecrawl.