跳转至

GFDecisionConsideration

API Reference / Decision / 类索引

  • 路径:addons/gf/extensions/decision/resources/gf_decision_consideration.gd
  • 模块:Decision
  • 继承:Resource
  • API:public
  • 类别:协议与扩展点 (protocol)
  • 首次版本:4.3.0

单个效用评分考虑项。 从决策上下文读取一个输入值,将它映射为 0 到 1 的效用分数。 子类可以重写 _score() 扩展项目自己的评分逻辑。

成员概览

类型 名称 签名
枚举 InputSource enum InputSource
属性 consideration_id var consideration_id: StringName = &""
属性 enabled var enabled: bool = true
属性 weight var weight: float = 1.0
属性 input_source var input_source: InputSource = InputSource.BLACKBOARD
属性 input_key var input_key: StringName = &""
属性 default_input var default_input: float = 0.0
属性 input_min var input_min: float = 0.0
属性 input_max var input_max: float = 1.0
属性 missing_score var missing_score: float = 0.0
属性 response_curve var response_curve: Curve = null
属性 invert var invert: bool = false
方法 score func score(context: GFDecisionContext) -> float:
方法 get_debug_snapshot func get_debug_snapshot(context: GFDecisionContext) -> Dictionary:
方法 _score func _score(context: GFDecisionContext) -> float:

枚举

InputSource

  • API:public
enum InputSource { ## 从 GFDecisionContext 黑板读取。 BLACKBOARD, ## 从 GFDecisionContext metadata 读取。 METADATA, ## 从 GFDecisionContext subject 读取。 SUBJECT, ## 从 GFDecisionContext target 读取。 TARGET, }

考虑项读取输入值的位置。

属性

consideration_id

  • API:public
var consideration_id: StringName = &""

考虑项标识,用于调试报告。

enabled

  • API:public
var enabled: bool = true

是否启用该考虑项。禁用时返回中性分数 1.0。

weight

  • API:public
var weight: float = 1.0

考虑项权重。具体聚合方式由 GFDecisionOption 决定。

input_source

  • API:public
var input_source: InputSource = InputSource.BLACKBOARD

输入来源。

input_key

  • API:public
var input_key: StringName = &""

输入键。为空时使用 default_input。

default_input

  • API:public
var default_input: float = 0.0

缺失或没有输入键时使用的默认输入值。

input_min

  • API:public
var input_min: float = 0.0

输入最小值,映射为 0。

input_max

  • API:public
var input_max: float = 1.0

输入最大值,映射为 1。

missing_score

  • API:public
var missing_score: float = 0.0

输入存在但无法转换为数字时返回的分数。输入缺失时优先使用 default_input。

response_curve

  • API:public
var response_curve: Curve = null

可选响应曲线。为空时使用线性归一化值。

invert

  • API:public
var invert: bool = false

是否反转最终分数。

方法

score

  • API:public
func score(context: GFDecisionContext) -> float:

计算考虑项分数。

参数:

名称 说明
context 决策上下文。

返回:0 到 1 之间的效用分数。

get_debug_snapshot

  • API:public
func get_debug_snapshot(context: GFDecisionContext) -> Dictionary:

获取考虑项调试快照。

参数:

名称 说明
context 决策上下文。

返回:调试快照字典。

结构:

  • return: 包含 consideration_id、enabled、score、weight、input_source 和 input_key 字段的 Dictionary。

_score

  • API:protected
func _score(context: GFDecisionContext) -> float:

自定义考虑项评分。 默认实现从 context 读取 input_key,并按 input_min/input_max 归一化。 子类重写时仍应返回 0 到 1 之间的值。

参数:

名称 说明
context 决策上下文。

返回:0 到 1 之间的原始效用分数。