December 11, 2013

A Layered Game Architecture II - Backend AI

The first part of A Layered Game Architecture gave an overview of frontend, backend and shared packages. Here, we continue with a look upon the backend components for actors and AI:
  



actor

Each interactable game object is represented as IActor. Actors are controlled, influenced, directed, moved, created and removed by states, goals, game physics and directors.
Actors are the central object in each game. To avoid dependencies to concrete behavioural implementations, each actor has only a IActorBehaviour reference and does not whether it is controlled by states, goals or in any other way. This allows to plug in, for example, your new sophisticated almighty AI controller instead of using goals, or to switch from Box2D physics to any home brewn physics algorithms without affecting other framework and game parts.

state

States offer separate representations of, for example, moving and waiting actors. Furthermore, game events of all kinds like input and collisions events can be sent and received. Typical events are BulletHit, BulletMissed, DesiredHeading.
States could also be used to implement a (primitive) AI. Then, actors would not get a GoalBrainAndStateBehaviour but a simpler StateBehaviour.

physics

The game physics makes sure that actors move and behave according to the physics rules of the game world. It takes care of collisions between multiple actors as well as between actors and the environment. Collision listeners get notified to initiate appropriate reactions. Velocity and acceleration is calculated from given player input and AI events.
Source and target for game physics is IMovable where data for positions, forces, velocities and acceleration is stored. Because a multiplayer client/server game architecture requires to move actors on server as well on client side, movables are parts of the shared base class ICharacter which resides on both client and server side.
The game physics takes desired actor movements as input and applies them to the game world model. Whether movement commands origin from player input or from AI thoughts is of no interest and simply unknown.

goals

Actors can try to achieve goals like finding level items, following and shooting the player or fleeing and hiding. A typical output of a goal is a new heading direction which is handed over to the physics components. Actor velocities or positions are not directly manipulated from goals to let the physics module handle and watch the complete game physics of all objects together once per frame.
Like states, goals can also send and receive game events of any kind.

Goals are a part of an actor's brain which is supported by its memory where recent observations, events and all kind of AI important information is stored and used for subsequent decision finding. Naturally, a brain has an assigned actor, but, to get back to the previously introduced behaviours, actors don't contain references to their brain.

The goal sub system was inspired by the great book Programming Game AI By Example from Mat Buckland.

No comments:

Post a Comment