Advertisement

FSM classes

Started by December 25, 2003 01:39 PM
6 comments, last by AN_D_K 21 years, 1 month ago
I need to build a basic FSM class (or set of classes) that will be used by my non-player-character classes (it''s course work but we''ve been told little about it). Does anyone know of any good articles, resources or examples that I could look at? I''ve already checked out this site and searched the forums but I still haven''t found anything that goes as far as how to actually impliment the FSM. Cheers
Just make an enum for the current state and for the transition you construct something with switch''s and if''s ? Never heard of pre-made classes for this being available, only for special applications like parser generators (yacc, etc).
Advertisement
Tell that to my lecturer. Switches and ifs are out as far as he is concerned. I could have thrown something together in an hour if it weren''t for that.

Sadly it''s an encapsulated class or bust
Where "FSM" = Finite State Machine?

If so, just have a 2d array. Lookup by "fsmtable[current_state][current_input]", value at cell is either a goto-new-state or an event number (or use parallel arrays to do both).

   a   b   c   d------------------0  1  -1  -1  -11 -1   2  -1  -12 -1  -1   3  -13 -1  -1  -1  0,1   <- goes back to state 0 after firing event 1  


That machine fires the event #1 after inputs a,b,c,d have been fed into the machine. Any other input will hit a -1 goto, which in this case means unknown input.

That's just a basic rundown.

[edited by - Nypyren on December 25, 2003 8:18:21 PM]
I use Steve Rabin''s FSM Class from "Game Programming Gems" and "AI Wisdom". (The one from AI Wisdom is specifically the code I''m using.) It''s very simple to use and very slick.

Dave Mark - President and Lead Designer
Intrinsic Algorithm -
"Reducing the world to mathematical equations!"

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Thanks for mentioning the book. It must be where my lecturer got his idea from. Sadly I don''t have any way of getting a hold of the book before my hand-in date (no good libraries near me and bad xmas post time).

Is there anything on the net that runs along these lines that I can have a look at? Or could someone please give me a brief summary to put me on the right track?



Advertisement
check out http://www.quantum-leaps.com/

It might have an implementation of FSM, from the book. It''s pretty intutive, it uses function pointers and the state is implicit in the function. So you can name your class methods as statesn, they are self documenting. The hiearchical FSM allows to take advantage of the class hiearchies of objects and oop inheritance concept to reuse state objects. It''s an intresting read, you might want to pick up the book as well.

Good Luck!

-ddn



Think classes, one for the statemachine which holds a list of states that are derived from some base state class. The state machine can then call an appropriate update function on the currently active state each frame.

Of course there are other things you''ll have to figure out like...

How do I get the state to effect the object it is supposed to control?



This topic is closed to new replies.

Advertisement