Proposed Specification

The enemies will be perceived as tuples containing a symbol (stored as a string or int) and a position (three floating-point numbers, one for each dimension X/Y/Z). This is done relatively to the current position and orientation, in the spirit of embodiment. It makes the AI easier to program in this case anyway.

The weapon is fired by calling a simple fire method. The projectile is launched automatically, and there is no need to reload. The projectile itself may be returned as an entity, depending on its type and speed. (For instance, bullets are too fast and are not perceived, whereas slower rockets may be followed.)

The aiming is done with the body turns, as defined for the movement. Because the direction of travel is independent from the orientation, this will prove satisfactory. This is the method used by human players, and proves relatively simple to master.

Because we may have AI that is too good at shooting, we'll probably need to add some noise to some of the functions. This will enable us to vary the skill of the AI implicitly.

Interfaces

The Weapon interface has two functions we are interested in. Firing launches the projectile, and weapon selection is handled by a requesting symbol (string or int). False is returned if something goes wrong.

 
 void Fire(); boor Select(const Symbol& weapon); 
 

Next, the Vision interface is extended to handle tracing projectiles. (It was used for finding obstacles.) The vector given is relative to the current view. The return value is the distance to the first obstacle.

 
 float TraceProjectile(const Vec3f& orientation); 
 

Finally, a query is used to gather the visible entities as an array. This is also part of the Vision module. The second parameter is used to filter the entities that the animat is interested in. (Only those that unify are returned.)

 
 void VisibleEntities(vector<Entity>& visible, const Entity::Type& unifier = 0 ); 
 

Letting the brain gather the entities manually provides it with the most flexibility to handle different situations (for instance, multiple different players). If only one enemy is present, a message-passing approach may be more suitable.

Code Skeleton

A successful implementation will involve more than just using all these interface calls, but here's a simple example nonetheless:

 
 void Think() {   // query the visual interface for an array of players         vision->VisibleEntities( players );   // scan the nearby players to find an enemy      for (int i=0; i<players.size(); ++i)      {           // remember target      }  // turn the view and launch a projectile      motion->Turn( target.GetPosition() );      weapon->Fire(); } 
 

This book does not cover the weapon selection until Part IV; a randomly selected weapon is assumed. The implementation of the different brains in the next few chapters will be split into parts, roughly corresponding to each of the skills discussed (that is, prediction, targeting, and aiming).



AI Game Development. Synthetic Creatures with Learning and Reactive Behaviors
AI Game Development: Synthetic Creatures with Learning and Reactive Behaviors
ISBN: 1592730043
EAN: 2147483647
Year: 2003
Pages: 399

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net