【问题标题】:Is this a correct implementation of a FuSM (Fuzzy State Machine)这是 FuSM(模糊状态机)的正确实现吗
【发布时间】:2015-05-23 23:24:32
【问题描述】:

我很困惑这是否真的算作一个 FuSM,因为最后,它只是一个 if else 条件,很多人说这不足以让它成为模糊逻辑?我也很困惑模糊 AI 和模糊状态机是否被认为是同一个? FuSM 是否必须支持同时执行多个状态才能成为 FuSM?这个实现是这样做的,但我不确定它是否正确。

希望我的问题不是太不清楚,也许我现在问这个问题还为时过早。我肯定很困惑,如果能对此有所了解,将不胜感激。

// 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();
}

两个简单的例子:

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
    }
}

【问题讨论】:

    标签: c# artificial-intelligence state-machine fuzzy-logic


    【解决方案1】:

    对于那里的任何人也感到困惑。我不认为这被认为是模糊逻辑,即使您可以在那里找到自称为模糊逻辑的模拟脚本。 一个例子: http://xbox.create.msdn.com/en-US/education/catalog/sample/fuzzy_logic

    问题是当你有许多变量时,比如生命值、弹药、视野中的敌人、速度、攻击性、伤害、命中率……你需要考虑所有因素来决定 AI 应该攻击、防御还是逃跑在上述变量中​​,您需要创建的 if 语句数量为 pow(numOfVariables, numOfStates)。解决该问题的一种方法是使用模糊逻辑,它会在给定当前输入值和为规则集指定的权重的情况下计算最佳输出/状态。

    我可以推荐看看这篇文章,它解释得非常好,而且它通过一个有用和实用的例子来做到这一点。 http://www.byond.com/forum/?post=37966

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-08
      • 2017-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多