I am super confused whether or not this actually counts as beeing a FuSM, because in the end, it is just an if else condition, which many say is not enough for it to be fuzzy logic? I'm am also confused whether or not fuzzy AI and a Fuzzy State Machine are considered beeing one and the same? And must a FuSM support multiple states being executed at the same time in order for it to be a FuSM? This implementation does this, but I'm not sure it does it correct.
Hope my question is not too unclear, maybe it is too early for me to ask. I'm definitely confused and some light on it would be appreciated.
// Some states may not be executed simultaneously
public enum StateType
{
MovementXZ, // Can move while doing everything else
MovementY, // Can jump & crawl while doing everything else
Action // Can use his hands (shoot & stuff) while doing everything else
}
public class FuzzyStateMachine
{
private readonly Dictionary<StateType, List<IFuzzyState>> _states;
public void AddState(IFuzzyState state)
{
_states[state.StateType].Add(state);
}
public void ExecuteStates()
{
foreach (List<IFuzzyState> states in _states.Values)
{
// Selects the state with the maximum "DOA" value.
IFuzzyState state = states.MaxBy(x => x.CalculateDOA());
state.Execute();
}
}
}
public interface IFuzzyState
{
StateType StateType { get; }
/// <summary>
/// Calculates the degree of activation (a value between [0, 1])
/// </summary>
/// <returns></returns>
double CalculateDOA();
// TODO: implement: OnEnterState, OnExitState and OnStay instead of just Execute()
void Execute();
}
Two simple examples:
public class SeekCoverState : IFuzzyState
{
public StateType StateType
{
get { return StateType.MovementXZ; }
}
public double CalculateDOA()
{
return 1 - Agent.Health / 100d;
}
public void Execute()
{
// Move twoards cover
}
}
public class ShootAtEnemyState : IFuzzyState
{
public StateType StateType
{
get { return StateType.Action; }
}
public double CalculateDOA()
{
// Return the properbility of hidding the target or something.
}
public void Execute()
{
// Shoot
}
}