THE INNER PRODUCT // DavE MaRk
GettinG More out of nuMbers
Tecniques for more sophis Tica Ted ai
We have lonG been used to nuMbers in GaMes. thousands of years
ago, when people first started playing games, the simple act of keeping
score was dealt with in terms of numbers. Even before games, when people
had to simply scratch by for food, numbers were an integral part of their
lives. From how many rabbits the hunter killed to how many sling stones he
had left in his pouch, numbers have been a part of competitive activity for
all of history.
Coming back to the present, numbers are everywhere for the game
player. Some are concrete values that have analogs in real life: How
much ammo do we have? How many resources will this take to build?
What is the range of that weapon? Some are a little more nebulous, if not
altogether contrived: What level am I? What condition are my gloves in?
What armor bonus does this magic ring afford? And, although the medical
community might be a bit startled by the simplicity, games often parade a
single number in front of us to tell us how much “life” we have. (“He’s only
mostly dead.”) Suffice to say that we have educated our gaming clientele
to forgive this intentional shredding of the coveted suspension of disbelief.
Even though some games have attempted to obscure this relationship
by removing some of the observable references to this numeric fixation,
gamers still recognize that the numbers are still there, churning away
behind the wizard’s curtain.
nuMbers in GaMes
» As programmers, our fixation with numbers is not coincidental. After all,
along with logic, mathematics is the language of our medium. Computers
excel in their capacity to crunch all these numbers. They’re in their element,
so to speak. This capacity is a primary reason that the pen-and-paper RPGs
of the 1970s and 1980s computers so energetically made the transition to
the computer RPGs of the 1980s and beyond. Resolving combat in Ultima
(1980) and Wizardry (1981) was far swifter that shuffling through charts,
tables, and scribbles on scratch paper in D&D.
Numbers surround us, whether in overt use or under the hood. The
interesting—and sometimes even disconcerting—thing is that they aren’t
used more often. Even with all the advances and slick architectures that
artificial intelligence programmers use, we too often fall back on the most
simple of logical constructs to make our decision code. The most obvious
example is the venerable if/then statement. Testing for the existence of a
criterion is one of the core building blocks of computational logic. “If I see the
player, attack the player.” Certainly, this sort of binary simplicity has its place.
Left to itself, however, it can fall woefully short of even being adequate.
We could extend the above example by putting a number in the
equation, such as, “If the player is < 30 [units of distance] away from
me, attack him.” But really, what have we gained? We are still testing for
the existence of a criterion, albeit one that is defined elsewhere in the
statement or in the program. After all, “see the player” and “player < 30”
are simply functions. There is still a razor edge separating the two potential
states of “idle” and “attack.” All subtlety is lost.
So, how might we do things differently? One answer lies not in the
existence of numbers in our world but what those numbers represent and,
ultimately, how we use them.
gaME DEvElOPER | JaNUaRy 2011 48
lookinG in Ward
» Stop for a moment and do a self-inventory. Right now, as you sit reading
this column, are you hungry? Sure, for the sake of simplicity, you may
answer “yes” or “no.” But there is usually more to it than that. When my
daughter was younger, she tended to cease using “hungry” when she was
no longer empty. (This usually meant that she ate two or three bites only
to come back wanting more about 20 minutes later.) I, on the other hand,
could easily see myself defining “hungry” as “no longer full.” My wife has a
penchant for answering somewhat cryptically, saying “I could be.” (This is
usually less convenient than it sounds.)
All this makes sense to us on an intuitive level. “Hunger” is a
continuum. We don’t just transition from “completely full” to “famished”—it
is a gradient descent. What we do with that information may change,
however, depending on where we are in that scale. For example, we can
make judgment decisions, such as, “I’m not hungry enough to bother
eating right now ... I want to finish writing this column.” We can also make
comparative judgments, such as, “I’m a little hungry, but not as hungry as I
am tired.” We can even go so far as use this information to make estimates
on our future state: “I’m only a little hungry now, but if I don’t eat before
I get on this flight, my abdomen will implode somewhere over Wyoming.
Maybe I’d better grab a snack while I can.”
Compare this to how the AI for game characters is often written. The
subtlety of the differences in value seems to be lost on them. Soldiers
may only reload when their gun is completely out of ammunition, despite
being in the proverbial calm before the storm. Sidekicks may elect to waste
a large, valuable health kit on something that amounts to a cosmetically
unfortunate skin abrasion. The coded rules that would guide the behaviors
above are easy for us to infer:
if (MyAmmo == 0)
if (MyHealth < 100)
Certainly we could have changed the threshold for reloading to
MyAmmo <= 5, but that only kicks the can down the road a bit. We
could just as easily have found our agent in a situation where he had
six remaining bullets in his magazine and, to co-opt a classic novel title,
all was quiet on the western front. Dude, seriously—you’re not doing
anything else right now, might as well shove some bullets into that
gun. An agent built to only pay homage to the Single Guiding Rule of
Reloading would still stubbornly wait until he had five before reaching
for his ammo belt.
Additionally, there are other times when a rule like the above could
backfire (so to speak) with the agent reloading too soon. If you are faced
with one final enemy who needs one final shot to be dispatched, you don’t
automatically reach for your reload when you have five bullets. You finish
off your aggressor so as to get some peace and quiet for a change.