• ### Popular Now

• 15
• 15
• 11
• 9
• 10

#### Archived

This topic is now archived and is closed to further replies.

# AI Wisdom SML...

This topic is 5250 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am working on the Implementing a State Machine Language chapters 6.5 and 6.6 from AI Wisdom. However Steve does not mention how multiple State Machines could be put to use? What would be the general design/ structure for this? Give I have an gamestate, NPC''s physical states and mental states Attacking,defending etc. As well as then states of attacking! Passing, running etc.. thanks for any feedback

##### Share on other sites
well you might use one FSM for the agent movement and another for weapon selection and aiming

or you might switch in different FSMs depending whether your agent is in combat or gathering resources.

Or you might use one at the agent level and one at the squad level

My Website: ai-junkie.com | My Book: AI Techniques for Game Programming

##### Share on other sites
Mat,

He''s talking about how to implement the FSM language "gem" that Steve Rabin wrote in AI Wisdom. It uses a setup where the class inherits from a State class. If you want to do multiple states, it''s a bit more tricky.

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

##### Share on other sites
Yep it is a bit more tricky, But do u have any idea where i can find a step up to solving it!?

I am right in thinking this is the approach to take no?
If a team of players can be attacking, defending etc. But also each player can be attacking with a ball, running to space..etc or defending an area, player, chasing ball etc. Aswell as physical states of running , jumping etc used for the animations, then all these FSM's need to be organised someway?

[edited by - blackeye on November 6, 2003 10:47:02 AM]

##### Share on other sites
Perhaps if you give us a quick outline of the SML and its inheritance structure, we could have a crack at the problem... not all of us have gotten around to putting that book on our bookshelves!

As I read it, you desire simultaneous states for the agent, such as ''walking'' + ''chewing gum''... correct?

My first thought was that this should be possible by creating new classes that inherit from state and then defining a character class that inherits from these new classes, but with further thought, I don''t think that would work... or would necessarily be the right way to go about it.

I''m not actually certain that you could achieve this given a simple inheritance structure like agent<-state, since what you really desire is
     /  <-- substate1     \  <-- substate2      | ...agent<  <-- substatei      | ...      / <-- substaten-1      \ <-- substaten

Cheers,

Timkin

##### Share on other sites
Ok mate here goes, Get a cup of coffee, take a seat, and the ride will begin!

First here are my various states in my program ...
{The actual states may added to later, but the enums should not change}

