Skip to content

Commit

Permalink
整理import
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoZuohong committed Jul 18, 2024
1 parent 2933f7a commit 8653de8
Show file tree
Hide file tree
Showing 46 changed files with 255 additions and 315 deletions.
19 changes: 2 additions & 17 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from arknights_mower.solvers.reclamation_algorithm import ReclamationAlgorithm
from arknights_mower.solvers.secret_front import SecretFront
from arknights_mower.utils import config, path, rapidocr
from arknights_mower.utils.csleep import MowerExit
from arknights_mower.utils.datetime import format_time
from arknights_mower.utils.depot import 创建csv, 创建json
from arknights_mower.utils.device.adb_client.session import Session
from arknights_mower.utils.device.scrcpy import Scrcpy
Expand All @@ -19,7 +21,6 @@
from arknights_mower.utils.path import get_path
from arknights_mower.utils.plan import Plan, PlanConfig, Room
from arknights_mower.utils.simulator import restart_simulator
from arknights_mower.utils.solver import MowerExit

global base_scheduler
base_scheduler = None
Expand Down Expand Up @@ -59,22 +60,6 @@ def main():
simulate()


# newbing说用这个来定义休息时间省事
def format_time(seconds):
if seconds < 0: # 权宜之计 配合刷生息演算
return f"{0} 分钟" # 权宜之计 配合刷生息演算
# 计算小时和分钟
rest_hours = int(seconds / 3600)
rest_minutes = int((seconds % 3600) / 60)
# 根据小时是否为零来决定是否显示
if rest_hours == 0:
return f"{rest_minutes} 分钟"
elif rest_minutes == 0:
return f"{rest_hours} 小时"
else:
return f"{rest_hours} 小时 {rest_minutes} 分钟"


def get_logic_exp(trigger):
for k in ["left", "operator", "right"]:
if not isinstance(trigger[k], str):
Expand Down
24 changes: 24 additions & 0 deletions arknights_mower/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import lzma
import pickle

from arknights_mower import __rootdir__

with lzma.open(f"{__rootdir__}/models/avatar.pkl", "rb") as f:
avatar = pickle.load(f)


with lzma.open(f"{__rootdir__}/models/secret_front.pkl", "rb") as f:
secret_front = pickle.load(f)


with lzma.open(f"{__rootdir__}/models/navigation.pkl", "rb") as f:
navigation = pickle.load(f)

with lzma.open(f"{__rootdir__}/models/riic_base_digits.pkl", "rb") as f:
riic_base_digits = pickle.load(f)

with lzma.open(f"{__rootdir__}/models/noto_sans.pkl", "rb") as f:
noto_sans = pickle.load(f)

with lzma.open(f"{__rootdir__}/models/shop.pkl", "rb") as f:
shop = pickle.load(f)
17 changes: 0 additions & 17 deletions arknights_mower/solvers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +0,0 @@
from .credit import CreditSolver
from .cultivate_depot import cultivate as cultivateDepotSolver
from .depotREC import depotREC as DepotSolver
from .mail import MailSolver
from .mission import MissionSolver
from .recruit import RecruitSolver
from .report import ReportSolver

__all__ = [
"CreditSolver",
"MailSolver",
"MissionSolver",
"RecruitSolver",
"DepotSolver",
"cultivateDepotSolver",
"ReportSolver",
]
10 changes: 2 additions & 8 deletions arknights_mower/solvers/auto_fight.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import lzma
import pickle
from time import sleep

import cv2
from scipy.signal import argrelmax
from skimage.metrics import structural_similarity

from arknights_mower import __rootdir__
from arknights_mower.solvers.secret_front import templates
from arknights_mower.models import avatar, secret_front
from arknights_mower.utils import typealias as tp
from arknights_mower.utils.image import cropimg, loadres, thres2
from arknights_mower.utils.log import logger
from arknights_mower.utils.solver import BaseSolver
from arknights_mower.utils.tile_pos import Calc, find_level
from arknights_mower.utils.vector import sa, va

with lzma.open(f"{__rootdir__}/models/avatar.pkl", "rb") as f:
avatar = pickle.load(f)


