瀏覽代碼

Merge pull request #290 from runhey/hya

Hya
huangrunheng 2 年之前
父節點
當前提交
42776b11b9
共有 72 個文件被更改,包括 1907 次插入 和 27 次删除
  1. 1 1
      .gitignore
  2. 2 0
      README.md
  3. 1 1
      module/config/config_manual.py
  4. 2 1
      module/config/config_menu.py
  5. 2 0
      module/config/config_model.py
  6. 11 7
      module/device/method/window.py
  7. 2 1
      requirements-in.txt
  8. 1 0
      requirements.txt
  9. 3 1
      tasks/Hyakkiyakou/.gitignore
  10. 14 0
      tasks/Hyakkiyakou/README.md
  11. 165 0
      tasks/Hyakkiyakou/agent/agent.py
  12. 121 0
      tasks/Hyakkiyakou/agent/focus.py
  13. 5 0
      tasks/Hyakkiyakou/agent/utils.py
  14. 125 3
      tasks/Hyakkiyakou/assets.py
  15. 63 0
      tasks/Hyakkiyakou/config.py
  16. 217 0
      tasks/Hyakkiyakou/debugger.py
  17. 42 6
      tasks/Hyakkiyakou/hya/click.json
  18. 二進制
      tasks/Hyakkiyakou/hya/hya_bean0.png
  19. 二進制
      tasks/Hyakkiyakou/hya/hya_bean05.png
  20. 二進制
      tasks/Hyakkiyakou/hya/hya_bean1.png
  21. 二進制
      tasks/Hyakkiyakou/hya/hya_bean10.png
  22. 二進制
      tasks/Hyakkiyakou/hya/hya_bean2.png
  23. 二進制
      tasks/Hyakkiyakou/hya/hya_bean3.png
  24. 二進制
      tasks/Hyakkiyakou/hya/hya_bean4.png
  25. 二進制
      tasks/Hyakkiyakou/hya/hya_bean5.png
  26. 二進制
      tasks/Hyakkiyakou/hya/hya_bean6.png
  27. 二進制
      tasks/Hyakkiyakou/hya/hya_bean7.png
  28. 二進制
      tasks/Hyakkiyakou/hya/hya_bean8.png
  29. 二進制
      tasks/Hyakkiyakou/hya/hya_bean9.png
  30. 二進制
      tasks/Hyakkiyakou/hya/hya_friend_remote_1.png
  31. 二進制
      tasks/Hyakkiyakou/hya/hya_friend_remote_2.png
  32. 二進制
      tasks/Hyakkiyakou/hya/hya_friend_same_1.png
  33. 二進制
      tasks/Hyakkiyakou/hya/hya_friend_same_2.png
  34. 二進制
      tasks/Hyakkiyakou/hya/hya_hclose_red.png
  35. 二進制
      tasks/Hyakkiyakou/hya/hya_htitle.png
  36. 二進制
      tasks/Hyakkiyakou/hya/hya_hya_state_buff02.png
  37. 二進制
      tasks/Hyakkiyakou/hya/hya_hya_state_buff03.png
  38. 二進制
      tasks/Hyakkiyakou/hya/hya_hya_state_buff05.png
  39. 二進制
      tasks/Hyakkiyakou/hya/hya_hya_state_buff06.png
  40. 二進制
      tasks/Hyakkiyakou/hya/hya_hya_state_buff07.png
  41. 二進制
      tasks/Hyakkiyakou/hya/hya_resf_0.png
  42. 二進制
      tasks/Hyakkiyakou/hya/hya_resf_1.png
  43. 二進制
      tasks/Hyakkiyakou/hya/hya_resf_2.png
  44. 二進制
      tasks/Hyakkiyakou/hya/hya_resf_3.png
  45. 二進制
      tasks/Hyakkiyakou/hya/hya_resf_4.png
  46. 二進制
      tasks/Hyakkiyakou/hya/hya_resf_5.png
  47. 二進制
      tasks/Hyakkiyakou/hya/hya_resf_6.png
  48. 二進制
      tasks/Hyakkiyakou/hya/hya_resf_7.png
  49. 二進制
      tasks/Hyakkiyakou/hya/hya_resf_8.png
  50. 二進制
      tasks/Hyakkiyakou/hya/hya_resf_9.png
  51. 二進制
      tasks/Hyakkiyakou/hya/hya_resr_0.png
  52. 二進制
      tasks/Hyakkiyakou/hya/hya_resr_1.png
  53. 二進制
      tasks/Hyakkiyakou/hya/hya_resr_2.png
  54. 二進制
      tasks/Hyakkiyakou/hya/hya_resr_3.png
  55. 二進制
      tasks/Hyakkiyakou/hya/hya_resr_4.png
  56. 二進制
      tasks/Hyakkiyakou/hya/hya_resr_5.png
  57. 二進制
      tasks/Hyakkiyakou/hya/hya_resr_6.png
  58. 二進制
      tasks/Hyakkiyakou/hya/hya_resr_7.png
  59. 二進制
      tasks/Hyakkiyakou/hya/hya_resr_8.png
  60. 二進制
      tasks/Hyakkiyakou/hya/hya_resr_9.png
  61. 18 0
      tasks/Hyakkiyakou/hya/image1.json
  62. 47 0
      tasks/Hyakkiyakou/hya/image2.json
  63. 182 0
      tasks/Hyakkiyakou/hya/image3.json
  64. 110 0
      tasks/Hyakkiyakou/hya/image4.json
  65. 38 0
      tasks/Hyakkiyakou/hya/image5.json
  66. 11 0
      tasks/Hyakkiyakou/hya/ocr.json
  67. 16 0
      tasks/Hyakkiyakou/hya/swipe.json
  68. 8 6
      tasks/Hyakkiyakou/prepare/get_images.py
  69. 245 0
      tasks/Hyakkiyakou/script_task.py
  70. 58 0
      tasks/Hyakkiyakou/slave/hya_color.py
  71. 55 0
      tasks/Hyakkiyakou/slave/hya_device.py
  72. 342 0
      tasks/Hyakkiyakou/slave/hya_slave.py

+ 1 - 1
.gitignore

@@ -33,7 +33,7 @@ module/config/argument/setting.json
 !dev_tools/Spyxx/spyxx_amd64.exe
 !dev_tools/Spyxx/spyxx_amd64.exe
 !dev_tools/ViewWizard2/ViewWizard2.exe
 !dev_tools/ViewWizard2/ViewWizard2.exe
 !dev_tools/ViewWizard3/ViewWizard.exe
 !dev_tools/ViewWizard3/ViewWizard.exe
-hya
+./hya
 
 
 
 
 
 

+ 2 - 0
README.md

@@ -53,6 +53,8 @@ This project is licensed under the GNU General Public License v3.0.
 
 
 ## 声明 Announcement
 ## 声明 Announcement
 本软件开源、免费,仅供学习交流使用。开发者团队拥有本项目的最终解释权。使用本软件产生的所有问题与本项目与开发者团队无关。
 本软件开源、免费,仅供学习交流使用。开发者团队拥有本项目的最终解释权。使用本软件产生的所有问题与本项目与开发者团队无关。
+OAS is a free open source software, if you paid for OAS from any channel, please refund.
+OAS 是一款免费开源软件,如果你在任何渠道付费购买了OAS,请退款。
 
 
 ## 关于 Alas
 ## 关于 Alas
 OAS 基于碧蓝航线脚本 [AzurLaneAutoScript](https://github.com/LmeSzinc/AzurLaneAutoScript) 开发,考虑到星穹铁道脚本 [StarRailCopilot](https://github.com/LmeSzinc/StarRailCopilot) 中所提及的问题,
 OAS 基于碧蓝航线脚本 [AzurLaneAutoScript](https://github.com/LmeSzinc/AzurLaneAutoScript) 开发,考虑到星穹铁道脚本 [StarRailCopilot](https://github.com/LmeSzinc/StarRailCopilot) 中所提及的问题,

+ 1 - 1
module/config/config_manual.py

@@ -17,7 +17,7 @@ class ConfigManual:
         > BondlingFairyland > EvoZone > GoryouRealm
         > BondlingFairyland > EvoZone > GoryouRealm
         > TrueOrochi > RichMan
         > TrueOrochi > RichMan
         > CollectiveMissions
         > CollectiveMissions
-        > Pets > TalismanPass > SoulsTidy > Delegation
+        > Pets > TalismanPass > SoulsTidy > Delegation > Hyakkiyakou
         > Secret > WeeklyTrifles > MysteryShop > Duel > MetaDemon > FrogBoss
         > Secret > WeeklyTrifles > MysteryShop > Duel > MetaDemon > FrogBoss
         """
         """
 
 

+ 2 - 1
module/config/config_menu.py

@@ -25,7 +25,8 @@ class ConfigMenu:
                                    'TalismanPass', 'DemonEncounter', 'Pets', 'SoulsTidy', 'Delegation', 'WantedQuests',
                                    'TalismanPass', 'DemonEncounter', 'Pets', 'SoulsTidy', 'Delegation', 'WantedQuests',
                                    'Tako']
                                    'Tako']
         # 很肝的任务
         # 很肝的任务
-        self.menu["Liver Emperor Exclusive"] = ['BondlingFairyland', 'EvoZone', 'GoryouRealm', 'Exploration',]
+        self.menu["Liver Emperor Exclusive"] = ['BondlingFairyland', 'EvoZone', 'GoryouRealm', 'Exploration',
+                                                'Hyakkiyakou']
         # 阴阳寮
         # 阴阳寮
         self.menu["Guild"] = ['KekkaiUtilize', 'KekkaiActivation', 'RealmRaid', 'RyouToppa', 'CollectiveMissions',
         self.menu["Guild"] = ['KekkaiUtilize', 'KekkaiActivation', 'RealmRaid', 'RyouToppa', 'CollectiveMissions',
                               'Hunt']
                               'Hunt']

+ 2 - 0
module/config/config_model.py

@@ -54,6 +54,7 @@ from tasks.FrogBoss.config import FrogBoss
 from tasks.BondlingFairyland.config import BondlingFairyland
 from tasks.BondlingFairyland.config import BondlingFairyland
 from tasks.EvoZone.config import EvoZone
 from tasks.EvoZone.config import EvoZone
 from tasks.GoryouRealm.config import GoryouRealm
 from tasks.GoryouRealm.config import GoryouRealm
+from tasks.Hyakkiyakou.config import Hyakkiyakou
 # ----------------------------------------------------------------------------------------------------------------------
 # ----------------------------------------------------------------------------------------------------------------------
 
 
 # 每周任务---------------------------------------------------------------------------------------------------------------
 # 每周任务---------------------------------------------------------------------------------------------------------------
@@ -106,6 +107,7 @@ class ConfigModel(ConfigBase):
     bondling_fairyland: BondlingFairyland = Field(default_factory=BondlingFairyland)
     bondling_fairyland: BondlingFairyland = Field(default_factory=BondlingFairyland)
     evo_zone: EvoZone = Field(default_factory=EvoZone)
     evo_zone: EvoZone = Field(default_factory=EvoZone)
     goryou_realm: GoryouRealm = Field(default_factory=GoryouRealm)
     goryou_realm: GoryouRealm = Field(default_factory=GoryouRealm)
+    hyakkiyakou: Hyakkiyakou = Field(default_factory=Hyakkiyakou)
 
 
     # 这些是每周任务
     # 这些是每周任务
     true_orochi: TrueOrochi = Field(default_factory=TrueOrochi)
     true_orochi: TrueOrochi = Field(default_factory=TrueOrochi)

