fix: 실패한 타일 제외

This commit is contained in:
21in7
2026-03-25 21:20:20 +09:00
parent bc7bb4d1e6
commit c99ca1e43c
9 changed files with 36 additions and 8 deletions

View File

@@ -134,14 +134,14 @@ rcon.print("WALK:" .. string.format("%.1f", dist))
before_count = self._get_item_count(ore)
target_count = before_count + count
total_mined = 0
failed_positions = set() # 실패한 좌표 기억
failed_positions: set[tuple[int, int]] = set() # Lua exclude 키와 동일한 정수 타일 좌표만 저장
for round_num in range(15): # 최대 15번 시도
# 1. Lua에서 가장 가까운 광석 찾기 (실패한 좌표 제외)
# 제외 좌표를 Lua 테이블로 전달
exclude_lua = "local exclude = {}\n"
for i, (fx, fy) in enumerate(failed_positions):
exclude_lua += f'exclude["{fx:.0f},{fy:.0f}"] = true\n'
exclude_lua += f'exclude["{fx},{fy}"] = true\n'
find_result = self.rcon.lua(P + f"""
{exclude_lua}
@@ -156,9 +156,12 @@ table.sort(res, function(a, b)
end)
-- 제외 목록에 없는 가장 가까운 광석 찾기
for _, e in ipairs(res) do
local key = string.format("%.0f,%.0f", e.position.x, e.position.y)
-- Lua 키를 "정수 타일"로 통일 (반올림/절삭 방식 차이로 exclude가 빗나가는 문제 방지)
local tx = math.floor(e.position.x + 0.5)
local ty = math.floor(e.position.y + 0.5)
local key = string.format("%d,%d", tx, ty)
if not exclude[key] then
rcon.print(string.format("%.1f,%.1f", e.position.x, e.position.y))
rcon.print(key)
return
end
end
@@ -176,14 +179,14 @@ rcon.print("ALL_EXCLUDED")
return False, f"{ore} 근처 타일 {len(failed_positions)}개 모두 접근 불가 — 다른 위치로 이동 필요"
try:
parts = find_result.split(",")
ox, oy = float(parts[0]), float(parts[1])
parts = find_result.strip().split(",")
ox, oy = int(parts[0]), int(parts[1])
except:
return False, f"좌표 파싱 실패: {find_result}"
# 2. 광석 위치로 걸어가기
print(f" [채굴] 광석({ox:.0f},{oy:.0f})으로 이동... (시도 {round_num+1}, 제외: {len(failed_positions)}개)")
ok, msg = self.move(int(ox), int(oy))
print(f" [채굴] 광석({ox},{oy})으로 이동... (시도 {round_num+1}, 제외: {len(failed_positions)}개)")
ok, msg = self.move(ox, oy)
if not ok:
print(f" [채굴] 이동 실패: {msg}")
failed_positions.add((ox, oy))