Browse Source

Merge nearaura dev through fe65e54b for invite, focus and island fixes

Runhey still reports Repository not found. Integrate bb6f2103..fe65e54b
(five commits including two merge commits) with a normal history-preserving
merge from the authorized fallback; both destination dev branches started
at aa2307d3 and were independently rechecked before publication.

Adopt the upstream friend-tab PNG unchanged, together with its 56x15 ROI
and JSON metadata. Guard Hyakkiyakou focus selection when no track matches
the heatmap, clear stale focus, and return zero for off-screen sampling.
Adopt Moon Sea transition stabilization, up to three OCR/marker rereads,
and the store-island fallback when no other marker is available.

These fixes were absent locally. Retain local bounded random-island entry,
column-safe marker tracking, cancel priority, and all prior mail, raid,
exploration, retry, template search and battle isolation fixes recorded
in 3289033f and subsequent merges. No blanket ours/theirs resolution or
skipped mixed patch; the merge was conflict-free. Include upstream's four
new regression tests. No additional production changes were necessary.

Validation: 587 tests passed across tests/ and both FrogBoss suites (three
existing deprecation warnings). Changed Python syntax and production imports
passed. Verified upstream PNG byte identity, dimensions, JSON/rule agreement,
and real template matching positive/negative cases with 0/2-pixel padding.
Additional offline checks cover negative/overflow focus coordinates and
stale focus clearing. git diff --check passed. No emulator/game run.
unknown 1 day ago
parent
commit
9867fea3f6

+ 1 - 1
tasks/Component/GeneralInvite/assets.py

