/** * Test the 5x1x1 game to verify if it's really finished * TGN: 1. y 0 2. b Pass 3. 0 */ import { TrigoGame } from "../inc/trigo/game.js"; const StoneType = { EMPTY: 0, BLACK: 1, WHITE: 2, }; function printBoard(game: TrigoGame) { const shape = game.getShape(); const board = game.getBoard(); const stones = []; for (let x = 0; x < shape.x; x++) { const stone = board[x]?.[0]?.[0]; if (stone === undefined) { stones.push("?"); } else { stones.push(stone === StoneType.BLACK ? "B" : stone === StoneType.WHITE ? "W" : "."); } } console.log(`Board: [${stones.join(", ")}]`); console.log(` Shape: ${shape.x}×${shape.y}×${shape.z}`); } console.log("Testing 5x1x1 game from self-play:"); console.log("TGN: 1. y 0 2. b Pass 3. 0"); console.log(); const game = new TrigoGame({ x: 5, y: 1, z: 1 }); console.log("Initial board:"); printBoard(game); console.log(); // Move 1: Black y (y=3 in 5x1x1) console.log("Move 1: Black plays y"); game.drop({ x: 3, y: 0, z: 0 }); printBoard(game); // Move 2: White 0 (x=2, center) console.log("Move 2: White plays 0"); game.drop({ x: 2, y: 0, z: 0 }); printBoard(game); // Move 3: Black b (x=1) console.log("Move 3: Black plays b"); game.drop({ x: 1, y: 0, z: 0 }); printBoard(game); // Move 4: White Pass console.log("Move 4: White passes"); game.pass(); printBoard(game); // Move 5: Black 0 (x=2, center) - should capture White console.log("Move 5: Black plays 0 (should capture White)"); game.drop({ x: 2, y: 0, z: 0 }); printBoard(game); console.log(); // Check terminal status const territory = game.getTerritory(); console.log(`Territory: Black=${territory.black}, White=${territory.white}, Neutral=${territory.neutral}`); console.log(); // Check if White can still capture console.log("Checking if White can capture:"); const whiteCanCapture = game.hasCapturingMove(StoneType.WHITE); console.log(`White has capturing move? ${whiteCanCapture}`); if (whiteCanCapture) { console.log("\n⚠️ WHITE CAN STILL CAPTURE!"); console.log("Simulating White's capturing move:"); // Try all positions for White const shape = game.getShape(); const board = game.getBoard(); for (let x = 0; x < shape.x; x++) { if (board[x][0][0] === StoneType.EMPTY) { // Create a test game to try this move const testGame = TrigoGame.fromJSON(game.toJSON()); try { testGame.drop({ x, y: 0, z: 0 }); const testBoard = testGame.getBoard(); const testStones = []; for (let i = 0; i < shape.x; i++) { const stone = testBoard[i][0][0]; testStones.push(stone === StoneType.BLACK ? "B" : stone === StoneType.WHITE ? "W" : "."); } console.log(` If White plays at x=${x}: [${testStones.join(", ")}]`); // Check if this captured any Black stones const capturedInMove = testGame.getCurrentStep()?.captured || []; if (capturedInMove.length > 0) { console.log(` ✓ This move captures ${capturedInMove.length} Black stone(s)!`); } } catch (e) { // Move not valid (suicide, etc.) } } } } console.log(); console.log("Checking if Black can capture:"); const blackCanCapture = game.hasCapturingMove(StoneType.BLACK); console.log(`Black has capturing move? ${blackCanCapture}`); console.log(); console.log("=".repeat(80)); console.log("CONCLUSION:"); if (!whiteCanCapture && !blackCanCapture) { console.log("✓ Game is correctly finished - no captures possible"); } else { console.log("✗ Game should NOT be finished - captures still possible!"); } console.log("=".repeat(80));