Repository navigation
fix(combat): 迂回判定改为节点地图属性优先 #585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,12 +138,24 @@ def map_decision_session( | |
| return session | ||
|
|
||
|
|
||
| def detour_map(detour: bool | None, node: str = 'Z') -> TrackingMap: | ||
| """最小地图:入口 0 与单个战斗节点;``detour=None`` 模拟旧 YAML 缺该属性。""" | ||
| raw: dict[str, dict[str, object]] = { | ||
| '0': {'position': [0.1, 0.2], 'next': [node], 'type': 'NULL'}, | ||
| node: {'position': [0.5, 0.2], 'next': [], 'type': 'FIGHT'}, | ||
| } | ||
| if detour is not None: | ||
| raw[node]['detour'] = detour | ||
| return TrackingMap.from_dict(raw) | ||
|
|
||
|
|
||
| def make_engine( | ||
| frame: CapturedFrame, | ||
| tmp_path: Path, | ||
| *, | ||
| single: bool = False, | ||
| detour: bool = False, | ||
| map_detour: bool | None = True, | ||
| record_replay: bool = False, | ||
| ) -> CombatEngine: | ||
| context = SimpleNamespace( | ||
|
|
@@ -165,6 +177,7 @@ def make_engine( | |
| if not single: | ||
| engine._tracking = TrackingSession() | ||
| engine._tracking.tracker = RecordingFusion() | ||
| engine._tracking.map_data = detour_map(map_detour) | ||
| if record_replay: | ||
| engine._tracking.log_path = tmp_path / 'tracking.jsonl' | ||
| engine._tracking.detector = MagicMock(detection_status='no_cluster') | ||
|
|
@@ -291,6 +304,106 @@ def click(device: AndroidController, *_args: object) -> bool: | |
| assert engine._tracking.current_node == ('0' if clicked else 'Z') | ||
|
|
||
|
|
||
| def test_detour_available_reads_node_attribute_and_keeps_unknown_none() -> None: | ||
| """会话只报告地图资料;未加载、未确认或缺少字段一律返回 None。""" | ||
| session = TrackingSession() | ||
| assert session.detour_available('Z') is None | ||
| session.tracker = RecordingFusion() | ||
| session.map_data = detour_map(True) | ||
| assert session.detour_available('Z') is True | ||
| assert session.detour_available('0') is None | ||
| assert session.detour_available('missing') is None | ||
| session._decision_estimate = estimate('Z') | ||
| assert session.detour_available() is True | ||
| session.map_data = detour_map(None) | ||
| assert session.detour_available('Z') is None | ||
|
|
||
|
|
||
| def test_node_detour_ignores_missing_button_detection( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| frame: CapturedFrame, | ||
| evidence: EnemyObservation, | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| """节点属性可迂回时,按钮模板未检出不再阻止迂回。""" | ||
| engine = make_engine(frame, tmp_path, detour=True, map_detour=True) | ||
| monkeypatch.setattr(integration_module, 'observe_enemy', lambda *_a, **_k: evidence) | ||
| monkeypatch.setattr( | ||
| handlers_module, 'image_exist', MagicMock(side_effect=AssertionError('应使用节点属性')) | ||
| ) | ||
| click = MagicMock(return_value=True) | ||
| monkeypatch.setattr(handlers_module, 'click_image', click) | ||
| monkeypatch.setattr(handlers_module, 'wait_leave_page', MagicMock(return_value=frame.image)) | ||
| engine._make_decision(CombatPhase.SPOT_ENEMY_SUCCESS) | ||
| click.assert_called_once() | ||
| assert engine._tracking.tracker.observations[-1].action == 'detour' | ||
|
|
||
|
|
||
| def test_node_detour_true_warns_when_button_not_detected( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| frame: CapturedFrame, | ||
| evidence: EnemyObservation, | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| """地图标记可迂回但画面未检测到按钮时,保留反向冲突的反馈告警。""" | ||
| engine = make_engine(frame, tmp_path, detour=True, map_detour=True) | ||
| monkeypatch.setattr(integration_module, 'observe_enemy', lambda *_a, **_k: evidence) | ||
| warning = MagicMock() | ||
| monkeypatch.setattr(handlers_module._log, 'warning', warning) | ||
| click = MagicMock(return_value=True) | ||
| monkeypatch.setattr(handlers_module, 'click_image', click) | ||
| monkeypatch.setattr(handlers_module, 'wait_leave_page', MagicMock(return_value=frame.image)) | ||
| engine._make_decision(CombatPhase.SPOT_ENEMY_SUCCESS) | ||
| click.assert_called_once() | ||
| messages = [call.args[0] for call in warning.call_args_list] | ||
| assert any('可迂回' in message and '未检测到' in message for message in messages) | ||
|
|
||
|
|
||
| def test_node_detour_false_overrides_detected_button_and_warns( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| frame: CapturedFrame, | ||
| evidence: EnemyObservation, | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| """地图标记不可迂回时不点击,并保留画面与资料不一致的反馈信息。""" | ||
| engine = make_engine(frame, tmp_path, detour=True, map_detour=False) | ||
| monkeypatch.setattr( | ||
| integration_module, 'observe_enemy', lambda *_a, **_k: replace(evidence, detour=True) | ||
| ) | ||
| click = MagicMock() | ||
| enter = MagicMock() | ||
| warning = MagicMock() | ||
| monkeypatch.setattr(handlers_module, 'click_image', click) | ||
| monkeypatch.setattr(handlers_module, 'click_enter_fight', enter) | ||
| monkeypatch.setattr(handlers_module._log, 'warning', warning) | ||
| engine._make_decision(CombatPhase.SPOT_ENEMY_SUCCESS) | ||
| click.assert_not_called() | ||
| enter.assert_called_once() | ||
| messages = [call.args[0] for call in warning.call_args_list] | ||
| assert any('不可迂回' in message and '反馈' in message for message in messages) | ||
| assert engine._last_action == 'fight' | ||
| assert engine._tracking.tracker.observations[-1].action == 'fight' | ||
|
|
||
|
|
||
| def test_missing_node_detour_falls_back_to_button_detection( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| frame: CapturedFrame, | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| """旧活动图没有迂回属性且本次未采到敌情时,仍按截图按钮决定。""" | ||
| engine = make_engine(frame, tmp_path, detour=True, map_detour=None) | ||
| monkeypatch.setattr(integration_module, 'observe_enemy', lambda *_a, **_k: None) | ||
| monkeypatch.setattr(handlers_module, 'get_enemy_info', MagicMock(return_value={'DD': 6})) | ||
| monkeypatch.setattr(handlers_module, 'get_enemy_formation', MagicMock(return_value='复纵阵')) | ||
| monkeypatch.setattr(handlers_module, 'image_exist', MagicMock(return_value=True)) | ||
| click = MagicMock(return_value=True) | ||
| monkeypatch.setattr(handlers_module, 'click_image', click) | ||
| monkeypatch.setattr(handlers_module, 'wait_leave_page', MagicMock(return_value=frame.image)) | ||
| engine._make_decision(CombatPhase.SPOT_ENEMY_SUCCESS) | ||
| click.assert_called_once() | ||
| assert engine._tracking.tracker.observations[-1].action == 'detour' | ||
|
|
||
|
|
||
| def test_click_time_proxy_keeps_shared_click_interface( | ||
| monkeypatch: pytest.MonkeyPatch, frame: CapturedFrame | ||
| ) -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 以下是审核结果:
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
该变更为文档说明,无实际代码逻辑,但作为评审,指出以下可改进点:
表述存在潜在歧义:文档称“按钮漏检不会让可迂回节点被当成不可迂回”,但后半段又允许“仅有旧 YAML 坐标的活动图”回退按钮识别,此时若按钮漏检仍可能导致误判。建议明确该结论仅适用于节点资料包含
detour属性的情况,或补充说明回退场景下的兜底策略。“节点资料与画面冲突”未定义:未说明冲突的具体判定标准(例如按钮显示与资料属性不一致、坐标偏移等),建议补充明确冲突的触发条件,便于实现和测试。
建议增加操作记录维度:文档提到输出反馈告警,但未说明告警级别、频率限制或是否会影响后续流程。建议补充告警的触发阈值和使用方式,避免过度刷屏或掩盖真实问题。
其余内容无实质性错误,逻辑与现有设计兼容。