@@ -50,7 +50,7 @@ class GeneralInviteAssets:
 	# 判断是否点中好友了 
 	I_SELECTED = RuleImage(roi_front=(895,373,33,32), roi_back=(895,373,33,32), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_selected.png")
 	# 用来判断当前的列表是哪儿的 
-	I_FLAG_1_ON = RuleImage(roi_front=(354,126,62,21), roi_back=(354,126,62,21), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_flag_1_on.png")
+	I_FLAG_1_ON = RuleImage(roi_front=(358,129,56,15), roi_back=(358,129,56,15), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_flag_1_on.png")
 	# description 
 	I_FLAG_1_OFF = RuleImage(roi_front=(353,126,58,22), roi_back=(353,126,58,22), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_flag_1_off.png")
 	# description 

BIN
tasks/Component/GeneralInvite/gi/gi_flag_1_on.png


+ 2 - 2
tasks/Component/GeneralInvite/gi/image.json

@@ -173,8 +173,8 @@
   {
     "itemName": "flag_1_on",
     "imageName": "gi_flag_1_on.png",
-    "roiFront": "354,126,62,21",
-    "roiBack": "354,126,62,21",
+    "roiFront": "358,129,56,15",
+    "roiBack": "358,129,56,15",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "用来判断当前的列表是哪儿的"

+ 8 - 1
tasks/Hyakkiyakou/agent/agent.py

@@ -114,7 +114,7 @@ class Agent:
         return z
 
     @classmethod
-    def argmax_gamma(cls, z: np.ndarray, tracks: list[tuple]) -> Focus:
+    def argmax_gamma(cls, z: np.ndarray, tracks: list[tuple]) -> Focus | None:
         max_y, max_x = np.unravel_index(np.argmax(z), z.shape)
         max_variance = 2000
         max_index = -1
@@ -124,6 +124,8 @@ class Agent:
             if variance < max_variance:
                 max_index = index
                 max_variance = variance
+        if max_index < 0:
+            return None
         return Focus(inputs=tracks[max_index])
 
     def decision(self, tracks: list[tuple], state: list, freeze: bool = False) -> list:
@@ -147,6 +149,11 @@ class Agent:
     def check_observe(self, tracks: list[tuple]):
         z = Agent.gamma(tracks=tracks, weights=self.weights, priorities=self.priorities)
         focus = Agent.argmax_gamma(z=z, tracks=tracks)
+        if focus is None:
+            if self.focus is not None:
+                logger.info('Focus disappear')
+            self.focus = None
+            return
         omega = focus.omega(z)
         if omega < self.OBSERVE_THRESHOLD:
             if self.focus is not None:

+ 4 - 0
tasks/Hyakkiyakou/agent/focus.py

@@ -41,6 +41,10 @@ xywh: ({self._cx}, {self._cy}, {self._w}, {self._h})
 velocity: {self._v}"""
 
     def omega(self, z):
+        height, width = z.shape[:2]
+        if not (0 <= self._cy < height and 0 <= self._cx < width):
+            self._omega = 0.
+            return self._omega
         __omega = z[self._cy, self._cx]
         self._omega = __omega
         return __omega

+ 29 - 16
tasks/SixRealms/moon_sea/map.py

@@ -42,28 +42,41 @@ class MoonSeaMap(MoonSeaSkills):
         if nearest and abs(nearest[0] + nearest[2] / 2 - center_x) <= 60:
             return nearest
 
-    def decide(self, prefer_store=False) -> tuple:
-        self.screenshot()
-        if self.appear(self.I_BOSS_FIRE):
-            # 最后的boss
-            return MoonSeaType.island106, 0, (0, 0, 0, 0)
-        kind, rounds, roi = self._read_map_ocr()
+    def _island_candidates(self, skip_store=True) -> dict:
         candidates = {}
         for island in self.island_markers:
-            if island == MoonSeaType.island101 and self.appear(self.I_M_STORE):
+            if skip_store and island == MoonSeaType.island101 and self.appear(self.I_M_STORE):
                 continue
             boxes = self._marker_boxes(island)
             if boxes:
                 candidates[island] = boxes
-        if prefer_store and kind != MoonSeaType.island101 and MoonSeaType.island101 in candidates:
-            kind = MoonSeaType.island101
-            roi = max(candidates[kind])
-        elif kind != MoonSeaType.island100:
-            roi = self._nearby_marker(candidates.get(kind, []), roi) or roi
-        elif candidates:
-            # OCR 未识别出岛型时,沿用从右向左的选岛顺序。
-            kind, roi = max(((island, max(boxes)) for island, boxes in candidates.items()),
-                            key=lambda candidate: candidate[1][0])
+        return candidates
+
+    def decide(self, prefer_store=False) -> tuple:
+        # 转场还没结束就截图时,OCR 可能给出不在任何一列岛上的坐标。重读几次(每次约 1.2s,
+        # 转场一般 2~4s 内结束),重新拿到对得上标牌的坐标就能自愈。
+        for _ in range(3):
+            self.screenshot()
+            if self.appear(self.I_BOSS_FIRE):
+                # 最后的boss
+                return MoonSeaType.island106, 0, (0, 0, 0, 0)
+            kind, rounds, roi = self._read_map_ocr()
+            candidates = self._island_candidates()
+            if not candidates:
+                # 只剩宁息岛时也得进去,否则回合推进不了。
+                candidates = self._island_candidates(skip_store=False)
+            if prefer_store and kind != MoonSeaType.island101 and MoonSeaType.island101 in candidates:
+                kind = MoonSeaType.island101
+                roi = max(candidates[kind])
+            elif kind != MoonSeaType.island100:
+                roi = self._nearby_marker(candidates.get(kind, []), roi) or roi
+            elif candidates:
+                # OCR 未识别出岛型时,沿用从右向左的选岛顺序。
+                kind, roi = max(((island, max(boxes)) for island, boxes in candidates.items()),
+                                key=lambda candidate: candidate[1][0])
+            if not candidates.get(kind) or self._nearby_marker(candidates[kind], roi):
+                break
+            logger.warning('Island {} at {} matches no marker, re-read the map'.format(kind.name, roi))
         logger.info('Island type: {}, Residue: {}, ROI: {}'.format(kind, rounds, roi))
         return kind, rounds, roi
 

+ 2 - 0
tasks/SixRealms/moon_sea/moon_sea.py

@@ -55,6 +55,8 @@ class MoonSea(MoonSeaMap, MoonSeaL101, MoonSeaL102, MoonSeaL103, MoonSeaL104, Mo
     def one(self):
         self.cnt_skill101 = 1
         self._start()
+        # 选完技能还有「获得新技能」转场,先等地图稳定,免得把转场帧的坐标当成岛屿位置。
+        self.wait_animate_stable(self.C_MAIN_ANIMATE_KEEP, timeout=3)
         while 1:
             self.screenshot()
             if not self.in_main():

+ 28 - 0
tests/tasks/Hyakkiyakou/test_agent_focus.py

@@ -0,0 +1,28 @@
+import numpy as np
+
+from tasks.Hyakkiyakou.agent.agent import Agent
+from tasks.Hyakkiyakou.agent.focus import Focus
+
+# 2026-11-21 14:36:42 崩溃帧:两个 class=0 的框都不会画进热力图,
+# 最后一个框中心 x=1320,画面宽 1280。
+OFFSCREEN_FRAME = [
+    (41, 0, 0.9723028540611267, 847, 293, 41, 98, 0.041499774903059006),
+    (45, 0, 0.6597861051559448, 1320, 404, 64, 99, 0.3642634451389313),
+]
+
+
+def test_empty_heatmap_does_not_focus_the_last_offscreen_track():
+    agent = Agent()
+    z = Agent.gamma(OFFSCREEN_FRAME, weights=agent.weights, priorities=agent.priorities)
+
+    assert Agent.argmax_gamma(z, OFFSCREEN_FRAME) is None
+
+    agent.check_observe(OFFSCREEN_FRAME)
+    assert agent.focus is None
+
+
+def test_focus_outside_the_frame_reads_as_no_observation():
+    focus = Focus(inputs=OFFSCREEN_FRAME[-1])
+    z = np.zeros((720, 1280), dtype=np.float32)
+
+    assert focus.omega(z) == 0.0

+ 21 - 0
tests/test_six_realms_island_entry.py

@@ -83,6 +83,27 @@ class IslandEntryTests(unittest.TestCase):
                     patch.object(task, "_marker_boxes", side_effect=lambda kind: boxes.get(kind, [])):
                 self.assertEqual(task.decide(prefer_store=prefer_store), ocr)
 
+    def test_decide_rereads_when_ocr_box_matches_no_marker(self):
+        task = OfflineMoonSea()
+        stale = (870, 358, 20, 90)
+        fresh = (716, 396, 20, 90)
+        boxes = {MoonSeaType.island104: [fresh]}
+        with patch.object(task, "_read_map_ocr",
+                          side_effect=[(MoonSeaType.island104, 19, stale),
+                                       (MoonSeaType.island104, 19, fresh)]), \
+                patch.object(task, "_marker_boxes", side_effect=lambda kind: boxes.get(kind, [])):
+            self.assertEqual(task.decide(), (MoonSeaType.island104, 19, fresh))
+
+    def test_decide_falls_back_to_store_island_when_it_is_the_only_one(self):
+        task = OfflineMoonSea()
+        store = (649, 359, 20, 90)
+        with patch.object(task, "_read_map_ocr",
+                          return_value=(MoonSeaType.island100, 11, (0, 0, 0, 0))), \
+                patch.object(task, "_marker_boxes",
+                             side_effect=lambda kind: [store] if kind == MoonSeaType.island101 else []), \
+                patch.object(task, "appear", side_effect=lambda rule, **kwargs: rule is task.I_M_STORE):
+            self.assertEqual(task.decide(), (MoonSeaType.island101, 11, store))
+
     def test_disappearing_marker_times_out_without_clicking_adjacent_island(self):
         task = OfflineMoonSea()
         adjacent = (290, 330, 20, 90)