+ 11 - 7
module/device/method/window.py

@@ -130,11 +130,12 @@ class Window(Handle):
         logger.info(f"Mumu emulator head height: {height}")
         logger.info(f"Mumu emulator head height: {height}")
         return height
         return height
 
 
-    def click_window_message(self, x: int, y: int):
+    def click_window_message(self, x: int, y: int, fast: bool = False):
         """
         """
 
 
         :param x:
         :param x:
         :param y:
         :param y:
+        :param fast:
         :return:
         :return:
         """
         """
         # 我不知道为什么的使用的pywin32==306的版本会导致获取的图片的是(1024, 576)
         # 我不知道为什么的使用的pywin32==306的版本会导致获取的图片的是(1024, 576)
@@ -143,7 +144,10 @@ class Window(Handle):
 
 
         x = int(x / self.window_scale_rate)
         x = int(x / self.window_scale_rate)
         y = int(y / self.window_scale_rate)
         y = int(y / self.window_scale_rate)
-        # print(f"我点击的x:{x}, y:{y}")
+        if fast:
+            press_time: float = (random.randint(10, 40)) / 1000.0
+        else:
+            press_time: float = (random.randint(100, 200)) / 1000.0
         emulator_type = len(self.control_handle_list)
         emulator_type = len(self.control_handle_list)
         if emulator_type == 2:  # mumu模拟器
         if emulator_type == 2:  # mumu模拟器
             SendMessage(self.control_handle_list[0], WM_ACTIVATE, WA_ACTIVE, 0)  # 激活窗口
             SendMessage(self.control_handle_list[0], WM_ACTIVATE, WA_ACTIVE, 0)  # 激活窗口
