예제 소스
SGF 기보로 학습하는 바둑 LLM 인공지능 · 파일 169개
ladder_server_smoke.py
#!/usr/bin/env python3
"""VLM 서버 축 가드 점검 (모델 없이 띄운 서버에 GO19 요청).
python -m vlm_server serve --no-load --port 9349 --log-jsonl logs/ladder_smoke.jsonl &
python scripts/ladder_server_smoke.py --port 9349
"""
from __future__ import annotations
import argparse
import io
import socket
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from PIL import Image # noqa: E402
from scripts.mariago_ensemble_proxy import MoveRequest, recv_reply, send_request # noqa: E402
N = 19
X, O = 1, 2
# 좌상·우상·좌하에 떨어진 돌을 둬 계가 경로(돌>6)를 타게 한다.
FILLER_B = [(15, 3), (3, 15), (16, 15)]
FILLER_W = [(3, 3), (15, 15), (2, 9)]
LADDER_B = [(4, 5), (5, 4), (6, 5), (4, 6)]
LADDER_W = [(5, 5)]
def board(black, white) -> bytes:
b = bytearray(N * N)
for r, c in black:
b[r * N + c] = X
for r, c in white:
b[r * N + c] = O
return bytes(b)
def png() -> bytes:
buf = io.BytesIO()
Image.new("RGB", (8, 8), (200, 160, 90)).save(buf, format="PNG")
return buf.getvalue()
def ask(port: int, cells: bytes, side: int, epoch: int):
with socket.create_connection(("127.0.0.1", port), timeout=30) as s:
send_request(s, MoveRequest(side, png(), cells, epoch, []), epoch)
return recv_reply(s)
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--port", type=int, default=9349)
a = ap.parse_args()
fails = 0
cells = board(LADDER_B + FILLER_B, LADDER_W + FILLER_W)
ok, mv, err = ask(a.port, cells, O, 101)
good = ok and mv not in ((5, 6), "pass")
fails += 0 if good else 1
print(f"[{'OK' if good else 'FAIL'}] 백 축 걸림 → 도망·PASS 대신 다른 곳: 선택={mv} err={err}")
cells = board(LADDER_B + FILLER_B, LADDER_W + FILLER_W + [(12, 13)])
ok, mv, err = ask(a.port, cells, O, 102)
good = ok and mv == (5, 6)
fails += 0 if good else 1
print(f"[{'OK' if good else 'FAIL'}] 축머리 있음 → 도망 (5,6): 선택={mv} err={err}")
print("PASS" if fails == 0 else f"FAIL {fails}")
return 1 if fails else 0
if __name__ == "__main__":
raise SystemExit(main())