Top Banner
Introduction to Game AI CS 395 Game Design Spring 2003
61

Introduction to Game AI CS 395 Game Design Spring 2003.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Game AI CS 395 Game Design Spring 2003.

Introduction to Game AI

CS 395 Game Design

Spring 2003

Page 2: Introduction to Game AI CS 395 Game Design Spring 2003.

Expectations on term projects

• Designing and implementing a full game from scratch can be too hard

• Exceptions: Text-based interactive fiction, arcade games, …

• What to do?

Page 3: Introduction to Game AI CS 395 Game Design Spring 2003.

Solution One: Leverage

– We’re supplying toolkits and resources for some projects

• Neverworld3

• Self-explanatory simulator compiler

– There are lots of resources around if you look

• Game engines

• Graphics frameworks

• Games with available source code (e.g., FreeCiv)

– Building on top of such software is strongly recommended.

Page 4: Introduction to Game AI CS 395 Game Design Spring 2003.

Solution Two: Extension an existing game

• Extensions to existing games can be acceptable (aka “mods”)– Must involve significant design work, including

analysis of tradeoffs and portfolio of experiments generated in the course of design

– Must be substantially larger than a typical homework problem

Page 5: Introduction to Game AI CS 395 Game Design Spring 2003.

Term Project To Do List

• Identify your teammates early• Identify your project area early• Request for Proposals will be made very soon

(Thursday)

Page 6: Introduction to Game AI CS 395 Game Design Spring 2003.

Overview

• Why AI is important for games– And why it needs improving

• Roles for AIs in games– The opponent– Characters– The World

• Example credits: – Spatial reasoning in MOO3

• Thanks to Kevin Dill for screenshots and example– Tactical decision making in first-person shooters

• Thanks to John Laird, Mike VanLent, for their GDC 2001 tutorial material

Page 7: Introduction to Game AI CS 395 Game Design Spring 2003.

Why AI is important for games

• Essential to the modeled world– NPC’s of all types: opponents, helpers, extras, …– Unrealistic characters reduced immersion– Stupid, lame behaviors reduced fun– Superhuman behaviors reduced fun

• Until recently, given short shrift by developers– Graphics ate almost all the resources– Can’t start developing the AI until the modeled world

was ready to run• AI development always late in development cycle

• Situation rapidly changing– AI now viewed as helpful in selling the product– Still one of the key constraints on game design

Page 8: Introduction to Game AI CS 395 Game Design Spring 2003.

Interview with Soren Johnson, www.gamespy.com

GameSpin: What about the [civ3] AI? One of the complaints that players have always had about the AI is that it cheats. Does it still cheat?

Johnson: The AI has been totally reworked. We started from scratch. We stretched out the difficulty levels. Chieftain is easier than it was in Civ II and Deity is now harder. Does the AI cheat? Yes, but sometimes in favor of the player! Below Prince level it cheats for the player, and above Prince level it cheats against the player. At Prince level there is no cheating.

Right now, no one at Firaxis can beat the AI at Deity level, though we certainly expect players to find ways to do so within a few months of the game being released.

When we rewrote the AI we threw out the old AI completely. We also looked at some popular tactics like ICS -- infinite city sprawl -- that some players used to beat the AI in Civ II at Deity level. These won't work in Civ III.

Page 9: Introduction to Game AI CS 395 Game Design Spring 2003.

AI in game marketing

• “It may be hard to believe that the future of 21st century art is represented by a giant bipedal tiger who farts, break dances and flings livestock around when he's bored.”– Review of Black and White in Salon.com, 4/10/2000

• “The most versatile 3D Batman yet, with over 500 animated movements, special fighting moves and a multi-functional cape with its own A.I.”– from www.xbox.com

Page 10: Introduction to Game AI CS 395 Game Design Spring 2003.

Game flaws engendered by bad AI

• Mindless hordes of opponents– “Life is much, much easier thanks to

random numbers”

• Rampant cheating by computer opponents• Focus on violence as principle mode of interaction

Page 11: Introduction to Game AI CS 395 Game Design Spring 2003.

