Beyond AI Pseudo-code and Towards Sensory Systems

Alex J. Champandard on November 21, 2007

Over the last few weeks, this tutorial series designed and implemented simple dog behaviors using random decisions structured within behavior trees. This article shows you the C++ source code of the game’s AI logic as it is today.

Also, it’s time for you to put your thinking hats on; you need to decide what features to implement next. The biggest thing missing in the AI is the ability to perceive information from the world. Here’s another chance for you to design behaviors to show off the dog’s perception abilities.

Behavior Tree Implementation

The source code for the AI is split into four files, two .h headers and two .cpp source files. These define a Dog entity, and build up a behavior tree using low-level actions — as discussed in the previous tutorials.

The documentation is formatted up using AsciiDoc. Feel free to browse it here:

As you can see, the bulk of the code is in the two implementation files, first to define the actions and then to build behavior trees out of them.

AI Logic Source CodeBehavior Tree Source CodeAI Actions Source CodeLow-Level AI Source Code

First Sensations

The next logical step for the AI is to start integrating it with information from the world instead of making random decisions. This requires using a simple sensory system for gathering information.

So here’s your chance to help design some simple doggy behaviors. Here are the requirements:

  1. Behaviors must demonstrate awareness of the environment — whether objects, annotated areas, or other dogs.

  2. The props and behaviors must be easy to implement, preferably within a few hours of work.

  3. Only certain animations described in the start of this AI tutorial are available for use.

Otherwise, you’re free to let your scary ideas go wild. Thing about interaction with other dogs, or meaningful zones that are annotated in the code.

Post a comment below if you want to help out!

Discussion 6 Comments

bknafla on November 22nd, 2007

I am new to this type of collaborative development and therefore my first participation might not fit the form needed here but I wanted to point to an interesting article of Richard Evans and Thomas Barnet Lamb about the AI model in Black and White ( http://www.gamasutra.com/features/20020424/evans_pfv.htm ). Basically they say that agents (in this case the dogs) should be aware of activities other dogs and they themselves are involved in. Only then they know how to act and how to react to the behavior of another dog. For example if the low level sensory system tells a dog about another dog in his neighborhood (via a spatial sensory system). Then another sensor might tell him (for example by inspecting the behavior animation or just by reading a symbolic behavior-description tag) that this other dog searches for another dog to play with him. Based on this knowledge he might decide to run to the other dog and start a "lets" play behavior with the associated animation. Cheers, Bjoern

FreddieFreeloader on November 22nd, 2007

What about doing smell? Let scent accumulate over the time at a dogs position (in some relatively coarse-grained grid) in much the same manner as it does for pheromones in Ant Colony Optimization. Each cycle, all dogs deposits a fixed amount of smell at it's current position, while smell either dissipates or disappears from all positions. This would have the strength of a particular scent depend on how fast dogs move through the environment. Also, peeing and pooping could leave larger "chunks" (?) of scent. Support this with a tracking behaviour that, in the same vein as ACO (go in the direction where the concentration of scent is highest), has the dog following a trail of smell using a combination of the sniffing and sneaking animations. This behaviour could then be used either to simply track other dogs or in combination with peeing and pooping, such that the dog would mark it's territory near concentrations of smell.

phoenix946 on April 22nd, 2010

I have been trying to get this to work on my own computer (learning a bit about gameAI++ and Ogre in the process), because I wanted to get some experience with Behaviour Trees and this seemed like a good place to start. However I've now reached the point where I need the mesh file, "puppy_r1_ogre.mesh", which I can't find. You mention in the tutorial you "bought stock assets", does this mean that the puppy model is not publicly available? If it is in fact available, could you link where I can get it please?

alexjc on April 22nd, 2010

Hi, It's the [URL="http://www.3drt.com/3dm/characters/puppy/puppies-collection-shots.htm"]Puppies Pack[/URL] from 3DRT. The prices have gone up a lot since the two/three years I originally used them. There are possibly some free dog models you can find, though the animations won't work of course... I think Tuan Kuranes got it working with some free models, but I can't remember where he posted the information. Alex

sizmos on May 14th, 2012

the links seem to be broken

cod3monk3y on August 29th, 2014

Links to .cpp/.h are still broken. Great series, Alex.

If you'd like to add a comment or question on this page, simply log-in to the site. You can create an account from the sign-up page if necessary... It takes less than a minute!