Game AI CS 4730 Computer Game Design Some slides - - PowerPoint PPT Presentation

game ai
SMART_READER_LITE
LIVE PREVIEW

Game AI CS 4730 Computer Game Design Some slides - - PowerPoint PPT Presentation

Game AI CS 4730 Computer Game Design Some slides courtesy Tiffany Barnes, NCSU CS 4730 The Loop of Life Games are driven by a


slide-1
SLIDE 1

CS ¡4730 ¡

Game ¡AI ¡

CS ¡4730 ¡– ¡Computer ¡Game ¡Design ¡ ¡ Some ¡slides ¡courtesy ¡Tiffany ¡Barnes, ¡NCSU ¡

slide-2
SLIDE 2

CS ¡4730 ¡

The ¡Loop ¡of ¡Life ¡

  • Games ¡are ¡driven ¡by ¡a ¡game ¡loop ¡that ¡

performs ¡a ¡series ¡of ¡tasks ¡every ¡frame ¡

  • Some ¡games ¡have ¡separate ¡loops ¡for ¡the ¡front ¡

and ¡and ¡the ¡game ¡itself ¡

  • Other ¡games ¡have ¡a ¡unified ¡main ¡loop ¡

2

slide-3
SLIDE 3

CS ¡4730 ¡

The ¡Game ¡Loop ¡

  • Tasks ¡

– Handling ¡Jme ¡ – Gathering ¡player ¡input ¡ – Networking ¡ – SimulaJon ¡ – Collision ¡detecJon ¡and ¡response ¡ – Object ¡updates ¡ – Rendering ¡ – Other ¡miscellaneous ¡tasks ¡

3

slide-4
SLIDE 4

CS ¡4730 ¡

The ¡Game ¡Loop ¡

  • Tasks ¡

– Handling ¡Jme ¡ – Gathering ¡player ¡input ¡ – Networking ¡ – Simula:on ¡ – Collision ¡detecJon ¡and ¡response ¡ – Object ¡updates ¡ – Rendering ¡ – Other ¡miscellaneous ¡tasks ¡

4

slide-5
SLIDE 5

CS ¡4730 ¡

What ¡all ¡do ¡you ¡have ¡to ¡simulate? ¡

  • Physics ¡
  • Environments ¡
  • LighJng ¡
  • Sounds ¡
  • Behaviors ¡

5

slide-6
SLIDE 6

CS ¡4730 ¡

Some ¡Terms ¡To ¡Know ¡

  • AI: ¡ArJficial ¡Intelligence ¡– ¡does ¡not ¡have ¡to ¡

mean ¡perfect ¡human-­‑like ¡intelligence! ¡

  • Turing ¡Test: ¡ ¡Can ¡a ¡normal ¡user ¡tell ¡the ¡

difference ¡between ¡interacJng ¡with ¡a ¡ computer ¡and ¡a ¡person ¡

  • NPC: ¡ ¡Non-­‑Player ¡Character ¡– ¡any ¡thing ¡in ¡the ¡

world ¡that ¡needs ¡to ¡be ¡modeled, ¡can ¡make ¡ decisions, ¡and ¡can ¡potenJally ¡have ¡player ¡ interacJon ¡

6

slide-7
SLIDE 7

CS ¡4730 ¡

Discussion ¡

  • How ¡good ¡should ¡the ¡AI ¡be? ¡

7

slide-8
SLIDE 8

CS ¡4730 ¡

Discussion ¡

  • Are ¡people ¡more ¡fun ¡than ¡NPCs? ¡ ¡Why? ¡

8

slide-9
SLIDE 9

CS ¡4730 ¡

AI ¡vs. ¡Game ¡AI ¡

  • Modern ¡AI ¡research ¡is ¡more ¡in ¡geneJc ¡

algorithms ¡and ¡neural ¡networks ¡

  • This ¡isn’t ¡really ¡an ¡opJon ¡for ¡game ¡AI ¡(right ¡

now) ¡

– We ¡value ¡efficiency ¡over ¡complexity ¡ – Too ¡much ¡other ¡stuff ¡to ¡do ¡in ¡the ¡game ¡loop! ¡ – AI ¡for ¡us ¡just ¡has ¡to ¡be ¡“good ¡enough” ¡to ¡be ¡fun ¡

  • We ¡will ¡look ¡at ¡three ¡main ¡AI ¡roles: ¡