Roles for AIs in games

• The opponent• Characters• The world

Page 12: Introduction to Game AI CS 395 Game Design Spring 2003.

The opponent

• Emphasis: Outsmarting you• Example: Classic board games• Questions:

– What problems do they have to solve?

– How do they work?

Page 13: Introduction to Game AI CS 395 Game Design Spring 2003.

Opponents in classic board games

• Move generator figures out what moves are possible

• Static evaluator figures out how good each move is, based on changes in board position

• Search algorithms look ahead, in a simple form of mental simulation, to figure out the best alternative based counter-moves and counter-moves

Page 14: Introduction to Game AI CS 395 Game Design Spring 2003.

Example

Current board position

Page 15: Introduction to Game AI CS 395 Game Design Spring 2003.

Example Your possible moves, as

produced by move generator

How good each move looks in terms of its

immediate results, as computed by the static

evaluator

6 18 -2

Page 16: Introduction to Game AI CS 395 Game Design Spring 2003.

ExampleYour

opponent’s possible

countermoves

8 2 -100 25 18 12

What position these countermoves leave you in

Page 17: Introduction to Game AI CS 395 Game Design Spring 2003.

ExampleThis process

can be continued

until resourcesrun out

Use minimaxto estimateyour best

move

Page 18: Introduction to Game AI CS 395 Game Design Spring 2003.

Minimax Example

-98 210 1088 22 18-12 -40-10 3 5

Run staticevaluatoron leaves

Page 19: Introduction to Game AI CS 395 Game Design Spring 2003.

Minimax Example

-98 210 1088 22 18-12 -40-10 3 5

Propagate scores upwardby taking maxwhen your turn

8 5 -98 210 22 18

Page 20: Introduction to Game AI CS 395 Game Design Spring 2003.

Minimax Example

-98 210 1088 22 18-12 -40-10 3 5

8 5 -98 210 22 18

Propagatescores upward

taking minwhen opponent’s

turn

5 -9818

Page 21: Introduction to Game AI CS 395 Game Design Spring 2003.

Minimax Example

-98 210 1088 22 18-12 -40-10 3 5

8 5 -98 210 22 18

Select bestoption based

on deeperestimate

5 -9818

Page 22: Introduction to Game AI CS 395 Game Design Spring 2003.

Search issues

• Lots of techniques for more efficient search– Alpha-beta pruning, “book” openings, stability

measures, conspiracy numbers

• Basic problem is still exponential– Search and brute force only go so far

– Q: Why did Deep Blue win?

• Knowledge/search tradeoff– Simon & Chase experiments: Chess experts use spatial

memory for board positions

– Standard patterns as encoding lessons from experience/deeper search?

Page 23: Introduction to Game AI CS 395 Game Design Spring 2003.

Opponents in turn-based strategy games

• Examples: Many strategy war games, Civilization-style games

• What problems do they have to solve?• How are they similar to, and different from, board

games?

Page 24: Introduction to Game AI CS 395 Game Design Spring 2003.

nuSketch Battlespace

Page 25: Introduction to Game AI CS 395 Game Design Spring 2003.
Page 26: Introduction to Game AI CS 395 Game Design Spring 2003.
Page 27: Introduction to Game AI CS 395 Game Design Spring 2003.
Page 28: Introduction to Game AI CS 395 Game Design Spring 2003.

Comic Graphs provide visualization

of alternatives,support for AAR

Page 29: Introduction to Game AI CS 395 Game Design Spring 2003.

Example from MOO3

Homeworld

Colony

Colony

EnemyColony

Where should you put

your next

colony?

Page 30: Introduction to Game AI CS 395 Game Design Spring 2003.

Understanding your terrain is key

Homeworld

Colony

Colony

EnemyColony

Inside your

empire

Page 31: Introduction to Game AI CS 395 Game Design Spring 2003.

Understanding borders prioritizes threats

Homeworld

Colony

Colony

EnemyColony

Good choice for blocking threats

Page 32: Introduction to Game AI CS 395 Game Design Spring 2003.

Multiple ways to deal with threats

