Artificial Intelligence in Game Design - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Artificial Intelligence in Game Design

Description:

Player swings Raise shield. Player waits Swing sword. Player moves Move towards player. Run. Hit points – PowerPoint PPT presentation

Number of Views:69
Avg rating:3.0/5.0
Slides: 18
Provided by: Amyan5
Learn more at: http://www.csis.ysu.edu
Category:

less

Transcript and Presenter's Notes

Title: Artificial Intelligence in Game Design


1
Artificial Intelligence in Game Design
  • Representing NPCs as Finite State Machines

2
Finite State Machines
  • Non-player character in one of several possible
    states
  • Must be some initial state
  • That state controls actions taken by the NPC
  • Transitions to other states caused by
    internal/external stimuli

Another State
Current StateActions incurrent state
Stimuli
Another State
Stimuli
3
Guardbot Example
Chase Move towards player Energy Energy - 1
PatrolMove back and forth in front of
door Energy at 100
Player visible
Player not visible
Energy below 50
ReturnMove towards door Energy Energy - 1
At door
4
Pac-Man Example
5
Finite State Machines
  • Note Each state can be reflex agentExample
    fight state

Fight Player swings ? Raise shield Player waits
? Swing sword Player moves ? Move towards player
Run
Hit points lt 5
6
Designing FSMs
  • What different things does NPC do?
  • Types of action taken
  • Chase, wander, etc.
  • Steps in some process
  • Get food from fridge ? Cook food ? eat food
  • Can include terminal state
  • Object destroyed and deallocated

ReturnMove towards door Energy Energy - 1
Energy 0
Dead
7
Implementing FSMs
  • Can treat each state like a C/Java class
  • Possibly derived from some base State class
  • Typical methods in class
  • Enter() Executed once when state
    enteredExample entering Fight state causes
    NPC to select weapon
  • Exit() Executed before go to another state
    Example exiting Guard door state causes NPC
    to lock door

8
Implementing FSMs
  • Typical methods in class
  • Update() Executed by the game engine each
    framewhile NPC in this stateExample reflex
    actions taken by NPC in Fight state
  • int CheckTransitions()
  • Executed by the game engine each framewhile NPC
    in this state
  • Returns the number of the next state to enter
    based on current stimuli (same as current state
    if no change)

9
Implementing FSMs
  • class Chase extends State
  • int stateNumber 1 // Patrol 0, Return 2
  • public void Enter() say(intruder
    alert)
  • void Exit() say(intruder has escaped)
  • void Update()
  • moveTowards(player.getLocation)
  • if (rand() lt 0.3) say (exterminate)
  • energyLevel--
  • int checkTransitions()
  • if (energyLevel lt distance(location(do
    or.getLocation))
  • distance(location(door.getLocation)
    ) gt 10) return 2
  • else return 1

10
Emotional FSMs
  • States represent emotions for character
  • Actions express emotion
  • Stimuli change emotional state

Player HP lt 10
Confident
Angry
Small hit by player
Heavy hit by player
My HP lt 10
Heavy hit by me
Frightened
11
Emotional FSMs
  • Can combine with action states appropriate to
    emotion
  • Looks more realistic if orc displays fear before
    running

Player HP lt 10
Confident
Angry
Small hit by player
Heavy hit by player
My HP lt 10
Heavy hit by me
Frightened
My HP lt 5
Running
12
Emotional FSMs
  • NPC must clearly express emotional state
  • Facial expression (difficult in low resolution)
  • Body language
  • Posture, motion, etc.
  • Sound (speakers must be on)
  • Spoken phrases
  • Sounds (growl, etc.)
  • Abilities
  • Strong emotion might make character less accurate!

13
Emotional FSMs
Confident Smiles Shouts insult Stands ground Angry Growls Frowns Faster attack Less accurate Fearful Backs away Grimaces Slower attack
14
Timeouts in FSMs
  • Problem Abrupt transitions in FSMsExample
  • As player approaches, NPC jumps back and forth
    between Walk around and Run states

Player lt 5 feet away
Player gt 5 feet away
15
Timeouts in FSMs
  • Solution State timeouts
  • Continue high-emotion states for fixed amount of
    time after stimulus gone
  • Keep running for time even after at safe distance
  • Supported by evidence from biology

Stay in running state for at least 10 seconds
even in player not close
16
Timeouts in FSMs
  • class Run extends State
  • int timeoutvoid Update()
    Flee(player.getLocation()) if
    (distance(location, player.getLocation()) lt 5)
    timeout 10 // run for 10 frames
    even after escape) int CheckTransitions()
    if (timeout gt 0) timeout--
    return 1 // stay in run state
  • else return 0 // go to walk around
    state

17
Weaknesses of FSMs
  • Abrupt transitions between emotional states
  • Confident ? Terrified not a realistic transition
  • May need more intermediate statesConfident ?
    Worried ? Terrified
  • Multiple next states may be indicated by stimuli
  • Must make sure all are mutually exclusive

Attack
Chasing
Within 1 unit
Return
Energy lt 10
Write a Comment
User Comments (0)
About PowerShow.com