Tricks of the Windows Game Programming Gurus. André LaMothe New York, Sams Publishing (1999)

Book, 1005 pages plus CD-ROM of example source code.

This book is not so much a ‘bible’ of the computer game industry as it is a grimoire4. It is especially loved because it contains numerous source code examples both in the text and on the accompanying CD-ROM.

Chapter 12, “Making Silicon Think with Artificial Intelligence” does a fine job of introducing, discussing and showing with source code the most common techniques of AI for computer games. These include, in order:

Deterministic AI
These are predetermined or preprogrammed behaviors (including random vectors and velocities). All external input is ignored. Pac Man is a classic example of Deterministic AI.

Tracking Algorithms
These can be as simple as the standard

if (player_x > monster_x)
monster_x ++;

or as complicated as curved trajectory tracking and calculating future target location and adjusting vector and velocity accordingly.

Evasion Algorithms
These are simply the reverse of the tracking algorithm above.

Patterns and Basic Control Scripting
Patterns are frequently stored as defines or bits and use a simple vocabulary such as: GO_FORWARD = 1, TURN_RIGHT_90 = 2, WAIT_X = wait X cycles, etc. These commands are then read and interpreted though a series of switch statements.

Patterns with Conditional Logic Processing
This combines pre-designed patterns with some conditional such as:

If (test_distance > 7)
AI_State = TRACK_PLAYER;
Else
AI_State = AVOID_PLAYER;

Modeling Behavioral State Systems
“To create a truly robust Finite State Machine (FSM) you need two properties:

A reasonable number of states, each of which represents a different goal or
motive.

Lots of input to the FSM, such as the state of the environment and the other objects within the environment.” — p. 729

A master Finite State Machine (FSM) with substates (from page p. 730).

Elementary State Machines
This involves separating the AI into “High Level” states, “Medium level logic” and “Low level logic.” See next diagram (from page 731).

LaMothe continues stating that, “A personality is nothing more than a collection of predictable behaviors.” And later, “…you should be able to model personality types using logic and probability distributions that track a few behavioral traits and place a probability on each.”

LaMothe also suggests adding a “radii of influence” that further adjusts and influences a computer personality (see below):

Modeling Memory and Learning with Software
This is a fairly obvious AI routine with the addition of agents transferring knowledge and data. See the sample source code for memory and learning. (Note: Word may not correctly open the file which is a Visual Studio C++ file.)

Planning and Decision Trees
LaMothe states that high-level AI = planning = a high-level set of actions. He also suggests building a decision tree of nodes that represent a production rule and/or an action which can be loaded at runtime from a file.

Pathfinding
LaMothe begins by describing basic, primitive pathfinding algorithms including “Trial and Error.”

Contour Tracing
This method involves constantly shooting a ‘line’ from the subject to the goal. Whenever an obstacle is encountered a new path is traced around it:

As LeMothe says, “This works, but it looks a little stupid because the algorithm traces around things instead of going through the obvious shortest path. But it works.” But there’s something to be said for an algorithm that is guaranteed to work.

Collision Avoidance Tracks
This method involves calculating (possibly pre-computing), or ‘drawing’ during level design, avoidance paths around all obstacles and storing them for later use. See diagram below:


This system is fine if you have the luxury of pre-computing or pre-designing terrain.

Waypoint Pathfinding
This method consists of constructing a series of predefined waypoints and paths (see diagram below). Source code is also included showing implementation of this method in a driving/racing game.

Robust Pathfinding
Breadth-First, Bidirectional Breadth-First, Depth-First, Dijkstra’s Search and A* Searches are described. However, LaMothe cautions that none of these are applicable to real-time pathfinding.

Advanced AI Scripting
LaMothe describes some basic scripting techniques and suggests using the compiler pre-processor commands to turn a pseudo-English scripting language into standard C/C++ code. The script file (xxx.scr) would be added as an include to the code and then compiled and linked into the executable.

Artificial Neural Networks
Neural Nets have been around since they were first described by McCulloch and Pitts in 1943. A neural net basically emulates the human brain by creating logic circuits that fire when two inputs are greater than a predetermined value (theta). A bias can also be added to simulate long term memory. See LaMothe’s in depth article here (neural.doc). Also in the same subdirectory is source code and executable examples of neural network implementation.

Genetic Algorithms
LaMothe only briefly describes Genetic Algorithms that emulate the process of “natural selection” to solve AI tasks. Obviously, the key to creating robust genetic algorithms rests with the algorithm evaluation criteria.

Fuzzy Set Theory, Fuzzy Linguistic Variables and Rules, Fuzzy Manifolds and
Membership, Fuzzy Associative Matrices

Key Fuzzy Logic terms and concepts:
DOM = Degree of Membership
FLV = Fuzzy Linguistic Variable
FAM = Fuzzy Associative Matrix (Matrices)
Logical AND means minimum of the set
Logical OR means maximum of the set

The key principles of fuzzy logic are:

  1. As opposed to “crisp” logic, fuzzy linguistic variables (FLV) do not fall into precise categories rather they have Degrees of Membership (DOM). See first chart 12.46 above.
  2. Sets of FLVs are ANDED (means minimum of the set) or ORED (means
    maximum of the set) and then used to index the Fuzzy Associative Matrix (FAM) as in above (chart 12.47). Each cell of the FAM can have a number of values or instructions.


Copyright© 2007 — D. Ezra Sidran — Scarab Industries

HTML version by: Ralph the Wizard - Wizard Information Technology Services, LLC