火力规则:装备匹配规则实现,目标规则实现,阵位规则简单实现(需要细化)

This commit is contained in:
MHW
2026-04-07 17:04:13 +08:00
parent 72f4caf555
commit 2fafd931cc
6 changed files with 777 additions and 1 deletions

View File

@@ -4,6 +4,8 @@ import com.solution.rule.domain.ultimately.fact.DroolsFact;
import java.util.Map;
import static com.solution.rule.utils.RuleFunction.equipmentRule;
import static com.solution.rule.utils.RuleFunction.target;
import static com.solution.rule.utils.RuleFunction.position;
global java.util.Map globalParams;
@@ -74,6 +76,77 @@ function Map buildParam(){
param.put("redMatchKeywords_missile", "防空,导弹,导弹发射");
param.put("missileScore", 1);
// ===================== 目标分配参数(写入 Tasks.task.execute =====================
// executeTypeDefault生成 execute[0] 的类型字段
param.put("executeTypeDefault", "assault");
// targetPickModeroundRobin(稳定轮询) / random(伪随机但同输入稳定)
param.put("targetPickMode", "roundRobin");
// minTargetsPerRed / maxTargetsPerRedCap每个红方任务最少/最多分配的目标数
param.put("minTargetsPerRed", 1);
param.put("maxTargetsPerRedCap", 3);
// radToTargetsCsvsuccessTargetRad(命中率) -> 每红装目标数 的映射(阈值:目标数),按阈值从大到小匹配
// 例0.8:1,0.5:2,0.2:3 表示 successTargetRad>=0.8 分1个>=0.5 分2个>=0.2 分3个
param.put("radToTargetsCsv", "0.8:1,0.5:2,0.2:3");
// rangeParseRegex从 attDefaultValue/attExplain 中提取射程数值的正则取第1个数字
param.put("rangeParseRegex", "(\\\\d+(?:\\\\.\\\\d+)?)");
// rangeUnit提取数值的单位km/m二选一
param.put("rangeUnit", "km");
// minRangeToAllowAssignKm若解析到的蓝方射程小于该值则该蓝方装备不参与被分配无法解析则忽略此过滤
param.put("minRangeToAllowAssignKm", 0);
// ===================== 低命中率补拿装备参数 =====================
// redHitRateThreshold红方装备命中率阈值低于该值时触发补拿
param.put("redHitRateThreshold", 0.6);
// maxExtraWeaponsPerTask每条蓝方任务最多补拿几件红装
param.put("maxExtraWeaponsPerTask", 2);
// maxSupplementRounds补拿循环最大轮次防死循环
param.put("maxSupplementRounds", 2);
// extraPickMinScore补拿时红装最低匹配分
param.put("extraPickMinScore", 1);
// ===================== 阵位规则参数(写入 SubComponents.platform[].positions =====================
// positionRuleEnabled是否启用阵位规则。true=执行阵位生成false=跳过,不改 platform.positions。
param.put("positionRuleEnabled", true);
// positionAnchorMode锚点模式。当前实现使用 hybrid蓝方 taskWeapons.coordinate 的中心点作为主锚点)。
param.put("positionAnchorMode", "hybrid");
// trackPointDirectionMode航向计算模式。
// - head2next取 trackPoints[0] -> trackPoints[1] 作为方向(默认)
// - tail2prev取倒数第二个 -> 最后一个点作为方向
param.put("trackPointDirectionMode", "head2next");
// fallbackBearingDeg当 trackPoints 缺失或无法计算方位时使用该默认方位角0-360
param.put("fallbackBearingDeg", 0);
// deployDistanceKmMin部署距离下限km。最终距离不会小于该值。
param.put("deployDistanceKmMin", 8);
// deployDistanceKmMax部署距离上限km。最终距离不会大于该值。
param.put("deployDistanceKmMax", 30);
// deployDistanceKmDefault默认部署距离km
// 当 distanceByPlatformCsv 未命中任何关键词时,使用该值。
param.put("deployDistanceKmDefault", 15);
// distanceByPlatformCsv按“关键词”覆盖部署距离km不写死具体类型完全由业务配置。
// 格式:关键词:距离,关键词:距离(示例:防空:18,反坦克:10,迫击炮:8
// 匹配范围:红方装备 Name / Platform_type 文本包含关键词即命中。
// 优先级:命中后覆盖 deployDistanceKmDefault但最终仍受 deployDistanceKmMin 与 deployDistanceKmMax 约束。
param.put("distanceByPlatformCsv", "");
// formationType编队样式可选 line / wedge / circle。
param.put("formationType", "line");
// formationSpacingMeters编队间距影响同一红装下 platform[] 点位离散程度。
// 说明Java 侧会与 minInterPlatformDistanceMeters 比较,取更大值,避免平台重叠过近。
param.put("formationSpacingMeters", 300);
// formationHeadingOffsetDeg编队相对主航向的偏转角主要用于 wedge/circle 的分散方向。
param.put("formationHeadingOffsetDeg", 15);
// defaultDeployHeight默认部署高度用于 positions 第3位高度值基线。
param.put("defaultDeployHeight", 30);
// heightFollowBlueRatio高度跟随蓝方比例>=0
// 计算方式:高度 = defaultDeployHeight + 蓝方锚点平均高度 * heightFollowBlueRatio。
// 0 表示不跟随蓝方高度,仅使用默认高度。
param.put("heightFollowBlueRatio", 0.0);
// enableWarZoneClamp是否启用作战区约束。true=超出 warZoneLocation 时回拉到区内。
param.put("enableWarZoneClamp", true);
// warZoneClampMode作战区约束模式。当前实现使用 nearestInside沿锚点到目标点方向二分回拉到区内
param.put("warZoneClampMode", "nearestInside");
// minInterPlatformDistanceMeters平台最小间距下限用于抑制平台点位过度重叠。
param.put("minInterPlatformDistanceMeters", 80);
return param;
}
@@ -86,3 +159,23 @@ then
globalParams.putAll(buildParam());
equipmentRule($fact, globalParams);
end
rule "目标匹配"
salience 90
when
$fact : DroolsFact(task != null)
then
// 显式目标分配规则:填充 Tasks.task.execute.targetList[*].targetId
globalParams.putAll(buildParam());
target($fact, globalParams);
end
rule "阵位匹配"
salience 80
when
$fact : DroolsFact(task != null)
then
// 显式阵位规则:填充 redWeapons.SubComponents.platform[].positions
globalParams.putAll(buildParam());
position($fact, globalParams);
end