feat: AIPlanner에서 건설 전 이동 보장 로직 추가

- `_ensure_move_before_build_actions` 메서드를 추가하여, LLM이 "move" 후 "place_entity"/"insert_to_entity"/"set_recipe" 순서를 놓치는 경우를 방지
- 최근 이동 좌표와 비교하여 필요 시 자동으로 이동 액션을 삽입하는 로직 구현
- 관련 단위 테스트 추가 및 README.md에 변경 사항 반영
This commit is contained in:
kswdev0
2026-03-26 11:56:33 +09:00
parent e0ca8f7b52
commit 6e5f781529
3 changed files with 71 additions and 0 deletions

View File

@@ -265,9 +265,49 @@ class AIPlanner:
print(f"[AI] 완료 후: {plan.get('after_this', '')}")
actions = plan.get("actions", [])
actions = self._ensure_move_before_build_actions(actions)
print(f"[AI] {len(actions)}개 행동 계획됨")
return actions
@staticmethod
def _ensure_move_before_build_actions(actions: list[dict]) -> list[dict]:
"""
LLM이 "move 후 배치" 순서를 놓치는 경우가 있어,
place_entity/insert_to_entity/set_recipe 앞에 최근 move가 같은 좌표가 아니면
안전장치로 move를 끼워 넣는다.
"""
out: list[dict] = []
last_move_xy: tuple[object, object] | None = None
for a in actions:
if not isinstance(a, dict):
continue
act = a.get("action")
params = a.get("params") if isinstance(a.get("params"), dict) else {}
if act == "move":
mx = params.get("x")
my = params.get("y")
last_move_xy = (mx, my)
out.append(a)
continue
if act in ("place_entity", "insert_to_entity", "set_recipe"):
tx = params.get("x")
ty = params.get("y")
if tx is not None and ty is not None:
if last_move_xy != (tx, ty):
out.append({
"action": "move",
"params": {"x": tx, "y": ty},
"reason": "안전장치: 건설/삽입 거리 제한 때문에 move 먼저",
})
last_move_xy = (tx, ty)
out.append(a)
return out
def record_feedback(self, action: dict, success: bool, message: str = ""):
self.feedback_log.append({
"action": action.get("action", ""),