Presentation is loading. Please wait.

Presentation is loading. Please wait.

Finite State Machines in Games

Similar presentations


Presentation on theme: "Finite State Machines in Games"— Presentation transcript:

1 Finite State Machines in Games
Jarret Raim 2004 Based on AI Game Programming Wisdom 2

2 Problem: Can’t remember what we were doing
FSM Example States Attack Chase Spawn Wander Events E: see an enemy S: hear a sound D: die Attack ~E ~S Chase E S D D E Wander E ~E Spawn D Problem: Can’t remember what we were doing

3 FSM Implementation - Code
Simplest method After an action, the state might change. Requires a recompile for changes No pluggable AI Not accessible to non-programmers No set structure Can be a bottleneck. void RunLogic( int *state ) { switch( *state ) { case 0: //Wander Wander(); if( SeeEnemy() ) *state = 1; if( Dead() ) *state = 2; break; case 1: //Attack Attack(); *state = 0; case 3: //Dead SlowlyRot() }

4 FSM Example Problem: Can’t remember what we were doing
Attack Problem: Can’t remember what we were doing ~E ~S Chase E S D D E Wander E ~E Spawn D Solution: Add an stack to keep track of the states I have visited

5 Stack FSM – Thief 3 Stack allows AI to move back and forth between states. Leads to more realistic behavior without increasing FSM complexity.


Download ppt "Finite State Machines in Games"

Similar presentations


Ads by Google