Advertisement

Your thoughts: Steve Rabin's Macro style FSM for AI

Started by August 28, 2003 11:35 AM
4 comments, last by GalaxyQuest 21 years, 3 months ago
From: Game Programming Gems 1, chapter 3.0, "Designing a General Robust AI Engine" What: Steve details a FSM based on c/c++ macros. Complete with a simple messaging system. I have even seen an updated version of this which is wrapped in a class for cleaner programming & upgrading. Comments: I think its rather neat. If possible, I could seen this becoming even more powerful if each FSM state or state actions where driven by a scripting system, such as lua. Was curious if any of you have played with his system, and if so, what are some of its weaknessess/problems you came across. I think for a first iteration of a game im making, it may be worth it. Then when I become more experienced, I can judge it more (obviously!). - John
If I''m not mistaken, in AI Programming Wisdom, Steve Rabin lays out the system in greater detail than in Game Programming Gems.
Advertisement
quote: Original post by ares32585
If I''m not mistaken, in AI Programming Wisdom, Steve Rabin lays out the system in greater detail than in Game Programming Gems.

You are correct. And I love it! I am using it in my current project on most all of my classes. I didn''t use the messaging system because it was overkill for the type of game that I have, but the FSM language makes constructing, reading, and maintaining the states a real simple task! I had the chance to tell him in person when we were at the Microsoft party at the GDC. Ask Ferretman or Geta for the amusing details.

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!"

Fox, maybe you can answer this:

Do you use the version that is wrapped within a class structure?

If so, and you say most of your game objects include steve''s fsm design, so you allow multiple objects to use the same instance of a FSM, or must each object construct a new fsm for itself?

Also, seemed like his FSM was heavily coupled with the messaging. How did you change it to your needs?

- John
Each class of mine that needs to use the StateMachine inherits from it. That way, all the variables are now included as part of the class (and therefore each object). So if instance 4 of object type A is in state 2, it is stored accordingly and processed accordingly - separate from other objects.

As for the messaging, just use the chapter BEFORE he introduces the messaging. Grab the class off the CD and just build from there.

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!"

I''ll admit I haven''t actually tried to use his macros for constructing state machines, and while I like the idea a lot, I have a couple pretty severe reservations.

First, any programming design that has preprocessor macros as its fundamental level will undoubtedly generate newer, more complex and more bizarre macros as the complexity (and bizarrity) of what you want to do with them increases.

Second, that scripting system you allude to on the To Do List... you do realize that by generating your AI code via the preprocessor, the logic is frozen at compile time. The best you could hope for on-the-fly scripting is to recompile your newly edited AI state "scripts" and re-load them as a DLL, and even that would be heinous.

Personally, I''m not to this point in development yet, but I have written a nice parameter loading system (a la scott bilas) in lex & yacc that takes a script which defines an Object and generates the code for all its designer-specifiable properties and how to load it at run-time. I''d been planning on coming up with a system very similar to Rabin''s for doing NPC logic, except using lex and yacc instead of the preprocessor.

That way, I feel lex & yacc can much better handle an increased complexity in state machine grammar than the C-preproccesor, and I''ll be able to see what code the compiler ''sees'' as I''m stepping through during debugging.

But seriously, that''s good news that you''re happy with it! Please let us know the pros and cons as your project matures.

adam

This topic is closed to new replies.

Advertisement