1 / 13

CSCE 4013 Game Programming Spring 2014

CSCE 4013 Game Programming Spring 2014. Prof. John Gauch jgauch@uark.edu. The primary goal of the game AI is to provide automatic control of characters and objects W e want the actions and motions of characters and objects in the game to look natural and give the illusion of intelligence

marion
Download Presentation

CSCE 4013 Game Programming Spring 2014

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. CSCE 4013Game ProgrammingSpring 2014 Prof. John Gauch jgauch@uark.edu

  2. The primary goal of the game AI is to provide automatic control of characters and objects We want the actions and motions of characters and objects in the game to look natural and give the illusion of intelligence One of the oldest and easiest way to do this is to use finite state machines Programming Game AI

  3. Finite state machines are normally used to recognize and process input strings Finite number of states Input controls motion between states Stop when goal state is reached Finite state machines are Simple and easy to code and debug Low computational overhead Intuitive and flexible Finite State Machines

  4. Finite State Machines

  5. Formal definition A finite set of states S1, S2, … Sn A finite input alphabet A1, A2, … Am A finite set of transition rules of the form {Ai: Sj => Sk} One state designated as start state One state designated as end state Input sequence is accepted if machine we can go from start state to end state when reading input Finite State Machines

  6. Finite State Machines

  7. Use in video games Ghosts behavior in Pac-Man use Evade state and Chase state to control motion When player eats power pills, all ghosts go from Chase to Evade When power pill timer gets to zero, ghosts go from Evade to Chase Also used in games like Quake, Soccer, Warcraft to control non-player characters Finite State Machines

  8. One way to implement finite state machines for a game is to use constants or enumerated typed for the names of states hard code the state transitions using a series of if statements or switch statements Works for small cases, but gets messy for large state machines Implementation

  9. Consider game where player can be in three states: Patrol, RunAway, and Attack Actions depend on interactions with enemy Implementation

  10. enumStateType {RunAway, Patrol, Attack}; void UpdateState(StateTypeCurrentState) { switch(CurrentState) { case RunAway: EvadeEnemy(); if (Safe()) ChangeState(Patrol); break; Implementation

  11. case Patrol: FollowPatrolPath(); if (Threatened()) { if (StrongerThanEnemy()) ChangeState(Attack); else ChangeState(RunAway); } break; Implementation

  12. case Attack: if (WeakerThanEnemy()) ChangeState(RunAway); else BashEnemyOverHead(); break; } } Implementation

  13. This approach can be improved by embedding the rules for the state transitions within the states themselves This design pattern can be implemented using some advanced object oriented techniques (see West World Project) Implementation

More Related