– State-­‑based ¡behavior, ¡planning/strat, ¡pathfinding ¡

9

slide-10
SLIDE 10

CS ¡4730 ¡

What ¡Makes ¡“Good ¡AI”? ¡

  • Perceived ¡by ¡user ¡as ¡challenging ¡

– Cruel, ¡but ¡fair! ¡

  • User ¡is ¡surprised ¡by ¡the ¡game ¡

– but ¡later ¡understands ¡why ¡

  • Feeling ¡that ¡reality ¡will ¡provide ¡answers ¡

– able ¡to ¡make ¡progress ¡solving ¡problem ¡

  • What ¡games ¡have ¡used ¡AI ¡effecJvely? ¡

10

slide-11
SLIDE 11

CS ¡4730 ¡

The ¡Bar ¡To ¡Reach ¡

  • Have ¡you ¡failed ¡in ¡your ¡adempt ¡to ¡create ¡a ¡

game ¡if ¡your ¡NPCs ¡can’t ¡pass ¡the ¡Turing ¡Test? ¡

  • NO! ¡ ¡Of ¡course ¡not! ¡
  • SomeJmes ¡NPCs ¡can ¡pass ¡the ¡Turing ¡Test ¡in ¡

very ¡specific ¡circumstances ¡

– Computer ¡chess ¡player ¡

  • SomeJmes ¡NPCs ¡will ¡never ¡pass ¡the ¡Turing ¡

Test ¡and ¡we’re ¡okay ¡with ¡that! ¡

– Koopa ¡Troopas ¡in ¡Super ¡Mario ¡Bros. ¡3 ¡

11

slide-12
SLIDE 12

CS ¡4730 ¡

“Good ¡Enough” ¡

  • Your ¡AI ¡needs ¡to ¡be ¡“good ¡enough ¡for ¡the ¡

player ¡to ¡be ¡challenged…” ¡

  • And ¡“bad ¡enough ¡for ¡the ¡player ¡to ¡have ¡fun…” ¡
  • Games ¡are ¡ogen ¡played ¡to ¡escape ¡from ¡reality ¡
  • Playing ¡against ¡an ¡AI ¡that’s ¡“too ¡good” ¡is ¡

incredibly ¡frustraJng ¡

  • Imagine ¡a ¡computer ¡player ¡of ¡Othello ¡or ¡

Scrabble ¡that ¡ONLY ¡took ¡opJmal ¡moves ¡

12

slide-13
SLIDE 13

CS ¡4730 ¡

The ¡AI ¡Loop ¡

  • Given ¡the ¡changes ¡to ¡the ¡environment, ¡what ¡

should ¡the ¡NPC ¡do? ¡

  • CogniJon ¡of ¡the ¡NPC ¡

– PercepJon ¡(processing ¡the ¡state ¡of ¡the ¡ environment) ¡or ¡“Sense” ¡ – Decision ¡making ¡(decide ¡what ¡to ¡do ¡based ¡on ¡ percepJon) ¡or ¡“Plan” ¡ – Control ¡(update ¡NPC ¡one ¡Jme ¡step) ¡or ¡“Act” ¡

13

slide-14
SLIDE 14

CS ¡4730 ¡

PercepJon ¡

  • The ¡NPC’s ¡esJmaJon ¡of ¡game-­‑related ¡

informaJon ¡

  • Includes ¡perceived ¡strategies ¡of ¡PCs ¡
  • IdenJfies ¡most ¡important ¡factors ¡for ¡the ¡NPC ¡

to ¡respond ¡to ¡

  • Think ¡of ¡it ¡as ¡the ¡NPCs ¡“adenJon ¡span” ¡

14

slide-15
SLIDE 15

CS ¡4730 ¡

Decision ¡Making ¡

  • Determining ¡a ¡course ¡of ¡acJon ¡for ¡this ¡Jme ¡

step ¡for ¡this ¡parJcular ¡state ¡of ¡the ¡game ¡

  • Usually ¡requires ¡a ¡trade ¡off ¡between ¡accuracy ¡
  • f ¡the ¡decision ¡and ¡speed ¡of ¡computaJon ¡
  • Computer ¡COULD ¡simulate ¡out ¡several ¡steps ¡to ¡

