3

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
    }
}
smci
  • 32,567
  • 20
  • 113
  • 146
BjarkeCK
  • 5,694
  • 5
  • 41
  • 59

1 Answers1

0

For anyone out there also confused. I don't think this is considered fuzzy logic, even tho you can find simular scripts out there calling themself for fuzzy logic. One example beeing: http://xbox.create.msdn.com/en-US/education/catalog/sample/fuzzy_logic

The problem is when you have many variables such as, Health, Ammo, Enemies in sight, Speed, Agressiveness, Damage, Chance to hit... and you need to decide whether the AI should Attack, Defend or Flee considering all of the variables above, the number of if statements you would need to make would be pow(numOfVariables, numOfStates). One way to solve that problem is using fuzzy logic, which calculates the best output / state, given the current input values and the weights specified for your rule sets.

I can recommend checking out this post, it explains it really well, and it does it with a usefull and practicle example. http://www.byond.com/forum/?post=37966

BjarkeCK
  • 5,694
  • 5
  • 41
  • 59