class AutoFight(BaseSolver):
def run(self, level_name, opers, actions):
Expand Down Expand Up @@ -62,7 +56,7 @@ def number(self, scope: tp.Scope, height: int, thres: int) -> int:
)
score = []
for i in range(10):
im = templates[i]
im = secret_front[i]
result = cv2.matchTemplate(digit, im, cv2.TM_SQDIFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
score.append(min_val)
Expand Down
4 changes: 1 addition & 3 deletions arknights_mower/solvers/base_mixin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import lzma
import pickle
from datetime import datetime, timedelta
Expand All @@ -10,9 +8,9 @@
from arknights_mower import __rootdir__
from arknights_mower.utils import rapidocr, segment
from arknights_mower.utils.character_recognize import operator_list
from arknights_mower.utils.csleep import MowerExit
from arknights_mower.utils.image import cropimg, loadres, thres2
from arknights_mower.utils.log import logger
from arknights_mower.utils.solver import MowerExit

with lzma.open(f"{__rootdir__}/models/operator_room.model", "rb") as f:
OP_ROOM = pickle.loads(f.read())
Expand Down
29 changes: 12 additions & 17 deletions arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import copy
import json
import os
Expand All @@ -11,30 +9,27 @@

import cv2

# 借用__main__.py里的时间计算器
from arknights_mower.__main__ import format_time
from arknights_mower.data import agent_list, base_room_list
from arknights_mower.solvers import (
CreditSolver,
DepotSolver,
MailSolver,
RecruitSolver,
ReportSolver,
cultivateDepotSolver,
)
from arknights_mower.solvers.base_mixin import BaseMixin
from arknights_mower.solvers.credit import CreditSolver
from arknights_mower.solvers.credit_fight import CreditFight
from arknights_mower.solvers.cultivate_depot import cultivate as cultivateDepotSolver
from arknights_mower.solvers.depotREC import depotREC as DepotSolver
from arknights_mower.solvers.mail import MailSolver
from arknights_mower.solvers.mission import MissionSolver
from arknights_mower.solvers.navigation import NavigationSolver
from arknights_mower.solvers.operation import OperationSolver
from arknights_mower.solvers.reclamation_algorithm import ReclamationAlgorithm
from arknights_mower.solvers.recruit import RecruitSolver
from arknights_mower.solvers.report import ReportSolver
from arknights_mower.solvers.secret_front import SecretFront
from arknights_mower.solvers.shop import CreditShop
from arknights_mower.solvers.skland import SKLand
from arknights_mower.utils import config, detector, hot_update, rapidocr
from arknights_mower.utils import typealias as tp
from arknights_mower.utils.datetime import get_server_weekday
from arknights_mower.utils.device import Device
from arknights_mower.utils.csleep import MowerExit, csleep
from arknights_mower.utils.datetime import format_time, get_server_weekday
from arknights_mower.utils.device.device import Device
from arknights_mower.utils.digit_reader import DigitReader
from arknights_mower.utils.graph import SceneGraphSolver
from arknights_mower.utils.image import cropimg, loadres, thres2
Expand All @@ -52,8 +47,6 @@
scheduling,
try_add_release_dorm,
)
from arknights_mower.utils.simulator import restart_simulator
from arknights_mower.utils.solver import MowerExit


def daily_report(
Expand Down Expand Up @@ -3381,7 +3374,7 @@ def maa_plan_solver(self):
self.MAA.stop()
break
else:
self.csleep(5)
csleep(5)
self.device.exit()
self.check_current_focus()

Expand Down Expand Up @@ -3414,6 +3407,8 @@ def maa_plan_solver(self):
if remaining_time > 0:
if remaining_time > 300:
if self.close_simulator_when_idle:
from arknights_mower.utils.simulator import restart_simulator

restart_simulator(start=False)
elif self.exit_game_when_idle:
self.device.exit()
Expand Down
2 changes: 1 addition & 1 deletion arknights_mower/solvers/depotREC.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from arknights_mower.utils.graph import SceneGraphSolver

from .. import __rootdir__
from ..utils.device import Device
from ..utils.device.device import Device
from ..utils.image import loadimg
from ..utils.log import logger
from ..utils.path import get_path
Expand Down
9 changes: 2 additions & 7 deletions arknights_mower/solvers/navigation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import lzma
import pickle
import re

import cv2

from arknights_mower import __rootdir__
from arknights_mower.models import navigation
from arknights_mower.utils import hot_update
from arknights_mower.utils.graph import SceneGraphSolver
from arknights_mower.utils.log import logger
Expand Down Expand Up @@ -144,9 +142,6 @@
"hard",
]

with lzma.open(f"{__rootdir__}/models/navigation.pkl", "rb") as f:
templates = pickle.load(f)


class NavigationSolver(SceneGraphSolver):
def run(self, name: str):
Expand Down Expand Up @@ -307,7 +302,7 @@ def transition(self):
return
for i in location[prefix]:
result = cv2.matchTemplate(
self.recog.gray, templates[i], cv2.TM_SQDIFF_NORMED
self.recog.gray, navigation[i], cv2.TM_SQDIFF_NORMED
)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
if min_val < val:
Expand Down
4 changes: 2 additions & 2 deletions arknights_mower/solvers/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import cv2

