Week 2 - School of Engineering and Information Technology

Download Report

Transcript Week 2 - School of Engineering and Information Technology

Topic 2
Agents, Animats and Game Platforms
•
•
•
•
•
•
•
•
What are agents and artificial life?
Considerations for game AI
Goal orientation, planning and control
Reactive techniques for games
Reflective vs Reactive behaviour
The FEAR platform
Creating and running an animat
Evaluating the performance of an animat
Reading: Champandard Chapter 3; Chapter 4;
The FEAR documentation
ICT219
1
Agents
• Arguably the most important development in AI of the last decade
has been the notion of agents
• Comes from the philosophical notions of action, and the notion of
Rational Economic Man
• An agent is a self-contained bundle of software with the
characteristics of autonomy, action and rationality
• Related to, but more sophisticated than, the notion of an object in
OOL. Higher level of abstraction, in which what counts is the choice
of action in response to goals and situation.
• Newell’s concept of behavioural laws governing action eg
An agent will choose the action most likely to lead to an outcome that matches one of its goals.
• In a multi-agent system complex behaviour emerges as the result of
the interactions between many, relatively simple agents according to
social principles
ICT219
2
Artificial Life – Cellular automata
• A-life shares some elements with agent research, especially the multiagent approach
• Earliest forms were a class of game called cellular automata
eg Conway’s Life
• A few rules control the birth, survival and death of counters on a
rectangular grid, to produce growing, complex patterns over cycles
Cells can be either live (contain counter) or dead (no counter). Each cell has 8
neighbours. To decide what will happen in a cell for each cycle, count the
number of live and dead cells
1) A dead cell with exactly 3 live neighbors becomes a live cell (birth).
2) A live cell with 2 or 3 live neighbors stays alive (survival).
3) In all other cases, a cell dies or remains dead (overcrowding or loneliness).
Artificial Life - Norns
• However, A-life today is
about making biologically
plausible software models
•Some of this work has
resulted in extremely valuable
creatures which
may be used in game-playing
scenarios eg Norns in
Cyberlife’s Creatures
• Norns have a simulated
body, with a ‘digestive
system’ and ‘biochemistry’
ICT219
Image: Cyberlife/New Scientist
4
Considerations for Game AI
• Are the AI approaches applicable to the software design of NPCs?
ie able to provide:
- control of primitive behaviours eg picking things up, pressing switches,
using objects, etc.
- movement
move around the game world, dealing with obstacles and navigating
to target destinations
- decision-making working out what tasks to perform, and in what order
• Traditionally, these things were done by laborious, detailed,
procedural programming - now becoming more difficult as games
evolve
• From a games point of view, you don’t care if you use as AI or not
• But we want to learn about AI, so we’ll care
ICT219
5
Considerations for Game AI
• In nouvelle game AI, we consider how the needs of game designers
work for (and against) AI methods
• In games, some NPC characters need to behave intelligently to be
believable and entertaining – maybe easier to accomplish with AI
programs...
• ...but only if the program can really perform (very fast response to
new situation) - challenging for AI
• Software control of actions within
a game has until recently needed
to be explicit – ie scripting
• For each of a number of situations
arising in the game, a standard
behaviour response is rigidly encoded
• More recently, agent and other AI
technologies have enabled implicit
control – NPC assesses situation,
chooses its action with respect to its
own goals
Considerations for Game AI
• Basic conflict for game design: Building in intelligence allows NPC
characters to behave autonomously, yet human designers need to
control them, to make the game work as expected
• Eg many games follow a script like a movie, so that a certain
sequence of events happens to unfold a story line. If NPCs
(especially learning ones) can run their own show, they might not
stick to the script!
• What role would intelligent decisions have in a scripted storyline?
• One idea would be implicit design – no explicit script, just the
elements of an interesting world and both player and NPC improvise
• Another is to alternate sequences of scripted action (in which the
NPCs intelligence is switched off) with free form action (in which the
intelligence is on). Might be difficult to keep on track though!
ICT219
7
ICT219
8
Goal-orientation, planning
• Goals may be defined as a representation of a state of affairs
which is marked as somehow desirable, to be achieved
• Maintenance goals involve making sure some state of affairs is
not lost (eg keep breathing)
• Achieving a goal may involve a number of actions to move the
actual state of the world closer to the desired state (eg move
toward a source of food or target)
• It might not be clear what to do next to get closer to a goal –
planning is needed to select and order individual actions
• All this requires collecting and maintaining models of the worldstate, comparing them to goal states and then making decisions
• This can take a lot of design and a lot of computation
• Planning programs exist, but they tend to be slow and complex
ICT219
9
The problem of planning
• Conventional AI planning program requires
• i) a list of goals represented using a knowlege representation
• ii) a problem in the form of some data representing opportunities
or problems
• iii) a set of possible actions which the machine can choose from
iv) a planning algorithm which organises actions into a optimal
plan
The program would then do standard information processing:
1) accepts these as data files
2) process the data
3) prints out an optimal plan, ie ordered list of actions
ICT219
10
Reflective vs Reactive Behaviour
• This distinction is important to game development, mostly
because of the need for fast reactions
• Early AI tended to be reflective – meaning that a problemsolving algorithm would exhaustively consider all possible
courses of action, then choose the optimal (in terms of goal
satisfaction) one
• Humans don’t really do that, though. They satisfice, which
means come up with a “good enough” solution, but more quickly,
especially when time is an issue. Saves mental effort
• Reflective programs build representational models from input
data, evaluate or reason about them, plan a course of action
then output it – expensive in computing power
• Reactive programs use the world as their model. They interact
directly with the world, exploiting simple signals and regularities
there, to get behaviour which is not perfect, but fast
• Now game AI tends to be mostly reactive
One does not want to be stuck in
high-level planning when there’s an
emergency bearing down on you
<train bearing down>
Image: Benjamin Hobson, The Canal Gallery
Maybe it’s quicker and easier to
sense the world and act directly on
it, instead of building and maintaining
internal models of the world
This is how insects are able to do
a lot of clever things without a big
brain and lots of memory
Image: Mike Williams
ICT219
12
Reactive Techniques for Games
• Another advantage of reactive designs is that they tend to be
deterministic – fully specified by inputs
• That means reactive code can very simple, easy to
test and be highly optimised for speed eg
- lookup tables
- scripts
- rule-based systems
- Finite State Machines
•Benefits for animats
- fits in with the idea of embodiment very well
- environment can be enriched which provides more information to the animat
- most learning techniques are based on reactive mappings
- easy to create, test and maintain
ICT219
13
Environments, simulations, platforms
•
According to the notion of embodiment, the best place for an AI in
immersed in the world, connected to it by many sensors and actuators
Eg a robot roams about a house, sensing with cameras, microphones and using
motorised limbs to move
•
Game AI modifies this slightly, and says the ‘world’ doesn’t have to be
physical – it can be a computer simulation of the real world
Advantages
- Cheaper and smaller than robots in the real world
- Can develop and make changes faster in simulation
- Can’t do any harm if it goes wrong
Disadvantages
- world may be too simple to properly challenge an AI program
- world may not be realistic, or even logically consistent
- may have to build - or at least configure - an artificial world; extra work
•
In game AI, we are more or less forced use to a simulated world. But
this is still better than prepared, cut-and-dried data sets
FEAR Platform - Overview
• To simplify writing of AI code, the environment and integrating the
two, we will use a standard development platform, called Flexible
Embodied Animat aRchitecture (FEAR)
• Creates embodied animats ie that have a (simulated) body, are
subject to physical constraints in the (simulated) world and do not
have full information about the game
• Just as human game players has an avatar in the game world, so a
disembodied AI software controls its own avatar
• FEAR is designed to work with the engine of Quake II, an old first
person shooter
• The game developer specifies the interfaces, modules and
architectures of an animat in a given world, in a domain-specific
language called XML
ICT219
15
FEAR Platform
– Interfaces - provide a set of functions that can be called,
messages that can be passed back, type definitions and constant
declarations
– Modules - the implementation behind the interfaces. Usually runtime code, but you can store data in these too. To formalise
dependencies between modules, each imports and exports
interfaces
– Architectures – are built up from nested components ie a
hierarchy or tree. The root of the hierarchy is usually the brain of an
animat
• These high-level XML specifications are processed into C++ source
code - ready for compilation - using customised templates
• This is called code generation or metaprogramming
• Think of FEAR as developing toward an “IDE for Games AI”
ICT219
16
Compiling an Animat
• Take a demo animat from the AIGameDev website
• Or write your own animat by generating your own XLM
template and writing C++ code (usually called Brain)
• Unless you are an expert it is better to modify an existing
animat than make a new one completely from scratch
• Compile the animat using the MS Visual Studio 6.0
• Check that it has compiled, debug as necessary
ICT219
17
customise an
XML template
and/or...
use/modify an
existing animat
build using
Visual Studio
C++ compiler
modules
(FEAR) Server
animats
(FEAR) Server
sv add <name>
FEAR/Quake2
ICT219
18
Running the Animat
• Run the FEAR/Quake 2 server with a command line
prompt by double clicking (FEAR) Server. Force the
animat under test in by typing
sv add <name of animate directory>
====== Quake2 Initialized ======
==== InitGame ====
------- Server Initialization ------49 entities inhibited
0 teams with 0 entities
-------- FEAR Initialisation -------obituaries disabled
acceleration disabled
0 bots requested
------------------------------------sv add 05-Dr.Spin
Dr. Spin connected
Dr. Spin entered the game.
bots = 1
• To observe the animat’s behaviour, enter the game as a
human player clicking (FEAR) Player.
ICT219
19
Evaluating Performance of Animat
• It will be important to measure the performance of the animat in
order to compare brain designs (which is better?)
• Measuring behaviour can be difficult, as ethologists (scientists
studying animal behaviour) or psychologists (scientists studying
human behaviour) learned
• One advantage of a game platform is that it has a built-in measure
for animats, which is their score
• In Quake II, press the F1 key to view the score for yourself (‘The
Creator’) and your animat
• These statistics are crude, but might be enough to begin with
• To compare the scores of two animats, you need to have exposed
them to the same challenges, for the same amount of time (a
controlled experiment)
• We distinguish between single-trial measurements and
tournaments (gathering statistics over multiple trials).
Summary
• Agents are an AI development which enables software to choose
actions autonomously to achieve one or more goals which it has
• Artificial life is an attempt to model the more biological aspects of life,
such as reproduction (Life) or the digestion of food (eg Norns)
• Both these technologies can be used to make lifelike, believable and
entertaining NPCs for computer games
• The software control of NPCs can be explicit (eg scripts) or implicit
(eg rational agent)
• Good control of gameplay in interactive games is part of the art
• In conventional AI, accomplishment of goals required planning, which
could be complex and processor-intensive
• Conventional AI planners were reflective, which means they did not
excel in time critical situations (like games)
• Behavioural control in games tends to be reactive, which means less
logical modeling of the world and more reacting directly to stimuli
ICT219
21
References
Newell, A. The Knowledge Level, Artificial Intelligence, 1982, 18, 87-127
Martin Gardner. The fantastic combination of John Conway's new solitaire
game of “life”. Scientific American, 1970, 223, 120-123
Cliff D. & Grand S. The Creatures Global Digital Ecosystem. Artificial Life, 1999, 5, 1,
77-93. Available at
http://citeseer.ist.psu.edu/cache/papers/cs/26466/http:zSzzSzwww-uk.hpl.hp.comzSzpeoplezSzdave_cliffzSzcreatures.pdf/cliff99creatures.pdf
Champandard, A. FEAR User Guide. Online Manual for FEAR/Quake 2 Platform
Available at http://fear.sourceforge.net/docs/latest/guide/Guide.html
ICT219
22