Artificial Intelligence in Game Design Representing NPCs as Finite State Machines.

Slides:



Advertisements
Similar presentations
8.3. A GENT AND D ECISION M AKING AI Agent driven AI and associated decision making techniques.
Advertisements

UNIT 1. Defensive Stance With the feet slightly wider than shoulder width, put one foot back at a 45- degree angle. Look straight at the attacker. Arms.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Flocking and more.  NPC groups can move in cohesive groups not just independently ◦ Meadow of sheep grazing? ◦ Hunting flock of birds? ◦ Ants? Bees?
Entering the Band Room C Conversation  Voice Level 1 or 2 H Help  Clipboard in the front of the room or wait for class to start and raise your hand A.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 7: User-Defined Functions II.
Chapter 7: User-Defined Functions II
Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification.
Michael Zyda Finite State Machines Michael Zyda
Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees.
Artificial Intelligence in Game Design Introduction to Learning.
Artificial Intelligence in Game Design Hierarchical Finite State Machines.
Game Design Storyboard, maps, graphics, timeline.
CS 4730 Game AI CS 4730 – Computer Game Design Some slides courtesy Tiffany Barnes, NCSU.
Chapter 2: Algorithm Discovery and Design
Game Design and Programming. Objectives Classify the games How games are design How games are implemented What are the main components of a game engine.
Artificial Intelligence in Game Design Probabilistic Finite State Machines.
Run time vs. Compile time
Artificial Intelligence in Game Design Representing NPCs as Finite State Machines.
Chapter 2: Algorithm Discovery and Design
Artificial Intelligence in Game Design Camera Control.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
Artificial Intelligence in Game Design Event and Sense Management.
CPSC 171 Introduction to Computer Science 3 Levels of Understanding Algorithms More Algorithm Discovery and Design.
Artificial Intelligence in Game Design Problems and Goals.
Artificial Intelligence in Game Design
Maze Challenge Maze Challenge activity > TeachEngineering.org
Computer Lab “Teach-To’s” Classroom Expectations
Engine House Number 10 Our Trip to the Fire Station Our Lady of Peace Kindergarten April 28, 2009 Ms. Susan GruberMs. Jill Stock.
Lecture 03: Theory of Automata:08 Finite Automata.
Artificial Intelligence in Game Design Behavior Trees.
Artificial Intelligence in Game Design
What is Energy?.
Lecture 07: Formal Methods in SE Finite Automata Lecture # 07 Qaisar Javaid Assistant Professor.
School Bus Safety Policy for Podar Jumbo Kids BUS STUDENT TRAINING.
Math / Physics 101 GAM 376 Robin Burke Fall 2006.
Artificial Intelligence in Game Design Lecture 6: Fuzzy Logic and Fuzzy State Machines.
Jonathan Ziegler AI Game Programming 3/20/08.  Different NPCs and games require different sorts of behaviors  General methodology of game AI design.
Artificial Intelligence in Game Design
Threads in Java. Processes and Threads Processes –A process has a self-contained execution environment. –Has complete set of runtime resources including.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
Artificial Intelligence in Game Design Cooperative Movement.
Artificial Intelligence in Game Design
Jumping, Climbing, and Tactical Reasoning Section 2.5 Tom Schaible CSE 497 – AI & Game Programming.
Artificial Intelligence in Game Design Complex Steering Behaviors and Combining Behaviors.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
1 Kyung Hee University Statecharts Spring Kyung Hee University Specifying Objects’ Behaviour  Interaction diagrams show message-passing behaviour.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Artificial Intelligence for Games Finite State Machines
AI Evaluation David Nowell CIS 588 2/14/05 Baldur’s Gate.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
F.E.A.R. Game AI Evaluation by Robert Rak. What is F.E.A.R. ? FEAR is a First Person Shooter game Player takes on the role of an elite strike force team.
Warlords Patrick Levoshko SE 558 – Multiplayer Game Design.
Dr Nick Mitchell (Room CM 224)
Artificial Intelligence in Game Design Lecture 8: Complex Steering Behaviors and Combining Behaviors.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
Spanish traditional games. Grab the flag Aim: to take the handkerchief before the other person and run away without being touched or, in case the other.
Assembly Language Co-Routines
Artificial Intelligence in Game Design Lecture 20: Hill Climbing and N-Grams.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
1 Game AI Finite State Machine. 2 Finite State Machine (FSM) is the Most Commonly used Game AI Technology Today Finite State Machine (FSM) is the Most.
Finite State Machines Logical and Artificial Intelligence in Games Lecture 3a.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Decision Making: Decision Tree & State Machines Session 07
What kind of school do we want?
Artificial Intelligence in Game Design
CO Games Development 2 Week 19 Extensions to Finite State Machines
Finite State Machines in Games
Chapter 7: User-Defined Functions II
When a function is called...
Presentation transcript:

