1 / 16

Game AI Finite State Machine

Game AI Finite State Machine. Introduction (1/2). Finite State Machine (FSM) is the most commonly used Game AI technology Simple Efficient Easily extensible Powerful enough to handle a wide variety of situations Theory (Simplified) A set states, S An input vocabulary, I

vachel
Download Presentation

Game AI Finite State Machine

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Game AI Finite State Machine

  2. Introduction (1/2) • Finite State Machine (FSM) is the most commonly used Game AI technology • Simple • Efficient • Easily extensible • Powerful enough to handle a wide variety of situations • Theory (Simplified) • A set states, S • An input vocabulary, I • Transition function, T(s, i) • Map a state s and an input i to another state

  3. Introduction (2/2) • Practical use • State • Behavior • Transition • Across states • Conditions • It’s all about driving behavior • Flow-chart Diagram • UML (universe modeling language) state chart • Arrow • Transition • Rectangle • State

  4. An Example of FSM seeEnemy wander Attack Win Dead Rot

  5. FSM for Games • Character AI • “Decision-Action” Model • Behavior • Mental state • Transition • Players’ action • The other characters’ actions • Some features in the game world

  6. Implement FSM • Code-based FSM • Simple Code One Up • Straightforward • Most common • Macro-assisted FSM language • Data-Driven FSM • FSM Script Language

  7. Coding an FSM – Code Example 1 void RunLogic(int &state) { switch(state) { case 0: // Wander Wander(); if (SeeEnemy()) state = 1; if (Dead()) state = 2; break; case 1: // Attack Attack(); if (Win()) state = 0; if (Dead()) state = 2; break; case 2: // Dead SlowlyRot(); break; } } What is the problem with the above code ?

  8. Coding an FSM – Code Example 2 void RunLogic(FSM *fsm) { // Do action based on the state and determine next input input = STATE_NULL; switch(fsm->GetStateID()) { case STATE_WANDER: // Wander Wander(); if (SeeEnemy()) input = STATE_SEE_ENEMY; if (Dead()) input = STATE_DEAD; break; case STATE_ATTACK: // attack Attack(); if (Win()) input = STATE_WANDER; if (Dead()) input = STATE_DEAD; break; case STATE_DEAD: // Dead SlowlyRot(); break; } // DO state transition based on computed input fsm->StateTransition(input); }

  9. Mealy & Moore Machines • Mealy Machine • A Mealy machine is an FSM whose actions are performed on transitions • Moore Machine • A Moore machine’s actions reside in states • More intuitive for game developers

  10. FSM Language Use Macros • Coding a state machine directly causes lack of structure • Going complex when FSM at their largest • Use Macro • Beneficial Properties • Structure • Readability • Debugging • Simplicity

  11. FSM Language Use Macros – An Example #define BeginStateMachine … #define State(a) … … bool MyStateMachine::States(StateMachineEvent event, int state) { BeginStateMachine State(STATE_WANDER) OnUpdate Wander(); if (SeeEnemy()) SetState(STATE_ATTACK); if (Dead()) SetState(STATE_DEAD); State(STATE_ATTACK) OnUpdate Attack(); SetState(STATE_WANDER); if (Dead()) SetState(STATE_DEAD); State(STATE_DEAD); OnUpdate RotSlowly(); EndStateMachine }

  12. Data-Driven FSM • Scripting language • Text-based script file • Transformed into • C++ • Integrated into source code • Bytecode • Interpreted by the game • Authoring • Compiler • AI editing tool • Game • FSM script engine • FSM interface

  13. Data-Driven FSM Diagram Authoring Games FSMs FSM Script Engine bytecode Compiler Artist, Designers, & Developers AI Editing Tool FSM Interface Condition & Action Code Game Engine Condition & Action Vocabulary

  14. AI Editing Tool for FSM • Pure text • Syntax ? • Visual graph with text • Used by designers, artists, or developers • Non-programmers • Conditions & action vocabulary • SeeEnemy • CloseToEnemy • Attack • …

  15. FSM Interface • Facilitating the binding between vocabulary and the game world • Gluing layers that Implement the condition & action vocabulary in the game world • Native conditions • SeeEnemy(), CloseToEnemy() • Action library • Attack(…) • Evade(…) • Flee(…) • Wander(…)

  16. FSM Script Language Benefits Accelerated productivity Contributions from artists & designers Ease of Use Extensibility

More Related