Spaces:
Sleeping
Sleeping
File size: 3,902 Bytes
15f353f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
/**
* Test case to verify incorrect terminal detection
*
* Scenario: 5x1x1 board
* 1. a y - Black a(0), White y(3)
* 2. b z - Black b(1), White z(4)
* 3. 0 - Black 0(2) captures White {y, z}
*
* After move 3:
* Board: [Black(a), Black(b), Black(0), Empty(y), Empty(z)]
*
* Problem: System declares game finished with "Black: 5, White: 0"
* Reality: White can still play at y or z and potentially capture Black stones
*/
import { TrigoGame } from "../inc/trigo/game.js";
function testTerminalDetection() {
console.log("================================================================================");
console.log("Testing Terminal Detection Bug in 5x1x1 Board");
console.log("================================================================================\n");
const game = new TrigoGame({ x: 5, y: 1, z: 1 });
game.startGame();
console.log("Initial board (5x1x1):");
console.log("Positions: a(0) - b(1) - 0(2) - y(3) - z(4)\n");
// Move 1: Black a, White y
console.log("Move 1: Black plays a(0)");
game.drop({ x: 0, y: 0, z: 0 });
console.log("Board:", game.getBoard().flat().flat());
console.log("Territory:", game.getTerritory());
console.log("\nMove 1b: White plays y(3)");
game.drop({ x: 3, y: 0, z: 0 });
console.log("Board:", game.getBoard().flat().flat());
console.log("Territory:", game.getTerritory());
// Move 2: Black b, White z
console.log("\nMove 2: Black plays b(1)");
game.drop({ x: 1, y: 0, z: 0 });
console.log("Board:", game.getBoard().flat().flat());
console.log("Territory:", game.getTerritory());
console.log("\nMove 2b: White plays z(4)");
game.drop({ x: 4, y: 0, z: 0 });
console.log("Board:", game.getBoard().flat().flat());
console.log("Territory:", game.getTerritory());
// Move 3: Black 0 - should capture White {y, z}
console.log("\nMove 3: Black plays 0(2) - should capture White stones");
game.drop({ x: 2, y: 0, z: 0 });
console.log("Board:", game.getBoard().flat().flat());
console.log("Territory:", game.getTerritory());
console.log("Game status:", game.getGameStatus());
// Check valid moves for White
console.log("\n" + "=".repeat(80));
console.log("Analysis after Move 3:");
console.log("=".repeat(80));
const validMoves = game.validMovePositions();
console.log("\nValid move positions for White:", validMoves);
console.log("Number of valid moves:", validMoves.length);
// Check if White can capture
const whiteCanCapture = game.hasCapturingMove(2);
console.log("\nWhite has capturing move available?", whiteCanCapture);
// Try White playing at y(3)
console.log("\n" + "=".repeat(80));
console.log("Hypothetical: What if White plays at y(3)?");
console.log("=".repeat(80));
const testGame = game.clone();
try {
testGame.drop({ x: 3, y: 0, z: 0 });
console.log("Board after White y(3):", testGame.getBoard().flat().flat());
console.log("Territory:", testGame.getTerritory());
// Check if any Black stones were captured
const boardAfter = testGame.getBoard().flat().flat();
const blackStones = boardAfter.filter(s => s === 1).length;
const whiteStones = boardAfter.filter(s => s === 2).length;
console.log(`Stones on board: Black=${blackStones}, White=${whiteStones}`);
if (blackStones < 3) {
console.log("\n⚠️ BLACK STONES WERE CAPTURED!");
console.log("This proves the game was NOT terminal after move 3!");
}
} catch (error: any) {
console.log("Error:", error.message);
}
// Conclusion
console.log("\n" + "=".repeat(80));
console.log("CONCLUSION:");
console.log("=".repeat(80));
console.log("The current terminal detection logic is INCORRECT.");
console.log("It only checks hasBlack && hasWhite, which fails when one player");
console.log("has all their stones captured.");
console.log("\nThe game should continue until no more captures are possible,");
console.log("not just when neutral territory is zero.");
}
testTerminalDetection();
|