Artificial Intelligence in Game Design Representing NPCs as Finite State Machines

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 Current State Actions in current state Another State Stimuli Another State Stimuli

“Guardbot” Example Patrol Move back and forth in front of door Energy at 100% Chase Move towards player Energy = Energy - 1 Player visible Return Move towards door Energy = Energy - 1 At door Player not visible Energy below 50% start

Pac-Man Example

Finite State Machines Each state can be reflex agent Example: “fight” state Fight Player swings  Raise shield Player waits  Swing sword Player moves  Move towards player Run Hit points < 5

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 Return Move towards door Energy = Energy - 1 Energy == 0 Dead

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 entered Example: 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

Implementing FSMs Typical methods in class: –Update() Executed by game engine each frame while NPC in this state Example: reflex actions taken by NPC in “Fight” state –int CheckTransitions() Executed by game engine each frame while NPC in this state Returns ID of the next state to enter based on current stimuli (same as current state if no change)

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() < 0.3) say (“exterminate”); energyLevel--; } int checkTransitions() { if (energyLevel <= distance(location(door.getLocation)) || distance(location(door.getLocation)) > 10) return 2; else return 1; }

Emotional FSMs States represent emotions for character Actions express emotion Stimuli change emotional state ConfidentAngry Frightened Player HP < 10 Player hit > 5 HP My HP < 10Heavy hit by me Player hit > 10 HP

Emotional FSMs Can combine with action states appropriate to emotion –Looks more realistic if orc displays fear before running ConfidentAngry Frightened Player HP < 10 Player hit > 5 HP My HP < 10Heavy hit by me Player hit > 10 HP My HP < 5 Running

Emotional FSMs and Personalities Can “tweak” parameters for different NPCs Differences must be large enough to be noticeable ConfidentAngry Frightened Player HP < 5 Player hit > 1 HP My HP < 5Heavy hit by me Player hit > 20 HP Orc with anger management issues

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!

Emotional FSMs Confident Smiles Shouts insult Stands ground Angry Growls Frowns Faster attack Less accurate Fearful Backs away Grimaces Slower attack

Timeouts in FSMs Problem: Abrupt transitions in FSMs –As player approaches, NPC jumps back and forth between “Walk around” and “Run” states Player < 5 feet away Player >= 5 feet away

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

Timeouts in FSMs class Run extends State { int timeout; void Update() { Flee(player.getLocation()); if (distance(location, player.getLocation()) 0) { timeout--; return 1; // stay in run state } else return 0; // go to walk around state }

Extended “Guardbot” Example Patrol Move back and forth in front of door Energy at 100% Player visible Escaped Move towards door Energy = Energy - 1 At door Player not visible Energy below 50% Return Move towards door Energy = Energy - 1 Player visible Fire Player within 2 units Turning Player in front Forward Player to side Dodge Obstacle in front

FSM Issues Problems with Finite State Machines: Complexity –Potentially hundreds of states Design difficult Debugging impossible Duplication –Many blocks of states similar Example: Return state also needs “Turn”, “Move”, and “Dodge” –Many transitions similar Example: Need “low energy” transition from all states in “Chase”

Hierarchical State Machines Single high-level state contains entire low-level FSM –Need initial state that high-level passes control to –Need final states that correspond to transitions from high-level state Chase Turning Forward Player to side Dodge Obstacle in front Start Player to side Player in front Obstacle not in front Escaped Player not within 10 units Fire Player within 2 units

Hierarchical State Machines Usually implemented as stack –Push low-level state on stack when enter –Pop and move to next state when finished Start Chasing Guarding Door Chasing Guarding Door Turning Chasing Guarding Door … Escaped Chasing Guarding Door Escaped Guarding Door

Exiting Low-level States “Interrupts” may cause exit before task is completed –Example: Caution flag interrupts passing All states on stack may have interrupt conditions –Check all at each frame –Better than having same transition for all states Turning Chasing Guarding Door Forward Player in front Return Go to HQ Energy < 50% Emergency recall

Exiting Low-level States Can store current low level state and return if necessary once exception handled Build Farm Clear landBuild barnPlant crops Dam break Fix Dam Return to appropriate state when dam fixed

Weaknesses of FSMs Abrupt transitions between emotional states –Confident  Terrified not a realistic transition –May need more intermediate states Confident  Worried  Terrified Multiple next states may be indicated by stimuli –Must make sure all are mutually exclusive Chasing Attack Within 1 unit Return Energy < 10