feat(ai): BrainGraph 核心程序集 + AiSignal + Blackboard(可自省)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace BaseGames.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// 具名、可枚举的 AI 临时值容器(每敌人实例一份)。
|
||||
/// 保留"具名"是为了让调试器/MCP 能通用枚举当前值。
|
||||
/// </summary>
|
||||
public sealed class Blackboard
|
||||
{
|
||||
readonly Dictionary<string, object> _values = new Dictionary<string, object>();
|
||||
|
||||
public void Set<T>(string key, T value) => _values[key] = value;
|
||||
|
||||
public T Get<T>(string key)
|
||||
=> _values.TryGetValue(key, out var v) && v is T t ? t : default;
|
||||
|
||||
public bool Has(string key) => _values.ContainsKey(key);
|
||||
|
||||
public IReadOnlyCollection<string> Keys => _values.Keys;
|
||||
|
||||
public void Clear() => _values.Clear();
|
||||
|
||||
/// <summary>供调试器/MCP 自省:key → 值的字符串表示。</summary>
|
||||
public Dictionary<string, string> Snapshot()
|
||||
{
|
||||
var result = new Dictionary<string, string>(_values.Count);
|
||||
foreach (var kv in _values)
|
||||
{
|
||||
result[kv.Key] = kv.Value is System.IFormattable f
|
||||
? f.ToString(null, CultureInfo.InvariantCulture)
|
||||
: kv.Value?.ToString() ?? "null";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user