Homeworld

Colony

Colony

EnemyColony

Page 33: Introduction to Game AI CS 395 Game Design Spring 2003.

Example: eTDG10 Map

Page 34: Introduction to Game AI CS 395 Game Design Spring 2003.

SR Regions for eTDG10 map (hand-sketched)

Page 35: Introduction to Game AI CS 395 Game Design Spring 2003.

Hard constraints from SR regions

Page 36: Introduction to Game AI CS 395 Game Design Spring 2003.

Voronoi diagram for free space

Page 37: Introduction to Game AI CS 395 Game Design Spring 2003.

Junctions provide seeds for open regions

Page 38: Introduction to Game AI CS 395 Game Design Spring 2003.

Regions extended from seeds

Page 39: Introduction to Game AI CS 395 Game Design Spring 2003.

Edges outside regions form corridor seeds

Page 40: Introduction to Game AI CS 395 Game Design Spring 2003.

Combined results for eTDG10

Page 41: Introduction to Game AI CS 395 Game Design Spring 2003.

The coordination problemTelling your brigades to attack Scum Division will generally lead to them all

being slaughtered

Page 42: Introduction to Game AI CS 395 Game Design Spring 2003.

The coordination problem

Lack of coordination will lead them down same path, each being wiped out one at a time, even though a coordinated

attack would have succeeded

What if they had a richer,

non-local understanding

of space?

Page 43: Introduction to Game AI CS 395 Game Design Spring 2003.

The coordination problem

Enable player to communicate intent via sketching and language,

specifying paths and synchronization

Visually identify paths (mobility

corridors, avenues of approach) as part of terrain

analysis

Page 44: Introduction to Game AI CS 395 Game Design Spring 2003.

Richer spatial reasoning will lead to better opponents

Page 45: Introduction to Game AI CS 395 Game Design Spring 2003.

Richer spatial reasoning will lead to better opponents

Narrow route with no side

ways out

Funnel for focusing

combat power

Page 46: Introduction to Game AI CS 395 Game Design Spring 2003.

Characters

• Examples: First-person shooters, adventure/action games

• What problems do they have to solve?

Page 47: Introduction to Game AI CS 395 Game Design Spring 2003.

The World

• Common trick: Share AI computations between computer characters– Pathfinding and navigation

– Awareness of player actions and alignment

– Strategic thinking

• Examples: More than you might think

Page 48: Introduction to Game AI CS 395 Game Design Spring 2003.

Types of Behavior to Capture

• Wander randomly if don’t see or hear an enemy.• When see enemy, attack• When hear an enemy, chase enemy• When die, respawn• When health is low and see an enemy, retreat

• Extensions:– When see power-ups during wandering, collect them.

Page 49: Introduction to Game AI CS 395 Game Design Spring 2003.

Execution Flow of an AI Engine

Sense

Think

Act

G

A

M

E

?

Finite-state machines

Decision trees

Neural nets

Fuzzy logic

Rule-based systems

Planning systems

Page 50: Introduction to Game AI CS 395 Game Design Spring 2003.

Conflicting Goals for AI in Games

Goal Driven

Reactive

Human

CharacteristicsKnowledge

Intensive

Low CPU & Memory

Usage

Fast & Easy Development

Page 51: Introduction to Game AI CS 395 Game Design Spring 2003.

Complexity

• Complexity of Execution– How fast does it run as more knowledge is added?

– How much memory is required as more knowledge is added?

• Complexity of Specification– How hard is it to write the code?

– As more “knowledge” is added, how much more code needs to be added?

Page 52: Introduction to Game AI CS 395 Game Design Spring 2003.

Expressiveness of Specification

• What can easily be written?• Propositional:

– Statements about specific objects in the world – no variables

– Jim is in room7, Jim has the rocket launcher, the rocket launcher does splash damage.

– Go to room8 if you are in room7 through door14.

• Predicate Logic:– Allows general statement – using variables– All rooms have doors– All splash damage weapons can be used around corners– All rocket launchers do splash damage– Go to a room connected to the current room.

