From 3458688f47f205fe95fc8078a4b22e9c5035d029 Mon Sep 17 00:00:00 2001 From: gihyeon Date: Wed, 25 Mar 2026 12:48:38 +0900 Subject: [PATCH] =?UTF-8?q?=EC=88=9C=EC=88=98=20=ED=94=8C=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=20=EC=A0=84=ED=99=98:=20ACTION=5FDELAY=20=EC=B6=95?= =?UTF-8?q?=EC=86=8C,=20=EC=97=90=EB=9F=AC=20=ED=8A=B8=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=EB=B0=B1=20=EC=B6=94=EA=B0=80,=20=ED=83=80=EC=9E=84?= =?UTF-8?q?=EC=8A=A4=ED=83=AC=ED=94=84=20=EB=A1=9C=EA=B9=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 10ece9f..8ba5792 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,8 @@ """ -main.py — 컨텍스트 압축 통합 버전 +main.py — 순수 AI 플레이 버전 -초반: StateReader 직접 사용 (상세 정보 필요) -중반 이후: ContextCompressor로 자동 전환 (건물 50개 초과 시) +치트 없이 실제 게임 메커닉으로 플레이. +걷기/채굴/제작에 실제 시간이 걸리므로 ACTION_DELAY를 줄임. """ import time import os @@ -16,7 +16,7 @@ from action_executor import ActionExecutor RCON_HOST = os.getenv("FACTORIO_HOST", "127.0.0.1") RCON_PORT = int(os.getenv("FACTORIO_PORT", "25575")) RCON_PASSWORD = os.getenv("FACTORIO_PASSWORD", "factorio_ai") -ACTION_DELAY = 0.5 +ACTION_DELAY = 0.2 # 행동 자체에 시간이 걸리므로 간격 짧게 LOG_FILE = "agent_log.jsonl" # 건물 N개 이상이면 압축 모드로 전환 @@ -25,7 +25,8 @@ COMPRESS_THRESHOLD = 50 def run(): print("=" * 60) - print(" 팩토리오 완전 자율 AI 에이전트 (컨텍스트 압축 포함)") + print(" 팩토리오 순수 AI 에이전트 (치트 없음)") + print(" - 실제 걷기 / 실제 채굴 / 실제 제작 / 건설 거리 제한") print("=" * 60) with FactorioRCON(RCON_HOST, RCON_PORT, RCON_PASSWORD) as rcon: @@ -36,7 +37,7 @@ def run(): total_actions = 0 queue: list[dict] = [] - entity_count = 0 # 마지막으로 파악한 건물 수 + entity_count = 0 while True: try: @@ -46,7 +47,6 @@ def run(): # ── 압축 레벨 자동 선택 ────────────────────── if entity_count < COMPRESS_THRESHOLD: - # 초반: 상세 상태 print("[상태] 초반 모드 — 상세 상태 수집") state = reader.get_full_state() summary = reader.summarize_for_ai(state) @@ -55,15 +55,12 @@ def run(): if isinstance(v, int) ) elif entity_count < 200: - # 중반: 구역별 압축 (level 1) print(f"[상태] 중반 모드 — 구역 압축 (건물 {entity_count}개)") summary = compressor.get_compressed_state(detail_level=1) else: - # 후반: 글로벌 압축 (level 0) print(f"[상태] 후반 모드 — 글로벌 압축 (건물 {entity_count}개)") summary = compressor.get_compressed_state(detail_level=0) - # 건물 수 업데이트 global_info = compressor._get_global_summary() entity_count = global_info.get("total_entities", entity_count) @@ -91,7 +88,7 @@ def run(): planner.record_feedback(action, success, message) if not success: - print(" → 실패. 재계획") + print(" → 실패. 재계획 요청") queue.clear() _log(total_actions, action, success, message) @@ -102,6 +99,8 @@ def run(): break except Exception as e: print(f"[오류] {e}") + import traceback + traceback.print_exc() time.sleep(5) @@ -109,7 +108,8 @@ def _log(step, action, success, message): with open(LOG_FILE, "a", encoding="utf-8") as f: f.write(json.dumps({ "step": step, "action": action, - "success": success, "message": message + "success": success, "message": message, + "timestamp": time.time() }, ensure_ascii=False) + "\n")