Friday, May 13, 2011

Artificial intelligence underpinnings

Objects such as creatures, wildlife, NPCs, and items are stored on the server side using MOOcode.  Living things, like NPCs and players execute a basic game loop known as a heartbeat.  NPC AI can be created by returning the next action to execute based on the NPC's circumstances with a moocode verb called suggest_next_action.  A few days ago I got the basic system for artificial intelligence in place, as such:

$creature - Creature is the most basic creature, and as such has the most basic AI.  Other NPCs and wildlife derive from this creature and execute it's basic AI when their higher level AI is not busy.  Creatures currently handle no AI whatsoever, since they are the basis for both players and NPCs.

$npc - NPC is the most basic non player creature.  There are two derivatives, $robot and $wildlife.  NPC AI first checks to see if the creature is both unarmed and contains a valid weapon.  If so, the $actions.wield command is queued on the NPC.  If all is well with our weapons, the NPC checks to see if it has a valid target, and if the target is in the same room.  If so, the NPC will queue up an attack.  If the creature is both equipped and not fighting, it will check if the creature wanders, and if so, roll dice to see how far and which direction the npc will walk, then queues $actions.walk on the npc.

$wildlife - wildlife is an extension of $npc that handles basic wildlife functions for creatures that are dynamically spawned and run around the world.   It has three derivatives: herbivores, carnivores, and sentient (such as non-player humans).  $wildlife:suggest_next_action handles the most basic wildlife problem: food.  Depending on what the creature eats and how hungry it is, it will either hunt another critter down to eat, or forage for plant matter.

No comments:

Post a Comment