게시판바둑 on-policy 학습: 대국 로그를 KataGo 라벨로 바꾸기예제 소스

예제 소스

바둑 on-policy 학습: 대국 로그를 KataGo 라벨로 바꾸기 · 파일 169개

test_coord_scan.py

"""열을 한 줄로 주는 프롬프트와, JSON이 두 번 나와도 마지막 답을 읽는 채점."""

from __future__ import annotations

import sys
import unittest
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))

from scripts.eval_coords_game import parse_scan, score  # noqa: E402
from vlm_server.dataset_baduk import col_line_indexed, column_scan_user  # noqa: E402


def _cells() -> bytes:
    cells = bytearray(19 * 19)
    cells[0 * 19 + 3] = 1
    cells[4 * 19 + 3] = 2
    cells[15 * 19 + 3] = 1
    return bytes(cells)


class ColLineTest(unittest.TestCase):
    def test_line_lists_rows_of_that_column(self) -> None:
        line = col_line_indexed(_cells(), 3)
        toks = line.split()
        self.assertEqual(len(toks), 19)
        self.assertEqual(toks[0], "00X")
        self.assertEqual(toks[4], "04O")
        self.assertEqual(toks[15], "15X")
        self.assertEqual(toks[1], "01.")

    def test_prompt_is_one_line_not_the_grid(self) -> None:
        user = column_scan_user(_cells(), 3)
        self.assertIn("00X 01. 02. 03. 04O", user)
        self.assertNotIn("보드 문자 격자", user)
        self.assertIn("이 줄만 보고", user)


class ParseScanTest(unittest.TestCase):
    def test_last_object_wins_when_json_is_repeated(self) -> None:
        raw = (
            '분석 {"X": [1], "O": [2]} 가 초안.\n'
            '<|start|>assistant to=user<|message|>{"X": [3, 4], "O": [10]}'
        )
        self.assertEqual(parse_scan(raw), {"X": [3, 4], "O": [10]})

    def test_keeps_complete_object_when_the_tail_is_cut(self) -> None:
        raw = '세는 중 {"X": [3], "O": [15]} 이어서 {"X": [3], "O":'
        self.assertEqual(parse_scan(raw), {"X": [3], "O": [15]})

    def test_score_column_against_last_json(self) -> None:
        rec = {"task": "col", "expect": {"X": [3], "O": [15]}, "board": "." * 361}
        raw = '{"X": [0], "O": []} {"X": [3], "O": [15]}'
        got = score(rec, raw)
        self.assertTrue(got["ok"])
        self.assertEqual(got["got"], {"X": [3], "O": [15]})


if __name__ == "__main__":
    unittest.main()