@@ -151,20 +155,20 @@ class Window(Handle):
             # SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y+self.mumu_head_height))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
             # SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y+self.mumu_head_height))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
             # mumu12模拟器 V3.5.16 之后后可以用下面的方式
             # mumu12模拟器 V3.5.16 之后后可以用下面的方式
             SendMessage(self.control_handle_list[1], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
             SendMessage(self.control_handle_list[1], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
-            time.sleep((random.randint(100, 200)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
+            time.sleep(press_time)
             SendMessage(self.control_handle_list[1], WM_LBUTTONUP, 0, MAKELONG(x, y))  # 模拟鼠标弹起 后是子窗口
             SendMessage(self.control_handle_list[1], WM_LBUTTONUP, 0, MAKELONG(x, y))  # 模拟鼠标弹起 后是子窗口
         elif emulator_type > 2:  # 夜神模拟器
         elif emulator_type > 2:  # 夜神模拟器
             SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
             SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
             SendMessage(self.control_handle_list[1], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
             SendMessage(self.control_handle_list[1], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
             SendMessage(self.control_handle_list[2], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
             SendMessage(self.control_handle_list[2], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
             SendMessage(self.control_handle_list[3], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
             SendMessage(self.control_handle_list[3], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
-            time.sleep((random.randint(100, 200)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
+            time.sleep(press_time)
             SendMessage(self.control_handle_list[3], WM_LBUTTONUP, 0, MAKELONG(x, y))  # 模拟鼠标弹起 后是子窗口
             SendMessage(self.control_handle_list[3], WM_LBUTTONUP, 0, MAKELONG(x, y))  # 模拟鼠标弹起 后是子窗口
         elif emulator_type == 1:  # 雷电模拟器
         elif emulator_type == 1:  # 雷电模拟器
             clickPos = MAKELONG(x, y)
             clickPos = MAKELONG(x, y)
-            SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, clickPos)  # 模拟鼠标按下
-            time.sleep((random.randint(100, 300)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
-            SendMessage(self.control_handle_list[0], WM_LBUTTONUP, 0, clickPos)  # 模拟鼠标弹起
+            SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, clickPos)
+            time.sleep(press_time)
+            SendMessage(self.control_handle_list[0], WM_LBUTTONUP, 0, clickPos)
 
 
     def long_click_window_message(self, x: int, y: int, duration: float):
     def long_click_window_message(self, x: int, y: int, duration: float):
         """
         """

+ 2 - 1
requirements-in.txt

@@ -18,4 +18,5 @@ ppocr-onnx==0.0.3.9
 onepush==1.2.0
 onepush==1.2.0
 paho-mqtt==1.6.1
 paho-mqtt==1.6.1
 fastapi==0.104.1
 fastapi==0.104.1
-uvicorn==0.23.2
+uvicorn==0.23.2
+oashya

+ 1 - 0
requirements.txt

@@ -39,6 +39,7 @@ mdurl==0.1.2              # via markdown-it-py
 mpmath==1.3.0             # via sympy
 mpmath==1.3.0             # via sympy
 msgpack==1.0.7            # via zerorpc
 msgpack==1.0.7            # via zerorpc
 numpy==1.24.3             # via -r requirements-in.txt, onnxruntime, opencv-python, ppocr-onnx, shapely
 numpy==1.24.3             # via -r requirements-in.txt, onnxruntime, opencv-python, ppocr-onnx, shapely
+oashya==0.0.7             # via -r requirements-in.txt
 onepush==1.2.0            # via -r requirements-in.txt
 onepush==1.2.0            # via -r requirements-in.txt
 onnxruntime==1.16.3       # via ppocr-onnx
 onnxruntime==1.16.3       # via ppocr-onnx
 opencv-python==4.7.0.72   # via -r requirements-in.txt, ppocr-onnx
 opencv-python==4.7.0.72   # via -r requirements-in.txt, ppocr-onnx

+ 3 - 1
tasks/Hyakkiyakou/.gitignore

@@ -1,3 +1,5 @@
 
 
 /utils/exp_gen.py
 /utils/exp_gen.py
-/temp
+/temp
+/agent/tagent.py
+/agent/tfocus.py

+ 14 - 0
tasks/Hyakkiyakou/README.md

@@ -0,0 +1,14 @@
+
+
+
+- agent: 砸豆子的决策模型
+- slave: 针对百鬼对接模拟器的接口
+- debugger.py: 辅助
+---
+
+detector: 检测器
+
+tracker: 跟踪器
+
+
+

+ 165 - 0
tasks/Hyakkiyakou/agent/agent.py

@@ -0,0 +1,165 @@
+import cv2
+import time
+import copy
+import numpy as np
+
+from datetime import datetime
+from pathlib import Path
+from numpy import uint8, fromfile
+from cached_property import cached_property
+
+from oashya.tracker import Tracker
+from oashya.labels import CLASSINDEX as CI
+from oashya.labels import id2label, id2name
+from module.logger import logger
+from tasks.Hyakkiyakou.agent.focus import Focus
+from tasks.Hyakkiyakou.debugger import Debugger
+
+
+def generate_gaussian_patch(size=(300, 300), mean=0, std_dev=60):
+    x = np.linspace(-150, 150, size[1])
+    y = np.linspace(-150, 150, size[0])
+    x, y = np.meshgrid(x, y)
+    z = np.exp(-(((x - mean) ** 2 + (y - mean) ** 2) / (2 * std_dev ** 2)))
+    return z
+
+
+def embed_patch_in_canvas(canvas, patch, position=(0, 0), patch_size=(300, 300)):
+    canvas_height, canvas_width = 720, 1280
+    patch_height, patch_width = patch_size
+    pos_x, pos_y = position
+    pos_x = max(0, min(pos_x, canvas_width))
+    pos_y = max(0, min(pos_y, canvas_width))
+
+    x1 = pos_x - patch_width // 2
+    y1 = pos_y - patch_height // 2
+    x2 = pos_x + patch_width // 2
+    y2 = pos_y + patch_height // 2
+    x1 = max(0, x1)
+    y1 = max(0, y1)
+    x2 = min(canvas_width, x2)
+    y2 = min(canvas_height, y2)
+    embed_w = x2 - x1
+    embed_h = y2 - y1
+    if embed_w <= 0 or embed_h <= 0:
+        logger.warning(f'Cannot embed patch in canvas: ({position})')
+        return canvas
+    if embed_w < patch_width or embed_h < patch_height:
+        _patch = patch[:embed_h, :embed_w]
+    else:
+        _patch = patch
+    # Embed the patch in the canvas
+    canvas[y1:y2, x1:x2] += _patch
+    return canvas
+
+
+class Agent:
+    GAUSSIAN = generate_gaussian_patch()
+    OBSERVE_THRESHOLD = 0.6
+    # --------------------------------------------------------------------------------
+
+    def __init__(self, strategy: dict = None):
+        self.z = np.zeros((720, 1280), dtype=np.float32)
+        self.focus: Focus = None
+        # 
+        strategy: dict = strategy if strategy is not None else {
+            # 'weights': [1., 1., 1., 0.6, 0.3, 0.3],
+            'priorities': [],
+            'invite_friend': False,
+            'auto_bean': False
+        }
+        self.strategy = strategy
+        self.weights: list[float] = strategy.get('weights', [1., 1., 0.7, 0.3, 0., 0.])
+        self.priorities: list[int] = strategy.get('priorities', [])
+        self.invite_friend: bool = strategy.get('invite_friend', False)
+        self.auto_bean: bool = strategy.get('auto_bean', False)
+        #
+        self.last_throw_time = datetime.now()
+        self.dbg_throw: int = 0
+        self.dbg_throw_n: int = 0
+
+    @classmethod
+    def gamma(cls, tracks: list[tuple],
+              weights: list[float],
+              priorities: list[int] = []) -> np.ndarray:
+        """
+        @param tracks:
+        @param weights: sp, ssr, sr, r, n, g
+        @param priorities:
+        @return:
+        """
+        z = np.zeros((720, 1280), dtype=np.float32)
+        for _id, _class, _conf, _cx, _cy, _w, _h, _v in tracks:
+            weight = 1.
+            mu = 0.8 + (_cx * 0.2) / 1280
+            match _class:
+                case _ if CI.MIN_G <= _class <= CI.MAX_G: weight = weights[5]
+                case _ if CI.MIN_N <= _class <= CI.MAX_N: weight = weights[4]
+                case _ if _class != CI.R_008 and _class != CI.R_007 and (CI.MIN_R <= _class <= CI.MAX_R):
+                    weight = weights[3]  # 不要童男童女
+                case _ if CI.MIN_SR <= _class <= CI.MAX_SR: weight = weights[2]
+                case _ if CI.MIN_SSR <= _class <= CI.MAX_SSR: weight = 1.5 * weights[1]
+                case _ if CI.MIN_SP <= _class <= CI.MAX_SP: weight = 1.5 * weights[0]
+                case CI.BUFF_005:  # freeze
+                    weight = -1.
+                    _cy += 100
+                case _: continue
+            for priority in priorities:  # 我的代码在你之上
+                if priority == _class:
+                    weight = 1.7
+                    break
+            if weight == 0.:
+                continue
+            z = embed_patch_in_canvas(canvas=z, patch=(mu * weight) * Agent.GAUSSIAN, position=(_cx, _cy))
+        return z
+
+    @classmethod
+    def argmax_gamma(cls, z: np.ndarray, tracks: list[tuple]) -> Focus:
+        max_y, max_x = np.unravel_index(np.argmax(z), z.shape)
+        max_variance = 2000
+        max_index = -1
+        for index, track in enumerate(tracks):
+            _id, _class, _conf, _cx, _cy, _w, _h, _v = track
+            variance = (max_x - _cx)**2 + (max_y - _cy)**2
+            if variance < max_variance:
+                max_index = index
+                max_variance = variance
+        return Focus(inputs=tracks[max_index])
+
+    def decision(self, tracks: list[tuple], state: list) -> list:
+        not_decision = [-1, -1, False, -1]
+        if not tracks:
+            return not_decision
+        # Cache the time interval for scattering beans
+        new_time = datetime.now()
+        delta_time = 1000 * (new_time - self.last_throw_time).total_seconds()  # ms
+        self.check_observe(tracks=tracks)
+        if self.focus is None:
+            return not_decision
+        result = self.focus.decision(tracks=tracks, strategy=self.strategy, state=[delta_time] + state)
+        if result[2]:
+            self.last_throw_time = new_time
+            self.dbg_throw += 1
+        else:
+            self.dbg_throw_n += 1
+        return result
+
+    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)
+        omega = focus.omega(z)
+        if omega < self.OBSERVE_THRESHOLD:
+            if self.focus is not None:
+                logger.info(f'Focus disappear')
+            self.focus = None
+            return
+        if self.focus is None or self.focus != focus:
+            logger.info(f'Focus changed, now: {id2name(focus._class)}')
+            self.focus = focus
+            self.focus.set_omega(omega)
+        elif self.focus == focus:
+            self.focus.update(focus)
+            self.focus.set_omega(omega)
+        # if Debugger.info_enable:
+        #     self.focus.show()
+

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

@@ -0,0 +1,121 @@
+import numpy as np
+
+from rich.table import Table
+from rich.text import Text
+from cached_property import cached_property
+
+from module.logger import logger
+
+from oashya.labels import id2label, id2name
+from oashya.labels import CLASSINDEX as CI
+
+
+class Focus:
+    def __init__(self, inputs: list[tuple]):
+        self._id: int = inputs[0]
+        self._class: int = inputs[1]
+        self._conf: int = inputs[2]
+        self._cx: int = inputs[3]
+        self._cy: int = inputs[4]
+        self._w: int = inputs[5]
+        self._h: int = inputs[6]
+        self._v: float = inputs[7]
+        # -----------------------
+        self._omega: float = 0.
+        self._omega_buff: float = 0.
+
+    def __eq__(self, o):
+        return self._id == o._id or o._class == self._class
+
+    def __str__(self):
+        return f"""
+id: {self._id}
+class: {self._class}
+label: {id2label(self._class)}
+name: {id2name(self._class)}
+conf: {self._conf}
+xywh: ({self._cx}, {self._cy}, {self._w}, {self._h})
+velocity: {self._v}"""
+
+    def omega(self, z):
+        __omega = z[self._cy, self._cx]
+        self._omega = __omega
+        return __omega
+
+    def set_omega(self, value):
+        self._omega = value
+
+    def show(self):
+        table = Table(show_lines=True)
+        table.add_column('Property', header_style="bright_cyan", style="cyan", no_wrap=True)
+        table.add_column("Value", style="green")
+        table.add_column('Property', header_style="bright_cyan", style="cyan", no_wrap=True)
+        table.add_column("Value", style="green")
+        table.add_row('id', str(self._id), 'conf', str(self._conf))
+        table.add_row('class', str(self._class), 'xywh', f'({self._cx}, {self._cy}, {self._w}, {self._h})')
+        table.add_row('label', id2label(self._class), 'velocity', str(self._v))
+        table.add_row('name', f'{id2name(self._class)}', 'omega', str(self._omega))
+        logger.print(table, justify='center')
+
+    def update(self, focus):
+        self._id = focus._id
+        self._class = focus._class
+        self._conf = focus._conf
+        self._cx = focus._cx
+        self._cy = focus._cy
+        self._w = focus._w
+        self._h = focus._h
+        self._v = focus._v
+
+    def decision(self, tracks, strategy, state) -> list:
+
+        buff_omega, buff_cx, buff_cy, buff_v, buff_class = self.omega_buff(tracks, strategy['invite_friend'])
+        if self._omega > buff_omega:
+            buffed = False
+            target_x = self._cx + self._v * 100 - (self._w // 2)
+            target_y = self._cy - 40
+        else:
+            buffed = True
+            target_x = buff_cx + buff_v * 100
+            target_y = buff_cy - 40  # top left corner
+
+        _r = self.r(vector=state, omega=self._omega, omega_buff=self._omega_buff)
+        throw = True if _r > 0 else False
+        # x, y, throw, number
+        return [target_x, target_y, throw, 10]
+
+    def omega_buff(self, tracks, invite_friend: bool) -> float:
+        max_omega = 0.
+        max_cx = 0
+        max_cy = 0
+        max_v = 0
+        max_class = 0
+
+        for _id, _class, _conf, _cx, _cy, _w, _h, _v in tracks:
+            _current_omega = 0.
+            match _class:
+                case CI.BUFF_004: _current_omega = 2.2
+                case CI.BUFF_006: _current_omega = 2.0
+                case CI.BUFF_007: _current_omega = 2.0 if invite_friend and _cx <= 1000 else 0
+                case CI.BUFF_002: _current_omega = 2.0 if self._omega >= 1.5 else 0
+                case CI.BUFF_003: _current_omega = 2.0 if self._omega >= 1.5 else 0
+                case CI.BUFF_003: _current_omega = 2.0 if self._omega >= 1.5 and _cx <= 640 else 0
+                case _: pass
+            if _current_omega > max_omega:
+                max_omega = _current_omega
+                max_cx = _cx
+                max_cy = _cy
+                max_v = _v
+                max_class = _class
+        return max_omega, max_cx, max_cy, max_v, max_class
+            
+    @classmethod
+    def r(cls, vector: list, omega: float, omega_buff: float) -> float:
+        _omega = max(omega, omega_buff)
+        tau = - 140 / (max(101, vector[0]) - 100)
+        upsilon = (vector[1] / 250 - vector[2] / 35)
+        upsilon = 100 * (upsilon**2 if upsilon > 0 else - upsilon**2)
+        result = _omega + tau + upsilon - 0.6
+        # print(f"total: {result:.4f} | {_omega:.4f} | {tau:.4f} | {upsilon:.4f}")
+        return result
+

+ 5 - 0
tasks/Hyakkiyakou/agent/utils.py

@@ -0,0 +1,5 @@
+
+
+
+
+

+ 125 - 3
tasks/Hyakkiyakou/assets.py

@@ -12,11 +12,23 @@ class HyakkiyakouAssets:
 
 
 	# Click Rule Assets
 	# Click Rule Assets
 	# description 
 	# description 
-	C_HSELECT_1 = RuleClick(roi_front=(158,209,225,405), roi_back=(158,209,225,405), name="hselect_1")
+	C_HSELECT_1 = RuleClick(roi_front=(200,318,115,273), roi_back=(200,318,115,273), name="hselect_1")
 	# description 
 	# description 
-	C_HSELECT_2 = RuleClick(roi_front=(531,225,202,363), roi_back=(531,225,202,363), name="hselect_2")
+	C_HSELECT_2 = RuleClick(roi_front=(570,307,142,285), roi_back=(570,307,142,285), name="hselect_2")
 	# description 
 	# description 
-	C_HSELECT_3 = RuleClick(roi_front=(875,210,219,394), roi_back=(875,210,219,394), name="hselect_3")
+	C_HSELECT_3 = RuleClick(roi_front=(934,298,115,306), roi_back=(934,298,115,306), name="hselect_3")
+	# description 
+	C_FRIEND_1 = RuleClick(roi_front=(446,227,181,67), roi_back=(446,227,181,67), name="friend_1")
+	# description 
+	C_FRIEND_2 = RuleClick(roi_front=(718,229,178,64), roi_back=(718,229,178,64), name="friend_2")
+	# description 
+	C_FRIEND_3 = RuleClick(roi_front=(445,310,183,66), roi_back=(445,310,183,66), name="friend_3")
+	# description 
+	C_FRIEND_4 = RuleClick(roi_front=(712,311,184,62), roi_back=(712,311,184,62), name="friend_4")
+	# description 
+	C_FRIEND_5 = RuleClick(roi_front=(449,394,178,61), roi_back=(449,394,178,61), name="friend_5")
+	# description 
+	C_FRIEND_6 = RuleClick(roi_front=(714,397,182,62), roi_back=(714,397,182,62), name="friend_6")
 
 
 
 
 	# Image Rule Assets
 	# Image Rule Assets
@@ -32,6 +44,116 @@ class HyakkiyakouAssets:
 	I_HEND = RuleImage(roi_front=(81,164,86,299), roi_back=(81,164,86,299), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hend.png")
 	I_HEND = RuleImage(roi_front=(81,164,86,299), roi_back=(81,164,86,299), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hend.png")
 	# 冰冻 
 	# 冰冻 
 	I_HFREEZE = RuleImage(roi_front=(1092,665,187,54), roi_back=(1092,665,187,54), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hfreeze.png")
 	I_HFREEZE = RuleImage(roi_front=(1092,665,187,54), roi_back=(1092,665,187,54), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hfreeze.png")
+	# description 
+	I_HTITLE = RuleImage(roi_front=(578,21,134,48), roi_back=(578,21,134,48), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_htitle.png")
+	# description 
+	I_HCLOSE_RED = RuleImage(roi_front=(1056,177,54,54), roi_back=(1056,177,54,54), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hclose_red.png")
+
+
+	# Image Rule Assets
+	# 左边概率up 
+	I_HYA_STATE_BUFF06 = RuleImage(roi_front=(331,7,126,41), roi_back=(137,1,342,66), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hya_state_buff06.png")
+	# 冰冻 
+	I_HYA_STATE_BUFF05 = RuleImage(roi_front=(158,5,127,45), roi_back=(147,0,322,62), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hya_state_buff05.png")
+	# 左边好友up 
+	I_HYA_STATE_BUFF07 = RuleImage(roi_front=(157,7,127,43), roi_back=(143,0,347,80), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hya_state_buff07.png")
+	# 左边减速 
+	I_HYA_STATE_BUFF02 = RuleImage(roi_front=(157,6,128,39), roi_back=(146,1,348,55), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hya_state_buff02.png")
+	# 左边砸豆加速 
+	I_HYA_STATE_BUFF03 = RuleImage(roi_front=(326,4,129,44), roi_back=(143,3,326,59), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_hya_state_buff03.png")
+
+
+	# Image Rule Assets
+	# description 
+	I_RESF_0 = RuleImage(roi_front=(615,13,30,46), roi_back=(606,11,43,51), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_0.png")
+	# description 
+	I_RESF_1 = RuleImage(roi_front=(617,13,31,46), roi_back=(610,11,42,50), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_1.png")
+	# description 
+	I_RESF_2 = RuleImage(roi_front=(611,14,33,47), roi_back=(602,10,47,57), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_2.png")
+	# description 
+	I_RESF_3 = RuleImage(roi_front=(619,14,28,45), roi_back=(610,12,40,49), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_3.png")
+	# description 
+	I_RESF_4 = RuleImage(roi_front=(611,14,37,47), roi_back=(608,14,43,47), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_4.png")
+	# description 
+	I_RESF_5 = RuleImage(roi_front=(612,10,35,48), roi_back=(612,10,35,48), threshold=0.9, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_5.png")
+	# description 
+	I_RESF_6 = RuleImage(roi_front=(616,10,29,49), roi_back=(616,10,29,49), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_6.png")
+	# description 
+	I_RESF_7 = RuleImage(roi_front=(611,14,38,44), roi_back=(611,14,38,44), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_7.png")
+	# description 
+	I_RESF_8 = RuleImage(roi_front=(615,10,32,50), roi_back=(615,10,32,50), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_8.png")
+	# description 
+	I_RESF_9 = RuleImage(roi_front=(612,12,38,49), roi_back=(612,12,38,49), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resf_9.png")
+	# description 
+	I_RESR_0 = RuleImage(roi_front=(636,11,34,47), roi_back=(636,11,34,47), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_0.png")
+	# description 
+	I_RESR_1 = RuleImage(roi_front=(638,13,29,48), roi_back=(638,13,29,48), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_1.png")
+	# description 
+	I_RESR_2 = RuleImage(roi_front=(639,15,30,39), roi_back=(639,15,30,39), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_2.png")
+	# description 
+	I_RESR_3 = RuleImage(roi_front=(639,14,30,41), roi_back=(639,14,30,41), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_3.png")
+	# description 
+	I_RESR_4 = RuleImage(roi_front=(636,13,32,46), roi_back=(636,13,32,46), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_4.png")
+	# description 
+	I_RESR_5 = RuleImage(roi_front=(639,13,31,46), roi_back=(639,13,31,46), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_5.png")
+	# description 
+	I_RESR_6 = RuleImage(roi_front=(638,12,32,44), roi_back=(638,12,32,44), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_6.png")
+	# description 
+	I_RESR_7 = RuleImage(roi_front=(638,15,34,42), roi_back=(638,15,34,42), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_7.png")
+	# description 
+	I_RESR_8 = RuleImage(roi_front=(638,13,33,47), roi_back=(638,13,33,47), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_8.png")
+	# description 
+	I_RESR_9 = RuleImage(roi_front=(638,12,32,47), roi_back=(638,12,32,47), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_resr_9.png")
+
+
+	# Image Rule Assets
+	# description 
+	I_BEAN0 = RuleImage(roi_front=(150,648,13,22), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean0.png")
+	# description 
+	I_BEAN1 = RuleImage(roi_front=(134,648,11,22), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean1.png")
+	# description 
+	I_BEAN2 = RuleImage(roi_front=(134,649,14,21), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean2.png")
+	# description 
+	I_BEAN3 = RuleImage(roi_front=(134,649,14,21), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean3.png")
+	# description 
+	I_BEAN4 = RuleImage(roi_front=(135,647,13,23), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean4.png")
+	# description 
+	I_BEAN5 = RuleImage(roi_front=(135,649,13,22), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean5.png")
+	# description 
+	I_BEAN6 = RuleImage(roi_front=(132,649,15,21), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean6.png")
+	# description 
+	I_BEAN7 = RuleImage(roi_front=(133,648,15,22), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean7.png")
+	# description 
+	I_BEAN8 = RuleImage(roi_front=(132,646,14,23), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean8.png")
+	# description 
+	I_BEAN9 = RuleImage(roi_front=(133,649,15,21), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean9.png")
+	# description 
+	I_BEAN05 = RuleImage(roi_front=(387,640,32,35), roi_back=(371,631,86,52), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean05.png")
+	# description 
+	I_BEAN10 = RuleImage(roi_front=(560,640,32,35), roi_back=(531,634,72,47), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_bean10.png")
+
+
+	# Image Rule Assets
+	# description 
+	I_FRIEND_SAME_1 = RuleImage(roi_front=(375,122,106,62), roi_back=(375,122,106,62), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_friend_same_1.png")
+	# description 
+	I_FRIEND_REMOTE_1 = RuleImage(roi_front=(498,125,106,56), roi_back=(498,125,106,56), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_friend_remote_1.png")
+	# description 
+	I_FRIEND_SAME_2 = RuleImage(roi_front=(377,126,100,60), roi_back=(377,126,100,60), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_friend_same_2.png")
+	# description 
+	I_FRIEND_REMOTE_2 = RuleImage(roi_front=(504,127,100,56), roi_back=(504,127,100,56), threshold=0.8, method="Template matching", file="./tasks/Hyakkiyakou/hya/hya_friend_remote_2.png")
+
+
+	# Ocr Rule Assets
+	# 最坏的情况下来判断豆子的数量 
+	O_BEAN_NUMBER = RuleOcr(roi=(119,645,45,29), area=(119,645,45,29), mode="Digit", method="Default", keyword="", name="bean_number")
+
+
+	# Swipe Rule Assets
+	# description 
+	S_BEAN_05TO10 = RuleSwipe(roi_front=(390,648,21,22), roi_back=(577,647,21,23), mode="default", name="bean_05to10")
+	# description 
+	S_BEAN_10TO05 = RuleSwipe(roi_front=(565,647,24,24), roi_back=(390,647,22,22), mode="default", name="bean_10to05")
 
 
 
 
 	# Click Rule Assets
 	# Click Rule Assets

+ 63 - 0
tasks/Hyakkiyakou/config.py

@@ -0,0 +1,63 @@
+from pydantic import BaseModel, Field
+from enum import Enum
+
+from tasks.Component.config_scheduler import Scheduler
+from tasks.Component.config_base import ConfigBase, Time
+
+
+class ModelPrecision(str, Enum):
+    FP32 = 'FP32'
+    INT8 = 'INT8'
+
+class InferenceEngine(str, Enum):
+    ONNXRUNTIME = 'Onnxruntime'
+    TENSORRT = 'TensorRT'
+
+
+class HyakkiyakouConfig(ConfigBase):
+    hya_limit_time: Time = Field(default=Time(minute=20), description='hya_limit_time_help')
+    hya_limit_count: int = Field(default=10, description='hya_limit_count_help')
+    hya_invite_friend: bool = Field(default=False, description='hya_invite_friend_help')
+    # 自动调整豆子数量
+    hya_auto_bean: bool = Field(default=False, description='hya_auto_bean_help')
+    hya_priorities: str = Field(default='', description='hya_priorities_help')
+    hya_sp: float = Field(default=1., description='hya_sp_help')
+    hya_ssr: float = Field(default=1., description='hya_ssr_help')
+    hya_sr: float = Field(default=0.7, description='hya_sr_help')
+    hya_r: float = Field(default=0.3, description='hya_r_help')
+    hya_n: float = Field(default=0.0, description='hya_n_help')
+    # 呱太和N卡不是一个东西
+    hya_g: float = Field(default=0.0, description='hya_g_help')
+
+
+class HyakkiyakouModels(ConfigBase):
+    # 置信度阈值
+    conf_threshold: float = Field(default=0.6, description='conf_threshold_help')
+    # nms阈值
+    iou_threshold: float = Field(default=0.7, description='iou_threshold_help')
+    # 模型的推理精度 目前全部是fp32
+    model_precision: ModelPrecision = Field(default=ModelPrecision.FP32, description='model_precision_help')
+    # 推理引擎 目前全部是onnxruntime
+    inference_engine: InferenceEngine = Field(default=InferenceEngine.ONNXRUNTIME, description='inference_engine_help')
+
+
+class DebugConfig(ConfigBase):
+    # 运行期间现实每一张的跟踪结果
+    hya_show: bool = Field(default=False, description='hya_show_help')
+    # 输出更多调试信息, 给使用者显示的
+    hya_info: bool = Field(default=False, description='hya_info_help')
+    # 保存图片,拿去回喂给模型
+    continuous_learning: bool = Field(default=False, description='continuous_learning_help')
+    # 保存每一张票的结果
+    hya_save_result: bool = Field(default=False, description='hya_save_result_help')
+    # 单独的设定截屏间隔, 单位ms
+    hya_interval: float = Field(default=300, description='hya_interval_help')
+
+
+class Hyakkiyakou(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    hyakkiyakou_config: HyakkiyakouConfig = Field(default_factory=HyakkiyakouConfig)
+    hyakkiyakou_models: HyakkiyakouModels = Field(default_factory=HyakkiyakouModels)
+    debug_config: DebugConfig = Field(default_factory=DebugConfig)
+
+

+ 217 - 0
tasks/Hyakkiyakou/debugger.py

@@ -0,0 +1,217 @@
+import cv2
+import copy
+import shutil
+import time
+import numpy as np
+
+from datetime import datetime
+from cached_property import cached_property
+from pathlib import Path
+from numpy import uint8, fromfile
+from rich.table import Table
+from threading import Event, Lock, Thread
+from oashya.labels import id2label, CLASSIFY, CLASSINDEX, id2name
+from oashya.utils import draw_tracks
+from oashya.tracker import Tracker
+
+from tasks.base_task import BaseTask
+from module.logger import logger
+from tasks.Hyakkiyakou.agent.focus import Focus
+
+
+def test_track(show: bool = False):
+    tracker = Tracker()
+    # --------------------------------
+    #
+    folder_save = Path('./tasks/Hyakkiyakou/temp/save')
+    shutil.rmtree(folder_save, ignore_errors=True)
+    folder_save.mkdir(parents=True, exist_ok=True)
+    folder_image = Path('./tasks/Hyakkiyakou/temp/20240621T221325')
+    #
+    start_time = datetime.now()
+    for index, file in enumerate(folder_image.iterdir()):
+        print(f'{index}-----------------------------------------------------------------------------------------------')
+        if file.suffix != '.png':
+            continue
+        image = cv2.imdecode(fromfile(str(file), dtype=uint8), -1)
+        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
+        results = tracker(image=image, response=[0, 0, False, 10])
+        print(results)
+        save_file = folder_save / f'{file.stem}.png'
+        draw_image = draw_tracks(image, results)
+        if show:
+            cv2.imshow('OAS Tracker', draw_image)
+            cv2.waitKey(500)
+            print('Press any key to continue')
+        else:
+            cv2.imwrite(str(save_file), draw_image)
+        # if index >= 14:
+        #     raise
+    end_time = datetime.now()
+    print(f'平均时间: {(end_time - start_time) / len([folder_image.iterdir()])}')
+
+
+def show_track(sync_image, sync_lock, stop_event):
+    # global glob_image
+    while True:
+        if stop_event.is_set():
+            logger.info('OAS Track Debugger stopped')
+            cv2.destroyAllWindows()
+            break
+        sync_lock.acquire()
+        if Debugger.sync_image is None:
+            logger.info('OAS Track Debugger not started')
+            time.sleep(1)
+            sync_lock.release()
+            continue
+        cv2.imshow('OAS Tracker', Debugger.sync_image)
+        sync_lock.release()
+        cv2.waitKey(100)
+
+
+class Debugger:
+    info_enable: bool = False
+    sync_image = None
+    sync_lock = Lock()
+    stop_event = Event()
+    sync_thread = Thread(target=show_track, daemon=True, name='OAS Track Debugger',
+                         args=(sync_image, sync_lock, stop_event))
+    # sync_event = Event()  # reserved for future use
+    # -------------------------------------------------------------------------
+
+    def __init__(self, 
+                 info_enable: bool = False, 
+                 continuous_learning: bool = False,
+                 hya_save_result: bool = False):
+        self._reset_thread_env()
+        Debugger.info_enable = info_enable
+        self.images_cache: dict = {}
+        self.continuous_learning = continuous_learning
+        self.hya_save_result = hya_save_result
+        if continuous_learning:
+            logger.info('Continuous Learning Mode Enabled')
+            save_time = datetime.now().strftime('%Y%m%dT%H')
+            self.hya_save_folder: Path = Path(f'./log/hya/{save_time}')
+            self.hya_save_folder.mkdir(parents=True, exist_ok=True)
+        if hya_save_result:
+            logger.info('Hyakkiyakou Save Result Mode Enabled')
+            save_time = datetime.now().strftime('%Y%m%dT%H')
+            self.hya_save_result_folder: Path = Path(f'./log/hyakkiyakou/{save_time}')
+            self.hya_save_result_folder.mkdir(parents=True, exist_ok=True)
+
+    @cached_property
+    def save_class(self) -> list[int]:
+        """
+        需要保存的类别
+        @return:
+        """
+        sp = [i for i in range(CLASSINDEX.MIN_SP, CLASSINDEX.MAX_SP + 1)]
+        ssr = [i for i in range(CLASSINDEX.MIN_SSR, CLASSINDEX.MAX_SSR + 1)]
+        g = [i for i in range(CLASSINDEX.MIN_G, CLASSINDEX.MAX_G + 1)]
+        return sp + ssr + g
+
+    def _reset_thread_env(self):
+        logger.info('Reset Debugger Thread Environment')
+        Debugger.sync_image = None
+        self.sync_lock = Lock()
+        self.stop_event = Event()
+        self.sync_thread = Thread(target=show_track, daemon=True, name='OAS Track Debugger',
+                                  args=(Debugger.sync_image, self.sync_lock, self.stop_event))
+
+    def show(self, results):
+        image = draw_tracks(self.device.image, results)
+        cv2.imshow('OAS Tracker', image)
+
+    def show_start(self):
+        logger.info('OAS Track Debugger show image start')
+        Debugger.sync_image = np.zeros((720, 1280, 3), dtype=np.uint8)
+        self.sync_thread.start()
+
+    def show_sync(self, image=None):
+        self.sync_lock.acquire()
+        if image is not None:
+            # deepcopy
+            Debugger.sync_image = copy.deepcopy(image)
+            # logger.info('OAS Track Debugger synced image')
+        self.sync_lock.release()
+
+    def show_stop(self):
+        logger.info('OAS Track Debugger show image stop')
+        self.stop_event.set()
+        self.sync_thread.join()
+
+    def check_class(self, _class: int) -> bool:
+        return _class in self.save_class
+
+    def deal_learning(self, image, tracks: list):
+        save_flag: bool = False
+        for _id, _class, _conf, _cx, _cy, _w, _h, _v in tracks:
+            if self.check_class(_class):
+                save_flag = True
+                break
+        if not save_flag:
+            return
+        time_now_image_name = f'hya_{int(time.time() * 1000)}'
+        self.images_cache[time_now_image_name] = image
+
+    def save_images(self):
+        if not self.images_cache:
+            self.images_cache: dict = {}
+            return
+        logger.info('OAS Track Debugger save images to train model')
+        for image_name, image in self.images_cache.items():
+            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
+            cv2.imwrite(str(self.hya_save_folder / f'{image_name}.png'), image)
+        self.images_cache.clear()
+
+    def save_result(self, image):
+        if not self.hya_save_result:
+            return
+        _now_name = f'hya_{int(time.time() * 1000)}.png'
+        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
+        cv2.imwrite(str(self.hya_save_result_folder / _now_name), image)
+
+    @classmethod
+    def show_info(cls, tracker, f: Focus):
+        table = Table(show_lines=True)
+        table.add_column('Property', header_style="bright_cyan", style="cyan", no_wrap=True)
+        table.add_column("Value", style="green")
+        table.add_column('Property', header_style="bright_cyan", style="cyan", no_wrap=True)
+        table.add_column("Value", style="green")
+        if f is not None:
+            try:
+                table.add_row('id', str(f._id), 'conf', f'{f._conf:.2f}')
+                table.add_row('class', str(f._class), 'xywh', f'({f._cx}, {f._cy}, {f._w}, {f._h})')
+                table.add_row('label', id2label(f._class), 'velocity', f'{f._v:.2f}')
+                table.add_row('name', f'{id2name(f._class)}', 'omega', str(f._omega))
+            except Exception as e:
+                pass
+        table.add_row('detect cost', f'{(tracker.detect_time.total_seconds() * 1000):.2f}ms',
+                    'track cost', f'{(tracker.track_time.total_seconds() * 1000):.2f}ms')
+        logger.print(table, justify='center')
+
+
+def test_debugger():
+    debugger = Debugger(info_enable=False, continuous_learning=True)
+    debugger.show_start()
+    folder_image = Path('./tasks/Hyakkiyakou/temp/20240621T221325')
+    for index, file in enumerate(folder_image.iterdir()):
+        print(f'{index}-----------------------------------------------------------------------------------------------')
+        if file.suffix != '.png':
+            continue
+        image = cv2.imdecode(fromfile(str(file), dtype=uint8), -1)
+        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
+        debugger.show_sync(image)
+        tracks = [[1, 190, 0.9, 0, 0, 0, 0, 0]]
+        debugger.deal_learning(image=image, tracks=tracks)
+        time.sleep(0.5)
+        if index >= 19:
+            break
+    debugger.show_stop()
+    debugger.save_images()
+
+
+if __name__ == '__main__':
+    # test_track()
+    test_debugger()
+    pass

+ 42 - 6
tasks/Hyakkiyakou/hya/click.json

@@ -1,20 +1,56 @@
 [
 [
   {
   {
     "itemName": "hselect_1",
     "itemName": "hselect_1",
-    "roiFront": "158,209,225,405",
-    "roiBack": "158,209,225,405",
+    "roiFront": "200,318,115,273",
+    "roiBack": "200,318,115,273",
     "description": "description"
     "description": "description"
   },
   },
   {
   {
     "itemName": "hselect_2",
     "itemName": "hselect_2",
-    "roiFront": "531,225,202,363",
-    "roiBack": "531,225,202,363",
+    "roiFront": "570,307,142,285",
+    "roiBack": "570,307,142,285",
     "description": "description"
     "description": "description"
   },
   },
   {
   {
     "itemName": "hselect_3",
     "itemName": "hselect_3",
-    "roiFront": "875,210,219,394",
-    "roiBack": "875,210,219,394",
+    "roiFront": "934,298,115,306",
+    "roiBack": "934,298,115,306",
+    "description": "description"
+  },
+  {
+    "itemName": "friend_1",
+    "roiFront": "446,227,181,67",
+    "roiBack": "446,227,181,67",
+    "description": "description"
+  },
+  {
+    "itemName": "friend_2",
+    "roiFront": "718,229,178,64",
+    "roiBack": "718,229,178,64",
+    "description": "description"
+  },
+  {
+    "itemName": "friend_3",
+    "roiFront": "445,310,183,66",
+    "roiBack": "445,310,183,66",
+    "description": "description"
+  },
+  {
+    "itemName": "friend_4",
+    "roiFront": "712,311,184,62",
+    "roiBack": "712,311,184,62",
+    "description": "description"
+  },
+  {
+    "itemName": "friend_5",
+    "roiFront": "449,394,178,61",
+    "roiBack": "449,394,178,61",
+    "description": "description"
+  },
+  {
+    "itemName": "friend_6",
+    "roiFront": "714,397,182,62",
+    "roiBack": "714,397,182,62",
     "description": "description"
     "description": "description"
   }
   }
 ]
 ]

二進制
tasks/Hyakkiyakou/hya/hya_bean0.png


二進制
tasks/Hyakkiyakou/hya/hya_bean05.png


二進制
tasks/Hyakkiyakou/hya/hya_bean1.png


二進制
tasks/Hyakkiyakou/hya/hya_bean10.png


二進制
tasks/Hyakkiyakou/hya/hya_bean2.png


二進制
tasks/Hyakkiyakou/hya/hya_bean3.png


二進制
tasks/Hyakkiyakou/hya/hya_bean4.png


二進制
tasks/Hyakkiyakou/hya/hya_bean5.png


二進制
tasks/Hyakkiyakou/hya/hya_bean6.png


二進制
tasks/Hyakkiyakou/hya/hya_bean7.png


二進制
tasks/Hyakkiyakou/hya/hya_bean8.png


二進制
tasks/Hyakkiyakou/hya/hya_bean9.png


二進制
tasks/Hyakkiyakou/hya/hya_friend_remote_1.png


二進制
tasks/Hyakkiyakou/hya/hya_friend_remote_2.png


二進制
tasks/Hyakkiyakou/hya/hya_friend_same_1.png


二進制
tasks/Hyakkiyakou/hya/hya_friend_same_2.png


二進制
tasks/Hyakkiyakou/hya/hya_hclose_red.png


二進制
tasks/Hyakkiyakou/hya/hya_htitle.png


二進制
tasks/Hyakkiyakou/hya/hya_hya_state_buff02.png


二進制
tasks/Hyakkiyakou/hya/hya_hya_state_buff03.png


二進制
tasks/Hyakkiyakou/hya/hya_hya_state_buff05.png


二進制
tasks/Hyakkiyakou/hya/hya_hya_state_buff06.png


二進制
tasks/Hyakkiyakou/hya/hya_hya_state_buff07.png


二進制
tasks/Hyakkiyakou/hya/hya_resf_0.png


二進制
tasks/Hyakkiyakou/hya/hya_resf_1.png


二進制
tasks/Hyakkiyakou/hya/hya_resf_2.png


二進制
tasks/Hyakkiyakou/hya/hya_resf_3.png


二進制
tasks/Hyakkiyakou/hya/hya_resf_4.png


二進制
tasks/Hyakkiyakou/hya/hya_resf_5.png


二進制
tasks/Hyakkiyakou/hya/hya_resf_6.png


二進制
tasks/Hyakkiyakou/hya/hya_resf_7.png


二進制
tasks/Hyakkiyakou/hya/hya_resf_8.png


二進制
tasks/Hyakkiyakou/hya/hya_resf_9.png


二進制
tasks/Hyakkiyakou/hya/hya_resr_0.png


二進制
tasks/Hyakkiyakou/hya/hya_resr_1.png


二進制
tasks/Hyakkiyakou/hya/hya_resr_2.png


二進制
tasks/Hyakkiyakou/hya/hya_resr_3.png


二進制
tasks/Hyakkiyakou/hya/hya_resr_4.png


二進制
tasks/Hyakkiyakou/hya/hya_resr_5.png


二進制
tasks/Hyakkiyakou/hya/hya_resr_6.png


二進制
tasks/Hyakkiyakou/hya/hya_resr_7.png


二進制
tasks/Hyakkiyakou/hya/hya_resr_8.png


二進制
tasks/Hyakkiyakou/hya/hya_resr_9.png


+ 18 - 0
tasks/Hyakkiyakou/hya/image1.json

@@ -52,5 +52,23 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "冰冻"
     "description": "冰冻"
+  },
+  {
+    "itemName": "htitle",
+    "imageName": "hya_htitle.png",
+    "roiFront": "578,21,134,48",
+    "roiBack": "578,21,134,48",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "hclose_red",
+    "imageName": "hya_hclose_red.png",
+    "roiFront": "1056,177,54,54",
+    "roiBack": "1056,177,54,54",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
   }
   }
 ]
 ]

+ 47 - 0
tasks/Hyakkiyakou/hya/image2.json

@@ -0,0 +1,47 @@
+[
+  {
+    "itemName": "hya_state_buff06",
+    "imageName": "hya_hya_state_buff06.png",
+    "roiFront": "331,7,126,41",
+    "roiBack": "137,1,342,66",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "左边概率up"
+  },
+  {
+    "itemName": "hya_state_buff05",
+    "imageName": "hya_hya_state_buff05.png",
+    "roiFront": "158,5,127,45",
+    "roiBack": "147,0,322,62",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "冰冻"
+  },
+  {
+    "itemName": "hya_state_buff07",
+    "imageName": "hya_hya_state_buff07.png",
+    "roiFront": "157,7,127,43",
+    "roiBack": "143,0,347,80",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "左边好友up"
+  },
+  {
+    "itemName": "hya_state_buff02",
+    "imageName": "hya_hya_state_buff02.png",
+    "roiFront": "157,6,128,39",
+    "roiBack": "146,1,348,55",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "左边减速"
+  },
+  {
+    "itemName": "hya_state_buff03",
+    "imageName": "hya_hya_state_buff03.png",
+    "roiFront": "326,4,129,44",
+    "roiBack": "143,3,326,59",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "左边砸豆加速"
+  }
+]

+ 182 - 0
tasks/Hyakkiyakou/hya/image3.json

@@ -0,0 +1,182 @@
+[
+  {
+    "itemName": "resf_0",
+    "imageName": "hya_resf_0.png",
+    "roiFront": "615,13,30,46",
+    "roiBack": "606,11,43,51",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_1",
+    "imageName": "hya_resf_1.png",
+    "roiFront": "617,13,31,46",
+    "roiBack": "610,11,42,50",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_2",
+    "imageName": "hya_resf_2.png",
+    "roiFront": "611,14,33,47",
+    "roiBack": "602,10,47,57",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_3",
+    "imageName": "hya_resf_3.png",
+    "roiFront": "619,14,28,45",
+    "roiBack": "610,12,40,49",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_4",
+    "imageName": "hya_resf_4.png",
+    "roiFront": "611,14,37,47",
+    "roiBack": "608,14,43,47",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_5",
+    "imageName": "hya_resf_5.png",
+    "roiFront": "612,10,35,48",
+    "roiBack": "612,10,35,48",
+    "method": "Template matching",
+    "threshold": 0.9,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_6",
+    "imageName": "hya_resf_6.png",
+    "roiFront": "616,10,29,49",
+    "roiBack": "616,10,29,49",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_7",
+    "imageName": "hya_resf_7.png",
+    "roiFront": "611,14,38,44",
+    "roiBack": "611,14,38,44",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_8",
+    "imageName": "hya_resf_8.png",
+    "roiFront": "615,10,32,50",
+    "roiBack": "615,10,32,50",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resf_9",
+    "imageName": "hya_resf_9.png",
+    "roiFront": "612,12,38,49",
+    "roiBack": "612,12,38,49",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_0",
+    "imageName": "hya_resr_0.png",
+    "roiFront": "636,11,34,47",
+    "roiBack": "636,11,34,47",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_1",
+    "imageName": "hya_resr_1.png",
+    "roiFront": "638,13,29,48",
+    "roiBack": "638,13,29,48",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_2",
+    "imageName": "hya_resr_2.png",
+    "roiFront": "639,15,30,39",
+    "roiBack": "639,15,30,39",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_3",
+    "imageName": "hya_resr_3.png",
+    "roiFront": "639,14,30,41",
+    "roiBack": "639,14,30,41",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_4",
+    "imageName": "hya_resr_4.png",
+    "roiFront": "636,13,32,46",
+    "roiBack": "636,13,32,46",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_5",
+    "imageName": "hya_resr_5.png",
+    "roiFront": "639,13,31,46",
+    "roiBack": "639,13,31,46",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_6",
+    "imageName": "hya_resr_6.png",
+    "roiFront": "638,12,32,44",
+    "roiBack": "638,12,32,44",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_7",
+    "imageName": "hya_resr_7.png",
+    "roiFront": "638,15,34,42",
+    "roiBack": "638,15,34,42",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_8",
+    "imageName": "hya_resr_8.png",
+    "roiFront": "638,13,33,47",
+    "roiBack": "638,13,33,47",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "resr_9",
+    "imageName": "hya_resr_9.png",
+    "roiFront": "638,12,32,47",
+    "roiBack": "638,12,32,47",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

+ 110 - 0
tasks/Hyakkiyakou/hya/image4.json

@@ -0,0 +1,110 @@
+[
+  {
+    "itemName": "bean0",
+    "imageName": "hya_bean0.png",
+    "roiFront": "150,648,13,22",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean1",
+    "imageName": "hya_bean1.png",
+    "roiFront": "134,648,11,22",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean2",
+    "imageName": "hya_bean2.png",
+    "roiFront": "134,649,14,21",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean3",
+    "imageName": "hya_bean3.png",
+    "roiFront": "134,649,14,21",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean4",
+    "imageName": "hya_bean4.png",
+    "roiFront": "135,647,13,23",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean5",
+    "imageName": "hya_bean5.png",
+    "roiFront": "135,649,13,22",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean6",
+    "imageName": "hya_bean6.png",
+    "roiFront": "132,649,15,21",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean7",
+    "imageName": "hya_bean7.png",
+    "roiFront": "133,648,15,22",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean8",
+    "imageName": "hya_bean8.png",
+    "roiFront": "132,646,14,23",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean9",
+    "imageName": "hya_bean9.png",
+    "roiFront": "133,649,15,21",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean05",
+    "imageName": "hya_bean05.png",
+    "roiFront": "387,640,32,35",
+    "roiBack": "371,631,86,52",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bean10",
+    "imageName": "hya_bean10.png",
+    "roiFront": "560,640,32,35",
+    "roiBack": "531,634,72,47",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

+ 38 - 0
tasks/Hyakkiyakou/hya/image5.json

@@ -0,0 +1,38 @@
+[
+  {
+    "itemName": "friend_same_1",
+    "imageName": "hya_friend_same_1.png",
+    "roiFront": "375,122,106,62",
+    "roiBack": "375,122,106,62",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "friend_remote_1",
+    "imageName": "hya_friend_remote_1.png",
+    "roiFront": "498,125,106,56",
+    "roiBack": "498,125,106,56",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "friend_same_2",
+    "imageName": "hya_friend_same_2.png",
+    "roiFront": "377,126,100,60",
+    "roiBack": "377,126,100,60",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "friend_remote_2",
+    "imageName": "hya_friend_remote_2.png",
+    "roiFront": "504,127,100,56",
+    "roiBack": "504,127,100,56",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

+ 11 - 0
tasks/Hyakkiyakou/hya/ocr.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "bean_number",
+    "roiFront": "119,645,45,29",
+    "roiBack": "119,645,45,29",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "最坏的情况下来判断豆子的数量"
+  }
+]

+ 16 - 0
tasks/Hyakkiyakou/hya/swipe.json

@@ -0,0 +1,16 @@
+[
+  {
+    "itemName": "bean_05to10",
+    "roiFront": "390,648,21,22",
+    "roiBack": "577,647,21,23",
+    "mode": "default",
+    "description": "description"
+  },
+  {
+    "itemName": "bean_10to05",
+    "roiFront": "565,647,24,24",
+    "roiBack": "390,647,22,22",
+    "mode": "default",
+    "description": "description"
+  }
+]

+ 8 - 6
tasks/Hyakkiyakou/prepare/get_images.py

@@ -25,7 +25,7 @@ class GenerateImages(GameUi, HyakkiyakouAssets):
     def run(self):
     def run(self):
         self.ui_get_current_page()
         self.ui_get_current_page()
         self.ui_goto(page_hyakkiyakou)
         self.ui_goto(page_hyakkiyakou)
-        for i in range(40):
+        for i in range(1):
             self.save_one()
             self.save_one()
 
 
     def save_one(self):
     def save_one(self):
@@ -49,7 +49,7 @@ class GenerateImages(GameUi, HyakkiyakouAssets):
                 self.click(click_button, interval=1)
                 self.click(click_button, interval=1)
         self.device.stuck_record_add('BATTLE_STATUS_S')
         self.device.stuck_record_add('BATTLE_STATUS_S')
         # 保存图片
         # 保存图片
-        save_img_timer = Timer(0.2)
+        save_img_timer = Timer(0.35)
         save_img_timer.start()
         save_img_timer.start()
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
@@ -58,8 +58,8 @@ class GenerateImages(GameUi, HyakkiyakouAssets):
                 break
                 break
             if not self.appear(self.I_CHECK_RUN):
             if not self.appear(self.I_CHECK_RUN):
                 continue
                 continue
-            if self.appear(self.I_HFREEZE):
-                continue
+            # if self.appear(self.I_HFREEZE):
+            #     continue
             if save_img_timer.reached():
             if save_img_timer.reached():
                 save_img_timer.reset()
                 save_img_timer.reset()
                 self.save_image()
                 self.save_image()
@@ -73,8 +73,10 @@ class GenerateImages(GameUi, HyakkiyakouAssets):
         # 时间戳毫秒级别
         # 时间戳毫秒级别
         time_now1 = int(time.time() * 1000)
         time_now1 = int(time.time() * 1000)
         time_now2 = time_now1 + 1
         time_now2 = time_now1 + 1
-        cv2.imwrite(str(self.save_folder / f'{time_now1}.png'), img1)
-        cv2.imwrite(str(self.save_folder / f'{time_now2}.png'), img2)
+        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
+        # cv2.imwrite(str(self.save_folder / f'{time_now1}.png'), img1)
+        # cv2.imwrite(str(self.save_folder / f'{time_now2}.png'), img2)
+        cv2.imwrite(str(self.save_folder / f'all{time_now1}.png'), image)
 
 
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':

+ 245 - 0
tasks/Hyakkiyakou/script_task.py

@@ -0,0 +1,245 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import time
+
+import cv2
+import numpy as np
+
+from datetime import datetime, timedelta
+from numpy import uint8, fromfile
+from random import choice
+from cached_property import cached_property
+# Use cmd to install: ./toolkit/python.exe -m pip install -i https://pypi.org/simple/ oashya --trusted-host pypi.org
+# update oashya:  ./toolkit/python.exe -m pip install --upgrade oashya
+from oashya.tracker import Tracker
+from oashya.labels import label2id
+from oashya.utils import draw_tracks
+
+from module.exception import TaskEnd
+from module.logger import logger
+from module.exception import RequestHumanTakeover
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_hyakkiyakou
+from tasks.Hyakkiyakou.config import Hyakkiyakou as HyakkiyakouConfig
+from tasks.Hyakkiyakou.config import InferenceEngine, ModelPrecision
+from tasks.Hyakkiyakou.assets import HyakkiyakouAssets
+from tasks.Hyakkiyakou.agent.agent import Agent
+from tasks.Hyakkiyakou.slave.hya_slave import HyaSlave
+from tasks.Hyakkiyakou.debugger import Debugger
+
+
+def plot_save(image, boxes):
+    color_palette = np.random.uniform(0, 255, size=(226, 3))
+    for box in boxes:
+        _cls = box[0]
+        _scores = box[1]
+        _x, _y, _w, _h = box[2]
+        x1 = int(_x - _w / 2)
+        y1 = int(_y - _h / 2)
+        x2 = int(_x + _w / 2)
+        y2 = int(_y + _h / 2)
+        cv2.rectangle(image, (x1, y1), (x2, y2), color_palette[_cls], 2)
+        #
+        cv2.putText(image, f'{_cls} {_scores:.2f}', (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color_palette[_cls],
+                    2)
+    save_file = './tasks/Hyakkiyakou/temp/image.png'
+    cv2.imwrite(save_file, image)
+
+
+class ScriptTask(GameUi, HyaSlave):
+
+    @property
+    def _config(self):
+        return self.config.hyakkiyakou
+
+    @cached_property
+    def tracker(self) -> Tracker:
+        hyakkiyakou_models = self._config.hyakkiyakou_models
+        conf = hyakkiyakou_models.conf_threshold
+        nms = hyakkiyakou_models.iou_threshold
+        if conf < 0.2 or conf > 1:
+            raise RequestHumanTakeover('conf_threshold should be in [0.2, 1]')
+        if nms < 0.2 or nms > 1:
+            raise RequestHumanTakeover('iou_threshold should be in [0.2, 1]')
+        inf_en = 'onnxruntime' if hyakkiyakou_models.inference_engine == InferenceEngine.ONNXRUNTIME else 'tensorrt'
+        precision = 'fp32' if hyakkiyakou_models.model_precision == ModelPrecision.FP32 else 'int8'
+        # 这个坑后面在补
+        if inf_en == 'tensorrt' or precision == 'int8':
+            raise RequestHumanTakeover('Only support onnxruntime')
+        debug_info: bool = self._config.debug_config.hya_info
+        args = {
+            'conf_threshold': conf,
+            'iou_threshold': nms,
+            'precision': precision,
+            'inference_engine': inf_en,
+            'debug': debug_info,
+        }
+        return Tracker(args=args)
+
+    @cached_property
+    def agent(self) -> Agent:
+        hya_config = self._config.hyakkiyakou_config
+        sp = hya_config.hya_sp
+        ssr = hya_config.hya_ssr
+        sr = hya_config.hya_sr
+        r = hya_config.hya_r
+        n = hya_config.hya_n
+        g = hya_config.hya_g
+        weights: list = [sp, ssr, sr, r, n, g]
+        str_priorities: str = hya_config.hya_priorities
+        if str_priorities == '':
+            priorities = []
+        else:
+            str_priorities = str_priorities.replace(' ', '').replace(',', ',')
+            try:
+                priorities = [label2id(s) for s in str_priorities.split(',')]
+            except Exception as e:
+                logger.error(f'Priority error: {str_priorities}')
+                logger.error(e)
+                raise RequestHumanTakeover
+        strategy: dict = {
+            'weights': weights,
+            'priorities': priorities,
+            'invite_friend': hya_config.hya_invite_friend,
+            'auto_bean': hya_config.hya_auto_bean
+        }
+        return Agent(strategy=strategy)
+
+    @cached_property
+    def debugger(self) -> Debugger:
+        debug_config = self._config.debug_config
+        hya_interval = debug_config.hya_interval
+        hya_save_result = debug_config.hya_save_result
+        if hya_interval <= 100 or hya_interval >= 1000:
+            raise RequestHumanTakeover('screenshot_interval must be between 1000 and 10000')
+        self.set_fast_screenshot_interval(hya_interval)
+        return Debugger(info_enable=debug_config.hya_info, 
+                        continuous_learning=debug_config.continuous_learning,
+                        hya_save_result=hya_save_result)
+
+    def run(self):
+        hya_count: int = 0
+        self.limit_count: int = self._config.hyakkiyakou_config.hya_limit_count
+        limit_time = self._config.hyakkiyakou_config.hya_limit_time
+        self.limit_time: timedelta = timedelta(hours=limit_time.hour, minutes=limit_time.minute,
+                                               seconds=limit_time.second)
+        self.ui_get_current_page()
+        self.ui_goto(page_hyakkiyakou)
+
+
+        while 1:
+            if hya_count >= self.limit_count:
+                logger.info('Hyakkiyakou count limit out')
+                break
+            if datetime.now() - self.start_time >= self.limit_time:
+                logger.info('Hyakkiyakou time limit out')
+                break
+                
+
+            self.one()
+            hya_count += 1
+
+        while 1:
+            self.screenshot()
+
+            if not self.appear(self.I_HACCESS):
+                continue
+            if self.appear(self.I_HCLOSE_RED):
+                break
+        self.ui_click_until_disappear(self.I_HCLOSE_RED)
+        self.set_next_run(task='Hyakkiyakou', success=True, finish=False)
+        raise TaskEnd
+
+    def one(self):
+        self.reset_state()
+        if not self.appear(self.I_HACCESS):
+            logger.warning('Page Error')
+        if self._config.hyakkiyakou_config.hya_invite_friend:
+            self.invite_friend(True)
+        # start
+        self.ui_click(self.I_HACCESS, self.I_HSTART, interval=2)
+        self.wait_until_appear(self.I_HTITLE)
+        # 随机选一个
+        click_button = choice([self.C_HSELECT_1, self.C_HSELECT_2, self.C_HSELECT_3])
+        while 1:
+            self.screenshot()
+            if not self.appear(self.I_HTITLE):
+                break
+            if self.appear_then_click(self.I_HSTART, interval=2):
+                continue
+            if not self.appear(self.I_HSELECTED):
+                self.click(click_button, interval=2)
+        self.device.stuck_record_add('BATTLE_STATUS_S')
+        # 正式开始
+        logger.hr('Start Hyakkiyakou')
+        init_bean_flag: bool = False
+        last_action = [0, 0, False, 10]
+        if self._config.debug_config.hya_show:
+            self.debugger.show_start()
+        while 1:
+            self.fast_screenshot()
+            if self.appear(self.I_HEND):
+                break
+            if not self.appear(self.I_CHECK_RUN):
+                continue
+            if not init_bean_flag:
+                init_bean_flag = True
+                self.bean_05to10()
+                time.sleep(0.5)
+            if not self.appear(self.I_HFREEZE):
+                # --------------------------------------------------------
+                self.slave_state = self.update_state()
+                tracks = self.tracker(image=self.device.image, response=last_action)
+                last_action = self.agent.decision(tracks=tracks, state=self.slave_state)
+                self.do_action(last_action, state=self.slave_state)
+            else:
+                # TODO freeze state
+                tracks = []
+            # debug
+            if self._config.debug_config.hya_show:
+                draw_image = draw_tracks(self.device.image, tracks=tracks)
+                self.debugger.show_sync(image=draw_image)
+            if self._config.debug_config.continuous_learning:
+                self.debugger.deal_learning(image=self.device.image, tracks=tracks)
+            if self._config.debug_config.hya_info:
+                self.debugger.show_info(tracker=self.tracker, f=self.agent.focus)
+
+        logger.info('Hyakkiyakou End')
+        if self._config.debug_config.hya_show:
+            self.debugger.show_stop()
+        if self._config.debug_config.hya_save_result:
+            # 走个动画
+            time.sleep(1.5)
+            self.debugger.save_result(self.device.image)
+        self.ui_click(self.I_HEND, self.I_HACCESS)
+        self.debugger.save_images()
+        del self.debugger
+        # you maybe update oashya
+        self.tracker.clear_tracks()
+
+    def do_action(self, action: list, state):
+        x, y, throw, bean = action
+        if not throw:
+            return
+        if state[0] <= 0:
+            return
+        self.fast_click(x=x, y=y)
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+
+    t = ScriptTask(c, d)
+    t.run()
+
+    # from tasks.Hyakkiyakou.agent.tagent import test_observe, test_state
+    # test_state()
+    # from debugger import test_track
+    # test_track(show=False)
+    pass
+

+ 58 - 0
tasks/Hyakkiyakou/slave/hya_color.py

@@ -0,0 +1,58 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import cv2
+from cached_property import cached_property
+
+from tasks.base_task import BaseTask
+
+
+class HyaColor(BaseTask):
+    BUFF_STATE_POS0: tuple[int] = (190, 42, 57, 37, 46)
+    BUFF_STATE_POS1: tuple[int] = (370, 35, 58, 39, 53)
+    BUFF_STATE_POS2: tuple[int] = (905, 35, 46, 29, 37)
+    BUFF_STATE_POS3: tuple[int] = (1060, 33, 53, 33, 39)
+
+    BEAN_NUM10: tuple[int] = (550, 657, 44, 32, 43)
+    BEAN_NUM05: tuple[int] = (400, 657, 44, 32, 43)
+
+    @cached_property
+    def buff_colors(self) -> list[tuple[int]]:
+        return [self.BUFF_STATE_POS0,
+                self.BUFF_STATE_POS1,
+                self.BUFF_STATE_POS2,
+                self.BUFF_STATE_POS3]
+
+    def show_point_color(self, x: int, y: int):
+        color = self.device.image[y, x]
+        print(f"({x}, {y}) color: {color}")
+        return color
+
+    def match_color(self, package: tuple, offset: int=5) -> bool:
+        x, y, r, g, b = package
+        img_r, img_g, img_b = self.device.image[y, x]
+        if abs(img_r - r) > offset:
+            return False
+        if abs(img_g - g) > offset:
+            return False
+        if abs(img_b - b) > offset:
+            return False
+        return True
+
+
+
+if __name__ == "__main__":
+    import timeit
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    hd = HyaColor(c, d)
+    img = cv2.imread(r'E:\Project\OnmyojiAutoScript\tasks\Hyakkiyakou\temp\20240615T144058\all1718433698934.png')
+    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+    hd.device.image = img
+
+    # print(hd.show_point_color(400, 657))
+    # print(hd.match_color(hd.BUFF_STATE_POS1))
+

+ 55 - 0
tasks/Hyakkiyakou/slave/hya_device.py

@@ -0,0 +1,55 @@
+import timeit
+
+from module.base.timer import Timer
+from module.logger import logger
+from module.base.utils import point2str
+from tasks.base_task import BaseTask
+
+
+class HyaDevice(BaseTask):
+    """
+    这个类主要是是优化截屏点击速度
+    1. 使用特别的method
+    2. 扔掉中间的冗余校验
+    3. 考虑JIT加速
+    我宣布世界上最好的 Linux 系统是 Windows
+    """
+    hya_screenshot_interval = Timer(0.2)  # 300ms
+
+    def fast_screenshot(self):
+        self.hya_screenshot_interval.wait()
+        self.hya_screenshot_interval.reset()
+        self.device.image = self.device.screenshot_window_background()
+        return self.device.image
+
+    def fast_click(self, x: int, y: int) -> None:
+        logger.info(
+            'Click %s @ %s' % (point2str(x, y), 'Click')
+        )
+        self.device.click_window_message(x=x, y=y, fast=True)
+
+    def set_fast_screenshot_interval(self, interval: float):
+        """
+
+        @param interval: ms
+        @return:
+        """
+        self.hya_screenshot_interval = Timer(interval / 1000.)
+
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    hd = HyaDevice(c, d)
+
+    def screenshot():
+        global hd
+        # hd.fast_screenshot()
+        hd.fast_click(420, 370)
+        hd.fast_click(750, 400)
+    execution_time = timeit.timeit(screenshot, number=50)
+    print(f"执行总的时间: {execution_time * 1000} ms")

+ 342 - 0
tasks/Hyakkiyakou/slave/hya_slave.py

@@ -0,0 +1,342 @@
+import cv2
+
+from cached_property import cached_property
+from pathlib import Path
+from enum import Enum
+
+from module.logger import logger
+from module.base.timer import Timer
+from module.atom.image import RuleImage
+from module.exception import RequestHumanTakeover
+from tasks.Hyakkiyakou.slave.hya_device import HyaDevice
+from tasks.Hyakkiyakou.slave.hya_color import HyaColor
+from tasks.Hyakkiyakou.assets import HyakkiyakouAssets
+
+
+class HyaBuff(int, Enum):
+    BUFF_STATE0 = -1  # None
+    BUFF_STATE2 = 0  # 式神减速
+    BUFF_STATE3 = 1  # 砸豆加速
+    BUFF_STATE5 = 2  # 式神冰冻
+    BUFF_STATE6 = 3  # 概率UP
+    BUFF_STATE7 = 4  # 好友UP
+
+    @classmethod
+    def from_index(cls, index: int):
+        for member in cls:
+            if member.value == index:
+                return member
+        raise ValueError(f"No HyaBuff member with value {index}")
+
+
+
+class HyaSlave(HyaDevice, HyaColor, HyakkiyakouAssets):
+    """
+    主要是用来跟游戏进行交互的
+    """
+    # x, y, w, h
+    HUNDRED0HUNDRED: list[int] = [117, 647, 18, 25]
+    DECADE0HUNDRED: list[int] = [131, 647, 18, 25]
+    UNIT0HUNDRED: list[int] = [146, 647, 18, 25]
+    DECADE0DECADE: list[int] = [126, 647, 18, 25]
+    UNIT0DECADE: list[int] = [140, 647, 18, 25]
+    UNIT0: list[int] = [132, 647, 18, 25]
+    # buff
+    BUFF_ROI1: list[int] = [150, 1, 150, 50]
+    BUFF_ROI2: list[int] = [320, 1, 140, 50]
+    BUFF_ROI3: list[int] = [840, 1, 150, 50]
+    BUFF_ROI4: list[int] = [1100, 1, 140, 50]
+
+    # 剩余豆子数量, 剩余式神数量, 一次砸豆子的数量, 第一个格子, 第二个格子, 第三个格子, 第四个格子
+    slave_state: tuple = [250, 36, 10,
+                          HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0]
+
+    @cached_property
+    def res_r(self) -> list[RuleImage]:
+        return [
+            self.I_RESR_0,
+            self.I_RESR_1,
+            self.I_RESR_2,
+            self.I_RESR_3,
+            self.I_RESR_4,
+            self.I_RESR_5,
+            self.I_RESR_6,
+            self.I_RESR_7,
+            self.I_RESR_8,
+            self.I_RESR_9,
+        ]
+
+    @cached_property
+    def res_f(self) -> list[RuleImage]:
+        return [
+            self.I_RESF_0,
+            self.I_RESF_1,
+            self.I_RESF_2,
+            self.I_RESF_3,
+            self.I_RESF_4,
+            self.I_RESF_5,
+            self.I_RESF_6,
+            self.I_RESF_7,
+            self.I_RESF_8,
+            self.I_RESF_9,
+        ]
+
+    @cached_property
+    def bean(self) -> list[RuleImage]:
+        return [
+            self.I_BEAN0,
+            self.I_BEAN1,
+            self.I_BEAN2,
+            self.I_BEAN3,
+            self.I_BEAN4,
+            self.I_BEAN5,
+            self.I_BEAN6,
+            self.I_BEAN7,
+            self.I_BEAN8,
+            self.I_BEAN9,
+        ]
+
+    @cached_property
+    def buff_state_rois(self) -> list[list[int]]:
+        return [
+            self.BUFF_ROI1,
+            self.BUFF_ROI2,
+            self.BUFF_ROI3,
+            self.BUFF_ROI4
+        ]
+
+    @cached_property
+    def buff_state_images(self) -> list[RuleImage]:
+        return [
+            self.I_HYA_STATE_BUFF02,  # 式神减速
+            self.I_HYA_STATE_BUFF03,  # 砸豆加速
+            self.I_HYA_STATE_BUFF05,  # 冰冻
+            self.I_HYA_STATE_BUFF06,  # 概率up
+            self.I_HYA_STATE_BUFF07,  # 好友UP
+        ]
+
+    def predict_res(self, current: int) -> int:
+        for i in range(current, current-5, -1):
+            unit = i % 10
+            unit_img = self.res_r[unit] if i >= 10 else self.res_f[unit]
+            if not self.appear(unit_img):
+                continue
+            if i < 10:
+                return i
+            decade = i // 10
+            decade_img = self.res_f[decade]
+            if not self.appear(decade_img):
+                continue
+            return i
+        logger.warning(f'Cannot predict result, current: {current}')
+        return current
+
+    def predict_bean(self, current: int):
+        possible_beans: list[int] = [current, current - 10, current - 20]
+        for bean in possible_beans:
+            if bean >= 100:
+                decade = bean // 10 % 10
+                decade_img = self.bean[decade]
+                decade_img.roi_back = self.DECADE0HUNDRED
+                if not self.appear(decade_img):
+                    continue
+                hundred = bean // 100
+                hundred_img = self.bean[hundred]
+                hundred_img.roi_back = self.HUNDRED0HUNDRED
+                if not self.appear(hundred_img):
+                    continue
+                return bean
+
+            elif bean >= 10:
+                decade = bean // 10
+                decade_img = self.bean[decade]
+                decade_img.roi_back = self.DECADE0DECADE
+                if not self.appear(decade_img):
+                    continue
+                unit = bean % 10
+                unit_img = self.bean[unit]
+                unit_img.roi_back = self.UNIT0DECADE
+                if self.appear(unit_img):
+                    return bean
+                for i in range(10):
+                    unit_img = self.bean[i]
+                    unit_img.roi_back = self.UNIT0DECADE
+                    if self.appear(unit_img):
+                        return max(0, (bean // 10) * 10 + i)
+            else:
+                unit = bean % 10
+                unit_img = self.bean[unit]
+                unit_img.roi_back = self.UNIT0
+                if self.appear(unit_img):
+                    return bean
+                for i in range(10):
+                    unit_img = self.bean[i]
+                    unit_img.roi_back = self.UNIT0
+                    if self.appear(unit_img):
+                        return max(0, i)
+        # 最坏的情况下用ocr
+        num = self.O_BEAN_NUMBER.ocr(self.device.image)
+        if isinstance(num, int) and num >= 0:
+            return num
+
+        logger.warning(f'Cannot predict bean, current: {current}')
+        return current
+
+    def predict_buff_state(self, pos: int, current: HyaBuff = None) -> HyaBuff:
+        color = self.buff_colors[pos]
+        if self.match_color(color):
+            return HyaBuff.BUFF_STATE0
+        roi = self.buff_state_rois[pos]
+        if current is not None and current != HyaBuff.BUFF_STATE0:
+            current_image = self.buff_state_images[current]
+            current_image.roi_back = roi
+            if self.appear(current_image):
+                return current
+        for i, img in enumerate(self.buff_state_images):
+            img.roi_back = roi
+            if self.appear(img):
+                # int to HyaBuff
+                return HyaBuff.from_index(i)
+        return HyaBuff.BUFF_STATE0
+
+    def recognize_bean_05(self) -> bool:
+        return self.appear(self.I_BEAN05)
+
+    def recognize_bean_10(self) -> bool:
+        return self.appear(self.I_BEAN10)
+
+    def bean_05to10(self):
+        self.swipe(self.S_BEAN_05TO10)
+
+    def bean_10to05(self):
+        self.swipe(self.S_BEAN_10TO05)
+
+    # main process
+    # ------------------------------------------------------------------------------------------------------------------
+
+    def invite_friend(self, same: bool = True):
+        logger.hr('Invite friend', 2)
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_FRIEND_SAME_1) or self.appear(self.I_FRIEND_SAME_2):
+                break
+            if self.appear_then_click(self.I_HINVITE, interval=4):
+                continue
+        if not self._invite_friend(True):
+            if not self._invite_friend(False):
+                raise RequestHumanTakeover('Invite friend failed')
+
+
+
+    def _invite_friend(self, same: bool = True) -> bool:
+        if not same:
+            logger.info('Invite different server friend')
+            self.ui_click(self.I_FRIEND_REMOTE_1, self.I_FRIEND_REMOTE_2)
+        invite_timer = Timer(8)
+        invite_timer.start()
+        while 1:
+            self.screenshot()
+            if not self.appear(self.I_HINVITE):
+                break
+            if self.click(self.C_FRIEND_1, interval=2):
+                continue
+            if self.click(self.C_FRIEND_2, interval=3):
+                continue
+            if invite_timer.reached():
+                logger.warning('Invite friend timeout, It may be no friend available')
+                return False
+        logger.info('Invite friend done')
+        return True
+
+    def update_state(self):
+        res_bean = self.predict_bean(self.slave_state[0])
+        res_shi = self.predict_res(self.slave_state[1])
+        num_bean = 5 if self.recognize_bean_05() else 10
+        buff_0 = self.predict_buff_state(pos=0, current=self.slave_state[3])
+        buff_1 = self.predict_buff_state(pos=1, current=self.slave_state[4])
+        buff_2 = self.predict_buff_state(pos=2, current=self.slave_state[5])
+        buff_3 = self.predict_buff_state(pos=3, current=self.slave_state[6])
+        self.slave_state = [
+            res_bean, res_shi, num_bean, buff_0, buff_1, buff_2, buff_3
+        ]
+        return self.slave_state
+
+    def reset_state(self):
+        self.slave_state = [250, 36, 10,
+                          HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0, HyaBuff.BUFF_STATE0]
+def covert_rgb():
+    images_folders: Path = Path(r'E:\Project\OnmyojiAutoScript\tasks\Hyakkiyakou\temp\20240614T214216')
+    save_folders = images_folders.parent / 'save14'
+    save_folders.mkdir(parents=True, exist_ok=True)
+    for file in images_folders.iterdir():
+        if file.suffix != '.png':
+            continue
+        img = cv2.imread(str(file))
+        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+        cv2.imwrite(str(save_folders / file.name), img)
+
+def test_predict_res():
+    import timeit
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    hd = HyaSlave(c, d)
+    img = cv2.imread('D:/Project/OnmyojiAutoScript/tasks/Hyakkiyakou/temp/20240621T221325/all1718979259551.png')
+    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+    hd.device.image = img
+    print(hd.predict_res(2))
+
+    # def do_test():
+    #     hd.predict_res(18)
+    # execution_time = timeit.timeit(do_test, number=100)
+    # print(f"执行总的时间: {execution_time * 1000} ms")
+    # total time is 36.2ms on my computer /cpu:AMD Ryzen 5 3550H with Radeon Vega Mobile
+    # 0.362ms per predict_res
+
+def test_predict_bean():
+    import timeit
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    hd = HyaSlave(c, d)
+    img = cv2.imread('./tasks/Hyakkiyakou/temp/20240621T221325/all1718979269677.png')
+    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+    hd.device.image = img
+    print(hd.predict_bean(15))
+    # def do_test():
+    #     hd.predict_bean(180)
+    # execution_time = timeit.timeit(do_test, number=100)
+    # print(f"执行总的时间: {execution_time * 1000} ms")
+    # total time is 17.9ms on my computer in 100 times
+
+def test_predict_buff():
+    import timeit
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    hd = HyaSlave(c, d)
+    img = cv2.imread(r'E:\Project\OnmyojiAutoScript\tasks\Hyakkiyakou\temp\save14\all1718372600237.png')
+    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+    hd.device.image = img
+    print(hd.predict_buff_state(1))
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    hd = HyaSlave(c, d)
+    # hd.invite_friend(False)
+
+    # test_predict_res()
+    test_predict_bean()
+    # test_predict_buff()
+