make ¡a ¡“beder” ¡decision, ¡but ¡at ¡a ¡cost ¡of ¡speed ¡ and ¡potenJally ¡“fun” ¡

15

slide-16
SLIDE 16

CS ¡4730 ¡

Control ¡

  • AdjusJng ¡the ¡appropriate ¡variables ¡of ¡the ¡NPC ¡

to ¡carry ¡out ¡the ¡decision ¡made ¡

– Steering ¡or ¡throdle ¡in ¡a ¡racing ¡game ¡ – Crouching ¡or ¡taking ¡a ¡shot ¡in ¡an ¡FPS ¡ – Using ¡a ¡poJon ¡or ¡casJng ¡a ¡spell ¡in ¡an ¡RPG ¡

16

slide-17
SLIDE 17

CS ¡4730 ¡

The ¡Sum ¡Of ¡The ¡Parts ¡

  • The ¡sum ¡of ¡all ¡these ¡parts ¡makes ¡up ¡the ¡AI ¡of ¡

an ¡NPC ¡

  • It ¡can ¡be ¡incredibly ¡complex ¡

– Large ¡fight ¡in ¡a ¡tacJcal ¡shooter ¡

  • It ¡can ¡be ¡padern ¡based ¡

– Behaviors ¡of ¡a ¡sentry ¡in ¡Metal ¡Gear ¡Solid ¡ – Behaviors ¡of ¡any ¡boxer ¡in ¡Punch ¡Out ¡

  • It ¡can ¡be ¡… ¡well, ¡stupid ¡

– Goombas ¡or ¡Koopas ¡in ¡Super ¡Mario ¡Bros. ¡3 ¡

17

slide-18
SLIDE 18

CS ¡4730 ¡

Pong ¡AI ¡

  • What ¡is ¡the ¡challenge ¡in ¡creaJng ¡the ¡AI ¡for ¡

Pong? ¡

18

slide-19
SLIDE 19

CS ¡4730 ¡

Chase/Evade ¡

  • Consider ¡a ¡very ¡

¡simple ¡AI ¡task ¡

  • Algorithm ¡for ¡ ¡

the ¡predator? ¡

slide-20
SLIDE 20

CS ¡4730 ¡

Enhancements ¡to ¡Chase ¡

  • Speed ¡Control ¡

– Velocity, ¡AcceleraJon ¡max/min ¡ – Limited ¡turning ¡Radius ¡

  • Randomness ¡

– Moves ¡ – Paderns ¡

slide-21
SLIDE 21

CS ¡4730 ¡

Steering ¡Behaviors ¡

  • Pursue ¡
  • Evade ¡
  • Wander ¡
  • Obstacle ¡Avoidance ¡
  • Wall/Path ¡following ¡
  • Queuing ¡ ¡
  • Combine ¡behaviors ¡with ¡weights ¡
  • What ¡could ¡go ¡wrong? ¡
slide-22
SLIDE 22

CS ¡4730 ¡

AI ¡Strategies ¡

  • ReacJon ¡vs. ¡DeliberaJon ¡
  • When ¡having ¡the ¡NPC ¡make ¡a ¡decision, ¡how ¡

much ¡thought ¡goes ¡into ¡the ¡next ¡move? ¡

  • How ¡is ¡the ¡AI ¡different ¡in: ¡

– Frozen ¡Synapse ¡ – Kingdom ¡Hearts ¡ – CivilizaJon ¡ – Halo ¡

22

slide-23
SLIDE 23

CS ¡4730 ¡

AI ¡Strategies ¡

  • ReacJon-­‑Based ¡

– Fast, ¡but ¡limited ¡capabiliJes ¡

  • ImplementaJons ¡

– Finite-­‑State ¡Machines ¡ – Rule-­‑Based ¡Systems ¡ – Set ¡Padern ¡

23

slide-24
SLIDE 24

CS ¡4730 ¡

AI ¡Strategies ¡

  • DeliberaJon-­‑Based ¡

– Much ¡slower, ¡but ¡more ¡adaptable ¡

  • ImplementaJons ¡

