c# - 这是 FuSM(模糊状态机)的正确实现吗

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

我非常困惑这是否真的算作 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
    }
}

最佳答案

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

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

我可以推荐您查看这篇文章,它解释得非常好,并且提供了一个有用且实用的示例。 http://www.byond.com/forum/?post=37966

关于c# - 这是 FuSM(模糊状态机)的正确实现吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29168444/

相关文章:

c# - ASP.NET SignalR - 空闲时消耗的带宽

c# - 无法将反序列化 Json 对象绑定(bind)到类模型中

java - 我们正在尝试开发井字游戏。我们应该使用什么算法?

machine-learning - 强化学习序列决策中的平稳性概念

c# - 自动映射器 : Max graph depth

c# - Entity Framework 5.0 复合外键到非主键 - 这可能吗?

scala - 将高度自治的参与者视为代理人是否合理?

wpf - 使用 MVVM 模式实现 UI 状态机

vhdl - 简单状态机问题

design-patterns - 在游戏开发中处理状态和状态变化的好技术是什么?