FSM silly question

Hello, guys !!!

My head is spinning like a record :cry: :cry: :cry: and i cannot figure this simple fsm thing.
I cannot decide what type of fsm is represented by the below code

//-- Finite state machine 
function AIFSM()
{
	switch (state)
	{
		case chase:
			Chase();
		break;
		case evade:
			Evade();
		break;
		case loadHealth:
			LoadHealth();
		break;
		case loadWeapons:
			LoadWeapons();
		break;
		
		default:
		break;
	
	
	}

}
function Chase()
{

	var enemy  = FindClosestEnemy();
	
	NavigateTowardsSpecificWaypoint(Vector3(enemy.transform.position.x+10,enemy.transform.position.y,enemy.transform.position.z+10) );
	
	var direction = transform.TransformDirection(Vector3.forward);
	var hit : RaycastHit;
	
	
	 // Bit shift the index of the layer (10) to get a bit mask
	var layerMask = 1 << 10;
	// This would cast rays only against colliders in layer 10.
	// But instead we want to collide against everything except layer 10. The ~ operator does this, it inverts a bitmask.
	layerMask =~ layerMask;

	
	// Did we hit anything?
	if (Physics.Raycast (Vector3(transform.position.x,transform.position.y,transform.position.z), direction, hit, 100,layerMask)) 
	{
		if(hit.collider.tag == "carColliderTag")
		{
			ammo.EnableAutoFire();
		
		}
		else
		{	
			ammo.DisableAutoFire();
	
		}
		
		
	}
	else
	{	
		ammo.DisableAutoFire();
	
	}
	
	if(health.GetHealth() < 35 )
	{
		state = loadHealth;
	}
	
	else if(health.GetReceivingDamage())
	{
		state = evade;
	}
	else if(ammo.GetSpeedAmount() + ammo.GetHomingAmount() + ammo.GetPowerAmount()  < 3)
	{
		state = loadWeapons;
	}
	
	
	
	
}
function Evade()
{
	ammo.DisableAutoFire();
	
	var RelativeWaypointPosition : Vector3 = transform.InverseTransformPoint( FindClosestEnemy().transform.position );
																				
																			
	// by dividing the horizontal position by the magnitude, we get a decimal percentage of the turn angle that we can use to drive the wheels
	
	inputSteer = -RelativeWaypointPosition.x / RelativeWaypointPosition.magnitude;
	
	inputHandbrake = 0;
	inputMotor = 1;
	inputBrake = 0 ;



	if(health.GetHealth() < 35 )
	{
		state = loadHealth;
	}
	else if(!health.GetReceivingDamage())
	{
		state = chase;
	}
	else if(ammo.GetSpeedAmount() + ammo.GetHomingAmount() + ammo.GetPowerAmount() < 3)
	{
		state = loadWeapons;
	}
	
	
}
function LoadHealth()
{

	ammo.DisableAutoFire();
	
	NavigateTowardsSpecificWaypoint(FindClosestHealthPack());
	
	
	
	if(health.GetHealthTaken())
	{
		health.SetHealthTaken(false);
		
		if(ammo.GetSpeedAmount() + ammo.GetHomingAmount() + ammo.GetPowerAmount() < 3)
		{
			state = loadWeapons;
		}
		else if(health.GetReceivingDamage())
		{
			state = evade;
		}
		else
		{
			state = chase;
		}
		
	}
	
	
	
}
function LoadWeapons()
{
	ammo.DisableAutoFire();
	
	NavigateTowardsSpecificWaypoint(FindClosestMissilePack()) ;
	
	if(ammo.GetWeaponsTaken())
	{
		ammo.SetWeaponsTaken(false);
		
		if(health.GetHealth() < 35 )
		{
			state = loadHealth;
		}
		else if(health.GetReceivingDamage())
		{
			state = evade;
		}
		else
		{
			state = chase;
		}
	}
	
	
}

i have a book ( AI for game developers David M.Bourg)
and it does not write a single line about moore/mealy machines.

Moore machines decide which state to go to based only on the current state, while Mealy Machines use both, the current state and the transition passed to the machine.

Nobody ever talks about Moore machines because it´s not the way we think about game logic, or about the behaviour of a standard NPC. “If NPC ‘x’ is in state ‘y’ and event ‘a’ happens, it goes to state ‘z’”. Moore Machine doesn´t need the event ‘a’ to decide which state to transit to.

In 99% of the books about game ai, when you read Finite State Machine, it´s assumed a Mealy Machine. I think, Alex Champandard´s book, AI Game Development: Synthetic Creatures with Learning and Reactive Behaviors, explains Moore Machines.

The code you posted is a Mealy machine because you can see a state transition based on health and other properties of the NPC, not just it´s current state.

Thanks a lot for your answer. :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile: :smile: !!!