#!/usr/bin/env node /** * TypeScript side of cross-language equivalence validation * * Reads TGN files and outputs: * - Final board state * - Territory calculation results * - Move count * * Output format: JSON for easy parsing by comparison script */ import { TrigoGame } from "@inc/trigo/game.js"; import { calculateTerritory } from "@inc/trigo/gameUtils.js"; import * as fs from "fs"; import * as path from "path"; interface GameResult { tgnFile: string; boardShape: { x: number; y: number; z: number }; moveCount: number; board: number[][][]; // 3D array: board[x][y][z] = stone type territory: { black: number; white: number; neutral: number; }; error?: string; } function processGame(tgnFile: string): GameResult { try { const tgnContent = fs.readFileSync(tgnFile, "utf-8"); // Parse TGN const game = TrigoGame.fromTGN(tgnContent); // Get final state const board = game.getBoard(); const shape = game.getShape(); const history = game.getHistory(); // Calculate territory const territory = calculateTerritory(board, shape); return { tgnFile: path.basename(tgnFile), boardShape: shape, moveCount: history.length, board, territory: { black: territory.black, white: territory.white, neutral: territory.neutral } }; } catch (error) { return { tgnFile: path.basename(tgnFile), boardShape: { x: 0, y: 0, z: 0 }, moveCount: 0, board: [], territory: { black: 0, white: 0, neutral: 0 }, error: error instanceof Error ? error.message : String(error) }; } } function main() { const args = process.argv.slice(2); if (args.length === 0) { console.error("Usage: validate_game_equivalence.ts [ ...]"); process.exit(1); } const results: GameResult[] = []; for (const tgnFile of args) { if (!fs.existsSync(tgnFile)) { console.error(`File not found: ${tgnFile}`); continue; } const result = processGame(tgnFile); results.push(result); } // Output as JSON console.log(JSON.stringify(results, null, 2)); } main();