“inaction breeds doubt and fear. action breeds confidence ...surban6/2018sp-gameai/...“inaction...

32
“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer fear, do not sit home and think about it. Go out and get busy.” -- Dale Carnegie

Upload: others

Post on 17-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer fear, do not sit home and think about it. Go out and get busy.” -- Dale Carnegie

Page 2: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Announcements

• AIIDE 2015 https://youtu.be/ZIAmoRsu3Z0?list=PLxGbBc3OuMgg7OuyLfvXQLR6HKcoglCfG&t=1713

• HW3. http://osi.gatech.edu/

• HW4 is posted, due this Sunday

Page 3: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Review

• The story thus far…

Page 4: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

N-1: formations

1. What’s the problem with independent shortest distance navigation with groups?

2. What’s a simple solution, and its drawbacks? Other workarounds?

3. Is it always sensible to replan paths when problems occur?

4. What are 3 ways of implementing fixed formations?

5. Discuss some problems with entities of different sizes.

Page 5: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Decision Making – FSMs

2018-02-13

B Ch2, M 5.1,5.3

Page 6: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Decision Making

• Historically a “mathematical model of computation” – Wikipedia• Classic AI:

– making the optimal choice of action (given what is known or is knowable at the time) that maximizes the chance of achieving a goal or receiving a reward (or minimizes penalty/cost)

• Game AI: – choosing the right goal/behavior/animation to support the experience

• Decision-making must connect directly to animation so player can see the results of decision-making directly (explainable AI)– What animation do I play now?– Where should I move?

Page 7: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Most game agents do more than move

• Shoot

• Patrol

• Farm

• Sleep

• Hide

• Hunt

• …

• We will call these “states”

Page 8: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Most game agents go through more than one state

Game agents will have different sets of states, and different ways of moving through those states based on their purpose in the game:

• Soldier: Patrol -> Shoot -> Hunt

• Farmer/Villager: Farm -> Patrol -> Sleep

Page 9: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

FSM theory

• A (model of a) device which has – a finite number of states (S)

– an input vocabulary (I)

– a transition function T(s,i) s’

– a start state I

– zero or more final states S

• Behavior– Can only be in one state at a given moment in time

– Can make transitions from one state to another or to cause an output (action) to take place.

Page 10: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

FSMs in Practice

• Each state represents some desired behavior

• Transition function often resides across states

– Each state determines subsequent states

• Can poll the world, or respond to events (more on this later)

• Support actions that depend on state & triggering event (Mealy) as well as entry & exit actions associated with states (Moore)

Page 11: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

FSM as GAI

• Character AI modeled as sequence of mental states

• World events (can) force a change in state

• Mental model easy to grasp (for all)

Gather Treasure

Flee

Fight

Monster In Sight

No Monster

Monster Dead Cornered

Jarret Raim

Page 12: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Question 1

Using the graph form, design/visualize an FSM for a security guard that patrols a school after hours. If it sees the player it needs to seek the player and give them a lecture till the player can slip away. Otherwise switch between Idle and Patrol.

States = {Idle, Patrol, Seek, Lecture}

Feel free to make up variables.

Page 13: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Idle Patrol

Seek Lecture

seesPlayer

seesPlayer

!seesPlayer

!seesPlayer

closeEnough

> 5 seconds in state

Page 14: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Mealy & MooreMealy Output = F( state, input )

Moore Output = F( state )

StateState

OnEnter / OnExit

Idle

Search

Flee

P / Yelp

IdleRelief / Startle

SearchGrowl / Sigh

FleeYelp / Sigh

P

Page 15: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

State Transition Table

Current State Condition State Transition

Gather Treasure Monster Flee

Flee Cornered Fight

Flee No Monster Gather Treasure

Fight Monster Dead Gather Treasure

Gather Treasure

Flee

Fight

Monster In Sight

No Monster

Monster Dead Cornered

Page 16: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Advantages

• Ubiquitous (not only in digital games)

• Quick and simple to code

• (can be) Easy* to debug

• Fast: Small computational overhead

• Intuitive

• Flexible

• Easy for designers without coding knowledge

Page 17: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Disadvantages

• When it fails, fails hard:

– A transition from one state to another requires forethought (get stuck in a state or can’t do the “correct” next action)

• Number of states can grow fast

– Exponentially with number of events in world (multiple ways to react to same event given other variables)

• Number of transitions can grow even faster

• Doesn’t work with sequences of actions/memory

Page 18: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Debugging FSM’s

• Offline Debugging– Logging

– Verbosity Levels

• Online Debugging– Graphical

representation is modified based on AI state

– Command line to modify AI behavior on the fly.

Page 19: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

FSM EXAMPLESWhere we see that they’re incredibly common, effective, and useful

Page 20: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Activity

• States:

• Transitions:

See also https://www.gamasutra.com/view/feature/3938/the_pacman_dossier.php?print=1

Page 21: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

FSM Examples: Pac Man

• Red: Shadow, blinky– “pursuer” or “chaser”– Chase target: pac-man’s tile

• Pink: Speedy, pinky– “ambusher”– Chase target: pac-man’s tile + 4 ahead

• Blue: Bashful, inky– “whimsical”– Chase target: double vector from red ghost to (pac + 2 ahead)

• Orange: Pokey, Clyde– “feigning ignorance”– Chase target: dist < 8 ? scatter tile : pac-man’s tile

http://gameinternals.com/post/2072558330/understanding-pac-man-ghost-behavior

Page 22: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

* Usually animations are linked to states, transitions, or both.

Prey Example

Page 23: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Hierarchical FSM Example

• Equivalent to regular FSMs• Easier to think about encapsulation

Page 24: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

FSM: Quake dog monsterSPAWN

IDLE

ATTACK

DIE

Main input event act. Dog specific act. (gen.) monster act.htt

p:/

/ai-

dep

ot.

com

/Fin

iteS

tate

Mac

hin

es/F

SM-F

ram

ewo

rk.h

tml

Page 25: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

FSM Examples

• Pac-Man

• FPSs

– What might be states?

– NPCs only?

Page 26: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

FSM Examples

• Pac-Man

• FPSs

• Sports Simulations

– What might be states?

Page 27: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

FSM Examples

• Pac-Man

• FPSs

• Sports Simulations

• RTSs

– What might be states?

Page 28: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

UnrealScript Example

off on idle

1st 2nd

reverse

turn key on

turn key off

turn key on

turn key off

shift up

shift up

shift down

shift down

shift up

shift down

stall

stall

Page 29: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

public void runStateMachine (Event e)

{

switch (state) {case 0: //off

if (e.isTurnOn()) { power=true; state=1;}break;

case 1: //onif (e.isTurnOn()) { startEngine(); state=2;}else if (e.isTurnOff()) { power=false; state=0;}break;

case 2: //idlemakeEngineSound();if (e.isUpShift()) { gear=1; state=3;}else if (e.isDownShift()) { gear=-1; state=9;}else if (e.isTurnOff()) { stopEngine(); state=1;}break;

…}

}

Page 30: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer
Page 31: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

FSM IMPLEMENTATIONSChoices have consequences

Page 32: “Inaction breeds doubt and fear. Action breeds confidence ...surban6/2018sp-gameAI/...“Inaction breeds doubt and fear. Action breeds confidence and courage. If you want to conquer

Trajectory Update

• HW4: A*

• To come: More decision making

– Planning

– Decision trees

– Behavior trees

– Rule based systems

– Fuzzy Logic

– Markov Systems