예제 소스
바둑 on-policy 학습: 대국 로그를 KataGo 라벨로 바꾸기 · 파일 169개
test_r5_moves.py
"""R5 착수가 빈 칸의 합법 수일 때만 학습 레코드가 된다."""
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.dataset_r5_moves import mix_with_r5, r5_record # noqa: E402
class R5MoveTest(unittest.TestCase):
def test_opening_star_point_is_kept(self) -> None:
cells = bytes(19 * 19)
rec = r5_record(cells, 3, 3, "t:1:1")
self.assertIsNotNone(rec)
self.assertEqual(rec["task"], "r5move")
self.assertIn('{"row": 3, "col": 3}', rec["messages"][1]["content"][0]["text"])
self.assertIn("백(O)", rec["usr"])
def test_occupied_point_is_dropped(self) -> None:
cells = bytearray(19 * 19)
cells[3 * 19 + 3] = 1
self.assertIsNone(r5_record(bytes(cells), 3, 3, "t:1:2"))
def test_mix_fits_the_trainer_cap(self) -> None:
coord = [{"task": "lookup", "id": i} for i in range(5)]
moves = [{"task": "move", "id": i} for i in range(10)]
r5 = [{"task": "r5move", "id": i} for i in range(8)]
mixed = mix_with_r5(coord + moves, r5, train_n=9, r5_n=3, seed=1)
self.assertEqual(len(mixed), 9)
self.assertEqual(sum(r["task"] == "lookup" for r in mixed), 5)
self.assertEqual(sum(r["task"] == "r5move" for r in mixed), 3)
self.assertEqual(sum(r["task"] == "move" for r in mixed), 1)
if __name__ == "__main__":
unittest.main()