O'Reilly logo

Programming Game AI by Example by Mat Buckland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Elsa: Walkin' to the can. Need to powda mah pretty li'l nose
Elsa: Ahhhhhh! Sweet relief!
Elsa: Leavin' the john
Miner Bob: Depositin' gold. Total savings now: 5
Miner Bob: Woohoo! Rich enough for now. Back home to mah li'l lady
Miner Bob: Leavin' the bank
Miner Bob: Walkin' home
Elsa: Walkin' to the can. Need to powda mah pretty li'l nose
Elsa: Ahhhhhh! Sweet relief!
Elsa: Leavin' the john
Miner Bob: ZZZZ...
Adding Messaging Capabilities to Your FSM
Well-designed games tend to be event driven. That is to say, when an event
occurs — a weapon is fired, a lever is pulled, an alarm tripped, etc. — the
event is broadcast to the relevant objects in the game so that they may
respond appropriately. These events are typically sent in the form of a
packet of data that contains information about the event such as what sent
it, what objects should respond to it, what the actual event is, a time stamp,
and so forth.
The reason event-driven architectures are generally preferred is because
they are efficient. Without event handling, objects have to continuously
poll the game world to see if a particular action has occurred. With event
handling, objects can simply get on with their business until an event mes-
sage is broadcast to them. Then, if that message is pertinent, they can act
upon it.
Intelligent game agents can use the same idea to communicate with each
other. When endowed with the power to send, handle, and respond to
events, it’s easy to design behavior like the following:
n
A wizard throws a fireball at an orc. The wizard sends a message
to the orc informing it of its impending doom so it may respond
accordingly, i.e., die horribly and in magnificent style.
n
A football player makes a pass to a teammate. The passer can
send a message to the receiver, letting it know where it should move
to intercept the ball and at what time it should be at that position.
n
A grunt is injured. It dispatches a message to each of its comrades
requesting help. When one arrives with aid, another message is
broadcast to let the others know they can resume their activities.
n
A character strikes a match to help light its way along a gloomy
corridor. A delayed message is dispatched to warn that the match
will burn down to his fingers in thirty seconds. If he is still holding
the match when he receives the message, he reacts by dropping the
match and shouting out in pain.
State-Driven Agent Design | 69
Adding Messaging Capabilities to Your FSM

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required