Game AI Overview What is Ar3ficial Intelligence AI in Games AI in

GameAIOverview
Introduc3on
•  History
•  Overview/Categorize
•  AgentBasedModeling
–  Sense->Think->Act
•  FSMinbiologicalsimula3on(separateslides)
–  HybridControllers
–  SimplePerceptualSchemas
•  Discussion:Examples
•  Resources(Homework,read)
WhatisAr3ficialIntelligence
•  ThetermAr3ficialIntelligence(AI)wascoined
byJohnMcCarthyin1956
–  “Thescienceandengineeringofmakingintelligent
machines.”
•  AIOrigin,eventhanthat(of-course)!
–  GreekMythology:
•  TalosofCrete(GiantBronzeMan)
•  Galatea(IvoryStatue)
–  Fic3on:Robot–1921KarelPatek
•  Asimov,Threelawsofrobo3cs
•  Hal–SpaceOdyssey
AIinGame
•  Pong
–  Predic)veLogic:howthecomputermovespaddle
•  Predictsballloca3onthenmovespaddlethere
•  Pacman
–  RuleBased(hardcoded)ghosts
•  Alwaysturnleb
•  Alwaysturnsright
•  Random
•  Turntowardsplayer
AIinGames
•  GameAIlesscomplicatedthanAItaughtin
machinelearningclassesorrobo3cs
–  Selfawareness
–  Worldismorelimited
–  Physicsismorelimited
–  Lessconstraints,‘lessintelligent’
•  More‘ar3ficial’than‘intelligent’(Donald
Kehoe)
ScriptedAI
•  Enemyunitsinthegamearedesignedto
followascriptedpacern.
•  Eithermovebackandforthinagivenloca3on
oracackaplayerifnearby(percep3on)
•  BecameastapletechniqueforAIdesign.
MoreComplexandTradi3onalAI
•  BehaviorModels
GameAgents
•  GameAgents,Examples:
–  AgentModel(Focus)
–  Enemy
–  Ally
–  Neutral
•  Loopsthrough:Sense-Think-ActCycle
Sense
Sensing
•  Howtheagentperceivesitsenvironment
–  Simplechecktheposi3onoftheplayeren3ty
–  Iden3fycovers,paths,areaofconflict
–  Hearing,sight,smell,touch(pain)…
•  Sight(limited)
Think
Act
Thinking
•  Decisionmaking,decidingwhatitneedstodo
asaresultofwhatitsenses(andpossible,
what‘state;’itisin)ComingUP!
•  Planning–morecomplexthinking.
–  Pathplanning
–  Raytracing
•  Range:Reac)vetoDelibera)ve
Ac3ng
•  AberthinkingActuatetheAc3on!
MoreComplexAgent
•  Behaviordependsonthestatetheyarein
•  Representa3on:FiniteStateMachine
hcps://sobware.intel.com/en-us/ar3cles/designingar3ficial-intelligence-for-games-part-1
Egyp3anTombFinitestateMachine
Wander
Attack
No Enemy
He
alt
h
• 
Lo
w
y
em
En
•  Wander–moveslowly,randomly
•  Search–movefaster,inlines
•  Chasing–directtoplayer
– 
– 
– 
– 
• 
Setofstates
Astar3ngstate
Aninputvocabulary
Atransi3onfunc3onthatmapsinputsandthecurrentstatetoa
nextstate
Definetransi3ons
–  Closeis100meters(smell/sense)
–  Visibleislineofsight
Chasing
CanExtendFSMeasily
•  Canhavesub-states
–  Sametransi3ons,but
differentac3ons
•  i.e.,-rangeacack
versusmeleeacack
–  SwitchStatement
Searching
Scarab
Afraid
Hidden
–  Whenplayergetsscarab
–  When3merexpires
Close by
•  Transi3on
•  HardCoded
Wandering
Visible
–  Moveawayfromplayer
fast
HowtoImplement
Far away
•  Ex:Addmagicalscarab(amulet)
•  Whenplayergetsscarab,
Mummyisafraid.Runs.
•  Behavior
Chasing
Finite-StateMachine:
ObjectOrientedwithPacern
Matching*parameters*
Finite-StateMachine:
HardcodedFSM
void Step(int *state) { // call by reference since state can change
switch(state) {
case 0: // Wander
Wander();
if( SeeEnemy() )
break;
{ *state = 1; }
case 1: // Attack
Attack();
if( LowOnHealth() ) { *state = 2; }
if( NoEnemy() )
{ *state = 0; }
break;
case 2: // Flee
Flee();
if( NoEnemy() )
break;
}
}
Searching
Hidden
•  Abstractmodelofcomputa3on
•  Formally:
Wandering
Far away
No
Flee
Mummies!Behavior
–  Spendallofeternitywanderingin
tomb
–  Whenplayerisclose,search
–  Whenseeplayer,chase
Makeseparatestates
–  Definebehaviorineachstate
Close by
• 
See Enemy
Visible
FiniteStateMachine
void AgentFSM
{
State( STATE_Wander )
Wander();
if( SeeEnemy() ) { setState( STATE_Attack ) }
State( STATE_ATTACK )
Attack();
if ( LowOnHealth ) { setState( STATE_Flee ) }
.
.
.
{ *state = 0; }
}
Becer
•  ADHocCode
•  Inefficient
•  ObjectOriented
•  Transi3onsareevents
–  Checkvariablesfrequently
Embellishments
•  Adap3veAI
–  Memory
•  Predic3on
•  PathPlanning,Tomorrow
PathPlanning
•  Problem:HowtonavigatefrompointAtopointBin
real3me.Possiblea3Dterrain.
•  Wewillstartwitha2Dterrain.
–  Whataboutifweignoretheproblem:
Resources
•  hcps://sobware.intel.com/en-us/ar3cles/
designing-ar3ficial-intelligence-for-gamespart-1(thereare4parts,readthefirst3)
•  hcp://www.policyalmanac.org/games/
aStarTutorial.htm(youwillimplementthis
visualiza3onasproject3)
•  hcp://www-cs-students.stanford.edu/~amitp/
gameprog.html(greatresourcesforgameAI)
NoPathPlanningbadSensors
WithBecerSensors(Red)
•  BluePlanning.
EnvironmentAssump3ons
•  2DGrid
ExploretheEnvironment
–  WatchAINaviga3onBloopers:
•  hcp://www.youtube.com/watch?v=lw9G-8gL5o0
ProblemStatement
•  PointA(star)toPointB(x):Shortestamount
ofstepsorfastest3me
CommonTheme:Fron3er
Implementa3on
•  Pickandremovealoca3onfromfron3er
•  Markloca3onas“doneprocessing”
•  Expandmylookingatitsunprocessed
neighborsandaddtofron3er
•  Fron3erExpands
•  Stopsatwalls
hcp://www.redblobgames.com/pathfinding/a-star/introduc3on.html
ShortestPath:BreathFirst
•  Wegotthevisi3ngpart,nowhowdowefind
theshortestpath?
–  Solu3on:Keeptrack:
Measurepathlinks
•  StartatGoalandtraversewhereit‘came
from’
–  Shortestpath
1.  wherewecamefrom,andlatercompute
2.  thedistancetraveledsofar
Embellishments:Makeifmore
efficient
•  AllPathsfromoneloca3ontoallothers
–  Earlyexit:Stopexpandingoncefron)ercovers
goal
•  hcp://www.redblobgames.com/pathfinding/
a-star/introduc3on.html
Movementcostnotenough
•  Somemovementsmaybemoreexpensive
thanothertomovethrough
–  Useanewheuris3cs
–  Addtofron3erifcostisless.
•  We:Board
•  Th:Board.Sketchoutthealgorithm.
SummaryfromBoard
•  AStarfavorneighborswithsmallestFvalue.
–  F=H+G
•  BreathFirstSearch
–  Exploreallneighbors,typicallyusingasimplequeue
thatexploresneighborsfirstinfirstout(FIFO).
•  BestFirstSearch:H
–  Favorneighborsthathaveshortestdistancetogoal.
•  Dijskstra:G
–  Favorneighborsthatareclosesttostar3ngpoint
(smallestG).
RevisitRepresen3ngofgridsasgraphs
•  GridtoNodeExample
Hackathontomorrow.
•  Hackathontomorrowwillbedoingnode
basedalgorithmson‘paper’butyouwillneed
tocovertittodigitaltext.
–  BestFirst,BreathFirst,Dijkstra,A*
•  YouwillalsodrawaFSMofsomegameen3ty,
inthesamevainasthemummyFSM.
•  Dijkstranodeonboard.