// InMatchStatesenum GameStates{	STATE_PreMatch,	STATE_PostMatch,	STATE_FirstHalf,	STATE_SecondHalf,	STATE_HalfTime};//My ball statesenum BallPlayStates{	STATE_InPlay,	STATE_Throw,	STATE_Corner,	STATE_FreeKick,	STATE_Penalty,	STATE_Goal,	STATE_CentreKick};// My team Statesenum TeamStates{	STATE_Initialize,	STATE_Neutral,	STATE_Attack,	STATE_Defend};//And the actual players states (Main AI bit)// the Physical states, so i can link my animations to their actions etcenum PhysicalStates{	STATE_Still,	STATE_Heading,	STATE_Running,	STATE_Tackling,	STATE_Shooting};// Now here are the mental states for when the team are attacking (more may be added later)enum AttackingStates{	STATE_RunWithBall,	STATE_RunToBall,	STATE_FindSpace,	STATE_Pass,	STATE_Shoot};// And the players mental defending statesenum DefendingStates{	STATE_GetBall,	STATE_MarkPlayer,	STATE_GotoZone,	STATE_Tackle};Ok, so i want model these using the examples from the book(AI Wisdom- Great book , u should all buy it if u look in this forum!).Here is my cState class which i can use..The header file....(Note, i understand the Macro's by what they allow, but not fully how they do it! But i dont need to worry to much about that!)...   #ifndef _CSTATEMACHINE_H#define _CSTATEMACHINE_H#include <assert.h>// Macros#define BeginStateMachine	if(state < 0){if(0){#define EndStateMachine		return(true);}}else{assert(0);							return(false);}return (false);#define State(a)			return(true);}}else if(a== state){if(0){#define OnEvent(a)			return(true);}else if(a== event){#define OnEnter				OnEvent(EVENT_Enter)#define OnUpdate			OnEvent(EVENT_Update)#define OnExit				OnEvent(EVENT_Exit)enum StateMachineEvent { EVENT_Update,						 EVENT_Message,						 EVENT_Enter,						 EVENT_Exit};class cStateMachine{public:	cStateMachine();	~cStateMachine(){}	Initialize ();	Update ();	SetState(unsigned int newState);private:	unsigned int m_currentState;	unsigned int m_nextState;	bool m_stateChange;	Process(StateMachineEvent event);	virtual bool States(StateMachineEvent event, int state) =0;};#endifAnd The Cpp file shows how this is used....   #include "cState.h"cStateMachine::cStateMachine(){	m_currentState = 0;	m_stateChange = false;	m_nextState = false;}cStateMachine::Initialize(){	Process(EVENT_Enter);}cStateMachine::Update(){	Process(EVENT_Update);}cStateMachine::Process(StateMachineEvent event){	States(event, m_currentState);	// Check for a state change	int safetyCount = 10;	while(m_stateChange && (--safetyCount >= 0))	{		assert((safetyCount > 0 ) && ("StateMachine::Process - States are flip-flopping in an infinite loop." ));		m_stateChange = false;		// Let the last state clean up		States(EVENT_Exit, m_currentState);		//Set the new state		m_currentState = m_nextState;		//Let the new state init		States(EVENT_Enter, m_currentState);	}}cStateMachine::SetState( unsigned int newState ){	m_stateChange = true;	m_nextState = newState;}Now i have a class created which inherits from this class.for example i have made a GameStateClass.h as...   #include "cState.h"class cGameStates : cStateMachine{public:		cGameStates();		~cGameStates();private:protected:	virtual bool GameStates(StateMachineEvent event,int state);};and the beutiful cpp file which shows we we have gone to this trouble!...   #include "cGameState.h"enum GameStates{	STATE_PreMatch,	STATE_PostMatch,	STATE_FirstHalf,	STATE_SecondHalf,	STATE_HalfTime};cGameStates::cGameStates(){	SetState(STATE_PreMatch);}bool cGameStates::GameStates(StateMachineEvent event, int state ){	BeginStateMachine		/////////////////////////////////		State(STATE_PreMatch)				OnEnter		OnUpdate		OnExit				//////////////////////////////////				State(STATE_PostMatch)		OnEnter			//Put any C++ initialization code here					OnUpdate			//Put any C++ code here that gets run on every game tick											OnExit			//Put any C++ cleanup code here			////////////////////////////////////		State(STATE_FirstHalf)			OnEnter			OnUpdate			OnExit		////////////////////////////////			State(STATE_SecondHalf)			OnEnter			OnUpdate			OnExit		////////////////////////////////////		State(STATE_HalfTime)			OnEnter			OnUpdate			OnExit		////////////////////////////////		EndStateMachine}

And there she is!
Now how the hell do i make all these state machines to fit together and talk to each other to manage the game states, and the players AI.(As i said the player AI states will be developed further when i get this simple structure working)As well as adding a msg state so players can send other players msg's such as pass to me etc..)

This make any sense now!I need my state classes structure and the flow of control?

Thanks for any help ppl can give
Pete.

[edited by - blackeye on November 6, 2003 7:16:28 PM]

##### Share on other sites
Sounds like you have a few needs:

1) A way for states to communicate.

You may want to look at some of the blackboard articles in that book. Each of the family of states could access a common resource which stores information. All of the states could read and write to it to communicate.

2) An owner.

Who owns all of the state machines? Someone needs to handle transitioning, updating, etc. Personally, I avoid macro driven state machines as I feel they make systems more confusing, but I am sure there is a good way to handle it under that system. Either the states need to know about other states in the same family, or something needs to sit above them to handle control flow.

3) (possibly) A better model of what you are trying to do.

What are your states responsibilities? What to the states do? What requirements are there, and who solves them? Make sure you know the problem before getting too far down the path of commiting to individual states.

##### Share on other sites
When using the FSM language from AI Wisdom, you will need to have your player class inherit from the StateMachine class. You didn't put your player class in the post... where is it? "Run With Ball" is not a game state... it's the state of a player. The problem is that you haven't broken down what your entities are. You have lots of states but they will attach to completely different objects.

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

[edited by - InnocuousFox on November 6, 2003 11:00:04 PM]

##### Share on other sites

Firstly
I have my a PlayerAI object which contains pointers to the attack and defend state machines.

My team class which has an array of player classes can have its own team state machine.

And my MatchEngine class has its own State Machine also.

MatchEngine->Team->Player->PlayerAI.

however i need myplayer Ai to be aware of the MAtchEngine state? So perhaps my playerAI FSM can Check The State of other machines such as match and team? Perhaps recieving a pointer to them on intialisation?
And a public GetState() function?

Thanks for ideas and help guys

##### Share on other sites
Yes... you will need to make the game class visible somehow to the rest of the application. There are a number of ways to do this.

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