【发布时间】: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