feat(engine): 实现阵营博弈机制

- FactionData 新增 threshold 和 skill 字段
- 修改能量累积逻辑:power 跨 tick 累积
- 阈值改为 10,达到后触发阵营技能
- festival 提升情绪,panic 降低情绪

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
empty
2025-12-30 12:10:28 +08:00
parent cec3e95a4b
commit 28976d9672
3 changed files with 20 additions and 16 deletions

View File

@@ -10,7 +10,7 @@ OPTIMIST_THRESHOLD = 0.6
FEARFUL_THRESHOLD = 0.6
# 阵营技能触发阈值
FACTION_POWER_THRESHOLD = 5
FACTION_POWER_THRESHOLD = 10
# 阵营事件对情绪的影响
FACTION_EVENT_EFFECTS = {
@@ -39,17 +39,18 @@ def update_factions(state: WorldState) -> None:
"""统计各派系并更新 world_state
流程:
1. 清空 factions.members
1. 清空 factions.members(但保留 power
2. 遍历所有 agents根据 emotion 分类
3. 更新 agent.faction 字段
4. 将 agent 加入对应 faction.members
5. 每个 agent 为 faction 增加 power += 1
5. 每个 agent 为 faction 增加 power += 1(累积)
"""
# 重置 factions
state.factions = Factions(
optimists=FactionData(power=0, members=[]),
fearful=FactionData(power=0, members=[])
)
# 保留现有 power只清空 members
current_optimist_power = state.factions.optimists.power
current_fearful_power = state.factions.fearful.power
state.factions.optimists.members = []
state.factions.fearful.members = []
for agent_id, agent in state.agents.items():
faction = classify_faction(agent)
@@ -57,11 +58,12 @@ def update_factions(state: WorldState) -> None:
if faction == "optimists":
state.factions.optimists.members.append(agent_id)
state.factions.optimists.power += 1
state.factions.optimists.power = current_optimist_power + 1
current_optimist_power = state.factions.optimists.power
elif faction == "fearful":
state.factions.fearful.members.append(agent_id)
state.factions.fearful.power += 1
# neutral 不加入任何派系
state.factions.fearful.power = current_fearful_power + 1
current_fearful_power = state.factions.fearful.power
def apply_faction_influence(state: WorldState) -> None:
@@ -79,7 +81,7 @@ def check_and_trigger_faction_event(state: WorldState) -> FactionEventResult:
"""检查并触发阵营事件
规则:
- 当 faction.power >= 5 时,触发对应世界事件
- 当 faction.power >= faction.threshold 时,触发对应技能
- optimists → festival提升情绪
- fearful → panic降低情绪
- 触发后该 faction.power 归零
@@ -87,13 +89,13 @@ def check_and_trigger_faction_event(state: WorldState) -> FactionEventResult:
result = FactionEventResult(type=None, source_faction=None)
# 检查乐观派
if state.factions.optimists.power >= FACTION_POWER_THRESHOLD:
if state.factions.optimists.power >= state.factions.optimists.threshold:
result = FactionEventResult(type="festival", source_faction="optimists")
_apply_faction_event(state, "festival")
state.factions.optimists.power = 0
# 检查恐惧派
elif state.factions.fearful.power >= FACTION_POWER_THRESHOLD:
elif state.factions.fearful.power >= state.factions.fearful.threshold:
result = FactionEventResult(type="panic", source_faction="fearful")
_apply_faction_event(state, "panic")
state.factions.fearful.power = 0

View File

@@ -47,6 +47,8 @@ class Stance(BaseModel):
class FactionData(BaseModel):
"""单个派系的数据"""
power: int = 0
threshold: int = 10
skill: str = ""
members: List[str] = Field(default_factory=list)

View File

@@ -31,8 +31,8 @@ def get_default_state() -> WorldState:
events=[],
global_meter=GlobalMeter(value=0, threshold=100, cooldown=0),
factions=Factions(
optimists=FactionData(power=0, members=[]),
fearful=FactionData(power=0, members=[])
optimists=FactionData(power=0, threshold=10, skill="festival", members=[]),
fearful=FactionData(power=0, threshold=10, skill="panic", members=[])
),
story_arcs=get_default_story_arcs(),
)