Page 53: Introduction to Game AI CS 395 Game Design Spring 2003.

Example FSM

Events:

E=Enemy Seen

S=Sound Heard

D=Die

SpawnD

Wander-E, -S, -D

D

-E

E

-S

AttackE, -D

E

-E

ChaseS, -E, -D

S

D

E

D

S

Action (callback) performed when a transition occurs

Code

Page 54: Introduction to Game AI CS 395 Game Design Spring 2003.

Example FSM

Events:

E=Enemy Seen

S=Sound Heard

D=Die

SpawnD

Wander-E, -S, -D

D

-E

E

-S

AttackE, -D

E

-E

ChaseS, -E, -D

S

D

E

D

S

Problem: No transition from attack to chase

Page 55: Introduction to Game AI CS 395 Game Design Spring 2003.

Example FSM - Better

Events:

E=Enemy Seen

S=Sound Heard

D=Die

Attack-SE, -D, S

S

-E

-S

S

E

-S

AttackE, -D, -S

E

-E

SpawnD

Wander-E, -S, -D

D

-E

ChaseS, -E, -D

D

D

S

ED

Page 56: Introduction to Game AI CS 395 Game Design Spring 2003.

Example FSM with Retreat

SpawnD

(-E,-S,-L)

Wander-E,-D,-S,-L

E

-SAttack-EE,-D,-S,-L

E

Chase-E,-D,S,-L

S

D

S

D

Events:

E=Enemy Seen

S=Sound Heard

D=Die

L=Low Health

Each feature with N values can require N times as many states

D

Retreat-EE,-D,-S,L

L

-E

Retreat-S-E,-D,S,L

Wander-L-E,-D,-S,L

Retreat-ESE,-D,S,L

Attack-ESE,-D,S,-L

E

E-E

-L

S

-S

L

-E E

L-L

-L

-L

L

D

Page 57: Introduction to Game AI CS 395 Game Design Spring 2003.

Hierarchical FSM

• Expand a state into its own FSM

Wander

Die

S/-S

E/-E

Attack

Chase

Spawn

StartTurn Right

Go-throughDoor

Pick-upPowerup

Page 58: Introduction to Game AI CS 395 Game Design Spring 2003.

Non-Deterministic HierarchicalFSM (Markov Model)

Attack

Die

No enemy Wander

Start

Start

Approach

Aim & Jump &Shoot

Aim & Slide Left& Shoot

Aim & Slide Right

& Shoot .3.3

.4

.3.3

.4

Page 59: Introduction to Game AI CS 395 Game Design Spring 2003.

Implementation

• Compile into an array of state-name, event• state-name := array[state-name, event]• Uses state-name to call execution logic• Add buffers to queue up events in case get

simultaneous events

event

state

• Hierarchical• Create array for every FSM• Have stack of states

• Classify events according to stack• Update state which is sensitive to current event

Page 60: Introduction to Game AI CS 395 Game Design Spring 2003.

FSM Evaluation

• Advantages:– Very fast – one array access– Can be compiled into compact data structure

• Dynamic memory: current state• Static memory: state diagram – array implementation

– Can create tools so non-programmer can build behavior– Non-deterministic FSM can make behavior unpredictable

• Disadvantages:– Number of states can grow very fast

• Exponentially with number of events: s=2e

– Number of arcs can grow even faster: a=s2

– Propositional representation

• Difficult to put in “pick up the better powerup”, attack the closest enemy

Page 61: Introduction to Game AI CS 395 Game Design Spring 2003.

References

• Web references:– www.gamasutra.com/features/19970601/

build_brains_into_games.htm

– csr.uvic.ca/~mmania/machines/intro.htm

– www.erlang/se/documentation/doc-4.7.3/doc/design_principles/fsm.html

– www.microconsultants.com/tips/fsm/fsmartcl.htm

– http://www.qrg.nwu.edu/papers/Files/How_QSR_can_improve_strategy_game_AIs_A3ISS_2001.PDF

• Deloura, Game Programming Gems, Charles River Media, 2000, Section 3.0 & 3.1, pp. 221-248.