
RC++: a rule-based language for game AI
Ian Wright
James Marshall
Sony Computer Entertainment Europe
Waverley House, 7-12 Noel Street
London W1V 4HH
E-mail:
ian_wright@scee.net
james_marshall@scee.net
KEYWORDS
Game AI, Rule-Based Languages, Tools, Agents
ABSTRACT
"Game AI" is the high-level control code for computer
entertainment applications. Games are diverse, and the
nature of game AI reflects this diversity. However, game AI,
in contrast to rendering code and other game code, is
distinguished by employing a high density of predicates on
rapidly changing game state, and a high density of
operations that change game state. Traditional programming
languages, such as C and C++, are not designed to facilitate
the creation of such code, unlike high-level AI rule-based
languages.
RC++, a full-featured, rule-based extension to C++,
designed for Sony Computer Entertainment’s PlayStation2
hardware, is described. RC++ is based on OPS5 (Forgy, 81)
and Poprulebase
1
, a rule-based extension to the Pop-11
programming language. It combines optimised execution
associated with OPS5 with the syntactical style and some of
the useful features of Poprulebase. It is designed to facilitate
the rapid creation of game AI by automating many of the
common programming tasks associated with creating game
rules, while maintaining the flexibility of C and C++ when
required. The aim of the paper is to demonstrate the
applicability of rule-based programming to game AI in
general, and the usefulness of RC++ for game AI in
particular.
THE RULES OF THE GAME
Currently, most game AI code consists of the
implementation of behavioural rules that encapsulate
knowledge about a particular game domain. For example,
rules to control racing cars, footballers, enemies, and so
forth. There are many different types of ‘rule’. The equations
of motion that control a bouncing ball are ‘behavioural rules’
in a general sense. Such rules normally involve analytical or
1
Poprulebase is part of the Poplog programming system, which contains the
languages Pop-11, Prolog, Lisp, ML, and the SIM_AGENT toolkit. It is
freely available from http: // www.cs.bham.ac.uk/ research/ poplog/
freepoplog.html.
numerical solutions to equations involving real numbers. In
contrast, a rule to decide whether a footballer should pass or
shoot involves conditions on world state, which may be
represented not just by real numbers, but by symbolic
representations of states-of-affairs, or combinations of such
quantitative and qualitative information. These two types of
behavioural rule require very different implementation
strategies. Physical equations, in particular, require
techniques from numerical mathematics, whereas ‘if-then’
rules require a different approach. This paper presents a
language, called RC++, which is designed to facilitate the
coding of ‘if-then’, as opposed to physics-based, rules.
There are also many different types of game ‘agent’. A
bouncing ball does not need to remember facts about its
world, whereas a virtual footballer needs to remember where
his team-mates are, what the current team strategy is, and so
forth. Many games implement both kinds of agent: passive
objects governed by approximations to physical laws and
active agents constrained by those laws, but able to store
information, make decisions, and perform actions that
change the virtual environment. Examples are balls (passive,
controlled by physical equations) and footballers (active,
controlled by rules) in a football game, or cars and drivers in
a racing game. The distinction between passive objects and
active agents is reflected in the game industry’s distinction
between physics modelling and game AI.
Implementing behavioural rules for active agents is required
by all games and is an everyday task for the game AI
programmer. Rules are to AI as polygons are to graphics.
The aim of RC++ is to provide methods and tools that allow
easy scripting of high volumes of predetermined or logic-
based events for game characters to perform, and ease the
implementation difficulties of more sophisticated techniques
required for correspondingly more intelligent behaviour.
PROCEDURAL LANGUAGES
C and C++ are fundamentally procedural languages. They
are not ideally suited to writing rule-based AI code. Game
AI code, in contrast to other game code, tends to be
condition-rich, requiring many tests on state and conditional
branching based on the results of those tests. A procedural
implementation, such as a C implementation, codes
condition checking on state as a succession of ordered ‘if’ or
‘switch’ statements. There is nothing intrinsically wrong