Spaces:
Sleeping
Sleeping
File size: 3,897 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 109 110 111 112 113 114 115 116 117 118 119 120 121 |
import { TrigoGame } from "../inc/trigo/game";
// Test hasCapturingMove() function
console.log("=== Test: hasCapturingMove() on 7x1x1 ===\n");
// 7x1x1: a(0), b(1), c(2), 0(3), x(4), y(5), z(6)
const game = new TrigoGame({ x: 7, y: 1, z: 1 });
game.startGame();
const labels = ["a", "b", "c", "0", "x", "y", "z"];
function showState(msg: string) {
console.log(`\n--- ${msg} ---`);
const board = game.getBoard();
const boardStr = labels.map((l, i) => {
const s = board[i][0][0];
return `${l}:${s === 0 ? "." : s === 1 ? "B" : "W"}`;
}).join(" ");
console.log(`Board: ${boardStr}`);
console.log(`Current player: ${game.getCurrentPlayer() === 1 ? "Black" : "White"}`);
console.log(`hasCapturingMove(): ${game.hasCapturingMove()}`);
const territory = game.getTerritory();
console.log(`Territory: B=${territory.black} W=${territory.white} N=${territory.neutral}`);
}
// Initial state
showState("Initial (empty board)");
// 1. Black plays 0 (center)
game.drop({ x: 3, y: 0, z: 0 });
console.log("\n1. Black: 0");
showState("After Black 0");
// 2. White plays z (corner)
game.drop({ x: 6, y: 0, z: 0 });
console.log("\n2. White: z");
showState("After White z");
// 3. Black plays y (threatens z)
game.drop({ x: 5, y: 0, z: 0 });
console.log("\n3. Black: y (captures White z!)");
showState("After Black y - White z captured");
// Let's create a different scenario where capturing is possible but not yet done
console.log("\n\n" + "=".repeat(60));
console.log("=== Test 2: Position with capturing move available ===");
console.log("=".repeat(60));
const game2 = new TrigoGame({ x: 7, y: 1, z: 1 });
game2.startGame();
// Build: 1. 0 z 2. b Pass
// After this, Black can play 'y' to capture White's z (z has 1 liberty at y)
const moves2 = [
{ pos: { x: 3, y: 0, z: 0 }, name: "0" }, // Black: center
{ pos: { x: 6, y: 0, z: 0 }, name: "z" }, // White: corner z (has 1 liberty at y)
{ pos: { x: 1, y: 0, z: 0 }, name: "b" }, // Black: b (doesn't threaten z)
{ pos: null, name: "Pass" }, // White: Pass
];
for (const move of moves2) {
if (move.pos) {
game2.drop(move.pos);
} else {
game2.pass();
}
}
const board2 = game2.getBoard();
const boardStr2 = labels.map((l, i) => {
const s = board2[i][0][0];
return `${l}:${s === 0 ? "." : s === 1 ? "B" : "W"}`;
}).join(" ");
console.log(`\nBoard: ${boardStr2}`);
console.log(`Current player: ${game2.getCurrentPlayer() === 1 ? "Black" : "White"}`);
console.log("Black can play 'y' to capture White's z");
// Now check both players
console.log(`\nhasCapturingMove(Black): ${game2.hasCapturingMove(1)}`);
console.log(`hasCapturingMove(White): ${game2.hasCapturingMove(2)}`);
console.log("\n" + "=".repeat(60));
console.log("=== Test 3: Position with NO capturing moves ===");
console.log("=".repeat(60));
const game3 = new TrigoGame({ x: 5, y: 1, z: 1 });
game3.startGame();
// 5x1x1: a(0), b(1), 0(2), x(3), y(4)
// Build a position where all stones are safe
// 1. 0 (Black center) 2. Pass 3. b 4. Pass 5. x
const moves3 = [
{ pos: { x: 2, y: 0, z: 0 }, name: "0" },
{ pos: null, name: "Pass" },
{ pos: { x: 1, y: 0, z: 0 }, name: "b" },
{ pos: null, name: "Pass" },
{ pos: { x: 3, y: 0, z: 0 }, name: "x" },
];
for (const move of moves3) {
if (move.pos) {
game3.drop(move.pos);
} else {
game3.pass();
}
}
const labels5 = ["a", "b", "0", "x", "y"];
const board3 = game3.getBoard();
const boardStr3 = labels5.map((l, i) => {
const s = board3[i][0][0];
return `${l}:${s === 0 ? "." : s === 1 ? "B" : "W"}`;
}).join(" ");
console.log(`\nBoard: ${boardStr3}`);
console.log(`Current player: ${game3.getCurrentPlayer() === 1 ? "Black" : "White"}`);
console.log(`hasCapturingMove(): ${game3.hasCapturingMove()}`);
const territory3 = game3.getTerritory();
console.log(`Territory: B=${territory3.black} W=${territory3.white} N=${territory3.neutral}`);
|