Fix background clicks and mirror scene boundaries with run feedback
This commit is contained in:
+198
-24
@@ -24,10 +24,11 @@ SYSTEM_RULES = (
|
||||
'事件当前有“选择后获得”且无需判定、无需战斗的选项时直接选择它,不反复滚动;避开写着战斗胜利后的选项。'
|
||||
'确定确认/进入/开始战斗直接执行。地图优先可达事件和商店,减少战斗。'
|
||||
'选好路线直接回车进入,关卡编队界面也直接回车开战;保留原编队,不再检查人员。'
|
||||
'保留当前编队。成捆的符咒++和鸡胸为核心,略过额外观测;其他苦难避开敌方体力上限和防御等级。'
|
||||
'保留当前编队。开局三级饰品三选一必须选择标准负载电池,再确认领取;不能当成额外观测拒绝。'
|
||||
'成捆的符咒++、标准负载电池和鸡胸为核心,保留不可出售或合成;仅略过单独的额外观测。其他苦难避开敌方体力上限和防御等级。'
|
||||
'3层起辛克莱1换3,黑兽奥提斯2换3,其他出战1换3。只在商店强化饰品。'
|
||||
'商店没有出战角色可替换技能时允许刷新,当前商店最多4次;有可替换角色先按技能表替换。'
|
||||
'第五层优先2号线卡包;卡包刷新次数为零时允许使用卡包观测。层末必须选择苦难再推进,不能当额外观测默认拒绝饰品。'
|
||||
'第一至第四层禁止选择2号线卡包,留到第五层优先选;刷新次数为零时允许使用卡包观测。层末必须选择苦难再推进,不能当额外观测默认拒绝饰品。'
|
||||
'卡包信息不清先点对应放大镜查看;核心饰品齐全时按通关速度选择现有卡包,不为可选饰品反复刷新。'
|
||||
'信息不足、重复操作仍无效、苦难无法明确核对,或你判断需要主助手分析时选 requires_analysis。'
|
||||
)
|
||||
@@ -37,6 +38,12 @@ def text_items(state):
|
||||
return state.get('items') or []
|
||||
|
||||
|
||||
def death_retry_screen(texts):
|
||||
combined = '\n'.join(texts)
|
||||
return ('全体罪人' in combined and '死亡' in combined
|
||||
or '当前剩余人员' in combined and '重试关卡' in combined)
|
||||
|
||||
|
||||
def button_enabled(state, item):
|
||||
try:
|
||||
from PIL import Image
|
||||
@@ -73,13 +80,28 @@ def map_candidates(state):
|
||||
if not (0 < x < rgb.shape[1] and 0 < y < rgb.shape[0]*.82):
|
||||
continue
|
||||
radius = int(125 * scale)
|
||||
# Event and shop nodes remain purple even when reachable. Their
|
||||
# connecting arrow, rather than node color, indicates availability.
|
||||
ax, ay = int(bx + 250*scale), int(by + dy*scale/2)
|
||||
arrow_roi = gray[max(0,ay-radius):min(gray.shape[0],ay+radius),
|
||||
max(0,ax-radius):min(gray.shape[1],ax+radius)]
|
||||
arrow_name = {'w':'up','d':'mid','s':'down'}[key]
|
||||
template = cv2.imread(str(assets / 'road_in_mir' / (arrow_name+'.png')), 0)
|
||||
template = cv2.resize(template, None, fx=scale, fy=scale, interpolation=cv2.INTER_AREA)
|
||||
arrow_reachable = False
|
||||
if arrow_roi.shape[0] >= template.shape[0] and arrow_roi.shape[1] >= template.shape[1]:
|
||||
_, arrow_score, _, arrow_pos = cv2.minMaxLoc(cv2.matchTemplate(arrow_roi, template, cv2.TM_CCOEFF_NORMED))
|
||||
sample = arrow_roi[arrow_pos[1]:arrow_pos[1]+template.shape[0],
|
||||
arrow_pos[0]:arrow_pos[0]+template.shape[1]]
|
||||
arrow_reachable = arrow_score > .85 and float(np.quantile(sample,.9)) > 90
|
||||
roi = rgb[max(0,y-radius):min(rgb.shape[0],y+radius), max(0,x-radius):min(rgb.shape[1],x+radius)]
|
||||
hsv = cv2.cvtColor(roi, cv2.COLOR_RGB2HSV)
|
||||
red = ((hsv[:,:,0] < 12) | (hsv[:,:,0] > 168)) & (hsv[:,:,1] > 150) & (hsv[:,:,2] > 150)
|
||||
green = (hsv[:,:,0] > 27) & (hsv[:,:,0] < 85) & (hsv[:,:,1] > 110) & (hsv[:,:,2] > 150)
|
||||
white = (hsv[:,:,1] < 100) & (hsv[:,:,2] > 175)
|
||||
colored = int((red | green).sum()) >= 80
|
||||
if not colored and int(white.sum()) < 80:
|
||||
cyan = (hsv[:,:,0] >= 80) & (hsv[:,:,0] <= 110) & (hsv[:,:,1] > 110) & (hsv[:,:,2] > 150)
|
||||
colored = int((red | green | cyan).sum()) >= 80
|
||||
if not colored and int(white.sum()) < 80 and not arrow_reachable:
|
||||
continue
|
||||
target = cv2.resize(cv2.cvtColor(roi, cv2.COLOR_RGB2GRAY), None, fx=2, fy=2)
|
||||
_, target_desc = orb.detectAndCompute(target, None)
|
||||
@@ -96,7 +118,7 @@ def map_candidates(state):
|
||||
score = sum(len(pair) == 2 and pair[0].distance < 0.7*pair[1].distance for pair in matches)
|
||||
scores.append((score, label))
|
||||
score, label = max(scores, default=(0, '类型未识别'))
|
||||
if not colored and score < 8:
|
||||
if not colored and score < 8 and not arrow_reachable:
|
||||
continue
|
||||
if score < 8:
|
||||
label = '类型未识别'
|
||||
@@ -122,7 +144,29 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
}}
|
||||
# Refresh requests leave the previous stock visible until networking ends.
|
||||
# Never buy, refresh again, or leave based on that stale inventory.
|
||||
if any('CONNECTING' in t.upper() for t in texts):
|
||||
if any(re.search(r'CON+ECTING|LOADING', t.upper()) for t in texts):
|
||||
return options
|
||||
if state.get('claim_requested'):
|
||||
# After claiming, never let the generic Enter action start another run.
|
||||
if ('探索状态' in texts and '进入' in texts and '探索中' not in texts
|
||||
or '驾驶席' in texts and '罪人' in texts):
|
||||
options['run_complete'] = {'description': '奖励领取后已返回大厅,结束本局。',
|
||||
'action': {'tool': 'run_complete', 'args': {}}}
|
||||
else:
|
||||
confirm = next((i for i in items if i['text'].replace(' ', '') in ('确认','继续')
|
||||
and button_enabled(state, i)), None)
|
||||
if confirm:
|
||||
options['modal_confirm'] = {'description': '确认最终领取弹窗。',
|
||||
'action': {'tool': 'click', 'args': {'x': confirm['x']+confirm['w']//2,
|
||||
'y': confirm['y']+confirm['h']//2}}}
|
||||
return options
|
||||
if death_retry_screen(texts):
|
||||
return options
|
||||
if '服务器发生错误' in combined:
|
||||
retry = next((i for i in items if i['text'].replace(' ', '') == '重试'), None)
|
||||
if retry:
|
||||
options['retry_network'] = {'description': '重试当前游戏服务器错误弹窗,不操作背景商店。',
|
||||
'action': {'tool': 'click', 'args': {'x': retry['x']+retry['w']//2, 'y': retry['y']+retry['h']//2}}}
|
||||
return options
|
||||
if '探索完成' in texts:
|
||||
claim = next((i for i in items if i['text'].replace(' ', '') == '领取'
|
||||
@@ -134,8 +178,17 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
'y':claim['y']+claim['h']//2}},
|
||||
}
|
||||
return options
|
||||
if '判定成功' in combined or '判定失败' in combined or '结果' in texts:
|
||||
continuation = next((i for i in items if i['text'].replace(' ', '') == '继续'
|
||||
gift_headers = sum(t == '获得E.G.O饰品' for t in texts)
|
||||
if gift_headers == 1 and '拒绝饰品' in texts and '选择' in texts:
|
||||
core = any(name in combined for name in ('成捆的符咒','标准负载电池','干巴柴涩鸡胸肉','干松紧致鸡胸肉'))
|
||||
if core:
|
||||
return options
|
||||
target = next(i for i in items if i['text'].replace(' ','') == '拒绝饰品')
|
||||
options['decline_extra_observation'] = {'description': '拒绝单张无关额外饰品。',
|
||||
'action': {'tool':'click','args':{'x':target['x']+target['w']//2,'y':target['y']+target['h']//2}}}
|
||||
return options
|
||||
if any(t in ('判定成功', '判定失败', '结果') for t in texts):
|
||||
continuation = next((i for i in items if i['text'].replace(' ', '') in ('继续', '开始战斗')
|
||||
and button_enabled(state,i)), None)
|
||||
options['event_finish'] = {
|
||||
'description': '判定结果已出现,快速连按回车结束事件并返回地图。',
|
||||
@@ -152,6 +205,9 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
'y': item['y'] + item['h']//2}},
|
||||
}
|
||||
return options
|
||||
if any('REC' in t.upper() for t in texts) and '选项' not in texts and not any(t in combined for t in ('选择一位罪人', '进行判定', '判定成功', '判定失败', '结果')):
|
||||
options['event_advance'] = {'description':'事件选项已经确定,按回车快速推进后续文本。', 'action':{'tool':'advance_dialog','args':{'presses':5}}}
|
||||
return options
|
||||
if '应该让谁' in combined and '选择一位罪人' not in combined and '进行判定' not in combined:
|
||||
options['event_advance'] = {
|
||||
'description': '对话已经跳过,按回车继续到选择罪人的判定界面。',
|
||||
@@ -193,7 +249,7 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
target = ('SKILL2', 'SKILL3') if '奥提斯' in header else (
|
||||
('SKILL1', 'SKILL2') if '辛克莱' in header and state.get('floor', 3) < 3 else ('SKILL1', 'SKILL3'))
|
||||
target_selected = False
|
||||
for number, fraction in enumerate((0.235, 0.49, 0.745), 1):
|
||||
for number, fraction in enumerate((0.244, 0.499, 0.752), 1):
|
||||
cx = round(width*fraction)
|
||||
skill_texts = [i for i in items if 'SKILL' in i['text'].upper()
|
||||
and abs(i['x']+i['w']/2 - (cx + width*.075)) < width*.05
|
||||
@@ -227,6 +283,11 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
'y': item['y'] + item['h']//2}},
|
||||
}
|
||||
return options
|
||||
if any('获得E.G.O饰品!' in t or '获得E.G.O饰品!' in t for t in texts):
|
||||
item=next((i for i in items if i['text'].replace(' ','')=='确认' and width*.4 < i['x']+i['w']/2 < width*.6),None)
|
||||
if item:
|
||||
options['modal_confirm']={'description':'按回车快速确认当前获得饰品弹窗。','action':{'tool':'keypress','args':{'key':'enter'}}}
|
||||
return options
|
||||
if '追加的苦难' in combined and '获得E.G.O' in combined:
|
||||
for number, fraction in enumerate((.188, .395, .60, .813), 1):
|
||||
cx = round(width*fraction)
|
||||
@@ -242,12 +303,12 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
if '选择' in item['text'] and '/' in item['text'] and button_enabled(state,item):
|
||||
options['hardship_confirm'] = {
|
||||
'description':'选择数量足够后确认层末饰品和苦难,直接前进。',
|
||||
'action':{'tool':'click','args':{'x':item['x']+item['w']//2,'y':item['y']+item['h']//2}},
|
||||
'action':{'tool':'keypress','args':{'key':'enter'}},
|
||||
}
|
||||
return options
|
||||
# Nested confirmation/detail windows override the reward/pack behind them.
|
||||
modal_question = ('确认' in texts and any('取消' in t for t in texts)
|
||||
and any('吗?' in t or '吗?' in t for t in texts))
|
||||
and any('吗?' in t or '吗?' in t or '要离开商店吗' in t for t in texts))
|
||||
pack_detail = '出现头目' in combined and '详细内容' in combined
|
||||
if modal_question or pack_detail:
|
||||
buttons = [i for i in items if i['text'].replace(' ', '') == '确认'
|
||||
@@ -256,11 +317,16 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
item = min(buttons, key=lambda i: i['y'])
|
||||
options['modal_confirm'] = {
|
||||
'description': '确认当前最上层弹窗;不操作背景奖励卡或卡包。',
|
||||
'action': {'tool': 'click', 'args': {'x': item['x'] + item['w']//2,
|
||||
'y': item['y'] + item['h']//2}},
|
||||
'action': ({'tool': 'keypress', 'args': {'key': 'enter'}}
|
||||
if any('要离开商店吗' in t for t in texts) else
|
||||
{'tool': 'click', 'args': {'x': item['x'] + item['w']//2,
|
||||
'y': item['y'] + item['h']//2}}),
|
||||
}
|
||||
return options
|
||||
if any('选择遭遇战奖励卡' in t for t in texts):
|
||||
for index,item in enumerate(items):
|
||||
if height*.48 < item['y'] < height*.65 and any(t in item['text'] for t in ('经费', '资源', '体力', '理智')):
|
||||
options['reward_card_anchor_%d'%index]={'description':'当前奖励卡:'+item['text'], 'action':{'tool':'click','args':{'x':item['x']+item['w']//2,'y':round(item['y']-height*.15)}}}
|
||||
for number, fraction in enumerate((0.355, 0.514, 0.674), 1):
|
||||
cx = round(width*fraction)
|
||||
detail = ';'.join(i['text'] for i in items
|
||||
@@ -293,6 +359,40 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
'y': item['y'] + item['h'] // 2}},
|
||||
}
|
||||
return options
|
||||
# The blessing's tier-III choice is not the optional observation. Only
|
||||
# offer the required Battery, never a generic decline/unchecked confirm.
|
||||
gift_selection = (any(re.match(r'^(?:选择|可选择)(?:E\.?G\.?O\.?)?饰品', t, re.I) for t in texts)
|
||||
or '饰品观测' in combined or '拒绝饰品' in texts)
|
||||
if gift_selection:
|
||||
battery = next((i for i in items if re.search(r'(标准负载|标准负荷|Standard-duty).*?(电池|Battery)', i['text'], re.I)), None)
|
||||
unselected = any(re.search(r'(?:选择|可选).*?0/\d', t) for t in texts)
|
||||
confirm = next((i for i in items if i['text'].replace(' ', '') in ('确认', '选择')
|
||||
and button_enabled(state, i)), None)
|
||||
if battery:
|
||||
if confirm and not unselected:
|
||||
options['confirm_startup_battery'] = {
|
||||
'description': '电池选项已可确认,领取开局必需的标准负载电池。',
|
||||
'action': {'tool': 'click', 'args': {'x': confirm['x']+confirm['w']//2,
|
||||
'y': confirm['y']+confirm['h']//2}},
|
||||
}
|
||||
else:
|
||||
options['select_startup_battery'] = {
|
||||
'description': '选择开局必需饰品标准负载电池;此三选一界面不可拒绝。',
|
||||
'action': {'tool': 'click', 'args': {'x': battery['x']+battery['w']//2,
|
||||
'y': battery['y']+battery['h']//2}},
|
||||
}
|
||||
# Unrecognized choices need analysis; never silently skip a required gift.
|
||||
# A separately labelled extra observation may still be declined.
|
||||
elif any(re.search(r'(额外|追加).*观测', t) for t in texts):
|
||||
refuse = next((i for i in items if i['text'].replace(' ', '') == '拒绝饰品'
|
||||
and button_enabled(state, i)), None)
|
||||
if refuse:
|
||||
options['decline_extra_observation'] = {
|
||||
'description': '拒绝明确标注的额外观测,不影响开局三级饰品选择。',
|
||||
'action': {'tool': 'click', 'args': {'x': refuse['x']+refuse['w']//2,
|
||||
'y': refuse['y']+refuse['h']//2}},
|
||||
}
|
||||
return options
|
||||
if any('选择' in t and '层主题卡包' in t for t in texts):
|
||||
# This screen has five clipped bags; title OCR anchors each visible bag.
|
||||
for number, fraction in enumerate((0.17, 0.335, 0.5, 0.665, 0.83), 1):
|
||||
@@ -311,13 +411,15 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
'to_x': cx, 'to_y': round(height*.91), 'duration': 1.8}},
|
||||
}
|
||||
return options
|
||||
in_shop = '商店' in texts and '刷新' in texts
|
||||
in_shop = any(t in ('商店','特殊商店') for t in texts) and '刷新' in texts
|
||||
party = ('辛克莱', '鸿璐', '希斯克利夫', '奥提斯', '格里高尔', '良秀', '浮士德')
|
||||
swaps = [(index, item) for index, item in enumerate(items)
|
||||
if '替换' in item['text'] and any(name in item['text'] for name in party)
|
||||
and not any('已购买' in sold['text']
|
||||
and abs(sold['x']+sold['w']/2-item['x']-item['w']/2) < width*.07
|
||||
and 0 < item['y']-sold['y'] < height*.25 for sold in items)]
|
||||
if in_shop and state.get('floor', 1) >= 2 and not state.get('symbol_upgraded', False):
|
||||
return options
|
||||
if in_shop:
|
||||
for index, item in swaps:
|
||||
options['swap_%d' % index] = {
|
||||
@@ -334,12 +436,12 @@ def candidates(state, previous_battle=False, refresh_used=0):
|
||||
'y': item['y'] + item['h'] // 2}},
|
||||
}
|
||||
end_screen = any(t.upper() in ('VICTORY', 'DEFEAT') or any(m in t for m in
|
||||
('正在探', '获得E.G.O饰品', '开始战斗', '主题卡包', '应该让谁上前', '选择遭遇战奖励卡')) for t in texts)
|
||||
battle = any(m in combined.upper() for m in ('WAVE', 'TURN', 'DURANTE', '胜率', '伤害'))
|
||||
('正在探', '获得E.G.O饰品', '选择E.G.O饰品', '饰品观测', '开始战斗', '主题卡包', '应该让谁', '选择一位罪人', '进行判定', '选择遭遇战奖励卡')) for t in texts)
|
||||
battle = any(m in combined.upper() for m in ('WAVE', 'TURN', 'DURANTE')) or any(t in ('胜率', '伤害') for t in texts)
|
||||
if not end_screen and (battle or previous_battle):
|
||||
options['battle'] = {'description': '仍处于战斗或特写:执行短批次 P→回车,两次后检查结算,不分析拼点。',
|
||||
'action': {'tool': 'battle', 'args': {'rounds': 2}}}
|
||||
known_buttons = ('确认', '继续', '进入', '开始战斗', 'SKIP', '进行判定', '拒绝饰品',
|
||||
known_buttons = ('确认', '继续', '进入', '开始战斗', 'SKIP', '进行判定',
|
||||
'离开', '下一层', '前往下一层', '领取奖励', '结束探索', 'TOUCHTOSTART', '选择')
|
||||
for index, item in enumerate(items):
|
||||
label = item['text'].replace(' ', '')
|
||||
@@ -423,7 +525,7 @@ def decide(cfg, state, options, recent):
|
||||
except (OSError, TimeoutError):
|
||||
if attempt:
|
||||
raise
|
||||
time.sleep(0.3)
|
||||
time.sleep(15)
|
||||
answer = result.get('answers', {}).get('action', {})
|
||||
choice = answer.get('choice')
|
||||
if answer.get('type') != 'choice' or choice not in options:
|
||||
@@ -431,6 +533,47 @@ def decide(cfg, state, options, recent):
|
||||
return choice, round((time.monotonic() - start) * 1000)
|
||||
|
||||
|
||||
def fixed_fallback(options):
|
||||
for key in ('run_complete','select_startup_battery','confirm_startup_battery','decline_extra_observation','retry_network','buy_swap','confirm_swap','confirm_reward','hardship_confirm','modal_confirm','claim_final','close_progress'):
|
||||
if key in options:
|
||||
return key
|
||||
judge=next((k for k in options if k.startswith('button_') and '进行判定' in options[k]['description']),None)
|
||||
if judge:
|
||||
return judge
|
||||
for prefix in ('skill_swap_', 'swap_', 'sinner_card_', 'sinner_'):
|
||||
keys=[k for k in options if k.startswith(prefix)]
|
||||
if keys:
|
||||
return keys[0]
|
||||
if 'shop_refresh' in options:
|
||||
return 'shop_refresh'
|
||||
routes=[k for k in options if k.startswith('route_')]
|
||||
if routes:
|
||||
return min(routes,key=lambda k: 0 if '商店' in options[k]['description'] else 1 if '事件' in options[k]['description'] else 3 if '精英' in options[k]['description'] or '集中' in options[k]['description'] else 2)
|
||||
events=[k for k in options if k.startswith('event_') and k!='event_scroll']
|
||||
safe=[k for k in events if any(t in options[k]['description'] for t in ('离开','继续走','无视','不理','走开')) and '战斗胜利' not in options[k]['description']]
|
||||
if safe:
|
||||
return safe[0]
|
||||
combat = ('战斗胜利', '进入战斗', '触发遭遇战', '开始战斗')
|
||||
direct=[k for k in events if not any(t in options[k]['description'] for t in ('判定',)+combat)]
|
||||
if direct:
|
||||
return direct[0]
|
||||
if len(events)==1 and not any(t in options[events[0]]['description'] for t in combat):
|
||||
return events[0]
|
||||
if 'event_scroll' in options:
|
||||
return 'event_scroll'
|
||||
rewards=[k for k in options if k.startswith('reward_card_')]
|
||||
if rewards:
|
||||
return min(rewards,key=lambda k: 0 if '经费' in options[k]['description'] else 1)
|
||||
buttons=[k for k in options if k.startswith('button_')]
|
||||
if len(buttons)==1:
|
||||
return buttons[0]
|
||||
for text in ('确认','继续','进入','开始战斗','离开'):
|
||||
match=next((k for k in buttons if text in options[k]['description']),None)
|
||||
if match:
|
||||
return match
|
||||
return 'requires_analysis'
|
||||
|
||||
|
||||
def execute(bridge, action):
|
||||
if action['tool'] == 'claim_final':
|
||||
result = bridge.call('click', action['args'])
|
||||
@@ -473,9 +616,9 @@ def execute(bridge, action):
|
||||
if not state.get('ok'):
|
||||
return state
|
||||
texts = [i['text'].replace(' ', '') for i in text_items(state)]
|
||||
terminal = any(t.upper() in ('VICTORY', 'DEFEAT') or any(m in t for m in
|
||||
('正在探', '获得E.G.O饰品', '开始战斗', '主题卡包',
|
||||
'应该让谁上前', '选择遭遇战奖励卡', '选项事件', '选择苦难')) for t in texts)
|
||||
terminal = death_retry_screen(texts) or any(t.upper() in ('VICTORY', 'DEFEAT') or any(m in t for m in
|
||||
('正在探', '获得E.G.O饰品', '选择E.G.O饰品', '饰品观测', '开始战斗', '主题卡包',
|
||||
'应该让谁', '选择一位罪人', '进行判定', '选择遭遇战奖励卡', '选项事件', '选择苦难', '选项', '结果')) for t in texts)
|
||||
if terminal:
|
||||
return {'ok': True, 'pairs': pairs, 'terminal': True, 'screen': state.get('screen')}
|
||||
return {'ok': True, 'pairs': pairs, 'terminal': False}
|
||||
@@ -521,6 +664,7 @@ def main():
|
||||
context = json.loads(context_path.read_text(encoding='utf-8')) if context_path.exists() else {'refresh_used': 0}
|
||||
stable_since = time.monotonic()
|
||||
last_fingerprint = None
|
||||
unknown_since = None
|
||||
try:
|
||||
for step in range(args.steps):
|
||||
if STOP_FILE.exists() or time.monotonic() > deadline:
|
||||
@@ -531,7 +675,7 @@ def main():
|
||||
state = {'ok': False, 'items': [{'text': 'MCP 截图暂不可用;游戏窗口可能正在重建。' + str(state.get('error','')),
|
||||
'x':0,'y':0,'w':0,'h':0,'score':1.0}]}
|
||||
fingerprint = tuple(item['text'] for item in text_items(state)
|
||||
if item.get('score', 0) > 0.93 and not item['text'].replace('.', '').isdigit())
|
||||
if item.get('score', 0) > 0.93 and not item['text'].replace('.', '').isdigit() and not re.fullmatch(r'[0-9:]+', item['text']))
|
||||
if any('正在探' in i['text'] or '主题卡包' in i['text'] for i in text_items(state)):
|
||||
context['refresh_used'] = 0
|
||||
for item in text_items(state):
|
||||
@@ -540,6 +684,8 @@ def main():
|
||||
context['floor'] = int(match[1])
|
||||
context_path.write_text(json.dumps(context), encoding='utf-8')
|
||||
state['floor'] = context.get('floor', 3)
|
||||
state['symbol_upgraded'] = context.get('symbol_upgraded', False)
|
||||
state['claim_requested'] = context.get('claim_requested', False)
|
||||
options = candidates(state, previous_battle, context['refresh_used'])
|
||||
if fingerprint != last_fingerprint:
|
||||
stable_since = time.monotonic()
|
||||
@@ -561,9 +707,17 @@ def main():
|
||||
action_id = json.dumps(options[key]['action'], sort_keys=True)
|
||||
if key not in ('requires_analysis', 'wait', 'battle') and repeats.get((fingerprint, action_id), 0) >= 2:
|
||||
del options[key]
|
||||
if len(options) == 2:
|
||||
unknown_since = unknown_since or time.monotonic()
|
||||
else:
|
||||
unknown_since = None
|
||||
# User explicitly prescribed the complete battle loop. Only scene
|
||||
# transitions return to Jev; combat does not require new decisions.
|
||||
if 'event_finish' in options:
|
||||
if any(re.search(r'CON+ECTING|LOADING', i['text'].upper()) for i in text_items(state)):
|
||||
choice, latency = 'wait', 0
|
||||
elif len(options)==2 and time.monotonic() - unknown_since < 10:
|
||||
choice, latency = 'wait', 0
|
||||
elif 'event_finish' in options:
|
||||
choice, latency = 'event_finish', 0
|
||||
elif 'skip_dialog' in options:
|
||||
choice, latency = 'skip_dialog', 0
|
||||
@@ -572,10 +726,27 @@ def main():
|
||||
elif 'battle' in options:
|
||||
choice, latency = 'battle', 0
|
||||
else:
|
||||
choice, latency = decide(cfg, state, options, recent)
|
||||
if os.environ.get('LC_FIXED_FALLBACK') == '1':
|
||||
choice, latency = fixed_fallback(options), 0
|
||||
else:
|
||||
choice, latency = decide(cfg, state, options, recent)
|
||||
action = options[choice]['action']
|
||||
record = {'step': step, 'choice': choice, 'action': action, 'jev_ms': latency,
|
||||
'screen': state.get('screen'), 'at': time.strftime('%Y-%m-%dT%H:%M:%S')}
|
||||
if choice == 'run_complete':
|
||||
record['state'] = 'completed'
|
||||
status.write_text(json.dumps(record, ensure_ascii=False), encoding='utf-8')
|
||||
run_path = RUNTIME_HOME / 'mirror_current_run.json'
|
||||
if run_path.exists():
|
||||
from datetime import datetime, timezone
|
||||
run = json.loads(run_path.read_text(encoding='utf-8'))
|
||||
now = datetime.now(timezone.utc)
|
||||
run.update(status='completed', dungeon_completed=True, final_reward_claimed=True,
|
||||
end_utc=now.isoformat(), elapsed_seconds=(now-datetime.fromisoformat(run['start_utc'])).total_seconds(),
|
||||
completion_evidence=state.get('screen'))
|
||||
run_path.write_text(json.dumps(run, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
print(json.dumps(record, ensure_ascii=False), flush=True)
|
||||
return
|
||||
if choice == 'requires_analysis':
|
||||
record.update(state='requires_analysis', items=text_items(state))
|
||||
status.write_text(json.dumps(record, ensure_ascii=False), encoding='utf-8')
|
||||
@@ -584,6 +755,9 @@ def main():
|
||||
action_id = json.dumps(action, sort_keys=True)
|
||||
repeats[(fingerprint, action_id)] = repeats.get((fingerprint, action_id), 0) + 1
|
||||
result = execute(bridge, action)
|
||||
if choice == 'claim_final' and result.get('ok'):
|
||||
context['claim_requested'] = True
|
||||
context_path.write_text(json.dumps(context), encoding='utf-8')
|
||||
if choice == 'shop_refresh':
|
||||
context['refresh_used'] += 1
|
||||
context_path.write_text(json.dumps(context), encoding='utf-8')
|
||||
|
||||
Reference in New Issue
Block a user