from arknights_mower.solvers.secret_front import templates
from arknights_mower.models import secret_front
from arknights_mower.utils import config
from arknights_mower.utils import typealias as tp
from arknights_mower.utils.graph import SceneGraphSolver
Expand Down Expand Up @@ -39,7 +39,7 @@ def number(self, scope: tp.Scope, height: Optional[int] = None):
)
score = []
for i in range(10):
im = templates[i]
im = secret_front[i]
result = cv2.matchTemplate(digit, im, cv2.TM_SQDIFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
score.append(min_val)
Expand Down
3 changes: 2 additions & 1 deletion arknights_mower/solvers/reclamation_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

from arknights_mower.utils import rapidocr
from arknights_mower.utils import typealias as tp
from arknights_mower.utils.csleep import MowerExit
from arknights_mower.utils.image import cropimg, loadres, thres2
from arknights_mower.utils.log import logger
from arknights_mower.utils.matcher import Matcher
from arknights_mower.utils.scene import Scene
from arknights_mower.utils.solver import BaseSolver, MowerExit
from arknights_mower.utils.solver import BaseSolver

src_pts = np.float32([[0, 97], [1920, 97], [-400, 1080], [2320, 1080]])
dst_pts = np.float32([[0, 0], [1920, 0], [0, 1000], [1920, 1000]])
Expand Down
2 changes: 1 addition & 1 deletion arknights_mower/solvers/recruit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
result_template_list,
)
from arknights_mower.utils import rapidocr, segment
from arknights_mower.utils.device import Device
from arknights_mower.utils.device.device import Device
from arknights_mower.utils.digit_reader import DigitReader
from arknights_mower.utils.email import recruit_rarity, recruit_template
from arknights_mower.utils.graph import SceneGraphSolver
Expand Down
14 changes: 3 additions & 11 deletions arknights_mower/solvers/report.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from __future__ import annotations

import datetime
import lzma
import os
import pickle

import cv2
import pandas as pd

from arknights_mower.data import __rootdir__
from arknights_mower.utils.device import Device
from arknights_mower.models import noto_sans
from arknights_mower.utils.device.device import Device
from arknights_mower.utils.digit_reader import DigitReader
from arknights_mower.utils.email import report_template
from arknights_mower.utils.graph import SceneGraphSolver
Expand All @@ -18,10 +14,6 @@
from arknights_mower.utils.path import get_path
from arknights_mower.utils.recognize import Recognizer, Scene, tp

number = {}
with lzma.open(f"{__rootdir__}/models/noto_sans.pkl", "rb") as f:
number = pickle.load(f)


def remove_blank(target: str):
if target is None or target == "":
Expand Down Expand Up @@ -207,7 +199,7 @@ def get_number(

score = []
for i in range(10):
im = number[i]
im = noto_sans[i]
result = cv2.matchTemplate(digit, im, cv2.TM_SQDIFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
score.append(min_val)
Expand Down
14 changes: 5 additions & 9 deletions arknights_mower/solvers/secret_front.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import lzma
import pickle
from datetime import datetime, timedelta
from typing import Optional

import cv2

from arknights_mower import __rootdir__
from arknights_mower.models import secret_front
from arknights_mower.utils import config
from arknights_mower.utils import typealias as tp
from arknights_mower.utils.csleep import MowerExit
from arknights_mower.utils.image import cropimg, thres2
from arknights_mower.utils.log import logger
from arknights_mower.utils.matcher import Matcher
from arknights_mower.utils.recognize import Scene
from arknights_mower.utils.solver import BaseSolver, MowerExit

with lzma.open(f"{__rootdir__}/models/secret_front.pkl", "rb") as f:
templates = pickle.load(f)
from arknights_mower.utils.solver import BaseSolver


def exp(card):
Expand Down Expand Up @@ -113,7 +109,7 @@ def number(self, scope: tp.Scope, height: Optional[int] = None):
)
score = []
for i in range(10):
im = templates[i]
im = secret_front[i]
result = cv2.matchTemplate(digit, im, cv2.TM_SQDIFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
score.append(min_val)
Expand All @@ -137,7 +133,7 @@ def stage_card(self, total, idx):
img = cv2.copyMakeBorder(img, 10, 10, 10, 10, cv2.BORDER_CONSTANT, None, (0,))
score = []
for i in self.target:
result = cv2.matchTemplate(img, templates[i], cv2.TM_SQDIFF_NORMED)
result = cv2.matchTemplate(img, secret_front[i], cv2.TM_SQDIFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
score.append(min_val)
name = list(self.target)[score.index(min(score))]
Expand Down
Loading

0 comments on commit 8653de8

Please sign in to comment.