狂气守卫: 修 OCR 抖动导致的误报(这次是假警)
18:12 那轮被守卫中止, 报"狂气从 8859 降到 6388 —— 已消耗"。逐层查下来是假警,
但过程暴露了守卫本身的真缺陷:
真相(放大 6 倍肉眼确认): 余额是 **6388**, 一分未花。
17:45 守卫读到 8859 <- OCR 误读, 却被当基线写进文件
18:12 守卫读到 6388(对的) <- 和错的基线比 -> 误判"已消耗" -> 中止整轮
根因: 同一个画面上 OCR 给出的值本身就会抖。实测在固定画面连读 5 次:
6388 出现 4 次, 8859 出现 1 次。
旧实现是"最后读到什么就是什么", 于是一次误读就能:
(a) 把基线抬到不可能的值(单次镜牢 +2995), 或
(b) 把正常值判成消费, 中止整轮。
修法(scripts/auto_cycle.py read_lunacy):
1. 只在主界面取数(底部资源条唯一确定存在的地方); 结算/奖励画面上别的 4 位数
会落进判定范围 —— LUNACY 标签右下 dy<70 / dx<130。
2. 取 5 次读数的**众数**, 且至少出现 2 次才采信; 都不一致时宁可返回 None,
也不拿错值当基线。
3. 连读失败不再静默放行(返回 None 时 lunacy_guard 会明确说明跳过)。
基线已按真实值更正为 6388, 并写了 lunacy_baseline.notes.txt 记录这次更正的依据。
重跑验证: 狂气校验 OK (狂气 6388 未变), daily 正常启动。
新增/改写 tests/test_auto_cycle.py 的 LunacyReadTest 4 个用例
(离群值不胜出、重试、全不一致时返回 None、非主界面不读)。全套 225/225 通过。
This commit is contained in:
+43
-12
@@ -109,25 +109,56 @@ class ScreenDetectTest(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class LunacyReadTest(unittest.TestCase):
|
class LunacyReadTest(unittest.TestCase):
|
||||||
"""狂气校验是"不许消费"的唯一防线, 读不到就是没校验, 所以要重试。"""
|
"""狂气校验是"不许消费"的唯一防线, 读不到就是没校验, 所以要重试。
|
||||||
|
|
||||||
def test_retries_until_the_label_shows_up(self):
|
2026-10-13 实测更麻烦的一种情况: 同一个画面上 OCR 会给出**两个不同的值**
|
||||||
calls = []
|
(放大 6 倍肉眼确认余额是 6388, 而连读 5 次得到 6388 四次、8859 一次)。
|
||||||
|
8859 被当成基线后, 之后正确的 6388 反而被判成"已消耗"并中止整轮。
|
||||||
|
所以要取众数, 不是"最后读到什么就是什么"。
|
||||||
|
"""
|
||||||
|
|
||||||
|
MAIN = [{'text': 'Window', 'x': 993, 'y': 804},
|
||||||
|
{'text': 'Sinners', 'x': 1093, 'y': 811},
|
||||||
|
{'text': 'Drive', 'x': 1201, 'y': 808},
|
||||||
|
{'text': 'Extract', 'x': 1389, 'y': 809},
|
||||||
|
{'text': 'Dispense', 'x': 1486, 'y': 810}]
|
||||||
|
|
||||||
|
def _frames(self, values):
|
||||||
|
"""按顺序返回若干帧; 每帧都是主界面 + LUNACY + 该帧的值。"""
|
||||||
|
seq = list(values)
|
||||||
|
|
||||||
def fake_items():
|
def fake_items():
|
||||||
calls.append(1)
|
v = seq.pop(0) if len(seq) > 1 else seq[0]
|
||||||
if len(calls) < 3:
|
if v is None:
|
||||||
return [{'text': 'LV 042', 'x': 60, 'y': 800}] # 这一帧没有 LUNACY
|
return list(self.MAIN)
|
||||||
return [{'text': 'LUNACY', 'x': 668, 'y': 795},
|
return list(self.MAIN) + [{'text': 'LUNACY', 'x': 671, 'y': 795},
|
||||||
{'text': '5864', 'x': 664, 'y': 823}]
|
{'text': str(v), 'x': 664, 'y': 823}]
|
||||||
|
|
||||||
with mock.patch.object(auto_cycle, 'items', fake_items), \
|
return fake_items
|
||||||
|
|
||||||
|
def test_outlier_does_not_win(self):
|
||||||
|
# 5 次里 4 次 6388、1 次 8859 -> 取 6388
|
||||||
|
with mock.patch.object(auto_cycle, 'items', self._frames([6388, 8859, 6388, 6388, 6388])), \
|
||||||
|
mock.patch.object(auto_cycle.time, 'sleep', lambda s: None):
|
||||||
|
self.assertEqual(auto_cycle.read_lunacy(), 6388)
|
||||||
|
|
||||||
|
def test_retries_until_the_label_shows_up(self):
|
||||||
|
with mock.patch.object(auto_cycle, 'items', self._frames([None, None, 5864, 5864, 5864])), \
|
||||||
mock.patch.object(auto_cycle.time, 'sleep', lambda s: None):
|
mock.patch.object(auto_cycle.time, 'sleep', lambda s: None):
|
||||||
self.assertEqual(auto_cycle.read_lunacy(), 5864)
|
self.assertEqual(auto_cycle.read_lunacy(), 5864)
|
||||||
self.assertEqual(len(calls), 3)
|
|
||||||
|
|
||||||
def test_gives_up_after_retries(self):
|
def test_gives_up_when_never_agreeing(self):
|
||||||
with mock.patch.object(auto_cycle, 'items', lambda: [{'text': 'LV 042', 'x': 60, 'y': 800}]), \
|
# 每个值都只出现一次 -> 不采信, 宁可返回 None 也不要拿错值当基线
|
||||||
|
with mock.patch.object(auto_cycle, 'items', self._frames([1000, 2000, 3000, 4000, 5000])), \
|
||||||
|
mock.patch.object(auto_cycle.time, 'sleep', lambda s: None):
|
||||||
|
self.assertIsNone(auto_cycle.read_lunacy())
|
||||||
|
|
||||||
|
def test_off_main_menu_is_not_read(self):
|
||||||
|
# 结算画面: 有 LUNACY 标签和 4 位数, 但没有主界面的按钮
|
||||||
|
fake = [{'text': 'LUNACY', 'x': 671, 'y': 795},
|
||||||
|
{'text': '8859', 'x': 664, 'y': 823},
|
||||||
|
{'text': 'Mirror Dungeon Result', 'x': 700, 'y': 400}]
|
||||||
|
with mock.patch.object(auto_cycle, 'items', lambda: fake), \
|
||||||
mock.patch.object(auto_cycle.time, 'sleep', lambda s: None):
|
mock.patch.object(auto_cycle.time, 'sleep', lambda s: None):
|
||||||
self.assertIsNone(auto_cycle.read_lunacy())
|
self.assertIsNone(auto_cycle.read_lunacy())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user