P0-2 镜牢简单键盘寻路改为按节点类型选方向
config 开着 mirror_keyboard_simple_pathfinding 时 AALC 每步只按 ↑ 进 最上面的节点(11-14:3 层只进过 1 次商店)。常规寻路要 mouse_drag 拖 地图,第二段拖动只受超时限制且超时会退回主界面;连线识别还依赖本机 坐标不对的 my_crop,所以不改用常规寻路(BACKLOG 方案 B)。 install_typed_keyboard_road() 替换 search_road/mirror 两处的简单键盘 寻路:仍只按键不拖地图,用 AALC 自带 ONNX 模型整屏识别巴士右侧一列 节点,按上游 all_node_weight 从低到高按 up/right/down,每次用原 _keyboard_enter_succeeded 确认,最多 3 次,都不行调用原函数按 ↑。 每步记录下一列候选和进入的方向、类型、理由。LCP_TYPED_ROAD=0 关闭。 README 同时补上 P0-1 商店清单与本补丁的说明。 验证:排序、方向映射、逐个回退、识别失败与开关均有单测,复制的权重 表和网格参数与上游源码比对一致;全套 529 项通过。方向上无连线时按键 不会进错节点这一点需实机确认,BACKLOG 已写明对照方法。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -659,3 +659,104 @@ def install_shop_lists(log=print, images_dir=os.path.join('assets', 'images')):
|
||||
log('[lc_mcp] patch: 镜牢商店清单按 assets/images/<主题>/<语言> 补齐: %s'
|
||||
% ', '.join('%s=%d' % item for item in filled.items()))
|
||||
return filled
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- 镜牢键盘寻路按节点类型
|
||||
|
||||
# config.yaml 开着 mirror_keyboard_simple_pathfinding 时, AALC 每一步只按 ↑ 进最上面的节点,
|
||||
# 完全不看节点类型(2026-11-14: 3 层只进过 1 次商店)。关掉它会走常规寻路, 那条路先用
|
||||
# mouse_drag 把地图拖到固定位置(当初开简单模式就是为了躲拖地图卡死), 连线识别还依赖
|
||||
# my_crop(交接文档实测在这台机器上坐标对不上)。
|
||||
# 这里保持"只按键、不拖地图": 用 AALC 自带的 ONNX 模型整屏识别巴士右侧下一列节点的类型,
|
||||
# 按上游 all_node_weight 从低到高依次按方向键, 每次都确认进得去; 都不行再退回原来的 ↑。
|
||||
ROAD_KEYS = {'U': 'up', 'M': 'right', 'D': 'down'} # 与上游 MirrorMap.enter_next_node 一致
|
||||
ROAD_TIE_ORDER = ('U', 'M', 'D') # 同类型时先试 ↑, 尽量贴近原简单模式
|
||||
UPSTREAM_ROAD_COLUMN_GAP = 520 # 上游 search_road 的网格参数(2560x1440 标定)
|
||||
UPSTREAM_ROAD_ROW_GAP = 437
|
||||
UPSTREAM_NODE_WEIGHT = {
|
||||
'battle': 4, 'boss_battle': 6, 'event': 1, 'focused_encounter': 6,
|
||||
'risky_encounter': 7, 'shop': 2, 'abnormality_focused_encounter': 6,
|
||||
}
|
||||
TYPED_ROAD_ENV = 'LCP_TYPED_ROAD' # 设为 0 时不装这个补丁, 完全回到原简单键盘寻路
|
||||
|
||||
|
||||
def rank_next_nodes(bus, nodes, scale, weights=UPSTREAM_NODE_WEIGHT,
|
||||
column_gap=UPSTREAM_ROAD_COLUMN_GAP, row_gap=UPSTREAM_ROAD_ROW_GAP):
|
||||
"""巴士右侧下一列的节点 -> [(方向, 类型, 权重), ...], 权重小的在前。
|
||||
|
||||
nodes 是 identify_nodes() 的输出 [[类型, (x, y)], ...]; 只取与巴士相隔一列的节点,
|
||||
按相对巴士的行差映射成 U/M/D。同一方向识别出多个时保留权重最小的那个。
|
||||
"""
|
||||
if not bus or not nodes:
|
||||
return []
|
||||
gap_x, gap_y = column_gap * scale, row_gap * scale
|
||||
best = {}
|
||||
for kind, (x, y) in nodes:
|
||||
if abs((x - bus[0]) - gap_x) > gap_x / 4:
|
||||
continue
|
||||
direction = {1: 'U', 0: 'M', -1: 'D'}.get(round((bus[1] - y) / gap_y))
|
||||
if direction is None:
|
||||
continue
|
||||
weight = weights.get(kind)
|
||||
if weight is None:
|
||||
continue
|
||||
if direction not in best or weight < best[direction][1]:
|
||||
best[direction] = (kind, weight)
|
||||
return sorted(((d, kind, w) for d, (kind, w) in best.items()),
|
||||
key=lambda item: (item[2], ROAD_TIE_ORDER.index(item[0])))
|
||||
|
||||
|
||||
def install_typed_keyboard_road(log=print, env=None):
|
||||
"""替换简单键盘寻路: 按节点类型挑方向, 失败时退回原 ↑ 逻辑。返回原函数, 未安装返回 None。"""
|
||||
env = os.environ if env is None else env
|
||||
if env.get(TYPED_ROAD_ENV) == '0':
|
||||
log('[lc_mcp] 键盘寻路按类型补丁已关闭(%s=0), 沿用原简单键盘寻路' % TYPED_ROAD_ENV)
|
||||
return None
|
||||
try:
|
||||
from tasks.mirror import mirror as mirror_mod
|
||||
from tasks.mirror import search_road as road
|
||||
from module.automation import auto
|
||||
from module.config import cfg
|
||||
except Exception as e:
|
||||
log('[lc_mcp] 键盘寻路按类型补丁跳过: 无法导入 %s' % e)
|
||||
return None
|
||||
original = getattr(road, 'search_road_simple_keyboard', None)
|
||||
if original is None or not hasattr(road, 'identify_nodes'):
|
||||
log('[lc_mcp] 键盘寻路按类型补丁跳过: 上游没有简单键盘寻路或节点识别')
|
||||
return None
|
||||
weights = getattr(road, 'all_node_weight', UPSTREAM_NODE_WEIGHT)
|
||||
column_gap = getattr(road, 'ROAD_COLUMN_GAP', UPSTREAM_ROAD_COLUMN_GAP)
|
||||
row_gap = getattr(road, 'ROAD_ROW_GAP', UPSTREAM_ROAD_ROW_GAP)
|
||||
|
||||
def search_road_simple_keyboard():
|
||||
if not cfg.mirror_keyboard_navigation:
|
||||
return original() # 上游会说明需要开启键盘寻路
|
||||
try:
|
||||
auto.mouse_to_blank()
|
||||
time.sleep(0.3)
|
||||
bus = auto.find_element('mirror/mybus_default_distance.png', take_screenshot=True)
|
||||
nodes = road.identify_nodes(bus[0]) if bus else None
|
||||
ranked = rank_next_nodes(bus, nodes, cfg.set_win_size / 1440, weights, column_gap, row_gap)
|
||||
except Exception as e:
|
||||
log('[lc_mcp] 键盘寻路: 识别下一列节点出错(%s: %s), 退回按 ↑' % (type(e).__name__, e))
|
||||
return original()
|
||||
if not ranked:
|
||||
log('[lc_mcp] 键盘寻路: %s, 退回按 ↑' % ('没找到巴士' if not bus else '下一列没识别到节点'))
|
||||
return original()
|
||||
log('[lc_mcp] 键盘寻路: 下一列 %s, 按权重从低到高依次尝试'
|
||||
% ' '.join('%s=%s(%d)' % item for item in ranked))
|
||||
for direction, kind, weight in ranked:
|
||||
auto.key_press(ROAD_KEYS[direction])
|
||||
time.sleep(1)
|
||||
if road._keyboard_enter_succeeded():
|
||||
reason = '下一列中最低' if direction == ranked[0][0] else '更优的方向没能进入'
|
||||
log('[lc_mcp] 键盘寻路: 进入 %s 方向的 %s(权重 %d, %s)' % (direction, kind, weight, reason))
|
||||
return True
|
||||
log('[lc_mcp] 键盘寻路: %s 方向的 %s 没能进入, 试下一个' % (direction, kind))
|
||||
log('[lc_mcp] 键盘寻路: 按类型都没进入, 退回按 ↑')
|
||||
return original()
|
||||
|
||||
road.search_road_simple_keyboard = search_road_simple_keyboard
|
||||
mirror_mod.search_road_simple_keyboard = search_road_simple_keyboard
|
||||
log('[lc_mcp] patch: 镜牢键盘寻路按节点类型选方向(不拖地图)')
|
||||
return original
|
||||
|
||||
Reference in New Issue
Block a user