– A* ¡/ ¡Dijkstra ¡ – Roadmaps ¡ – GeneJc ¡Algorithms ¡

24

slide-25
SLIDE 25

CS ¡4730 ¡

Set ¡Padern ¡

  • Describe ¡the ¡AI ¡behavior ¡of ¡a ¡Koopa ¡Troopa ¡

– Or ¡any ¡other ¡bad ¡guy ¡from ¡SMB3 ¡

25

slide-26
SLIDE 26

CS ¡4730 ¡

Finite-­‑State ¡Machines ¡

  • An ¡abstract ¡construct ¡for ¡determining ¡the ¡

behavior ¡of ¡an ¡NPC ¡

  • Any ¡given ¡behavior ¡state ¡is ¡represented ¡along ¡

with ¡rules ¡for ¡transiJoning ¡between ¡states ¡

  • The ¡standard ¡bad ¡guys ¡in ¡Metal ¡Gear ¡Solid ¡are ¡

excellent ¡examples ¡of ¡this ¡

26

slide-27
SLIDE 27

CS ¡4730 ¡

Switch ¡FSM ¡

27

slide-28
SLIDE 28

CS ¡4730 ¡

Switch ¡FSM ¡

void RunLogic( int * state ) { switch( state ) { case 0: //Wander Wander(); if( SeeEnemy() ) { *state = 1; } break; case 1: //Attack Attack(); if( LowOnHealth() ) { *state = 2; } if( NoEnemy() ) { *state = 0; } break; case 2: //Flee Flee(); if( NoEnemy() ) { *state = 0; } break; } } ¡

28

slide-29
SLIDE 29

CS ¡4730 ¡

Switch ¡FSM ¡

  • Within ¡each ¡state ¡can ¡be ¡more ¡complex ¡AI ¡
  • In ¡Metal ¡Gear ¡Solid, ¡when ¡an ¡enemy ¡sees ¡you, ¡

they ¡follow ¡you ¡as ¡long ¡as ¡you ¡are ¡“discovered” ¡

  • When ¡the ¡discovery ¡period ¡expires, ¡the ¡

enemies ¡return ¡to ¡their ¡previous ¡state, ¡which ¡is ¡ set ¡padern ¡

29

slide-30
SLIDE 30

CS ¡4730 ¡

More ¡Advanced ¡FSM ¡

30

slide-31
SLIDE 31

CS ¡4730 ¡

Problems ¡with ¡State ¡Machines ¡

  • Too ¡Predictable ¡

– SomeJmes ¡a ¡good ¡thing, ¡someJmes ¡not ¡

  • Limited ¡

– Can ¡have ¡a ¡very ¡small ¡set ¡of ¡opJons ¡available ¡at ¡ any ¡one ¡Jme ¡

31

slide-32
SLIDE 32

CS ¡4730 ¡

ProbabilisJc ¡FSMs ¡

  • We ¡can ¡change ¡the ¡personality ¡of ¡an ¡NPC ¡by ¡

adjusJng ¡the ¡state ¡probabiliJes ¡

32

Aggressive Passive Attack 50% 5% Evade 5% 60% Random 10% 10% Flock 20% 20% Pattern 15% 5%

slide-33
SLIDE 33

CS ¡4730 ¡

ProbabilisJc ¡FSMs ¡

  • Other ¡aspects: ¡

– Sight ¡ – Memory ¡ – Curiosity ¡ – Fear ¡ – Anger ¡ – Sadness ¡ – Sociability ¡

  • Modify ¡probabiliJes ¡on ¡the ¡fly? ¡

33

slide-34
SLIDE 34

CS ¡4730 ¡

Goal ¡Based ¡

  • The ¡NPC ¡has ¡a ¡central ¡goal ¡to ¡achieve ¡and ¡a ¡set ¡
  • f ¡operaJons ¡it ¡can ¡use ¡
  • It ¡will ¡selecJvely ¡choose ¡an ¡operaJon ¡based ¡on ¡

which ¡will ¡get ¡it ¡closer ¡to ¡the ¡goal ¡at ¡that ¡ moment ¡

  • Goal ¡could ¡be ¡nearly ¡anything ¡

– A ¡parJcular ¡score ¡ – Health ¡of ¡the ¡PC ¡

34