Spaces:
Running
Running
Commit
·
63a8db2
1
Parent(s):
3a12496
Deploy: fix build by keeping pre-built dist folder
Browse files- Updated deploy.sh to not remove dist folder
- Dockerfile expects pre-built frontend assets
This view is limited to 50 files because it contains too many changes.
See raw diff
- deploy.sh +2 -3
- trigo-web/backend/dist/backend/src/server.d.ts +2 -0
- trigo-web/backend/dist/backend/src/server.d.ts.map +1 -0
- trigo-web/backend/dist/backend/src/server.js +111 -0
- trigo-web/backend/dist/backend/src/server.js.map +1 -0
- trigo-web/backend/dist/backend/src/services/gameManager.d.ts +97 -0
- trigo-web/backend/dist/backend/src/services/gameManager.d.ts.map +1 -0
- trigo-web/backend/dist/backend/src/services/gameManager.js +352 -0
- trigo-web/backend/dist/backend/src/services/gameManager.js.map +1 -0
- trigo-web/backend/dist/backend/src/sockets/gameSocket.d.ts +4 -0
- trigo-web/backend/dist/backend/src/sockets/gameSocket.d.ts.map +1 -0
- trigo-web/backend/dist/backend/src/sockets/gameSocket.js +410 -0
- trigo-web/backend/dist/backend/src/sockets/gameSocket.js.map +1 -0
- trigo-web/backend/dist/inc/config.d.ts +49 -0
- trigo-web/backend/dist/inc/config.d.ts.map +1 -0
- trigo-web/backend/dist/inc/config.js +185 -0
- trigo-web/backend/dist/inc/config.js.map +1 -0
- trigo-web/backend/dist/inc/mctsAgent.d.ts +136 -0
- trigo-web/backend/dist/inc/mctsAgent.d.ts.map +1 -0
- trigo-web/backend/dist/inc/mctsAgent.js +553 -0
- trigo-web/backend/dist/inc/mctsAgent.js.map +1 -0
- trigo-web/backend/dist/inc/modelInferencer.d.ts +149 -0
- trigo-web/backend/dist/inc/modelInferencer.d.ts.map +1 -0
- trigo-web/backend/dist/inc/modelInferencer.js +377 -0
- trigo-web/backend/dist/inc/modelInferencer.js.map +1 -0
- trigo-web/backend/dist/inc/tgn/tgn.jison.cjs +793 -0
- trigo-web/backend/dist/inc/tgn/tgn.jison.cjs.map +1 -0
- trigo-web/backend/dist/inc/tgn/tgnParser.d.ts +98 -0
- trigo-web/backend/dist/inc/tgn/tgnParser.d.ts.map +1 -0
- trigo-web/backend/dist/inc/tgn/tgnParser.js +92 -0
- trigo-web/backend/dist/inc/tgn/tgnParser.js.map +1 -0
- trigo-web/backend/dist/inc/trigo/ab0yz.d.ts +35 -0
- trigo-web/backend/dist/inc/trigo/ab0yz.d.ts.map +1 -0
- trigo-web/backend/dist/inc/trigo/ab0yz.js +113 -0
- trigo-web/backend/dist/inc/trigo/ab0yz.js.map +1 -0
- trigo-web/backend/dist/inc/trigo/game.d.ts +357 -0
- trigo-web/backend/dist/inc/trigo/game.d.ts.map +1 -0
- trigo-web/backend/dist/inc/trigo/game.js +1002 -0
- trigo-web/backend/dist/inc/trigo/game.js.map +1 -0
- trigo-web/backend/dist/inc/trigo/gameUtils.d.ts +149 -0
- trigo-web/backend/dist/inc/trigo/gameUtils.d.ts.map +1 -0
- trigo-web/backend/dist/inc/trigo/gameUtils.js +448 -0
- trigo-web/backend/dist/inc/trigo/gameUtils.js.map +1 -0
- trigo-web/backend/dist/inc/trigo/index.d.ts +5 -0
- trigo-web/backend/dist/inc/trigo/index.d.ts.map +1 -0
- trigo-web/backend/dist/inc/trigo/index.js +21 -0
- trigo-web/backend/dist/inc/trigo/index.js.map +1 -0
- trigo-web/backend/dist/inc/trigo/parserInit.d.ts +9 -0
- trigo-web/backend/dist/inc/trigo/parserInit.d.ts.map +1 -0
- trigo-web/backend/dist/inc/trigo/parserInit.js +154 -0
deploy.sh
CHANGED
|
@@ -39,10 +39,9 @@ fi
|
|
| 39 |
echo "📦 Copying trigo-web to HF Space repository..."
|
| 40 |
cp -r "$TRIGO_WEB" "$HF_SPACE/"
|
| 41 |
|
| 42 |
-
# Remove node_modules
|
| 43 |
-
echo "🧹 Removing node_modules
|
| 44 |
find "$HF_SPACE/trigo-web" -type d -name "node_modules" -exec rm -rf {} + 2>/dev/null || true
|
| 45 |
-
find "$HF_SPACE/trigo-web" -type d -name "dist" -exec rm -rf {} + 2>/dev/null || true
|
| 46 |
|
| 47 |
# Remove test files
|
| 48 |
echo "🧹 Removing test files..."
|
|
|
|
| 39 |
echo "📦 Copying trigo-web to HF Space repository..."
|
| 40 |
cp -r "$TRIGO_WEB" "$HF_SPACE/"
|
| 41 |
|
| 42 |
+
# Remove node_modules folders (dist is kept - pre-built assets)
|
| 43 |
+
echo "🧹 Removing node_modules folders..."
|
| 44 |
find "$HF_SPACE/trigo-web" -type d -name "node_modules" -exec rm -rf {} + 2>/dev/null || true
|
|
|
|
| 45 |
|
| 46 |
# Remove test files
|
| 47 |
echo "🧹 Removing test files..."
|
trigo-web/backend/dist/backend/src/server.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export {};
|
| 2 |
+
//# sourceMappingURL=server.d.ts.map
|
trigo-web/backend/dist/backend/src/server.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/server.ts"],"names":[],"mappings":""}
|
trigo-web/backend/dist/backend/src/server.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
| 3 |
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
| 4 |
+
};
|
| 5 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 6 |
+
const express_1 = __importDefault(require("express"));
|
| 7 |
+
const http_1 = require("http");
|
| 8 |
+
const socket_io_1 = require("socket.io");
|
| 9 |
+
const cors_1 = __importDefault(require("cors"));
|
| 10 |
+
const dotenv_1 = __importDefault(require("dotenv"));
|
| 11 |
+
const path_1 = __importDefault(require("path"));
|
| 12 |
+
const fs_1 = __importDefault(require("fs"));
|
| 13 |
+
const url_1 = require("url");
|
| 14 |
+
const gameManager_1 = require("./services/gameManager");
|
| 15 |
+
const gameSocket_1 = require("./sockets/gameSocket");
|
| 16 |
+
// Get __dirname equivalent in ES modules
|
| 17 |
+
const __filename = (0, url_1.fileURLToPath)(import.meta.url);
|
| 18 |
+
const __dirname = path_1.default.dirname(__filename);
|
| 19 |
+
// Load environment variables
|
| 20 |
+
// Priority: .env.local > .env (load .env first, then .env.local overwrites)
|
| 21 |
+
// When running via ts-node: __dirname = backend/src/, so go up 1 level
|
| 22 |
+
// When running compiled: __dirname = dist/backend/src/, so go up 3 levels
|
| 23 |
+
const isDev = __dirname.includes("/src") && !__dirname.includes("/dist");
|
| 24 |
+
const levelsUp = isDev ? "../" : "../../../";
|
| 25 |
+
const envPath = path_1.default.join(__dirname, levelsUp, ".env");
|
| 26 |
+
const envLocalPath = path_1.default.join(__dirname, levelsUp, ".env.local");
|
| 27 |
+
// Load .env first (base configuration)
|
| 28 |
+
if (fs_1.default.existsSync(envPath)) {
|
| 29 |
+
dotenv_1.default.config({ path: envPath });
|
| 30 |
+
console.log("[Config] Loaded .env");
|
| 31 |
+
}
|
| 32 |
+
else {
|
| 33 |
+
console.log(`[Config] .env not found at: ${envPath}`);
|
| 34 |
+
}
|
| 35 |
+
// Load .env.local second (overrides .env for local development)
|
| 36 |
+
if (fs_1.default.existsSync(envLocalPath)) {
|
| 37 |
+
dotenv_1.default.config({ path: envLocalPath, override: true });
|
| 38 |
+
console.log("[Config] Loaded .env.local (overriding .env)");
|
| 39 |
+
}
|
| 40 |
+
else {
|
| 41 |
+
console.log(`[Config] .env.local not found at: ${envLocalPath}`);
|
| 42 |
+
}
|
| 43 |
+
const app = (0, express_1.default)();
|
| 44 |
+
const httpServer = (0, http_1.createServer)(app);
|
| 45 |
+
const io = new socket_io_1.Server(httpServer, {
|
| 46 |
+
cors: {
|
| 47 |
+
origin: process.env.NODE_ENV === "production"
|
| 48 |
+
? process.env.CLIENT_URL || "http://localhost:5173"
|
| 49 |
+
: true, // Allow all origins in development
|
| 50 |
+
methods: ["GET", "POST"],
|
| 51 |
+
credentials: true
|
| 52 |
+
}
|
| 53 |
+
});
|
| 54 |
+
// Create GameManager instance
|
| 55 |
+
const gameManager = new gameManager_1.GameManager();
|
| 56 |
+
const PORT = parseInt(process.env.PORT || "3000", 10);
|
| 57 |
+
const HOST = process.env.HOST || "0.0.0.0";
|
| 58 |
+
console.log(`[Config] Server Configuration:`);
|
| 59 |
+
console.log(`[Config] PORT: ${PORT}`);
|
| 60 |
+
console.log(`[Config] HOST: ${HOST}`);
|
| 61 |
+
console.log(`[Config] NODE_ENV: ${process.env.NODE_ENV || "development"}`);
|
| 62 |
+
console.log(`[Config] CLIENT_URL: ${process.env.CLIENT_URL || "not set"}`);
|
| 63 |
+
// Middleware
|
| 64 |
+
app.use((0, cors_1.default)());
|
| 65 |
+
app.use(express_1.default.json());
|
| 66 |
+
// Serve static files from frontend build (for production)
|
| 67 |
+
if (process.env.NODE_ENV === "production") {
|
| 68 |
+
const frontendPath = path_1.default.join(__dirname, "../../../../app/dist");
|
| 69 |
+
app.use(express_1.default.static(frontendPath));
|
| 70 |
+
// Serve index.html for all routes (SPA support)
|
| 71 |
+
app.get("*", (req, res, next) => {
|
| 72 |
+
if (req.path.startsWith("/health") || req.path.startsWith("/socket.io")) {
|
| 73 |
+
return next();
|
| 74 |
+
}
|
| 75 |
+
res.sendFile(path_1.default.join(frontendPath, "index.html"));
|
| 76 |
+
});
|
| 77 |
+
}
|
| 78 |
+
// Health check endpoint
|
| 79 |
+
app.get("/health", (_req, res) => {
|
| 80 |
+
res.json({ status: "ok", timestamp: new Date().toISOString() });
|
| 81 |
+
});
|
| 82 |
+
// Socket.io connection handling
|
| 83 |
+
io.on("connection", (socket) => {
|
| 84 |
+
console.log(`New client connected: ${socket.id}`);
|
| 85 |
+
// Setup game-related socket handlers
|
| 86 |
+
(0, gameSocket_1.setupSocketHandlers)(io, socket, gameManager);
|
| 87 |
+
// Echo test handler (for testing)
|
| 88 |
+
socket.on("echo", (data, callback) => {
|
| 89 |
+
const timestamp = new Date().toISOString();
|
| 90 |
+
const responseMessage = `Hello from server! Received: "${data.message}" at ${timestamp}`;
|
| 91 |
+
console.log(`[Echo] Client ${socket.id}: ${data.message}`);
|
| 92 |
+
// Send response via callback
|
| 93 |
+
if (callback && typeof callback === "function") {
|
| 94 |
+
callback({
|
| 95 |
+
message: responseMessage,
|
| 96 |
+
serverTime: timestamp,
|
| 97 |
+
clientTime: data.timestamp
|
| 98 |
+
});
|
| 99 |
+
}
|
| 100 |
+
});
|
| 101 |
+
socket.on("disconnect", () => {
|
| 102 |
+
console.log(`Client disconnected: ${socket.id}`);
|
| 103 |
+
});
|
| 104 |
+
});
|
| 105 |
+
// Start server
|
| 106 |
+
httpServer.listen(PORT, HOST, () => {
|
| 107 |
+
console.log(`Server running on ${HOST}:${PORT}`);
|
| 108 |
+
console.log(`Health check: http://${HOST}:${PORT}/health`);
|
| 109 |
+
console.log(`Environment: ${process.env.NODE_ENV || "development"}`);
|
| 110 |
+
});
|
| 111 |
+
//# sourceMappingURL=server.js.map
|
trigo-web/backend/dist/backend/src/server.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server.ts"],"names":[],"mappings":";;;;;AAAA,sDAA8B;AAC9B,+BAAoC;AACpC,yCAAmC;AACnC,gDAAwB;AACxB,oDAA4B;AAC5B,gDAAwB;AACxB,4CAAoB;AACpB,6BAAoC;AACpC,wDAAqD;AACrD,qDAA2D;AAE3D,yCAAyC;AACzC,MAAM,UAAU,GAAG,IAAA,mBAAa,EAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAE3C,6BAA6B;AAC7B,4EAA4E;AAC5E,uEAAuE;AACvE,0EAA0E;AAC1E,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACzE,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC;AAC7C,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AACvD,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;AAElE,uCAAuC;AACvC,IAAI,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;IAC5B,gBAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IACjC,OAAO,CAAC,GAAG,CAAC,sBAAs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C,wBAAwB,IAAI,IAAI,IAAI,SAAS,CAAC,CAAC;IAC3D,OAAO,CAAC,GAAG,CAAC,gBAAgB,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,EAAE,CAAC,CAAC;AACtE,CAAC,CAAC,CAAC"}
|
trigo-web/backend/dist/backend/src/services/gameManager.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { BoardShape } from "../../../inc/trigo";
|
| 2 |
+
import { TrigoGame } from "../../../inc/trigo/game";
|
| 3 |
+
export interface Player {
|
| 4 |
+
id: string;
|
| 5 |
+
nickname: string;
|
| 6 |
+
color: "black" | "white";
|
| 7 |
+
connected: boolean;
|
| 8 |
+
}
|
| 9 |
+
export interface GameState {
|
| 10 |
+
gameStatus: "waiting" | "playing" | "finished";
|
| 11 |
+
winner: "black" | "white" | null;
|
| 12 |
+
}
|
| 13 |
+
export interface GameRoom {
|
| 14 |
+
id: string;
|
| 15 |
+
adminId: string;
|
| 16 |
+
players: {
|
| 17 |
+
[playerId: string]: Player;
|
| 18 |
+
};
|
| 19 |
+
game: TrigoGame;
|
| 20 |
+
gameState: GameState;
|
| 21 |
+
createdAt: Date;
|
| 22 |
+
startedAt: Date | null;
|
| 23 |
+
}
|
| 24 |
+
export declare class GameManager {
|
| 25 |
+
private rooms;
|
| 26 |
+
private playerRoomMap;
|
| 27 |
+
private defaultBoardShape;
|
| 28 |
+
constructor();
|
| 29 |
+
createRoom(playerId: string, nickname: string, boardShape?: BoardShape, preferredColor?: "black" | "white"): GameRoom | null;
|
| 30 |
+
joinRoom(roomId: string, playerId: string, nickname: string, preferredColor?: "black" | "white"): GameRoom | null;
|
| 31 |
+
leaveRoom(roomId: string, playerId: string): void;
|
| 32 |
+
makeMove(roomId: string, playerId: string, move: {
|
| 33 |
+
x: number;
|
| 34 |
+
y: number;
|
| 35 |
+
z: number;
|
| 36 |
+
}): boolean;
|
| 37 |
+
passTurn(roomId: string, playerId: string): boolean;
|
| 38 |
+
resign(roomId: string, playerId: string): boolean;
|
| 39 |
+
/**
|
| 40 |
+
* Undo the last move (悔棋)
|
| 41 |
+
*/
|
| 42 |
+
undoMove(roomId: string, playerId: string): boolean;
|
| 43 |
+
/**
|
| 44 |
+
* Redo the last undone move (forward in history)
|
| 45 |
+
*/
|
| 46 |
+
redoMove(roomId: string, playerId: string): boolean;
|
| 47 |
+
/**
|
| 48 |
+
* Reset the game to initial state (new game in same room)
|
| 49 |
+
* Only admin can reset the game
|
| 50 |
+
*/
|
| 51 |
+
resetGame(roomId: string, adminId: string, options?: {
|
| 52 |
+
boardShape?: BoardShape;
|
| 53 |
+
playerColors?: {
|
| 54 |
+
[playerId: string]: "black" | "white";
|
| 55 |
+
};
|
| 56 |
+
}): {
|
| 57 |
+
success: boolean;
|
| 58 |
+
error?: string;
|
| 59 |
+
};
|
| 60 |
+
/**
|
| 61 |
+
* Get game board state for a room
|
| 62 |
+
*/
|
| 63 |
+
getGameBoard(roomId: string): number[][][] | null;
|
| 64 |
+
/**
|
| 65 |
+
* Get game statistics for a room
|
| 66 |
+
*/
|
| 67 |
+
getGameStats(roomId: string): {
|
| 68 |
+
totalMoves: number;
|
| 69 |
+
blackMoves: number;
|
| 70 |
+
whiteMoves: number;
|
| 71 |
+
capturedByBlack: number;
|
| 72 |
+
capturedByWhite: number;
|
| 73 |
+
territory: import("../../../inc/trigo").TerritoryResult;
|
| 74 |
+
};
|
| 75 |
+
/**
|
| 76 |
+
* Get current player for a room
|
| 77 |
+
*/
|
| 78 |
+
getCurrentPlayer(roomId: string): "black" | "white" | null;
|
| 79 |
+
/**
|
| 80 |
+
* Calculate and get territory for a room
|
| 81 |
+
*/
|
| 82 |
+
getTerritory(roomId: string): import("../../../inc/trigo").TerritoryResult;
|
| 83 |
+
/**
|
| 84 |
+
* End the game and determine winner based on territory
|
| 85 |
+
*/
|
| 86 |
+
endGameByTerritory(roomId: string): boolean;
|
| 87 |
+
/**
|
| 88 |
+
* Check if both players passed consecutively (game should end)
|
| 89 |
+
* Returns true if game was ended
|
| 90 |
+
*/
|
| 91 |
+
checkConsecutivePasses(roomId: string): boolean;
|
| 92 |
+
getRoom(roomId: string): GameRoom | undefined;
|
| 93 |
+
getPlayerRoom(playerId: string): GameRoom | undefined;
|
| 94 |
+
getActiveRooms(): GameRoom[];
|
| 95 |
+
private generateRoomId;
|
| 96 |
+
}
|
| 97 |
+
//# sourceMappingURL=gameManager.d.ts.map
|
trigo-web/backend/dist/backend/src/services/gameManager.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"gameManager.d.ts","sourceRoot":"","sources":["../../../../src/services/gameManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAuB,MAAM,yB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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
exports.GameManager = void 0;
|
| 4 |
+
const uuid_1 = require("uuid");
|
| 5 |
+
const game_1 = require("../../../inc/trigo/game");
|
| 6 |
+
class GameManager {
|
| 7 |
+
constructor() {
|
| 8 |
+
this.rooms = new Map();
|
| 9 |
+
this.playerRoomMap = new Map();
|
| 10 |
+
this.defaultBoardShape = { x: 5, y: 5, z: 5 }; // Default 5x5x5 board
|
| 11 |
+
console.log("GameManager initialized");
|
| 12 |
+
}
|
| 13 |
+
createRoom(playerId, nickname, boardShape, preferredColor) {
|
| 14 |
+
const roomId = this.generateRoomId();
|
| 15 |
+
const shape = boardShape || this.defaultBoardShape;
|
| 16 |
+
// Use preferred color if specified, default to black
|
| 17 |
+
const playerColor = preferredColor || "black";
|
| 18 |
+
const room = {
|
| 19 |
+
id: roomId,
|
| 20 |
+
adminId: playerId, // Room creator is admin
|
| 21 |
+
players: {
|
| 22 |
+
[playerId]: {
|
| 23 |
+
id: playerId,
|
| 24 |
+
nickname,
|
| 25 |
+
color: playerColor,
|
| 26 |
+
connected: true
|
| 27 |
+
}
|
| 28 |
+
},
|
| 29 |
+
game: new game_1.TrigoGame(shape, {
|
| 30 |
+
onStepAdvance: (_step, history) => {
|
| 31 |
+
console.log(`Step ${history.length}: Player made move`);
|
| 32 |
+
},
|
| 33 |
+
onCapture: (captured) => {
|
| 34 |
+
console.log(`Captured ${captured.length} stones`);
|
| 35 |
+
},
|
| 36 |
+
onWin: (winner) => {
|
| 37 |
+
console.log(`Game won by ${winner}`);
|
| 38 |
+
}
|
| 39 |
+
}),
|
| 40 |
+
gameState: {
|
| 41 |
+
gameStatus: "waiting",
|
| 42 |
+
winner: null
|
| 43 |
+
},
|
| 44 |
+
createdAt: new Date(),
|
| 45 |
+
startedAt: null
|
| 46 |
+
};
|
| 47 |
+
this.rooms.set(roomId, room);
|
| 48 |
+
this.playerRoomMap.set(playerId, roomId);
|
| 49 |
+
console.log(`Room ${roomId} created by ${playerId}`);
|
| 50 |
+
return room;
|
| 51 |
+
}
|
| 52 |
+
joinRoom(roomId, playerId, nickname, preferredColor) {
|
| 53 |
+
const room = this.rooms.get(roomId);
|
| 54 |
+
if (!room) {
|
| 55 |
+
return null;
|
| 56 |
+
}
|
| 57 |
+
const playerCount = Object.keys(room.players).length;
|
| 58 |
+
if (playerCount >= 2) {
|
| 59 |
+
return null; // Room is full
|
| 60 |
+
}
|
| 61 |
+
// Try to assign preferred color if specified
|
| 62 |
+
const firstPlayer = Object.values(room.players)[0];
|
| 63 |
+
let assignedColor;
|
| 64 |
+
if (preferredColor && preferredColor !== firstPlayer.color) {
|
| 65 |
+
// Preferred color is available
|
| 66 |
+
assignedColor = preferredColor;
|
| 67 |
+
}
|
| 68 |
+
else {
|
| 69 |
+
// Assign opposite of first player's color
|
| 70 |
+
assignedColor = firstPlayer.color === "black" ? "white" : "black";
|
| 71 |
+
}
|
| 72 |
+
room.players[playerId] = {
|
| 73 |
+
id: playerId,
|
| 74 |
+
nickname,
|
| 75 |
+
color: assignedColor,
|
| 76 |
+
connected: true
|
| 77 |
+
};
|
| 78 |
+
this.playerRoomMap.set(playerId, roomId);
|
| 79 |
+
// Start the game when second player joins
|
| 80 |
+
if (playerCount === 1) {
|
| 81 |
+
room.gameState.gameStatus = "playing";
|
| 82 |
+
room.startedAt = new Date();
|
| 83 |
+
}
|
| 84 |
+
return room;
|
| 85 |
+
}
|
| 86 |
+
leaveRoom(roomId, playerId) {
|
| 87 |
+
const room = this.rooms.get(roomId);
|
| 88 |
+
if (!room)
|
| 89 |
+
return;
|
| 90 |
+
if (room.players[playerId]) {
|
| 91 |
+
room.players[playerId].connected = false;
|
| 92 |
+
}
|
| 93 |
+
this.playerRoomMap.delete(playerId);
|
| 94 |
+
// Check if room should be deleted
|
| 95 |
+
const connectedPlayers = Object.values(room.players).filter((p) => p.connected);
|
| 96 |
+
if (connectedPlayers.length === 0) {
|
| 97 |
+
this.rooms.delete(roomId);
|
| 98 |
+
console.log(`Room ${roomId} deleted - no players remaining`);
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
makeMove(roomId, playerId, move) {
|
| 102 |
+
const room = this.rooms.get(roomId);
|
| 103 |
+
if (!room)
|
| 104 |
+
return false;
|
| 105 |
+
const player = room.players[playerId];
|
| 106 |
+
if (!player)
|
| 107 |
+
return false;
|
| 108 |
+
// Check game status
|
| 109 |
+
if (room.gameState.gameStatus !== "playing") {
|
| 110 |
+
return false;
|
| 111 |
+
}
|
| 112 |
+
// Convert player color to Stone type
|
| 113 |
+
const expectedPlayer = player.color === "black" ? game_1.StoneType.BLACK : game_1.StoneType.WHITE;
|
| 114 |
+
const currentPlayer = room.game.getCurrentPlayer();
|
| 115 |
+
// Check if it's the player's turn
|
| 116 |
+
if (currentPlayer !== expectedPlayer) {
|
| 117 |
+
return false;
|
| 118 |
+
}
|
| 119 |
+
// Attempt to make the move using TrigoGame
|
| 120 |
+
const position = { x: move.x, y: move.y, z: move.z };
|
| 121 |
+
const success = room.game.drop(position);
|
| 122 |
+
return success;
|
| 123 |
+
}
|
| 124 |
+
passTurn(roomId, playerId) {
|
| 125 |
+
const room = this.rooms.get(roomId);
|
| 126 |
+
if (!room)
|
| 127 |
+
return false;
|
| 128 |
+
const player = room.players[playerId];
|
| 129 |
+
if (!player)
|
| 130 |
+
return false;
|
| 131 |
+
// Check game status
|
| 132 |
+
if (room.gameState.gameStatus !== "playing") {
|
| 133 |
+
return false;
|
| 134 |
+
}
|
| 135 |
+
// Convert player color to Stone type
|
| 136 |
+
const expectedPlayer = player.color === "black" ? game_1.StoneType.BLACK : game_1.StoneType.WHITE;
|
| 137 |
+
const currentPlayer = room.game.getCurrentPlayer();
|
| 138 |
+
// Check if it's the player's turn
|
| 139 |
+
if (currentPlayer !== expectedPlayer) {
|
| 140 |
+
return false;
|
| 141 |
+
}
|
| 142 |
+
return room.game.pass();
|
| 143 |
+
}
|
| 144 |
+
resign(roomId, playerId) {
|
| 145 |
+
const room = this.rooms.get(roomId);
|
| 146 |
+
if (!room)
|
| 147 |
+
return false;
|
| 148 |
+
const player = room.players[playerId];
|
| 149 |
+
if (!player)
|
| 150 |
+
return false;
|
| 151 |
+
// Surrender the game
|
| 152 |
+
room.game.surrender();
|
| 153 |
+
// Update room state
|
| 154 |
+
room.gameState.gameStatus = "finished";
|
| 155 |
+
room.gameState.winner = player.color === "black" ? "white" : "black";
|
| 156 |
+
return true;
|
| 157 |
+
}
|
| 158 |
+
/**
|
| 159 |
+
* Undo the last move (悔棋)
|
| 160 |
+
*/
|
| 161 |
+
undoMove(roomId, playerId) {
|
| 162 |
+
const room = this.rooms.get(roomId);
|
| 163 |
+
if (!room)
|
| 164 |
+
return false;
|
| 165 |
+
const player = room.players[playerId];
|
| 166 |
+
if (!player)
|
| 167 |
+
return false;
|
| 168 |
+
// Check game status
|
| 169 |
+
if (room.gameState.gameStatus !== "playing") {
|
| 170 |
+
return false;
|
| 171 |
+
}
|
| 172 |
+
return room.game.undo();
|
| 173 |
+
}
|
| 174 |
+
/**
|
| 175 |
+
* Redo the last undone move (forward in history)
|
| 176 |
+
*/
|
| 177 |
+
redoMove(roomId, playerId) {
|
| 178 |
+
const room = this.rooms.get(roomId);
|
| 179 |
+
if (!room)
|
| 180 |
+
return false;
|
| 181 |
+
const player = room.players[playerId];
|
| 182 |
+
if (!player)
|
| 183 |
+
return false;
|
| 184 |
+
if (room.gameState.gameStatus !== "playing") {
|
| 185 |
+
return false;
|
| 186 |
+
}
|
| 187 |
+
return room.game.redo();
|
| 188 |
+
}
|
| 189 |
+
/**
|
| 190 |
+
* Reset the game to initial state (new game in same room)
|
| 191 |
+
* Only admin can reset the game
|
| 192 |
+
*/
|
| 193 |
+
resetGame(roomId, adminId, options) {
|
| 194 |
+
const room = this.rooms.get(roomId);
|
| 195 |
+
if (!room)
|
| 196 |
+
return { success: false, error: "Room not found" };
|
| 197 |
+
// Check admin permission
|
| 198 |
+
if (room.adminId !== adminId) {
|
| 199 |
+
return { success: false, error: "Only room admin can reset the game" };
|
| 200 |
+
}
|
| 201 |
+
const boardShape = options?.boardShape;
|
| 202 |
+
const playerColors = options?.playerColors;
|
| 203 |
+
// Apply player color assignments if provided
|
| 204 |
+
if (playerColors) {
|
| 205 |
+
const playerIds = Object.keys(room.players);
|
| 206 |
+
for (const playerId of playerIds) {
|
| 207 |
+
if (playerColors[playerId]) {
|
| 208 |
+
room.players[playerId].color = playerColors[playerId];
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
console.log(`Player colors assigned:`, playerColors);
|
| 212 |
+
}
|
| 213 |
+
// If board shape is provided and different from current, create a new game
|
| 214 |
+
if (boardShape) {
|
| 215 |
+
const currentShape = room.game.getShape();
|
| 216 |
+
if (boardShape.x !== currentShape.x ||
|
| 217 |
+
boardShape.y !== currentShape.y ||
|
| 218 |
+
boardShape.z !== currentShape.z) {
|
| 219 |
+
// Create new game with new board shape
|
| 220 |
+
room.game = new game_1.TrigoGame(boardShape, {
|
| 221 |
+
onStepAdvance: (_step, history) => {
|
| 222 |
+
console.log(`Step ${history.length}: Player made move`);
|
| 223 |
+
},
|
| 224 |
+
onCapture: (captured) => {
|
| 225 |
+
console.log(`Captured ${captured.length} stones`);
|
| 226 |
+
},
|
| 227 |
+
onWin: (winner) => {
|
| 228 |
+
console.log(`Game won by ${winner}`);
|
| 229 |
+
}
|
| 230 |
+
});
|
| 231 |
+
console.log(`Game ${roomId} reset with new board shape: ${boardShape.x}x${boardShape.y}x${boardShape.z}`);
|
| 232 |
+
}
|
| 233 |
+
else {
|
| 234 |
+
// Same shape, just reset
|
| 235 |
+
room.game.reset();
|
| 236 |
+
console.log(`Game ${roomId} reset to initial state`);
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
else {
|
| 240 |
+
// No shape provided, just reset
|
| 241 |
+
room.game.reset();
|
| 242 |
+
console.log(`Game ${roomId} reset to initial state`);
|
| 243 |
+
}
|
| 244 |
+
room.gameState.gameStatus = "playing";
|
| 245 |
+
room.gameState.winner = null;
|
| 246 |
+
room.startedAt = new Date();
|
| 247 |
+
return { success: true };
|
| 248 |
+
}
|
| 249 |
+
/**
|
| 250 |
+
* Get game board state for a room
|
| 251 |
+
*/
|
| 252 |
+
getGameBoard(roomId) {
|
| 253 |
+
const room = this.rooms.get(roomId);
|
| 254 |
+
if (!room)
|
| 255 |
+
return null;
|
| 256 |
+
return room.game.getBoard();
|
| 257 |
+
}
|
| 258 |
+
/**
|
| 259 |
+
* Get game statistics for a room
|
| 260 |
+
*/
|
| 261 |
+
getGameStats(roomId) {
|
| 262 |
+
const room = this.rooms.get(roomId);
|
| 263 |
+
if (!room)
|
| 264 |
+
return null;
|
| 265 |
+
return room.game.getStats();
|
| 266 |
+
}
|
| 267 |
+
/**
|
| 268 |
+
* Get current player for a room
|
| 269 |
+
*/
|
| 270 |
+
getCurrentPlayer(roomId) {
|
| 271 |
+
const room = this.rooms.get(roomId);
|
| 272 |
+
if (!room)
|
| 273 |
+
return null;
|
| 274 |
+
const currentStone = room.game.getCurrentPlayer();
|
| 275 |
+
return currentStone === game_1.StoneType.BLACK ? "black" : "white";
|
| 276 |
+
}
|
| 277 |
+
/**
|
| 278 |
+
* Calculate and get territory for a room
|
| 279 |
+
*/
|
| 280 |
+
getTerritory(roomId) {
|
| 281 |
+
const room = this.rooms.get(roomId);
|
| 282 |
+
if (!room)
|
| 283 |
+
return null;
|
| 284 |
+
return room.game.getTerritory();
|
| 285 |
+
}
|
| 286 |
+
/**
|
| 287 |
+
* End the game and determine winner based on territory
|
| 288 |
+
*/
|
| 289 |
+
endGameByTerritory(roomId) {
|
| 290 |
+
const room = this.rooms.get(roomId);
|
| 291 |
+
if (!room)
|
| 292 |
+
return false;
|
| 293 |
+
if (room.gameState.gameStatus !== "playing") {
|
| 294 |
+
return false;
|
| 295 |
+
}
|
| 296 |
+
// Calculate final territory
|
| 297 |
+
const territory = room.game.getTerritory();
|
| 298 |
+
// Determine winner
|
| 299 |
+
if (territory.black > territory.white) {
|
| 300 |
+
room.gameState.winner = "black";
|
| 301 |
+
}
|
| 302 |
+
else if (territory.white > territory.black) {
|
| 303 |
+
room.gameState.winner = "white";
|
| 304 |
+
}
|
| 305 |
+
else {
|
| 306 |
+
// Draw - could set winner to null or handle differently
|
| 307 |
+
room.gameState.winner = null;
|
| 308 |
+
}
|
| 309 |
+
room.gameState.gameStatus = "finished";
|
| 310 |
+
console.log(`Game ${roomId} ended. Black: ${territory.black}, White: ${territory.white}, Winner: ${room.gameState.winner}`);
|
| 311 |
+
return true;
|
| 312 |
+
}
|
| 313 |
+
/**
|
| 314 |
+
* Check if both players passed consecutively (game should end)
|
| 315 |
+
* Returns true if game was ended
|
| 316 |
+
*/
|
| 317 |
+
checkConsecutivePasses(roomId) {
|
| 318 |
+
const room = this.rooms.get(roomId);
|
| 319 |
+
if (!room)
|
| 320 |
+
return false;
|
| 321 |
+
const history = room.game.getHistory();
|
| 322 |
+
if (history.length < 2)
|
| 323 |
+
return false;
|
| 324 |
+
// Get last two moves
|
| 325 |
+
const lastMove = history[history.length - 1];
|
| 326 |
+
const secondLastMove = history[history.length - 2];
|
| 327 |
+
// Check if both were passes
|
| 328 |
+
if (lastMove.type === game_1.StepType.PASS && secondLastMove.type === game_1.StepType.PASS) {
|
| 329 |
+
// Two consecutive passes - end the game
|
| 330 |
+
this.endGameByTerritory(roomId);
|
| 331 |
+
return true;
|
| 332 |
+
}
|
| 333 |
+
return false;
|
| 334 |
+
}
|
| 335 |
+
getRoom(roomId) {
|
| 336 |
+
return this.rooms.get(roomId);
|
| 337 |
+
}
|
| 338 |
+
getPlayerRoom(playerId) {
|
| 339 |
+
const roomId = this.playerRoomMap.get(playerId);
|
| 340 |
+
if (!roomId)
|
| 341 |
+
return undefined;
|
| 342 |
+
return this.rooms.get(roomId);
|
| 343 |
+
}
|
| 344 |
+
getActiveRooms() {
|
| 345 |
+
return Array.from(this.rooms.values()).filter((room) => room.gameState.gameStatus !== "finished");
|
| 346 |
+
}
|
| 347 |
+
generateRoomId() {
|
| 348 |
+
return (0, uuid_1.v4)().substring(0, 8).toUpperCase();
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
exports.GameManager = GameManager;
|
| 352 |
+
//# sourceMappingURL=gameManager.js.map
|
trigo-web/backend/dist/backend/src/services/gameManager.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"gameManager.js","sourceRoot":"","sources":["../../../../src/services/gameManager.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AAEpC,kDAAyE;AAwBzE,MAAa,WAAW;IAKvB;QAJQ,UAAK,GAA0B,IAAI,GAAG,EAAE,CAAC;QACzC,kBAAa,GAAwB,IAAI,GAAG,EAAE,CAAC;QAC/C,sBAAiB,GAAe,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,sBAAsB;QAGnF,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACxC,CAAC;IAED,UAAU,CAAC,QAAgB,EAAE,QAAgB,EAAE,UAAuB,EAAE,cAAkC;QACzG,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,UAAU,IAAI,IAAI,CAAC,iBAAiB,CAAC;QAEnD,qDAAqD;QACrD,MAAM,WAAW,GAAG,cAAc,IAAI,OAAO,CAAC;QAE9C,MAAM,IAAI,GAAa;YACtB,EAAE,EAAE,MAAM;YACV,OAAO,EAAE,QAAQ,EA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4BAA4B;QAC5B,IAAI,QAAQ,CAAC,IAAI,KAAK,eAAQ,CAAC,IAAI,IAAI,cAAc,CAAC,IAAI,KAAK,eAAQ,CAAC,IAAI,EAAE,CAAC;YAC9E,wCAAwC;YACxC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC;QACb,CAAC;QAED,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,CAAC,MAAc;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED,aAAa,CAAC,QAAgB;QAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM;YAAE,OAAO,SAAS,CAAC;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED,cAAc;QACb,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAC5C,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,KAAK,UAAU,CAClD,CAAC;IACH,CAAC;IAEO,cAAc;QACrB,OAAO,IAAA,SAAM,GAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/C,CAAC;CACD;AAxZD,kCAwZC"}
|
trigo-web/backend/dist/backend/src/sockets/gameSocket.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Server, Socket } from "socket.io";
|
| 2 |
+
import { GameManager } from "../services/gameManager";
|
| 3 |
+
export declare function setupSocketHandlers(io: Server, socket: Socket, gameManager: GameManager): void;
|
| 4 |
+
//# sourceMappingURL=gameSocket.d.ts.map
|
trigo-web/backend/dist/backend/src/sockets/gameSocket.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"gameSocket.d.ts","sourceRoot":"","sources":["../../../../src/sockets/gameSocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,QA6avF"}
|
trigo-web/backend/dist/backend/src/sockets/gameSocket.js
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
exports.setupSocketHandlers = setupSocketHandlers;
|
| 4 |
+
function setupSocketHandlers(io, socket, gameManager) {
|
| 5 |
+
console.log(`Setting up socket handlers for ${socket.id}`);
|
| 6 |
+
// Join room
|
| 7 |
+
socket.on("joinRoom", (data, callback) => {
|
| 8 |
+
console.log("[gameSocket] joinRoom event received:", {
|
| 9 |
+
roomId: data.roomId,
|
| 10 |
+
nickname: data.nickname,
|
| 11 |
+
preferredColor: data.preferredColor,
|
| 12 |
+
hasCallback: !!callback,
|
| 13 |
+
socketId: socket.id
|
| 14 |
+
});
|
| 15 |
+
const { roomId, nickname, preferredColor } = data;
|
| 16 |
+
// Try to create or join room
|
| 17 |
+
try {
|
| 18 |
+
let room;
|
| 19 |
+
if (roomId) {
|
| 20 |
+
// Joining existing room
|
| 21 |
+
const existingRoom = gameManager.getRoom(roomId);
|
| 22 |
+
if (!existingRoom) {
|
| 23 |
+
// Room doesn't exist
|
| 24 |
+
if (callback) {
|
| 25 |
+
callback({
|
| 26 |
+
success: false,
|
| 27 |
+
error: "Room not found",
|
| 28 |
+
errorCode: "ROOM_NOT_FOUND"
|
| 29 |
+
});
|
| 30 |
+
}
|
| 31 |
+
return;
|
| 32 |
+
}
|
| 33 |
+
const playerCount = Object.keys(existingRoom.players).length;
|
| 34 |
+
if (playerCount >= 2) {
|
| 35 |
+
// Room is full
|
| 36 |
+
if (callback) {
|
| 37 |
+
callback({
|
| 38 |
+
success: false,
|
| 39 |
+
error: "Room is full",
|
| 40 |
+
errorCode: "ROOM_FULL"
|
| 41 |
+
});
|
| 42 |
+
}
|
| 43 |
+
return;
|
| 44 |
+
}
|
| 45 |
+
room = gameManager.joinRoom(roomId, socket.id, nickname, preferredColor);
|
| 46 |
+
}
|
| 47 |
+
else {
|
| 48 |
+
// Creating new room
|
| 49 |
+
room = gameManager.createRoom(socket.id, nickname, undefined, preferredColor);
|
| 50 |
+
}
|
| 51 |
+
if (room) {
|
| 52 |
+
socket.join(room.id);
|
| 53 |
+
// Get complete game data for frontend
|
| 54 |
+
const currentPlayer = gameManager.getCurrentPlayer(room.id);
|
| 55 |
+
const stats = gameManager.getGameStats(room.id);
|
| 56 |
+
const tgn = room.game.toTGN();
|
| 57 |
+
// Get player list with colors
|
| 58 |
+
const players = {};
|
| 59 |
+
for (const [pid, player] of Object.entries(room.players)) {
|
| 60 |
+
players[pid] = {
|
| 61 |
+
nickname: player.nickname,
|
| 62 |
+
color: player.color
|
| 63 |
+
};
|
| 64 |
+
}
|
| 65 |
+
const response = {
|
| 66 |
+
success: true,
|
| 67 |
+
roomId: room.id,
|
| 68 |
+
playerId: socket.id,
|
| 69 |
+
playerColor: room.players[socket.id]?.color,
|
| 70 |
+
isAdmin: room.adminId === socket.id,
|
| 71 |
+
adminId: room.adminId,
|
| 72 |
+
players, // Include all players in room
|
| 73 |
+
gameState: {
|
| 74 |
+
boardShape: room.game.getShape(),
|
| 75 |
+
currentPlayer,
|
| 76 |
+
currentMoveIndex: room.game.getCurrentStep(),
|
| 77 |
+
capturedStones: {
|
| 78 |
+
black: stats?.capturedByBlack || 0,
|
| 79 |
+
white: stats?.capturedByWhite || 0
|
| 80 |
+
},
|
| 81 |
+
gameStatus: room.gameState.gameStatus,
|
| 82 |
+
winner: room.gameState.winner,
|
| 83 |
+
tgn
|
| 84 |
+
}
|
| 85 |
+
};
|
| 86 |
+
// Send response via callback
|
| 87 |
+
if (callback) {
|
| 88 |
+
console.log("[gameSocket] Sending response via callback:", {
|
| 89 |
+
roomId: response.roomId,
|
| 90 |
+
playerColor: response.playerColor
|
| 91 |
+
});
|
| 92 |
+
callback(response);
|
| 93 |
+
}
|
| 94 |
+
else {
|
| 95 |
+
// Fallback to event emit for backward compatibility
|
| 96 |
+
console.log("[gameSocket] No callback, using roomJoined emit");
|
| 97 |
+
socket.emit("roomJoined", response);
|
| 98 |
+
}
|
| 99 |
+
// Notify other players
|
| 100 |
+
socket.to(room.id).emit("playerJoined", {
|
| 101 |
+
playerId: socket.id,
|
| 102 |
+
nickname: nickname
|
| 103 |
+
});
|
| 104 |
+
console.log(`Player ${socket.id} ${roomId ? "joined" : "created"} room ${room.id}`);
|
| 105 |
+
}
|
| 106 |
+
else {
|
| 107 |
+
// Generic failure
|
| 108 |
+
if (callback) {
|
| 109 |
+
callback({
|
| 110 |
+
success: false,
|
| 111 |
+
error: "Failed to join or create room",
|
| 112 |
+
errorCode: "UNKNOWN_ERROR"
|
| 113 |
+
});
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
catch (error) {
|
| 118 |
+
console.error(`Error in joinRoom handler:`, error);
|
| 119 |
+
if (callback) {
|
| 120 |
+
callback({
|
| 121 |
+
success: false,
|
| 122 |
+
error: "Server error",
|
| 123 |
+
errorCode: "SERVER_ERROR"
|
| 124 |
+
});
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
});
|
| 128 |
+
// Leave room
|
| 129 |
+
socket.on("leaveRoom", () => {
|
| 130 |
+
const room = gameManager.getPlayerRoom(socket.id);
|
| 131 |
+
if (room) {
|
| 132 |
+
socket.leave(room.id);
|
| 133 |
+
gameManager.leaveRoom(room.id, socket.id);
|
| 134 |
+
// Notify others
|
| 135 |
+
socket.to(room.id).emit("playerLeft", {
|
| 136 |
+
playerId: socket.id
|
| 137 |
+
});
|
| 138 |
+
}
|
| 139 |
+
});
|
| 140 |
+
// Game moves
|
| 141 |
+
socket.on("makeMove", (data) => {
|
| 142 |
+
const room = gameManager.getPlayerRoom(socket.id);
|
| 143 |
+
if (room && gameManager.makeMove(room.id, socket.id, data)) {
|
| 144 |
+
// Get updated game data
|
| 145 |
+
const currentPlayer = gameManager.getCurrentPlayer(room.id);
|
| 146 |
+
const stats = gameManager.getGameStats(room.id);
|
| 147 |
+
const lastStep = room.game.getLastStep();
|
| 148 |
+
const tgn = room.game.toTGN();
|
| 149 |
+
// Broadcast game update to all players in the room
|
| 150 |
+
io.to(room.id).emit("gameUpdate", {
|
| 151 |
+
currentPlayer,
|
| 152 |
+
action: "move",
|
| 153 |
+
lastMove: data,
|
| 154 |
+
capturedStones: {
|
| 155 |
+
black: stats?.capturedByBlack || 0,
|
| 156 |
+
white: stats?.capturedByWhite || 0
|
| 157 |
+
},
|
| 158 |
+
capturedPositions: lastStep?.capturedPositions,
|
| 159 |
+
currentMoveIndex: room.game.getCurrentStep(),
|
| 160 |
+
tgn
|
| 161 |
+
});
|
| 162 |
+
}
|
| 163 |
+
else {
|
| 164 |
+
socket.emit("error", { message: "Invalid move" });
|
| 165 |
+
}
|
| 166 |
+
});
|
| 167 |
+
// Pass turn
|
| 168 |
+
socket.on("pass", () => {
|
| 169 |
+
const room = gameManager.getPlayerRoom(socket.id);
|
| 170 |
+
if (room && gameManager.passTurn(room.id, socket.id)) {
|
| 171 |
+
const currentPlayer = gameManager.getCurrentPlayer(room.id);
|
| 172 |
+
const tgn = room.game.toTGN();
|
| 173 |
+
io.to(room.id).emit("gameUpdate", {
|
| 174 |
+
currentPlayer,
|
| 175 |
+
action: "pass",
|
| 176 |
+
currentMoveIndex: room.game.getCurrentStep(),
|
| 177 |
+
tgn
|
| 178 |
+
});
|
| 179 |
+
// Check for consecutive passes (game end)
|
| 180 |
+
if (gameManager.checkConsecutivePasses(room.id)) {
|
| 181 |
+
const territory = gameManager.getTerritory(room.id);
|
| 182 |
+
io.to(room.id).emit("gameEnded", {
|
| 183 |
+
winner: room.gameState.winner,
|
| 184 |
+
reason: "double-pass",
|
| 185 |
+
territory
|
| 186 |
+
});
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
});
|
| 190 |
+
// Resign
|
| 191 |
+
socket.on("resign", () => {
|
| 192 |
+
const room = gameManager.getPlayerRoom(socket.id);
|
| 193 |
+
if (room && gameManager.resign(room.id, socket.id)) {
|
| 194 |
+
io.to(room.id).emit("gameEnded", {
|
| 195 |
+
winner: room.gameState.winner,
|
| 196 |
+
reason: "resignation"
|
| 197 |
+
});
|
| 198 |
+
}
|
| 199 |
+
});
|
| 200 |
+
// Undo move
|
| 201 |
+
socket.on("undoMove", (callback) => {
|
| 202 |
+
const room = gameManager.getPlayerRoom(socket.id);
|
| 203 |
+
if (!room) {
|
| 204 |
+
if (callback)
|
| 205 |
+
callback({ success: false, error: "Not in a room", errorCode: "NOT_IN_ROOM" });
|
| 206 |
+
return;
|
| 207 |
+
}
|
| 208 |
+
if (room.gameState.gameStatus !== "playing") {
|
| 209 |
+
if (callback)
|
| 210 |
+
callback({ success: false, error: "Game not active", errorCode: "GAME_NOT_ACTIVE" });
|
| 211 |
+
return;
|
| 212 |
+
}
|
| 213 |
+
const success = gameManager.undoMove(room.id, socket.id);
|
| 214 |
+
if (success) {
|
| 215 |
+
const currentPlayer = gameManager.getCurrentPlayer(room.id);
|
| 216 |
+
const stats = gameManager.getGameStats(room.id);
|
| 217 |
+
const tgn = room.game.toTGN();
|
| 218 |
+
io.to(room.id).emit("gameUpdate", {
|
| 219 |
+
currentPlayer,
|
| 220 |
+
action: "undo",
|
| 221 |
+
currentMoveIndex: room.game.getCurrentStep(),
|
| 222 |
+
capturedStones: {
|
| 223 |
+
black: stats?.capturedByBlack || 0,
|
| 224 |
+
white: stats?.capturedByWhite || 0
|
| 225 |
+
},
|
| 226 |
+
tgn
|
| 227 |
+
});
|
| 228 |
+
if (callback)
|
| 229 |
+
callback({ success: true });
|
| 230 |
+
}
|
| 231 |
+
else {
|
| 232 |
+
if (callback)
|
| 233 |
+
callback({ success: false, error: "Cannot undo", errorCode: "UNDO_FAILED" });
|
| 234 |
+
}
|
| 235 |
+
});
|
| 236 |
+
// Redo move
|
| 237 |
+
socket.on("redoMove", (callback) => {
|
| 238 |
+
const room = gameManager.getPlayerRoom(socket.id);
|
| 239 |
+
if (!room) {
|
| 240 |
+
if (callback)
|
| 241 |
+
callback({ success: false, error: "Not in a room", errorCode: "NOT_IN_ROOM" });
|
| 242 |
+
return;
|
| 243 |
+
}
|
| 244 |
+
if (room.gameState.gameStatus !== "playing") {
|
| 245 |
+
if (callback)
|
| 246 |
+
callback({ success: false, error: "Game not active", errorCode: "GAME_NOT_ACTIVE" });
|
| 247 |
+
return;
|
| 248 |
+
}
|
| 249 |
+
if (!room.game.canRedo()) {
|
| 250 |
+
if (callback)
|
| 251 |
+
callback({ success: false, error: "Nothing to redo", errorCode: "NOTHING_TO_REDO" });
|
| 252 |
+
return;
|
| 253 |
+
}
|
| 254 |
+
const success = gameManager.redoMove(room.id, socket.id);
|
| 255 |
+
if (success) {
|
| 256 |
+
const currentPlayer = gameManager.getCurrentPlayer(room.id);
|
| 257 |
+
const stats = gameManager.getGameStats(room.id);
|
| 258 |
+
const lastStep = room.game.getLastStep();
|
| 259 |
+
const tgn = room.game.toTGN();
|
| 260 |
+
io.to(room.id).emit("gameUpdate", {
|
| 261 |
+
currentPlayer,
|
| 262 |
+
action: "redo",
|
| 263 |
+
lastMove: lastStep?.position,
|
| 264 |
+
capturedStones: {
|
| 265 |
+
black: stats?.capturedByBlack || 0,
|
| 266 |
+
white: stats?.capturedByWhite || 0
|
| 267 |
+
},
|
| 268 |
+
capturedPositions: lastStep?.capturedPositions,
|
| 269 |
+
currentMoveIndex: room.game.getCurrentStep(),
|
| 270 |
+
tgn
|
| 271 |
+
});
|
| 272 |
+
if (callback)
|
| 273 |
+
callback({ success: true });
|
| 274 |
+
}
|
| 275 |
+
else {
|
| 276 |
+
if (callback)
|
| 277 |
+
callback({ success: false, error: "Redo failed", errorCode: "REDO_FAILED" });
|
| 278 |
+
}
|
| 279 |
+
});
|
| 280 |
+
// Reset game
|
| 281 |
+
socket.on("resetGame", (data, callback) => {
|
| 282 |
+
const room = gameManager.getPlayerRoom(socket.id);
|
| 283 |
+
if (!room) {
|
| 284 |
+
const cb = typeof data === 'function' ? data : callback;
|
| 285 |
+
if (cb)
|
| 286 |
+
cb({ success: false, error: "Not in a room", errorCode: "NOT_IN_ROOM" });
|
| 287 |
+
return;
|
| 288 |
+
}
|
| 289 |
+
// Handle both old signature (no data) and new signature (with options)
|
| 290 |
+
const options = typeof data === 'object' && data !== null ? {
|
| 291 |
+
boardShape: data.boardShape,
|
| 292 |
+
playerColors: data.playerColors
|
| 293 |
+
} : undefined;
|
| 294 |
+
const responseCb = typeof data === 'function' ? data : callback;
|
| 295 |
+
const result = gameManager.resetGame(room.id, socket.id, options);
|
| 296 |
+
if (result.success) {
|
| 297 |
+
const currentPlayer = gameManager.getCurrentPlayer(room.id);
|
| 298 |
+
const tgn = room.game.toTGN();
|
| 299 |
+
// Get updated player info with new colors
|
| 300 |
+
const players = {};
|
| 301 |
+
for (const [pid, player] of Object.entries(room.players)) {
|
| 302 |
+
players[pid] = {
|
| 303 |
+
nickname: player.nickname,
|
| 304 |
+
color: player.color
|
| 305 |
+
};
|
| 306 |
+
}
|
| 307 |
+
io.to(room.id).emit("gameReset", {
|
| 308 |
+
currentPlayer,
|
| 309 |
+
boardShape: room.game.getShape(),
|
| 310 |
+
currentMoveIndex: 0,
|
| 311 |
+
capturedStones: { black: 0, white: 0 },
|
| 312 |
+
players,
|
| 313 |
+
tgn
|
| 314 |
+
});
|
| 315 |
+
if (responseCb)
|
| 316 |
+
responseCb({ success: true });
|
| 317 |
+
}
|
| 318 |
+
else {
|
| 319 |
+
if (responseCb)
|
| 320 |
+
responseCb({
|
| 321 |
+
success: false,
|
| 322 |
+
error: result.error || "Reset failed",
|
| 323 |
+
errorCode: result.error === "Only room admin can reset the game" ? "NOT_ADMIN" : "RESET_FAILED"
|
| 324 |
+
});
|
| 325 |
+
}
|
| 326 |
+
});
|
| 327 |
+
// Chat messages
|
| 328 |
+
socket.on("chatMessage", (data) => {
|
| 329 |
+
const room = gameManager.getPlayerRoom(socket.id);
|
| 330 |
+
if (room) {
|
| 331 |
+
const player = room.players[socket.id];
|
| 332 |
+
io.to(room.id).emit("chatMessage", {
|
| 333 |
+
author: player?.nickname || "Unknown",
|
| 334 |
+
content: data.content,
|
| 335 |
+
playerId: socket.id
|
| 336 |
+
});
|
| 337 |
+
}
|
| 338 |
+
});
|
| 339 |
+
// Change nickname
|
| 340 |
+
socket.on("changeNickname", (data, callback) => {
|
| 341 |
+
const room = gameManager.getPlayerRoom(socket.id);
|
| 342 |
+
if (!room) {
|
| 343 |
+
const error = { success: false, error: "Not in a room" };
|
| 344 |
+
if (callback)
|
| 345 |
+
callback(error);
|
| 346 |
+
return;
|
| 347 |
+
}
|
| 348 |
+
// Validate nickname
|
| 349 |
+
const validation = validateNickname(data.nickname);
|
| 350 |
+
if (!validation.valid) {
|
| 351 |
+
const error = { success: false, error: validation.error };
|
| 352 |
+
if (callback)
|
| 353 |
+
callback(error);
|
| 354 |
+
return;
|
| 355 |
+
}
|
| 356 |
+
// Update player nickname
|
| 357 |
+
const player = room.players[socket.id];
|
| 358 |
+
if (player) {
|
| 359 |
+
const oldNickname = player.nickname;
|
| 360 |
+
player.nickname = data.nickname;
|
| 361 |
+
// Broadcast to all players in room
|
| 362 |
+
io.to(room.id).emit("nicknameChanged", {
|
| 363 |
+
playerId: socket.id,
|
| 364 |
+
nickname: data.nickname,
|
| 365 |
+
oldNickname: oldNickname
|
| 366 |
+
});
|
| 367 |
+
console.log(`Player ${socket.id} changed nickname: ${oldNickname} -> ${data.nickname}`);
|
| 368 |
+
if (callback) {
|
| 369 |
+
callback({ success: true, nickname: data.nickname });
|
| 370 |
+
}
|
| 371 |
+
}
|
| 372 |
+
});
|
| 373 |
+
// Handle disconnection
|
| 374 |
+
socket.on("disconnect", () => {
|
| 375 |
+
console.log(`Client disconnected: ${socket.id}`);
|
| 376 |
+
const room = gameManager.getPlayerRoom(socket.id);
|
| 377 |
+
if (room) {
|
| 378 |
+
gameManager.leaveRoom(room.id, socket.id);
|
| 379 |
+
socket.to(room.id).emit("playerDisconnected", {
|
| 380 |
+
playerId: socket.id
|
| 381 |
+
});
|
| 382 |
+
}
|
| 383 |
+
});
|
| 384 |
+
}
|
| 385 |
+
/**
|
| 386 |
+
* Validate nickname according to the rules:
|
| 387 |
+
* - Length: 3-20 characters
|
| 388 |
+
* - Characters: alphanumeric + spaces only
|
| 389 |
+
* - No leading/trailing whitespace
|
| 390 |
+
*/
|
| 391 |
+
function validateNickname(nickname) {
|
| 392 |
+
if (!nickname || typeof nickname !== "string") {
|
| 393 |
+
return { valid: false, error: "Invalid nickname" };
|
| 394 |
+
}
|
| 395 |
+
const trimmed = nickname.trim();
|
| 396 |
+
if (trimmed.length < 3) {
|
| 397 |
+
return { valid: false, error: "Nickname must be at least 3 characters" };
|
| 398 |
+
}
|
| 399 |
+
if (trimmed.length > 20) {
|
| 400 |
+
return { valid: false, error: "Nickname must be 20 characters or less" };
|
| 401 |
+
}
|
| 402 |
+
if (!/^[a-zA-Z0-9 ]+$/.test(trimmed)) {
|
| 403 |
+
return { valid: false, error: "Only letters, numbers, and spaces allowed" };
|
| 404 |
+
}
|
| 405 |
+
if (trimmed !== nickname) {
|
| 406 |
+
return { valid: false, error: "No leading or trailing spaces allowed" };
|
| 407 |
+
}
|
| 408 |
+
return { valid: true };
|
| 409 |
+
}
|
| 410 |
+
//# sourceMappingURL=gameSocket.js.map
|
trigo-web/backend/dist/backend/src/sockets/gameSocket.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"gameSocket.js","sourceRoot":"","sources":["../../../../src/sockets/gameSocket.ts"],"names":[],"mappings":";;AAGA,kDA6aC;AA7aD,SAAgB,mBAAmB,CAAC,EAAU,EAAE,MAAc,EAAE,WAAwB;IACvF,OAAO,CAAC,GAAG,CAAC,kCAAkC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;IAE3D,YAAY;IACZ,MAAM,CAAC,EAAE,CACR,UAAU,EACV,CAAC,IAA+E,EAAE,QAAkC,EAAE,EAAE;QACvH,OAAO,CAAC,GAAG,CAAC,uCAAuC,EAAE;YACpD,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,WAAW,EAAE,CAAC,CAAC,QAAQ;YACvB,QAAQ,EAAE,MAAM,CAAC,EAAE;SACnB,CAAC,CAAC;QAEH,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;QAElD,6BAA6B;QAC7B,IAAI,CAAC;YACJ,IAAI,IAAI,CAAC;YAET,IAAI,MAAM,EAAE,CAAC;gBACZ,wBAAwB;g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3 |
+
*
|
| 4 |
+
* Provides centralized access to environment variables for ONNX model paths
|
| 5 |
+
* and other configuration values.
|
| 6 |
+
*
|
| 7 |
+
* Works across different contexts:
|
| 8 |
+
* - Frontend (Vite): Uses import.meta.env.VITE_* variables
|
| 9 |
+
* - Backend/Tools (Node): Uses process.env.* variables with dotenv
|
| 10 |
+
*/
|
| 11 |
+
/**
|
| 12 |
+
* ONNX Session Options
|
| 13 |
+
*/
|
| 14 |
+
export interface OnnxSessionOptions {
|
| 15 |
+
executionProviders: string[];
|
| 16 |
+
intraOpNumThreads?: number;
|
| 17 |
+
interOpNumThreads?: number;
|
| 18 |
+
graphOptimizationLevel?: "disabled" | "basic" | "extended" | "all";
|
| 19 |
+
enableCpuMemArena?: boolean;
|
| 20 |
+
enableMemPattern?: boolean;
|
| 21 |
+
}
|
| 22 |
+
/**
|
| 23 |
+
* Get ONNX model paths
|
| 24 |
+
* Returns paths appropriate for the current environment
|
| 25 |
+
*/
|
| 26 |
+
export declare function getOnnxModelPaths(): {
|
| 27 |
+
evaluationModel: string;
|
| 28 |
+
treeModel: string;
|
| 29 |
+
};
|
| 30 |
+
/**
|
| 31 |
+
* Get ONNX session options from environment variables
|
| 32 |
+
* Returns session options with threading and optimization configuration
|
| 33 |
+
*/
|
| 34 |
+
export declare function getOnnxSessionOptions(): OnnxSessionOptions;
|
| 35 |
+
/**
|
| 36 |
+
* Get absolute path to model file (Node.js only)
|
| 37 |
+
* Resolves relative paths to absolute paths from project root
|
| 38 |
+
*/
|
| 39 |
+
export declare function getAbsoluteModelPath(relativePath: string): string;
|
| 40 |
+
/**
|
| 41 |
+
* Load environment variables from .env file (Node.js only)
|
| 42 |
+
* Call this at the start of tool scripts
|
| 43 |
+
*
|
| 44 |
+
* Loading order:
|
| 45 |
+
* 1. .env (base configuration, committed to git)
|
| 46 |
+
* 2. .env.local (local overrides, not committed to git)
|
| 47 |
+
*/
|
| 48 |
+
export declare function loadEnvConfig(): Promise<void>;
|
| 49 |
+
//# sourceMappingURL=config.d.ts.map
|
trigo-web/backend/dist/inc/config.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../inc/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAWH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sBAAsB,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,UAAU,GAAG,KAAK,CAAC;IACnE,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC3B;AAGD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI;IACpC,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CAClB,CA2BA;AAGD;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,kBAAkB,CAoC1D;AAGD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAejE;AAGD;;;;;;;GAOG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAqCnD"}
|
trigo-web/backend/dist/inc/config.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
/**
|
| 3 |
+
* Configuration Utilities
|
| 4 |
+
*
|
| 5 |
+
* Provides centralized access to environment variables for ONNX model paths
|
| 6 |
+
* and other configuration values.
|
| 7 |
+
*
|
| 8 |
+
* Works across different contexts:
|
| 9 |
+
* - Frontend (Vite): Uses import.meta.env.VITE_* variables
|
| 10 |
+
* - Backend/Tools (Node): Uses process.env.* variables with dotenv
|
| 11 |
+
*/
|
| 12 |
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
| 13 |
+
if (k2 === undefined) k2 = k;
|
| 14 |
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
| 15 |
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
| 16 |
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
| 17 |
+
}
|
| 18 |
+
Object.defineProperty(o, k2, desc);
|
| 19 |
+
}) : (function(o, m, k, k2) {
|
| 20 |
+
if (k2 === undefined) k2 = k;
|
| 21 |
+
o[k2] = m[k];
|
| 22 |
+
}));
|
| 23 |
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
| 24 |
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
| 25 |
+
}) : function(o, v) {
|
| 26 |
+
o["default"] = v;
|
| 27 |
+
});
|
| 28 |
+
var __importStar = (this && this.__importStar) || (function () {
|
| 29 |
+
var ownKeys = function(o) {
|
| 30 |
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
| 31 |
+
var ar = [];
|
| 32 |
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
| 33 |
+
return ar;
|
| 34 |
+
};
|
| 35 |
+
return ownKeys(o);
|
| 36 |
+
};
|
| 37 |
+
return function (mod) {
|
| 38 |
+
if (mod && mod.__esModule) return mod;
|
| 39 |
+
var result = {};
|
| 40 |
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
| 41 |
+
__setModuleDefault(result, mod);
|
| 42 |
+
return result;
|
| 43 |
+
};
|
| 44 |
+
})();
|
| 45 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 46 |
+
exports.getOnnxModelPaths = getOnnxModelPaths;
|
| 47 |
+
exports.getOnnxSessionOptions = getOnnxSessionOptions;
|
| 48 |
+
exports.getAbsoluteModelPath = getAbsoluteModelPath;
|
| 49 |
+
exports.loadEnvConfig = loadEnvConfig;
|
| 50 |
+
const path = __importStar(require("path"));
|
| 51 |
+
const url_1 = require("url");
|
| 52 |
+
// Environment detection
|
| 53 |
+
const isNode = typeof process !== "undefined" && process.versions?.node;
|
| 54 |
+
const isBrowser = typeof window !== "undefined";
|
| 55 |
+
/**
|
| 56 |
+
* Get ONNX model paths
|
| 57 |
+
* Returns paths appropriate for the current environment
|
| 58 |
+
*/
|
| 59 |
+
function getOnnxModelPaths() {
|
| 60 |
+
// Frontend (Vite environment)
|
| 61 |
+
if (isBrowser && typeof import.meta.env !== "undefined") {
|
| 62 |
+
const evaluationModel = import.meta.env.VITE_ONNX_EVALUATION_MODEL;
|
| 63 |
+
const treeModel = import.meta.env.VITE_ONNX_TREE_MODEL;
|
| 64 |
+
if (!evaluationModel || !treeModel) {
|
| 65 |
+
throw new Error("ONNX model paths not configured. Check VITE_ONNX_EVALUATION_MODEL and VITE_ONNX_TREE_MODEL in .env");
|
| 66 |
+
}
|
| 67 |
+
return { evaluationModel, treeModel };
|
| 68 |
+
}
|
| 69 |
+
// Backend/Tools (Node environment)
|
| 70 |
+
if (isNode) {
|
| 71 |
+
const evaluationModel = process.env.ONNX_EVALUATION_MODEL;
|
| 72 |
+
const treeModel = process.env.ONNX_TREE_MODEL;
|
| 73 |
+
if (!evaluationModel || !treeModel) {
|
| 74 |
+
throw new Error("ONNX model paths not configured. Check ONNX_EVALUATION_MODEL and ONNX_TREE_MODEL in .env");
|
| 75 |
+
}
|
| 76 |
+
return { evaluationModel, treeModel };
|
| 77 |
+
}
|
| 78 |
+
// Should not reach here
|
| 79 |
+
throw new Error("Unknown environment - cannot determine model paths");
|
| 80 |
+
}
|
| 81 |
+
/**
|
| 82 |
+
* Get ONNX session options from environment variables
|
| 83 |
+
* Returns session options with threading and optimization configuration
|
| 84 |
+
*/
|
| 85 |
+
function getOnnxSessionOptions() {
|
| 86 |
+
// Default values
|
| 87 |
+
const options = {
|
| 88 |
+
executionProviders: ["cpu"],
|
| 89 |
+
graphOptimizationLevel: "all",
|
| 90 |
+
enableCpuMemArena: true,
|
| 91 |
+
enableMemPattern: true
|
| 92 |
+
};
|
| 93 |
+
// Frontend (Vite environment)
|
| 94 |
+
if (isBrowser && typeof import.meta.env !== "undefined") {
|
| 95 |
+
const intraThreadsEnv = import.meta.env.VITE_ONNX_INTRA_OP_NUM_THREADS;
|
| 96 |
+
const interThreadsEnv = import.meta.env.VITE_ONNX_INTER_OP_NUM_THREADS;
|
| 97 |
+
const graphOptEnv = import.meta.env.VITE_ONNX_GRAPH_OPTIMIZATION_LEVEL;
|
| 98 |
+
if (intraThreadsEnv)
|
| 99 |
+
options.intraOpNumThreads = parseInt(intraThreadsEnv, 10);
|
| 100 |
+
if (interThreadsEnv)
|
| 101 |
+
options.interOpNumThreads = parseInt(interThreadsEnv, 10);
|
| 102 |
+
if (graphOptEnv)
|
| 103 |
+
options.graphOptimizationLevel = graphOptEnv;
|
| 104 |
+
}
|
| 105 |
+
// Backend/Tools (Node environment)
|
| 106 |
+
if (isNode) {
|
| 107 |
+
const intraThreadsEnv = process.env.ONNX_INTRA_OP_NUM_THREADS;
|
| 108 |
+
const interThreadsEnv = process.env.ONNX_INTER_OP_NUM_THREADS;
|
| 109 |
+
const graphOptEnv = process.env.ONNX_GRAPH_OPTIMIZATION_LEVEL;
|
| 110 |
+
const cpuMemArenaEnv = process.env.ONNX_ENABLE_CPU_MEM_ARENA;
|
| 111 |
+
const memPatternEnv = process.env.ONNX_ENABLE_MEM_PATTERN;
|
| 112 |
+
if (intraThreadsEnv)
|
| 113 |
+
options.intraOpNumThreads = parseInt(intraThreadsEnv, 10);
|
| 114 |
+
if (interThreadsEnv)
|
| 115 |
+
options.interOpNumThreads = parseInt(interThreadsEnv, 10);
|
| 116 |
+
if (graphOptEnv)
|
| 117 |
+
options.graphOptimizationLevel = graphOptEnv;
|
| 118 |
+
if (cpuMemArenaEnv)
|
| 119 |
+
options.enableCpuMemArena = cpuMemArenaEnv === "true";
|
| 120 |
+
if (memPatternEnv)
|
| 121 |
+
options.enableMemPattern = memPatternEnv === "true";
|
| 122 |
+
}
|
| 123 |
+
return options;
|
| 124 |
+
}
|
| 125 |
+
/**
|
| 126 |
+
* Get absolute path to model file (Node.js only)
|
| 127 |
+
* Resolves relative paths to absolute paths from project root
|
| 128 |
+
*/
|
| 129 |
+
function getAbsoluteModelPath(relativePath) {
|
| 130 |
+
if (!isNode) {
|
| 131 |
+
return relativePath; // Browser environment - return as-is
|
| 132 |
+
}
|
| 133 |
+
// If already absolute, return as-is
|
| 134 |
+
if (path.isAbsolute(relativePath)) {
|
| 135 |
+
return relativePath;
|
| 136 |
+
}
|
| 137 |
+
// Resolve relative to project root
|
| 138 |
+
const __filename = (0, url_1.fileURLToPath)(import.meta.url);
|
| 139 |
+
const __dirname = path.dirname(__filename);
|
| 140 |
+
const rootDir = path.resolve(__dirname, "..");
|
| 141 |
+
return path.resolve(rootDir, relativePath);
|
| 142 |
+
}
|
| 143 |
+
/**
|
| 144 |
+
* Load environment variables from .env file (Node.js only)
|
| 145 |
+
* Call this at the start of tool scripts
|
| 146 |
+
*
|
| 147 |
+
* Loading order:
|
| 148 |
+
* 1. .env (base configuration, committed to git)
|
| 149 |
+
* 2. .env.local (local overrides, not committed to git)
|
| 150 |
+
*/
|
| 151 |
+
async function loadEnvConfig() {
|
| 152 |
+
if (!isNode) {
|
| 153 |
+
console.warn("[Config] loadEnvConfig() called in non-Node environment");
|
| 154 |
+
return;
|
| 155 |
+
}
|
| 156 |
+
try {
|
| 157 |
+
// Dynamically import dotenv (ESM-compatible)
|
| 158 |
+
const dotenv = (await Promise.resolve().then(() => __importStar(require("dotenv")))).default;
|
| 159 |
+
const __filename = (0, url_1.fileURLToPath)(import.meta.url);
|
| 160 |
+
const __dirname = path.dirname(__filename);
|
| 161 |
+
const rootDir = path.resolve(__dirname, "..");
|
| 162 |
+
// Load base .env file
|
| 163 |
+
const baseResult = dotenv.config({ path: path.join(rootDir, ".env") });
|
| 164 |
+
if (baseResult.error) {
|
| 165 |
+
console.warn("[Config] Failed to load .env:", baseResult.error.message);
|
| 166 |
+
}
|
| 167 |
+
else {
|
| 168 |
+
console.log("[Config] ✓ Base environment variables loaded from .env");
|
| 169 |
+
}
|
| 170 |
+
// Load .env.local for local overrides (if exists)
|
| 171 |
+
// Use override: true to allow .env.local to override .env values
|
| 172 |
+
const localResult = dotenv.config({
|
| 173 |
+
path: path.join(rootDir, ".env.local"),
|
| 174 |
+
override: true
|
| 175 |
+
});
|
| 176 |
+
if (!localResult.error) {
|
| 177 |
+
console.log("[Config] ✓ Local overrides loaded from .env.local");
|
| 178 |
+
}
|
| 179 |
+
// Silently ignore if .env.local doesn't exist (optional file)
|
| 180 |
+
}
|
| 181 |
+
catch (error) {
|
| 182 |
+
console.warn("[Config] dotenv not available:", error);
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
//# sourceMappingURL=config.js.map
|
trigo-web/backend/dist/inc/config.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../inc/config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BH,8CA8BC;AAOD,sDAoCC;AAOD,oDAeC;AAWD,sCAqCC;AAzKD,2CAA6B;AAC7B,6BAAoC;AAGpC,wBAAwB;AACxB,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC;AACxE,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;AAgBhD;;;GAGG;AACH,SAAgB,iBAAiB;IAIhC,8BAA8B;IAC9B,IAAI,SAAS,IAAI,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,WAAW,EAAE,CAAC;QACz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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Monte Carlo Tree Search (MCTS) Agent for Trigo
|
| 3 |
+
*
|
| 4 |
+
* Implements AlphaGo Zero-style MCTS with:
|
| 5 |
+
* - PUCT (Polynomial Upper Confidence Trees) selection
|
| 6 |
+
* - Neural network guidance for policy and value
|
| 7 |
+
* - Visit count statistics for training data generation
|
| 8 |
+
*
|
| 9 |
+
* Based on: Silver et al., "Mastering the Game of Go without Human Knowledge"
|
| 10 |
+
*/
|
| 11 |
+
import { TrigoGame } from "./trigo/game";
|
| 12 |
+
import type { Move } from "./trigo/types";
|
| 13 |
+
import { TrigoTreeAgent } from "./trigoTreeAgent";
|
| 14 |
+
import { TrigoEvaluationAgent } from "./trigoEvaluationAgent";
|
| 15 |
+
/**
|
| 16 |
+
* MCTS Configuration
|
| 17 |
+
*/
|
| 18 |
+
export interface MCTSConfig {
|
| 19 |
+
numSimulations: number;
|
| 20 |
+
cPuct: number;
|
| 21 |
+
temperature: number;
|
| 22 |
+
dirichletAlpha: number;
|
| 23 |
+
dirichletEpsilon: number;
|
| 24 |
+
}
|
| 25 |
+
/**
|
| 26 |
+
* MCTS Agent
|
| 27 |
+
* Combines tree search with neural network evaluation
|
| 28 |
+
*/
|
| 29 |
+
export declare class MCTSAgent {
|
| 30 |
+
private treeAgent;
|
| 31 |
+
private evaluationAgent;
|
| 32 |
+
private config;
|
| 33 |
+
constructor(treeAgent: TrigoTreeAgent, evaluationAgent: TrigoEvaluationAgent, config?: Partial<MCTSConfig>);
|
| 34 |
+
/**
|
| 35 |
+
* Select best move using MCTS
|
| 36 |
+
*
|
| 37 |
+
* @param game Current game state
|
| 38 |
+
* @param moveNumber Move number (for temperature schedule)
|
| 39 |
+
* @returns Selected move with visit count statistics
|
| 40 |
+
*/
|
| 41 |
+
selectMove(game: TrigoGame, moveNumber: number): Promise<{
|
| 42 |
+
move: Move;
|
| 43 |
+
visitCounts: Map<string, number>;
|
| 44 |
+
searchPolicy: Map<string, number>;
|
| 45 |
+
rootValue: number;
|
| 46 |
+
}>;
|
| 47 |
+
/**
|
| 48 |
+
* Run a single MCTS simulation
|
| 49 |
+
* Select -> Expand & Evaluate -> Backup
|
| 50 |
+
*/
|
| 51 |
+
private runSimulation;
|
| 52 |
+
/**
|
| 53 |
+
* Selection phase: Traverse tree using PUCT
|
| 54 |
+
*
|
| 55 |
+
* @param root Root node to start selection from
|
| 56 |
+
* @returns Leaf node and path taken
|
| 57 |
+
*/
|
| 58 |
+
private select;
|
| 59 |
+
/**
|
| 60 |
+
* Expand and evaluate leaf node using neural networks
|
| 61 |
+
*
|
| 62 |
+
* @param node Leaf node to expand
|
| 63 |
+
* @returns Value estimate from evaluation network
|
| 64 |
+
*/
|
| 65 |
+
private expandAndEvaluate;
|
| 66 |
+
/**
|
| 67 |
+
* Backup phase: Propagate value up the tree
|
| 68 |
+
*
|
| 69 |
+
* @param path Path from root to leaf
|
| 70 |
+
* @param value Value to propagate (white-positive: positive = white winning)
|
| 71 |
+
*/
|
| 72 |
+
private backup;
|
| 73 |
+
/**
|
| 74 |
+
* Calculate PUCT value for action selection
|
| 75 |
+
*
|
| 76 |
+
* PUCT = Q(s,a) + U(s,a) [for White, who maximizes]
|
| 77 |
+
* PUCT = -Q(s,a) + U(s,a) [for Black, who minimizes]
|
| 78 |
+
* where U(s,a) = c_puct * P(s,a) * sqrt(Σ_b N(s,b)) / (1 + N(s,a))
|
| 79 |
+
*
|
| 80 |
+
* @param node Current node
|
| 81 |
+
* @param actionKey Action to evaluate
|
| 82 |
+
* @param isWhite Whether current player is White
|
| 83 |
+
* @returns PUCT value
|
| 84 |
+
*/
|
| 85 |
+
private calculatePUCT;
|
| 86 |
+
/**
|
| 87 |
+
* Select action to play based on visit counts
|
| 88 |
+
* Uses temperature to control exploration vs exploitation
|
| 89 |
+
*
|
| 90 |
+
* @param node Root node
|
| 91 |
+
* @param temperature Selection temperature (τ=1 for exploration, τ→0 for greedy)
|
| 92 |
+
* @returns Selected move
|
| 93 |
+
*/
|
| 94 |
+
private selectPlayAction;
|
| 95 |
+
/**
|
| 96 |
+
* Compute search policy from visit counts
|
| 97 |
+
* π(a|s) = N(s,a)^(1/τ) / Σ_b N(s,b)^(1/τ)
|
| 98 |
+
*
|
| 99 |
+
* @param node Root node
|
| 100 |
+
* @param temperature Selection temperature
|
| 101 |
+
* @returns Normalized policy distribution
|
| 102 |
+
*/
|
| 103 |
+
private computeSearchPolicy;
|
| 104 |
+
/**
|
| 105 |
+
* Get root value estimate (weighted average of Q-values)
|
| 106 |
+
*/
|
| 107 |
+
private getRootValue;
|
| 108 |
+
/**
|
| 109 |
+
* Add Dirichlet noise to prior probabilities at root
|
| 110 |
+
* P(s,a) = (1 - ε) * p_a + ε * η_a
|
| 111 |
+
* where η ~ Dir(α)
|
| 112 |
+
*/
|
| 113 |
+
private addDirichletNoise;
|
| 114 |
+
/**
|
| 115 |
+
* Sample from Gamma distribution using Marsaglia and Tsang method (2000)
|
| 116 |
+
* Used for Dirichlet noise generation
|
| 117 |
+
*/
|
| 118 |
+
private sampleGamma;
|
| 119 |
+
/**
|
| 120 |
+
* Sample from standard normal distribution (Box-Muller transform)
|
| 121 |
+
*/
|
| 122 |
+
private randomNormal;
|
| 123 |
+
/**
|
| 124 |
+
* Create a new MCTS node
|
| 125 |
+
*/
|
| 126 |
+
private createNode;
|
| 127 |
+
/**
|
| 128 |
+
* Encode move to string key for storage in maps
|
| 129 |
+
*/
|
| 130 |
+
private encodeAction;
|
| 131 |
+
/**
|
| 132 |
+
* Decode string key back to move
|
| 133 |
+
*/
|
| 134 |
+
private decodeAction;
|
| 135 |
+
}
|
| 136 |
+
//# sourceMappingURL=mctsAgent.d.ts.map
|
trigo-web/backend/dist/inc/mctsAgent.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"mctsAgent.d.ts","sourceRoot":"","sources":["../../../inc/mctsAgent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;CACzB;AAuBD;;;GAGG;AACH,qBAAa,SAAS;IACrB,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,MAAM,CAAa;gBAI1B,SAAS,EAAE,cAAc,EACzB,eAAe,EAAE,oBAAoB,EACrC,MAAM,GAAE,OAAO,CAAC,UAAU,CAAM;IAgBjC;;;;;;OAMG;IACG,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;QAC9D,IAAI,EAAE,IAAI,CAAC;QACX,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAClC,SAAS,EAAE,MAAM,CAAC;KAClB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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
/**
|
| 3 |
+
* Monte Carlo Tree Search (MCTS) Agent for Trigo
|
| 4 |
+
*
|
| 5 |
+
* Implements AlphaGo Zero-style MCTS with:
|
| 6 |
+
* - PUCT (Polynomial Upper Confidence Trees) selection
|
| 7 |
+
* - Neural network guidance for policy and value
|
| 8 |
+
* - Visit count statistics for training data generation
|
| 9 |
+
*
|
| 10 |
+
* Based on: Silver et al., "Mastering the Game of Go without Human Knowledge"
|
| 11 |
+
*/
|
| 12 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 13 |
+
exports.MCTSAgent = void 0;
|
| 14 |
+
/**
|
| 15 |
+
* MCTS Agent
|
| 16 |
+
* Combines tree search with neural network evaluation
|
| 17 |
+
*/
|
| 18 |
+
class MCTSAgent {
|
| 19 |
+
constructor(treeAgent, evaluationAgent, config = {}) {
|
| 20 |
+
this.treeAgent = treeAgent;
|
| 21 |
+
this.evaluationAgent = evaluationAgent;
|
| 22 |
+
// Default configuration (AlphaGo Zero-inspired)
|
| 23 |
+
this.config = {
|
| 24 |
+
numSimulations: config.numSimulations ?? 600,
|
| 25 |
+
cPuct: config.cPuct ?? 1.0,
|
| 26 |
+
temperature: config.temperature ?? 1.0,
|
| 27 |
+
dirichletAlpha: config.dirichletAlpha ?? 0.03,
|
| 28 |
+
dirichletEpsilon: config.dirichletEpsilon ?? 0.25
|
| 29 |
+
};
|
| 30 |
+
}
|
| 31 |
+
/**
|
| 32 |
+
* Select best move using MCTS
|
| 33 |
+
*
|
| 34 |
+
* @param game Current game state
|
| 35 |
+
* @param moveNumber Move number (for temperature schedule)
|
| 36 |
+
* @returns Selected move with visit count statistics
|
| 37 |
+
*/
|
| 38 |
+
async selectMove(game, moveNumber) {
|
| 39 |
+
// Create root node
|
| 40 |
+
const root = this.createNode(game, null, null);
|
| 41 |
+
// Check if root is already terminal (game over)
|
| 42 |
+
// Terminal conditions (checked in order of cost):
|
| 43 |
+
// 1. Both players have stones (cheap)
|
| 44 |
+
// 2. Board coverage > 50% (cheap)
|
| 45 |
+
// 3. No neutral territory (EXPENSIVE - only check if above pass)
|
| 46 |
+
// Get board state (cheap)
|
| 47 |
+
const board = game.getBoard();
|
| 48 |
+
const shape = game.getShape();
|
| 49 |
+
const totalPositions = shape.x * shape.y * shape.z;
|
| 50 |
+
// Count stones (cheap)
|
| 51 |
+
let stoneCount = 0;
|
| 52 |
+
let hasBlack = false;
|
| 53 |
+
let hasWhite = false;
|
| 54 |
+
for (let x = 0; x < shape.x; x++) {
|
| 55 |
+
for (let y = 0; y < shape.y; y++) {
|
| 56 |
+
for (let z = 0; z < shape.z; z++) {
|
| 57 |
+
const stone = board[x][y][z];
|
| 58 |
+
if (stone === 1) { // Black
|
| 59 |
+
hasBlack = true;
|
| 60 |
+
stoneCount++;
|
| 61 |
+
}
|
| 62 |
+
else if (stone === 2) { // White
|
| 63 |
+
hasWhite = true;
|
| 64 |
+
stoneCount++;
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
const coverageRatio = stoneCount / totalPositions;
|
| 70 |
+
// Early exit: Check cheap conditions first
|
| 71 |
+
let isRootTerminal = false;
|
| 72 |
+
let territory = null;
|
| 73 |
+
if (hasBlack && hasWhite && coverageRatio > 0.5) {
|
| 74 |
+
// Only calculate territory if cheap conditions pass (EXPENSIVE)
|
| 75 |
+
territory = game.getTerritory();
|
| 76 |
+
isRootTerminal = territory.neutral === 0;
|
| 77 |
+
}
|
| 78 |
+
if (isRootTerminal) {
|
| 79 |
+
// Game is over - return Pass move with exact value from territory
|
| 80 |
+
// Using same formula as training code
|
| 81 |
+
const scoreDiff = territory.white - territory.black;
|
| 82 |
+
let rootValue;
|
| 83 |
+
if (Math.abs(scoreDiff) < 1e-6) {
|
| 84 |
+
// Draw/tie case
|
| 85 |
+
rootValue = 0.0;
|
| 86 |
+
}
|
| 87 |
+
else {
|
| 88 |
+
// Match training formula from valueCausalLoss.py:_expand_value_targets
|
| 89 |
+
// The log term incentivizes winning by larger margins (logarithmically)
|
| 90 |
+
const territory_value_factor = 1.0; // Default from training config
|
| 91 |
+
const signScore = Math.sign(scoreDiff);
|
| 92 |
+
rootValue = signScore * (1 + Math.log(Math.abs(scoreDiff))) * territory_value_factor;
|
| 93 |
+
}
|
| 94 |
+
const currentPlayer = game.getCurrentPlayer();
|
| 95 |
+
return {
|
| 96 |
+
move: { player: currentPlayer === 1 ? "black" : "white", isPass: true },
|
| 97 |
+
visitCounts: new Map(),
|
| 98 |
+
searchPolicy: new Map(),
|
| 99 |
+
rootValue
|
| 100 |
+
};
|
| 101 |
+
}
|
| 102 |
+
// Run MCTS simulations
|
| 103 |
+
for (let i = 0; i < this.config.numSimulations; i++) {
|
| 104 |
+
await this.runSimulation(root);
|
| 105 |
+
}
|
| 106 |
+
// Temperature schedule: τ=1 for first 30 moves, τ→0 afterward
|
| 107 |
+
const temperature = moveNumber < 30 ? this.config.temperature : 0.01;
|
| 108 |
+
// Select move based on visit counts
|
| 109 |
+
const move = this.selectPlayAction(root, temperature);
|
| 110 |
+
// Set correct player for returned move
|
| 111 |
+
const currentPlayer = game.getCurrentPlayer();
|
| 112 |
+
move.player = currentPlayer === 1 ? "black" : "white";
|
| 113 |
+
// Compute search policy (normalized visit counts)
|
| 114 |
+
const searchPolicy = this.computeSearchPolicy(root, temperature);
|
| 115 |
+
// Get root value estimate (average Q-value weighted by visit counts)
|
| 116 |
+
const rootValue = this.getRootValue(root);
|
| 117 |
+
return {
|
| 118 |
+
move,
|
| 119 |
+
visitCounts: new Map(root.N),
|
| 120 |
+
searchPolicy,
|
| 121 |
+
rootValue
|
| 122 |
+
};
|
| 123 |
+
}
|
| 124 |
+
/**
|
| 125 |
+
* Run a single MCTS simulation
|
| 126 |
+
* Select -> Expand & Evaluate -> Backup
|
| 127 |
+
*/
|
| 128 |
+
async runSimulation(root) {
|
| 129 |
+
// 1. Selection: Traverse tree using PUCT until reaching unexpanded node
|
| 130 |
+
const { node, path } = this.select(root);
|
| 131 |
+
// 2. Expand and Evaluate: Get value from neural network
|
| 132 |
+
const value = await this.expandAndEvaluate(node);
|
| 133 |
+
// 3. Backup: Propagate value up the tree
|
| 134 |
+
this.backup(path, value);
|
| 135 |
+
}
|
| 136 |
+
/**
|
| 137 |
+
* Selection phase: Traverse tree using PUCT
|
| 138 |
+
*
|
| 139 |
+
* @param root Root node to start selection from
|
| 140 |
+
* @returns Leaf node and path taken
|
| 141 |
+
*/
|
| 142 |
+
select(root) {
|
| 143 |
+
const path = [];
|
| 144 |
+
let node = root;
|
| 145 |
+
// Traverse until we reach an unexpanded node
|
| 146 |
+
while (node.expanded) {
|
| 147 |
+
// Get all legal actions
|
| 148 |
+
const actionKeys = Array.from(node.P.keys());
|
| 149 |
+
// Terminal node check: if expanded but no actions, this is a terminal node
|
| 150 |
+
if (actionKeys.length === 0) {
|
| 151 |
+
break; // Return this terminal node as leaf
|
| 152 |
+
}
|
| 153 |
+
// Select action with best PUCT value
|
| 154 |
+
// Both players select HIGHEST PUCT value:
|
| 155 |
+
// - Black: PUCT = -Q + U, max PUCT = max(-Q) = min(Q) ✓
|
| 156 |
+
// - White: PUCT = Q + U, max PUCT = max(Q) ✓
|
| 157 |
+
const currentPlayer = node.state.getCurrentPlayer();
|
| 158 |
+
const isWhite = currentPlayer === 2;
|
| 159 |
+
let bestActionKey = actionKeys[0];
|
| 160 |
+
let bestPuct = this.calculatePUCT(node, bestActionKey, isWhite);
|
| 161 |
+
for (let i = 1; i < actionKeys.length; i++) {
|
| 162 |
+
const actionKey = actionKeys[i];
|
| 163 |
+
const puct = this.calculatePUCT(node, actionKey, isWhite);
|
| 164 |
+
if (puct > bestPuct) {
|
| 165 |
+
bestPuct = puct;
|
| 166 |
+
bestActionKey = actionKey;
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
// Record path
|
| 170 |
+
path.push({ node, actionKey: bestActionKey });
|
| 171 |
+
// Move to child (create if doesn't exist)
|
| 172 |
+
if (!node.children.has(bestActionKey)) {
|
| 173 |
+
// Decode action and apply to get child state
|
| 174 |
+
const action = this.decodeAction(bestActionKey);
|
| 175 |
+
const childState = node.state.clone();
|
| 176 |
+
if (action.isPass) {
|
| 177 |
+
childState.pass();
|
| 178 |
+
}
|
| 179 |
+
else if (action.x !== undefined && action.y !== undefined && action.z !== undefined) {
|
| 180 |
+
childState.drop({ x: action.x, y: action.y, z: action.z });
|
| 181 |
+
}
|
| 182 |
+
// Create child node (unexpanded)
|
| 183 |
+
const childNode = this.createNode(childState, node, action);
|
| 184 |
+
node.children.set(bestActionKey, childNode);
|
| 185 |
+
}
|
| 186 |
+
node = node.children.get(bestActionKey);
|
| 187 |
+
}
|
| 188 |
+
return { node, path };
|
| 189 |
+
}
|
| 190 |
+
/**
|
| 191 |
+
* Expand and evaluate leaf node using neural networks
|
| 192 |
+
*
|
| 193 |
+
* @param node Leaf node to expand
|
| 194 |
+
* @returns Value estimate from evaluation network
|
| 195 |
+
*/
|
| 196 |
+
async expandAndEvaluate(node) {
|
| 197 |
+
// Check if game is over (terminal state)
|
| 198 |
+
// Terminal conditions (checked in order of cost):
|
| 199 |
+
// 1. Both players have stones (cheap)
|
| 200 |
+
// 2. Board coverage > 50% (cheap)
|
| 201 |
+
// 3. No neutral territory (EXPENSIVE - only check if above pass)
|
| 202 |
+
// Get board state (cheap)
|
| 203 |
+
const board = node.state.getBoard();
|
| 204 |
+
const shape = node.state.getShape();
|
| 205 |
+
const totalPositions = shape.x * shape.y * shape.z;
|
| 206 |
+
// Count stones on board (cheap)
|
| 207 |
+
let stoneCount = 0;
|
| 208 |
+
let hasBlack = false;
|
| 209 |
+
let hasWhite = false;
|
| 210 |
+
for (let x = 0; x < shape.x; x++) {
|
| 211 |
+
for (let y = 0; y < shape.y; y++) {
|
| 212 |
+
for (let z = 0; z < shape.z; z++) {
|
| 213 |
+
const stone = board[x][y][z];
|
| 214 |
+
if (stone === 1) { // Black
|
| 215 |
+
hasBlack = true;
|
| 216 |
+
stoneCount++;
|
| 217 |
+
}
|
| 218 |
+
else if (stone === 2) { // White
|
| 219 |
+
hasWhite = true;
|
| 220 |
+
stoneCount++;
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
const coverageRatio = stoneCount / totalPositions;
|
| 226 |
+
// Early exit: Check cheap conditions first
|
| 227 |
+
let isTerminal = false;
|
| 228 |
+
let territory = null;
|
| 229 |
+
if (hasBlack && hasWhite && coverageRatio > 0.5) {
|
| 230 |
+
// Only calculate territory if cheap conditions pass (EXPENSIVE)
|
| 231 |
+
territory = node.state.getTerritory();
|
| 232 |
+
isTerminal = territory.neutral === 0;
|
| 233 |
+
}
|
| 234 |
+
if (isTerminal) {
|
| 235 |
+
// Game is over - return exact result from territory
|
| 236 |
+
// Using same formula as training code: target = sign(score) * (1 + log(|score|)) * factor
|
| 237 |
+
const scoreDiff = territory.white - territory.black;
|
| 238 |
+
let value;
|
| 239 |
+
if (Math.abs(scoreDiff) < 1e-6) {
|
| 240 |
+
// Draw/tie case
|
| 241 |
+
value = 0.0;
|
| 242 |
+
}
|
| 243 |
+
else {
|
| 244 |
+
// Match training formula from valueCausalLoss.py:_expand_value_targets
|
| 245 |
+
// target = sign(score) * (1 + log(|score|)) * territory_value_factor
|
| 246 |
+
// The log term incentivizes winning by larger margins (logarithmically)
|
| 247 |
+
// This balances winning incentive without overwhelming win/loss direction
|
| 248 |
+
const territory_value_factor = 1.0; // Default from training config
|
| 249 |
+
const signScore = Math.sign(scoreDiff);
|
| 250 |
+
value = signScore * (1 + Math.log(Math.abs(scoreDiff))) * territory_value_factor;
|
| 251 |
+
}
|
| 252 |
+
// Mark terminal node as expanded with empty action set to prevent revisits
|
| 253 |
+
// This caches the terminal value and avoids repeated getTerritory() calls
|
| 254 |
+
node.expanded = true;
|
| 255 |
+
node.P = new Map(); // No actions available (terminal)
|
| 256 |
+
node.N = new Map();
|
| 257 |
+
node.W = new Map();
|
| 258 |
+
node.Q = new Map();
|
| 259 |
+
node.children = new Map();
|
| 260 |
+
return value;
|
| 261 |
+
}
|
| 262 |
+
// Non-terminal state: expand with policy network and evaluate
|
| 263 |
+
// Get all valid moves
|
| 264 |
+
const currentPlayer = node.state.getCurrentPlayer() === 1 ? "black" : "white";
|
| 265 |
+
const validPositions = node.state.validMovePositions();
|
| 266 |
+
const moves = validPositions.map(pos => ({
|
| 267 |
+
x: pos.x,
|
| 268 |
+
y: pos.y,
|
| 269 |
+
z: pos.z,
|
| 270 |
+
player: currentPlayer
|
| 271 |
+
}));
|
| 272 |
+
moves.push({ player: currentPlayer, isPass: true });
|
| 273 |
+
// Get policy priors from tree agent
|
| 274 |
+
const scoredMoves = await this.treeAgent.scoreMoves(node.state, moves);
|
| 275 |
+
// Convert log probabilities to probabilities and normalize (stable softmax)
|
| 276 |
+
const maxScore = Math.max(...scoredMoves.map(m => m.score));
|
| 277 |
+
const expScores = scoredMoves.map(m => Math.exp(m.score - maxScore));
|
| 278 |
+
const sumExp = expScores.reduce((sum, exp) => sum + exp, 0);
|
| 279 |
+
// Initialize priors P(s,a)
|
| 280 |
+
node.P = new Map();
|
| 281 |
+
node.N = new Map();
|
| 282 |
+
node.W = new Map();
|
| 283 |
+
node.Q = new Map();
|
| 284 |
+
// Handle edge case: if all scores are -Infinity or sumExp is 0/NaN
|
| 285 |
+
const useFallback = !isFinite(sumExp) || sumExp < 1e-10;
|
| 286 |
+
for (let i = 0; i < scoredMoves.length; i++) {
|
| 287 |
+
const actionKey = this.encodeAction(scoredMoves[i].move);
|
| 288 |
+
// Use uniform distribution as fallback if normalization fails
|
| 289 |
+
const prior = useFallback ? (1.0 / scoredMoves.length) : (expScores[i] / sumExp);
|
| 290 |
+
node.P.set(actionKey, prior);
|
| 291 |
+
node.N.set(actionKey, 0);
|
| 292 |
+
node.W.set(actionKey, 0);
|
| 293 |
+
node.Q.set(actionKey, 0);
|
| 294 |
+
}
|
| 295 |
+
// Add Dirichlet noise at root
|
| 296 |
+
if (node.parent === null) {
|
| 297 |
+
this.addDirichletNoise(node.P);
|
| 298 |
+
}
|
| 299 |
+
// Mark as expanded
|
| 300 |
+
node.expanded = true;
|
| 301 |
+
// Get value estimate from evaluation agent
|
| 302 |
+
const evaluation = await this.evaluationAgent.evaluatePosition(node.state);
|
| 303 |
+
// Return value directly (value model returns white-positive by design)
|
| 304 |
+
return evaluation.value;
|
| 305 |
+
}
|
| 306 |
+
/**
|
| 307 |
+
* Backup phase: Propagate value up the tree
|
| 308 |
+
*
|
| 309 |
+
* @param path Path from root to leaf
|
| 310 |
+
* @param value Value to propagate (white-positive: positive = white winning)
|
| 311 |
+
*/
|
| 312 |
+
backup(path, value) {
|
| 313 |
+
// Propagate value up the tree (white-positive throughout)
|
| 314 |
+
// No sign flipping needed - Q values are always white-positive
|
| 315 |
+
for (let i = path.length - 1; i >= 0; i--) {
|
| 316 |
+
const { node, actionKey } = path[i];
|
| 317 |
+
// Update statistics
|
| 318 |
+
const n = node.N.get(actionKey) ?? 0;
|
| 319 |
+
const w = node.W.get(actionKey) ?? 0;
|
| 320 |
+
node.N.set(actionKey, n + 1);
|
| 321 |
+
node.W.set(actionKey, w + value);
|
| 322 |
+
node.Q.set(actionKey, (w + value) / (n + 1));
|
| 323 |
+
}
|
| 324 |
+
}
|
| 325 |
+
/**
|
| 326 |
+
* Calculate PUCT value for action selection
|
| 327 |
+
*
|
| 328 |
+
* PUCT = Q(s,a) + U(s,a) [for White, who maximizes]
|
| 329 |
+
* PUCT = -Q(s,a) + U(s,a) [for Black, who minimizes]
|
| 330 |
+
* where U(s,a) = c_puct * P(s,a) * sqrt(Σ_b N(s,b)) / (1 + N(s,a))
|
| 331 |
+
*
|
| 332 |
+
* @param node Current node
|
| 333 |
+
* @param actionKey Action to evaluate
|
| 334 |
+
* @param isWhite Whether current player is White
|
| 335 |
+
* @returns PUCT value
|
| 336 |
+
*/
|
| 337 |
+
calculatePUCT(node, actionKey, isWhite) {
|
| 338 |
+
const Q = node.Q.get(actionKey) ?? 0;
|
| 339 |
+
const N = node.N.get(actionKey) ?? 0;
|
| 340 |
+
const P = node.P.get(actionKey) ?? 0;
|
| 341 |
+
// Sum of all visit counts at this node
|
| 342 |
+
const totalN = Array.from(node.N.values()).reduce((sum, n) => sum + n, 0);
|
| 343 |
+
// Exploration term: U(s,a) = c_puct * P(s,a) * sqrt(Σ_b N(s,b) + 1) / (1 + N(s,a))
|
| 344 |
+
// +1 in sqrt to avoid zero exploration when node first expanded
|
| 345 |
+
const U = this.config.cPuct * P * Math.sqrt(totalN + 1) / (1 + N);
|
| 346 |
+
// Black minimizes Q (flips sign), White maximizes Q
|
| 347 |
+
return (isWhite ? Q : -Q) + U;
|
| 348 |
+
}
|
| 349 |
+
/**
|
| 350 |
+
* Select action to play based on visit counts
|
| 351 |
+
* Uses temperature to control exploration vs exploitation
|
| 352 |
+
*
|
| 353 |
+
* @param node Root node
|
| 354 |
+
* @param temperature Selection temperature (τ=1 for exploration, τ→0 for greedy)
|
| 355 |
+
* @returns Selected move
|
| 356 |
+
*/
|
| 357 |
+
selectPlayAction(node, temperature) {
|
| 358 |
+
const actionKeys = Array.from(node.N.keys());
|
| 359 |
+
if (temperature < 0.01) {
|
| 360 |
+
// Greedy: Select action with highest visit count
|
| 361 |
+
let bestActionKey = actionKeys[0];
|
| 362 |
+
let bestN = node.N.get(bestActionKey) ?? 0;
|
| 363 |
+
for (let i = 1; i < actionKeys.length; i++) {
|
| 364 |
+
const actionKey = actionKeys[i];
|
| 365 |
+
const n = node.N.get(actionKey) ?? 0;
|
| 366 |
+
if (n > bestN) {
|
| 367 |
+
bestN = n;
|
| 368 |
+
bestActionKey = actionKey;
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
return this.decodeAction(bestActionKey);
|
| 372 |
+
}
|
| 373 |
+
else {
|
| 374 |
+
// Temperature-based sampling: π(a|s) ∝ N(s,a)^(1/τ)
|
| 375 |
+
const nValues = actionKeys.map(key => node.N.get(key) ?? 0);
|
| 376 |
+
const nPowered = nValues.map(n => Math.pow(n, 1 / temperature));
|
| 377 |
+
const sumN = nPowered.reduce((sum, n) => sum + n, 0);
|
| 378 |
+
// Handle edge case: if all visits are 0 or sum is invalid
|
| 379 |
+
if (!isFinite(sumN) || sumN <= 0) {
|
| 380 |
+
// Fallback to uniform random selection (or use priors)
|
| 381 |
+
const randomIndex = Math.floor(Math.random() * actionKeys.length);
|
| 382 |
+
return this.decodeAction(actionKeys[randomIndex]);
|
| 383 |
+
}
|
| 384 |
+
// Sample from distribution
|
| 385 |
+
let rand = Math.random() * sumN;
|
| 386 |
+
for (let i = 0; i < actionKeys.length; i++) {
|
| 387 |
+
rand -= nPowered[i];
|
| 388 |
+
if (rand <= 0) {
|
| 389 |
+
return this.decodeAction(actionKeys[i]);
|
| 390 |
+
}
|
| 391 |
+
}
|
| 392 |
+
// Fallback (shouldn't reach here due to floating point precision)
|
| 393 |
+
return this.decodeAction(actionKeys[actionKeys.length - 1]);
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
/**
|
| 397 |
+
* Compute search policy from visit counts
|
| 398 |
+
* π(a|s) = N(s,a)^(1/τ) / Σ_b N(s,b)^(1/τ)
|
| 399 |
+
*
|
| 400 |
+
* @param node Root node
|
| 401 |
+
* @param temperature Selection temperature
|
| 402 |
+
* @returns Normalized policy distribution
|
| 403 |
+
*/
|
| 404 |
+
computeSearchPolicy(node, temperature) {
|
| 405 |
+
const policy = new Map();
|
| 406 |
+
const actionKeys = Array.from(node.N.keys());
|
| 407 |
+
// Compute π(a|s) ∝ N(s,a)^(1/τ)
|
| 408 |
+
const nPowered = actionKeys.map(key => Math.pow(node.N.get(key) ?? 0, 1 / temperature));
|
| 409 |
+
const sumN = nPowered.reduce((sum, n) => sum + n, 0);
|
| 410 |
+
// Handle edge case: if all visits are 0 or sum is invalid
|
| 411 |
+
if (!isFinite(sumN) || sumN <= 0) {
|
| 412 |
+
// Fallback to uniform distribution
|
| 413 |
+
const uniform = 1 / actionKeys.length;
|
| 414 |
+
for (const key of actionKeys) {
|
| 415 |
+
policy.set(key, uniform);
|
| 416 |
+
}
|
| 417 |
+
return policy;
|
| 418 |
+
}
|
| 419 |
+
for (let i = 0; i < actionKeys.length; i++) {
|
| 420 |
+
const actionKey = actionKeys[i];
|
| 421 |
+
policy.set(actionKey, nPowered[i] / sumN);
|
| 422 |
+
}
|
| 423 |
+
return policy;
|
| 424 |
+
}
|
| 425 |
+
/**
|
| 426 |
+
* Get root value estimate (weighted average of Q-values)
|
| 427 |
+
*/
|
| 428 |
+
getRootValue(node) {
|
| 429 |
+
const actionKeys = Array.from(node.N.keys());
|
| 430 |
+
const totalN = Array.from(node.N.values()).reduce((sum, n) => sum + n, 0);
|
| 431 |
+
if (totalN === 0) {
|
| 432 |
+
return 0;
|
| 433 |
+
}
|
| 434 |
+
let weightedSum = 0;
|
| 435 |
+
for (const actionKey of actionKeys) {
|
| 436 |
+
const q = node.Q.get(actionKey) ?? 0;
|
| 437 |
+
const n = node.N.get(actionKey) ?? 0;
|
| 438 |
+
weightedSum += q * n;
|
| 439 |
+
}
|
| 440 |
+
return weightedSum / totalN;
|
| 441 |
+
}
|
| 442 |
+
/**
|
| 443 |
+
* Add Dirichlet noise to prior probabilities at root
|
| 444 |
+
* P(s,a) = (1 - ε) * p_a + ε * η_a
|
| 445 |
+
* where η ~ Dir(α)
|
| 446 |
+
*/
|
| 447 |
+
addDirichletNoise(priors) {
|
| 448 |
+
const actionKeys = Array.from(priors.keys());
|
| 449 |
+
const alpha = this.config.dirichletAlpha;
|
| 450 |
+
const epsilon = this.config.dirichletEpsilon;
|
| 451 |
+
// Generate Dirichlet noise (simplified using Gamma distribution)
|
| 452 |
+
const noise = [];
|
| 453 |
+
let noiseSum = 0;
|
| 454 |
+
for (let i = 0; i < actionKeys.length; i++) {
|
| 455 |
+
// Gamma(α, 1) approximation using rejection sampling
|
| 456 |
+
const sample = this.sampleGamma(alpha);
|
| 457 |
+
noise.push(sample);
|
| 458 |
+
noiseSum += sample;
|
| 459 |
+
}
|
| 460 |
+
// Handle edge case: if all Gamma samples are 0 (extremely unlikely but possible)
|
| 461 |
+
if (!isFinite(noiseSum) || noiseSum <= 0) {
|
| 462 |
+
// Fallback: use uniform noise (no mixing, keep original priors)
|
| 463 |
+
return;
|
| 464 |
+
}
|
| 465 |
+
// Normalize and mix with priors
|
| 466 |
+
for (let i = 0; i < actionKeys.length; i++) {
|
| 467 |
+
const actionKey = actionKeys[i];
|
| 468 |
+
const prior = priors.get(actionKey) ?? 0;
|
| 469 |
+
const noiseFraction = noise[i] / noiseSum;
|
| 470 |
+
priors.set(actionKey, (1 - epsilon) * prior + epsilon * noiseFraction);
|
| 471 |
+
}
|
| 472 |
+
}
|
| 473 |
+
/**
|
| 474 |
+
* Sample from Gamma distribution using Marsaglia and Tsang method (2000)
|
| 475 |
+
* Used for Dirichlet noise generation
|
| 476 |
+
*/
|
| 477 |
+
sampleGamma(alpha) {
|
| 478 |
+
if (alpha <= 0) {
|
| 479 |
+
throw new Error("Gamma distribution alpha must be > 0");
|
| 480 |
+
}
|
| 481 |
+
// For alpha < 1, use transformation: sample Gamma(alpha+1) then multiply by U^(1/alpha)
|
| 482 |
+
if (alpha < 1) {
|
| 483 |
+
const u = Math.random();
|
| 484 |
+
const g = this.sampleGamma(alpha + 1);
|
| 485 |
+
return g * Math.pow(u, 1 / alpha);
|
| 486 |
+
}
|
| 487 |
+
// For alpha >= 1, use Marsaglia and Tsang's method
|
| 488 |
+
const d = alpha - 1 / 3;
|
| 489 |
+
const c = 1 / Math.sqrt(9 * d);
|
| 490 |
+
while (true) {
|
| 491 |
+
let x, v;
|
| 492 |
+
do {
|
| 493 |
+
x = this.randomNormal();
|
| 494 |
+
v = 1 + c * x;
|
| 495 |
+
} while (v <= 0);
|
| 496 |
+
v = v * v * v;
|
| 497 |
+
const u = Math.random();
|
| 498 |
+
// Fast acceptance check
|
| 499 |
+
if (u < 1 - 0.0331 * x * x * x * x) {
|
| 500 |
+
return d * v;
|
| 501 |
+
}
|
| 502 |
+
// Fallback acceptance check
|
| 503 |
+
if (Math.log(u) < 0.5 * x * x + d * (1 - v + Math.log(v))) {
|
| 504 |
+
return d * v;
|
| 505 |
+
}
|
| 506 |
+
}
|
| 507 |
+
}
|
| 508 |
+
/**
|
| 509 |
+
* Sample from standard normal distribution (Box-Muller transform)
|
| 510 |
+
*/
|
| 511 |
+
randomNormal() {
|
| 512 |
+
const u1 = Math.random();
|
| 513 |
+
const u2 = Math.random();
|
| 514 |
+
return Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
|
| 515 |
+
}
|
| 516 |
+
/**
|
| 517 |
+
* Create a new MCTS node
|
| 518 |
+
*/
|
| 519 |
+
createNode(state, parent, action) {
|
| 520 |
+
return {
|
| 521 |
+
state,
|
| 522 |
+
parent,
|
| 523 |
+
action,
|
| 524 |
+
N: new Map(),
|
| 525 |
+
W: new Map(),
|
| 526 |
+
Q: new Map(),
|
| 527 |
+
P: new Map(),
|
| 528 |
+
children: new Map(),
|
| 529 |
+
expanded: false
|
| 530 |
+
};
|
| 531 |
+
}
|
| 532 |
+
/**
|
| 533 |
+
* Encode move to string key for storage in maps
|
| 534 |
+
*/
|
| 535 |
+
encodeAction(move) {
|
| 536 |
+
if (move.isPass) {
|
| 537 |
+
return "pass";
|
| 538 |
+
}
|
| 539 |
+
return `${move.x},${move.y},${move.z}`;
|
| 540 |
+
}
|
| 541 |
+
/**
|
| 542 |
+
* Decode string key back to move
|
| 543 |
+
*/
|
| 544 |
+
decodeAction(key) {
|
| 545 |
+
if (key === "pass") {
|
| 546 |
+
return { player: "black", isPass: true }; // Player will be updated when applied
|
| 547 |
+
}
|
| 548 |
+
const [x, y, z] = key.split(",").map(Number);
|
| 549 |
+
return { player: "black", x, y, z }; // Player will be updated when applied
|
| 550 |
+
}
|
| 551 |
+
}
|
| 552 |
+
exports.MCTSAgent = MCTSAgent;
|
| 553 |
+
//# sourceMappingURL=mctsAgent.js.map
|
trigo-web/backend/dist/inc/mctsAgent.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"mctsAgent.js","sourceRoot":"","sources":["../../../inc/mctsAgent.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAwCH;;;GAGG;AACH,MAAa,SAAS;IAMrB,YACC,SAAyB,EACzB,eAAqC,EACrC,SAA8B,EAAE;QAEhC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,eAAe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| 3 |
+
*
|
| 4 |
+
* Platform-agnostic inference logic that accepts ONNX session from platform-specific code.
|
| 5 |
+
* No direct dependency on onnxruntime packages - uses dependency injection pattern.
|
| 6 |
+
*
|
| 7 |
+
* Adapted from Node.js test_inference.js for cross-platform use
|
| 8 |
+
* Provides causal language model inference using GPT-2 ONNX model
|
| 9 |
+
*
|
| 10 |
+
* Vocabulary Design (128 tokens):
|
| 11 |
+
* 0-3: Special tokens (PAD=0, START=1, END=2, VALUE=3)
|
| 12 |
+
* 4-7: Reserved for future use
|
| 13 |
+
* 10: LF (newline) for multi-line game records
|
| 14 |
+
* 32-127: ASCII printable characters (direct identity mapping)
|
| 15 |
+
*
|
| 16 |
+
* This design uses direct identity mapping: token_id = ascii_value
|
| 17 |
+
* No complex formulas needed - simple and efficient.
|
| 18 |
+
*/
|
| 19 |
+
/**
|
| 20 |
+
* Minimal ONNX Tensor interface (platform-agnostic)
|
| 21 |
+
*/
|
| 22 |
+
export interface OnnxTensor {
|
| 23 |
+
readonly data: number[] | Float32Array | Int32Array | BigInt64Array | Uint8Array;
|
| 24 |
+
readonly dims: readonly number[];
|
| 25 |
+
readonly type: string;
|
| 26 |
+
}
|
| 27 |
+
/**
|
| 28 |
+
* Minimal ONNX Session interface (platform-agnostic)
|
| 29 |
+
*/
|
| 30 |
+
export interface OnnxSession {
|
| 31 |
+
readonly inputNames: readonly string[];
|
| 32 |
+
readonly outputNames: readonly string[];
|
| 33 |
+
run(feeds: Record<string, OnnxTensor>): Promise<Record<string, OnnxTensor>>;
|
| 34 |
+
}
|
| 35 |
+
/**
|
| 36 |
+
* Tensor constructor interface (platform-specific)
|
| 37 |
+
*/
|
| 38 |
+
export interface TensorConstructor {
|
| 39 |
+
new (type: string, data: BigInt64Array | Float32Array | Int32Array | Uint8Array, dims: number[]): OnnxTensor;
|
| 40 |
+
}
|
| 41 |
+
/**
|
| 42 |
+
* Configuration for the inferencer
|
| 43 |
+
*/
|
| 44 |
+
export interface InferencerConfig {
|
| 45 |
+
vocabSize: number;
|
| 46 |
+
seqLen: number;
|
| 47 |
+
modelPath?: string;
|
| 48 |
+
}
|
| 49 |
+
/**
|
| 50 |
+
* Inference result containing generated tokens and metadata
|
| 51 |
+
*/
|
| 52 |
+
export interface InferenceResult {
|
| 53 |
+
tokens: number[];
|
| 54 |
+
text: string;
|
| 55 |
+
logits: Float32Array;
|
| 56 |
+
inferenceTime: number;
|
| 57 |
+
}
|
| 58 |
+
/**
|
| 59 |
+
* Evaluation mode inputs for tree attention
|
| 60 |
+
*/
|
| 61 |
+
export interface EvaluationInputs {
|
| 62 |
+
prefixIds: number[];
|
| 63 |
+
evaluatedIds: number[];
|
| 64 |
+
evaluatedMask: number[];
|
| 65 |
+
}
|
| 66 |
+
/**
|
| 67 |
+
* Evaluation mode output
|
| 68 |
+
*/
|
| 69 |
+
export interface EvaluationOutput {
|
| 70 |
+
logits: Float32Array;
|
| 71 |
+
numEvaluated: number;
|
| 72 |
+
}
|
| 73 |
+
/**
|
| 74 |
+
* Model Inferencer for Causal Language Model
|
| 75 |
+
* Compatible with both frontend (onnxruntime-web) and backend (onnxruntime-node)
|
| 76 |
+
*/
|
| 77 |
+
export declare class ModelInferencer {
|
| 78 |
+
private session;
|
| 79 |
+
private config;
|
| 80 |
+
private TensorClass;
|
| 81 |
+
private readonly PAD_TOKEN;
|
| 82 |
+
private readonly START_TOKEN;
|
| 83 |
+
private readonly END_TOKEN;
|
| 84 |
+
private readonly VALUE_TOKEN;
|
| 85 |
+
constructor(TensorClass: TensorConstructor, config?: Partial<InferencerConfig>);
|
| 86 |
+
/**
|
| 87 |
+
* Set the inference session (created by platform-specific code)
|
| 88 |
+
*/
|
| 89 |
+
setSession(session: OnnxSession): void;
|
| 90 |
+
/**
|
| 91 |
+
* Run basic inference test
|
| 92 |
+
*/
|
| 93 |
+
testBasicInference(): Promise<InferenceResult>;
|
| 94 |
+
/**
|
| 95 |
+
* Generate tokens autoregressively from a prompt
|
| 96 |
+
*/
|
| 97 |
+
generateText(prompt: string, numTokens?: number): Promise<InferenceResult>;
|
| 98 |
+
/**
|
| 99 |
+
* Get model information
|
| 100 |
+
*/
|
| 101 |
+
getModelInfo(): {
|
| 102 |
+
inputs: string[];
|
| 103 |
+
outputs: string[];
|
| 104 |
+
} | null;
|
| 105 |
+
/**
|
| 106 |
+
* Get configuration
|
| 107 |
+
*/
|
| 108 |
+
getConfig(): InferencerConfig;
|
| 109 |
+
/**
|
| 110 |
+
* Run inference with token array input
|
| 111 |
+
* Returns raw logits as Float32Array
|
| 112 |
+
*/
|
| 113 |
+
runInference(tokens: number[]): Promise<Float32Array>;
|
| 114 |
+
/**
|
| 115 |
+
* Run tree attention inference (evaluation mode)
|
| 116 |
+
* For models exported with --evaluation flag
|
| 117 |
+
* @param inputs - Prefix, evaluated tokens, and attention mask
|
| 118 |
+
* @returns Logits for each evaluated position
|
| 119 |
+
*/
|
| 120 |
+
runEvaluationInference(inputs: EvaluationInputs): Promise<EvaluationOutput>;
|
| 121 |
+
/**
|
| 122 |
+
* Run value prediction inference (for evaluation mode models)
|
| 123 |
+
* For models exported with --evaluation-mode flag
|
| 124 |
+
* @param tokens - Token IDs (already includes START/END tokens and padding)
|
| 125 |
+
* @returns Predicted game outcome value in range [-1, 1]
|
| 126 |
+
*/
|
| 127 |
+
runValuePrediction(tokens: number[]): Promise<number>;
|
| 128 |
+
/**
|
| 129 |
+
* Compute softmax for a single position's logits
|
| 130 |
+
* @param logits - Full logits array
|
| 131 |
+
* @param position - Which evaluated position (0 = last prefix, 1-m = evaluated tokens)
|
| 132 |
+
* @returns Probability distribution over vocabulary
|
| 133 |
+
*/
|
| 134 |
+
softmax(logits: Float32Array, position: number): Float32Array;
|
| 135 |
+
/**
|
| 136 |
+
* Check if inferencer is ready
|
| 137 |
+
*/
|
| 138 |
+
isReady(): boolean;
|
| 139 |
+
/**
|
| 140 |
+
* Destroy the session and free resources
|
| 141 |
+
*/
|
| 142 |
+
destroy(): void;
|
| 143 |
+
private printModelInfo;
|
| 144 |
+
private createRandomInput;
|
| 145 |
+
private padSequence;
|
| 146 |
+
private validateOutput;
|
| 147 |
+
private getPredictions;
|
| 148 |
+
}
|
| 149 |
+
//# sourceMappingURL=modelInferencer.d.ts.map
|
trigo-web/backend/dist/inc/modelInferencer.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"modelInferencer.d.ts","sourceRoot":"","sources":["../../../inc/modelInferencer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,YAAY,GAAG,UAAU,GAAG,aAAa,GAAG,UAAU,CAAC;IACjF,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;CAC5E;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC,KACC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,aAAa,GAAG,YAAY,GAAG,UAAU,GAAG,UAAU,EAC5D,IAAI,EAAE,MAAM,EAAE,GACZ,UAAU,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,MAAM,EAA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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
/**
|
| 3 |
+
* ONNX Model Inferencer (Frontend/Backend Common)
|
| 4 |
+
*
|
| 5 |
+
* Platform-agnostic inference logic that accepts ONNX session from platform-specific code.
|
| 6 |
+
* No direct dependency on onnxruntime packages - uses dependency injection pattern.
|
| 7 |
+
*
|
| 8 |
+
* Adapted from Node.js test_inference.js for cross-platform use
|
| 9 |
+
* Provides causal language model inference using GPT-2 ONNX model
|
| 10 |
+
*
|
| 11 |
+
* Vocabulary Design (128 tokens):
|
| 12 |
+
* 0-3: Special tokens (PAD=0, START=1, END=2, VALUE=3)
|
| 13 |
+
* 4-7: Reserved for future use
|
| 14 |
+
* 10: LF (newline) for multi-line game records
|
| 15 |
+
* 32-127: ASCII printable characters (direct identity mapping)
|
| 16 |
+
*
|
| 17 |
+
* This design uses direct identity mapping: token_id = ascii_value
|
| 18 |
+
* No complex formulas needed - simple and efficient.
|
| 19 |
+
*/
|
| 20 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 21 |
+
exports.ModelInferencer = void 0;
|
| 22 |
+
/**
|
| 23 |
+
* Model Inferencer for Causal Language Model
|
| 24 |
+
* Compatible with both frontend (onnxruntime-web) and backend (onnxruntime-node)
|
| 25 |
+
*/
|
| 26 |
+
class ModelInferencer {
|
| 27 |
+
constructor(TensorClass, config = {}) {
|
| 28 |
+
this.session = null;
|
| 29 |
+
// TGN tokenizer: Compact 128-token vocabulary with direct ASCII mapping
|
| 30 |
+
// 0-3: Special tokens (PAD, START, END, VALUE)
|
| 31 |
+
// 4-7: Reserved for future use
|
| 32 |
+
// 10: Newline (LF)
|
| 33 |
+
// 32-127: ASCII printable characters (direct identity mapping)
|
| 34 |
+
this.PAD_TOKEN = 0;
|
| 35 |
+
this.START_TOKEN = 1;
|
| 36 |
+
this.END_TOKEN = 2;
|
| 37 |
+
this.VALUE_TOKEN = 3;
|
| 38 |
+
this.TensorClass = TensorClass;
|
| 39 |
+
this.config = {
|
| 40 |
+
vocabSize: config.vocabSize || 128, // Allow override via config
|
| 41 |
+
seqLen: 256,
|
| 42 |
+
...config
|
| 43 |
+
};
|
| 44 |
+
}
|
| 45 |
+
/**
|
| 46 |
+
* Set the inference session (created by platform-specific code)
|
| 47 |
+
*/
|
| 48 |
+
setSession(session) {
|
| 49 |
+
this.session = session;
|
| 50 |
+
console.log("[ModelInferencer] ✓ Session set successfully");
|
| 51 |
+
this.printModelInfo();
|
| 52 |
+
}
|
| 53 |
+
/**
|
| 54 |
+
* Run basic inference test
|
| 55 |
+
*/
|
| 56 |
+
async testBasicInference() {
|
| 57 |
+
if (!this.session) {
|
| 58 |
+
throw new Error("Inferencer not initialized. Call setSession() first.");
|
| 59 |
+
}
|
| 60 |
+
console.log("[ModelInferencer] Running basic inference test...");
|
| 61 |
+
const batchSize = 1;
|
| 62 |
+
const seqLen = this.config.seqLen;
|
| 63 |
+
// Create random input
|
| 64 |
+
const inputIds = this.createRandomInput(batchSize, seqLen);
|
| 65 |
+
const inputTensor = new this.TensorClass("int64", inputIds, [batchSize, seqLen]);
|
| 66 |
+
// Run inference
|
| 67 |
+
const startTime = performance.now();
|
| 68 |
+
const results = await this.session.run({ input_ids: inputTensor });
|
| 69 |
+
const inferenceTime = performance.now() - startTime;
|
| 70 |
+
// Get logits
|
| 71 |
+
const logits = results.logits;
|
| 72 |
+
// Validate output
|
| 73 |
+
this.validateOutput(logits, batchSize, seqLen);
|
| 74 |
+
// Get predictions
|
| 75 |
+
const predictions = this.getPredictions(logits.data, batchSize * seqLen);
|
| 76 |
+
// Convert tokens to text
|
| 77 |
+
const text = String.fromCharCode(...predictions.slice(0, 100));
|
| 78 |
+
console.log("[ModelInferencer] Inference completed:");
|
| 79 |
+
console.log(` Input shape: [${inputTensor.dims.join(", ")}]`);
|
| 80 |
+
console.log(` Output shape: [${logits.dims.join(", ")}]`);
|
| 81 |
+
console.log(` Output dtype: ${logits.type}`);
|
| 82 |
+
console.log(` Inference time: ${inferenceTime.toFixed(2)}ms`);
|
| 83 |
+
console.log(` Sample predictions: [${predictions.slice(0, 10).join(", ")}]`);
|
| 84 |
+
const logitsArray = Array.from(logits.data);
|
| 85 |
+
console.log(` Logits range: [${Math.min(...logitsArray).toFixed(3)}, ${Math.max(...logitsArray).toFixed(3)}]`);
|
| 86 |
+
return {
|
| 87 |
+
tokens: predictions,
|
| 88 |
+
text,
|
| 89 |
+
logits: logits.data,
|
| 90 |
+
inferenceTime
|
| 91 |
+
};
|
| 92 |
+
}
|
| 93 |
+
/**
|
| 94 |
+
* Generate tokens autoregressively from a prompt
|
| 95 |
+
*/
|
| 96 |
+
async generateText(prompt, numTokens = 10) {
|
| 97 |
+
if (!this.session) {
|
| 98 |
+
throw new Error("Inferencer not initialized. Call setSession() first.");
|
| 99 |
+
}
|
| 100 |
+
console.log(`[ModelInferencer] Generating ${numTokens} tokens from prompt: "${prompt}"`);
|
| 101 |
+
// Convert prompt to token IDs (byte values)
|
| 102 |
+
const promptTokens = Array.from(prompt).map((c) => c.charCodeAt(0));
|
| 103 |
+
console.log(` Prompt tokens (${promptTokens.length}): [${promptTokens.join(", ")}]`);
|
| 104 |
+
// Start with prompt tokens
|
| 105 |
+
const sequence = [...promptTokens];
|
| 106 |
+
const times = [];
|
| 107 |
+
// Generate tokens
|
| 108 |
+
for (let i = 0; i < numTokens; i++) {
|
| 109 |
+
// Pad sequence to fixed length
|
| 110 |
+
const paddedSequence = this.padSequence(sequence, this.config.seqLen);
|
| 111 |
+
// Create input tensor
|
| 112 |
+
const inputIds = new BigInt64Array(paddedSequence.map((t) => BigInt(t)));
|
| 113 |
+
const inputTensor = new this.TensorClass("int64", inputIds, [1, this.config.seqLen]);
|
| 114 |
+
// Run inference
|
| 115 |
+
const startTime = performance.now();
|
| 116 |
+
const results = await this.session.run({ input_ids: inputTensor });
|
| 117 |
+
times.push(performance.now() - startTime);
|
| 118 |
+
// Get prediction at the last non-padded position
|
| 119 |
+
const logits = results.logits.data;
|
| 120 |
+
const lastPos = sequence.length - 1; // Position before padding
|
| 121 |
+
const offset = lastPos * this.config.vocabSize;
|
| 122 |
+
// Find token with highest logit
|
| 123 |
+
let maxIdx = 0;
|
| 124 |
+
let maxVal = logits[offset];
|
| 125 |
+
for (let j = 1; j < this.config.vocabSize; j++) {
|
| 126 |
+
if (logits[offset + j] > maxVal) {
|
| 127 |
+
maxVal = logits[offset + j];
|
| 128 |
+
maxIdx = j;
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
sequence.push(maxIdx);
|
| 132 |
+
// Stop if END token is generated
|
| 133 |
+
if (maxIdx === this.END_TOKEN) {
|
| 134 |
+
console.log(" Generated END token, stopping...");
|
| 135 |
+
break;
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
// Convert generated tokens to text
|
| 139 |
+
const generatedText = String.fromCharCode(...sequence);
|
| 140 |
+
const avgTime = times.reduce((a, b) => a + b, 0) / times.length;
|
| 141 |
+
console.log(`[ModelInferencer] Generation complete:`);
|
| 142 |
+
console.log(` Generated text: "${generatedText}"`);
|
| 143 |
+
console.log(` Token sequence (${sequence.length}): [${sequence.join(", ")}]`);
|
| 144 |
+
console.log(` Avg inference time: ${avgTime.toFixed(2)}ms`);
|
| 145 |
+
console.log(` Tokens/sec: ${(1000 / avgTime).toFixed(2)}`);
|
| 146 |
+
return {
|
| 147 |
+
tokens: sequence,
|
| 148 |
+
text: generatedText,
|
| 149 |
+
logits: new Float32Array(), // Not returning full logits for generation
|
| 150 |
+
inferenceTime: avgTime
|
| 151 |
+
};
|
| 152 |
+
}
|
| 153 |
+
/**
|
| 154 |
+
* Get model information
|
| 155 |
+
*/
|
| 156 |
+
getModelInfo() {
|
| 157 |
+
if (!this.session)
|
| 158 |
+
return null;
|
| 159 |
+
return {
|
| 160 |
+
inputs: [...this.session.inputNames],
|
| 161 |
+
outputs: [...this.session.outputNames]
|
| 162 |
+
};
|
| 163 |
+
}
|
| 164 |
+
/**
|
| 165 |
+
* Get configuration
|
| 166 |
+
*/
|
| 167 |
+
getConfig() {
|
| 168 |
+
return this.config;
|
| 169 |
+
}
|
| 170 |
+
/**
|
| 171 |
+
* Run inference with token array input
|
| 172 |
+
* Returns raw logits as Float32Array
|
| 173 |
+
*/
|
| 174 |
+
async runInference(tokens) {
|
| 175 |
+
if (!this.session) {
|
| 176 |
+
throw new Error("Inferencer not initialized. Call setSession() first.");
|
| 177 |
+
}
|
| 178 |
+
const seqLen = this.config.seqLen;
|
| 179 |
+
// Prepend START_TOKEN to input
|
| 180 |
+
const tokensWithStart = [this.START_TOKEN, ...tokens];
|
| 181 |
+
// Pad to fixed length
|
| 182 |
+
const paddedTokens = new BigInt64Array(seqLen);
|
| 183 |
+
for (let i = 0; i < seqLen; i++) {
|
| 184 |
+
paddedTokens[i] =
|
| 185 |
+
i < tokensWithStart.length ? BigInt(tokensWithStart[i]) : BigInt(this.PAD_TOKEN);
|
| 186 |
+
}
|
| 187 |
+
// Create input tensor
|
| 188 |
+
const inputTensor = new this.TensorClass("int64", paddedTokens, [1, seqLen]);
|
| 189 |
+
// Run inference
|
| 190 |
+
const results = await this.session.run({ input_ids: inputTensor });
|
| 191 |
+
return results.logits.data;
|
| 192 |
+
}
|
| 193 |
+
/**
|
| 194 |
+
* Run tree attention inference (evaluation mode)
|
| 195 |
+
* For models exported with --evaluation flag
|
| 196 |
+
* @param inputs - Prefix, evaluated tokens, and attention mask
|
| 197 |
+
* @returns Logits for each evaluated position
|
| 198 |
+
*/
|
| 199 |
+
async runEvaluationInference(inputs) {
|
| 200 |
+
if (!this.session) {
|
| 201 |
+
throw new Error("Inferencer not initialized. Call setSession() first.");
|
| 202 |
+
}
|
| 203 |
+
const { prefixIds, evaluatedIds, evaluatedMask } = inputs;
|
| 204 |
+
const batchSize = 1;
|
| 205 |
+
const prefixLen = prefixIds.length;
|
| 206 |
+
const m = evaluatedIds.length;
|
| 207 |
+
// Convert to BigInt64Array for ONNX int64 tensors
|
| 208 |
+
const prefixIdsArray = new BigInt64Array(batchSize * prefixLen);
|
| 209 |
+
for (let i = 0; i < prefixLen; i++) {
|
| 210 |
+
prefixIdsArray[i] = BigInt(prefixIds[i]);
|
| 211 |
+
}
|
| 212 |
+
const evaluatedIdsArray = new BigInt64Array(batchSize * m);
|
| 213 |
+
for (let i = 0; i < m; i++) {
|
| 214 |
+
evaluatedIdsArray[i] = BigInt(evaluatedIds[i]);
|
| 215 |
+
}
|
| 216 |
+
// Mask is Float32Array
|
| 217 |
+
const maskArray = new Float32Array(m * m);
|
| 218 |
+
for (let i = 0; i < m * m; i++) {
|
| 219 |
+
maskArray[i] = evaluatedMask[i];
|
| 220 |
+
}
|
| 221 |
+
// Create ONNX tensors
|
| 222 |
+
const prefixIdsTensor = new this.TensorClass("int64", prefixIdsArray, [
|
| 223 |
+
batchSize,
|
| 224 |
+
prefixLen
|
| 225 |
+
]);
|
| 226 |
+
const evaluatedIdsTensor = new this.TensorClass("int64", evaluatedIdsArray, [batchSize, m]);
|
| 227 |
+
const evaluatedMaskTensor = new this.TensorClass("float32", maskArray, [1, m, m]);
|
| 228 |
+
// Run inference
|
| 229 |
+
const results = await this.session.run({
|
| 230 |
+
prefix_ids: prefixIdsTensor,
|
| 231 |
+
evaluated_ids: evaluatedIdsTensor,
|
| 232 |
+
evaluated_mask: evaluatedMaskTensor
|
| 233 |
+
});
|
| 234 |
+
// Extract logits
|
| 235 |
+
const logits = results.logits.data;
|
| 236 |
+
// Output shape: [batch, m+1, vocab_size]
|
| 237 |
+
// We return flattened array and num_evaluated for reshaping
|
| 238 |
+
return {
|
| 239 |
+
logits,
|
| 240 |
+
numEvaluated: m
|
| 241 |
+
};
|
| 242 |
+
}
|
| 243 |
+
/**
|
| 244 |
+
* Run value prediction inference (for evaluation mode models)
|
| 245 |
+
* For models exported with --evaluation-mode flag
|
| 246 |
+
* @param tokens - Token IDs (already includes START/END tokens and padding)
|
| 247 |
+
* @returns Predicted game outcome value in range [-1, 1]
|
| 248 |
+
*/
|
| 249 |
+
async runValuePrediction(tokens) {
|
| 250 |
+
if (!this.session) {
|
| 251 |
+
throw new Error("Inferencer not initialized. Call setSession() first.");
|
| 252 |
+
}
|
| 253 |
+
const seqLen = tokens.length;
|
| 254 |
+
// Convert to BigInt64Array for ONNX int64 tensors
|
| 255 |
+
const inputIds = new BigInt64Array(seqLen);
|
| 256 |
+
for (let i = 0; i < seqLen; i++) {
|
| 257 |
+
inputIds[i] = BigInt(tokens[i]);
|
| 258 |
+
}
|
| 259 |
+
// Create input tensor [1, seq_len]
|
| 260 |
+
const inputTensor = new this.TensorClass("int64", inputIds, [1, seqLen]);
|
| 261 |
+
// Run inference
|
| 262 |
+
const results = await this.session.run({
|
| 263 |
+
input_ids: inputTensor
|
| 264 |
+
});
|
| 265 |
+
// Extract value
|
| 266 |
+
// Output shape: [batch_size] = [1]
|
| 267 |
+
// For evaluation models, output name is "values" not "logits"
|
| 268 |
+
const values = results.values;
|
| 269 |
+
if (!values) {
|
| 270 |
+
throw new Error("Evaluation model did not return 'values' output. Check model export.");
|
| 271 |
+
}
|
| 272 |
+
const predictedValue = values.data[0];
|
| 273 |
+
return predictedValue;
|
| 274 |
+
}
|
| 275 |
+
/**
|
| 276 |
+
* Compute softmax for a single position's logits
|
| 277 |
+
* @param logits - Full logits array
|
| 278 |
+
* @param position - Which evaluated position (0 = last prefix, 1-m = evaluated tokens)
|
| 279 |
+
* @returns Probability distribution over vocabulary
|
| 280 |
+
*/
|
| 281 |
+
softmax(logits, position) {
|
| 282 |
+
const vocabSize = this.config.vocabSize;
|
| 283 |
+
const offset = position * vocabSize;
|
| 284 |
+
const probs = new Float32Array(vocabSize);
|
| 285 |
+
// Find max for numerical stability
|
| 286 |
+
let maxLogit = -Infinity;
|
| 287 |
+
for (let i = 0; i < vocabSize; i++) {
|
| 288 |
+
maxLogit = Math.max(maxLogit, logits[offset + i]);
|
| 289 |
+
}
|
| 290 |
+
// Compute exp and sum
|
| 291 |
+
let sumExp = 0;
|
| 292 |
+
for (let i = 0; i < vocabSize; i++) {
|
| 293 |
+
probs[i] = Math.exp(logits[offset + i] - maxLogit);
|
| 294 |
+
sumExp += probs[i];
|
| 295 |
+
}
|
| 296 |
+
// Normalize
|
| 297 |
+
for (let i = 0; i < vocabSize; i++) {
|
| 298 |
+
probs[i] /= sumExp;
|
| 299 |
+
}
|
| 300 |
+
return probs;
|
| 301 |
+
}
|
| 302 |
+
/**
|
| 303 |
+
* Check if inferencer is ready
|
| 304 |
+
*/
|
| 305 |
+
isReady() {
|
| 306 |
+
return this.session !== null;
|
| 307 |
+
}
|
| 308 |
+
/**
|
| 309 |
+
* Destroy the session and free resources
|
| 310 |
+
*/
|
| 311 |
+
destroy() {
|
| 312 |
+
this.session = null;
|
| 313 |
+
console.log("[ModelInferencer] Session destroyed");
|
| 314 |
+
}
|
| 315 |
+
// Private helper methods
|
| 316 |
+
printModelInfo() {
|
| 317 |
+
if (!this.session)
|
| 318 |
+
return;
|
| 319 |
+
console.log("[ModelInferencer] Model Information:");
|
| 320 |
+
console.log(" Inputs:");
|
| 321 |
+
this.session.inputNames.forEach((name, i) => {
|
| 322 |
+
console.log(` [${i}] ${name}`);
|
| 323 |
+
});
|
| 324 |
+
console.log(" Outputs:");
|
| 325 |
+
this.session.outputNames.forEach((name, i) => {
|
| 326 |
+
console.log(` [${i}] ${name}`);
|
| 327 |
+
});
|
| 328 |
+
}
|
| 329 |
+
createRandomInput(batchSize, seqLen) {
|
| 330 |
+
const size = batchSize * seqLen;
|
| 331 |
+
const data = new BigInt64Array(size);
|
| 332 |
+
for (let i = 0; i < size; i++) {
|
| 333 |
+
data[i] = BigInt(Math.floor(Math.random() * this.config.vocabSize));
|
| 334 |
+
}
|
| 335 |
+
return data;
|
| 336 |
+
}
|
| 337 |
+
padSequence(tokens, targetLen) {
|
| 338 |
+
const padded = [...tokens];
|
| 339 |
+
while (padded.length < targetLen) {
|
| 340 |
+
padded.push(this.PAD_TOKEN);
|
| 341 |
+
}
|
| 342 |
+
return padded.slice(0, targetLen); // Truncate if too long
|
| 343 |
+
}
|
| 344 |
+
validateOutput(logits, batchSize, seqLen) {
|
| 345 |
+
const expectedShape = [batchSize, seqLen, this.config.vocabSize];
|
| 346 |
+
if (logits.dims.length !== 3) {
|
| 347 |
+
throw new Error(`Expected 3D output, got ${logits.dims.length}D`);
|
| 348 |
+
}
|
| 349 |
+
if (logits.dims[0] !== expectedShape[0] ||
|
| 350 |
+
logits.dims[1] !== expectedShape[1] ||
|
| 351 |
+
logits.dims[2] !== expectedShape[2]) {
|
| 352 |
+
throw new Error(`Shape mismatch! Expected [${expectedShape.join(", ")}], ` +
|
| 353 |
+
`got [${logits.dims.join(", ")}]`);
|
| 354 |
+
}
|
| 355 |
+
if (logits.type !== "float32") {
|
| 356 |
+
throw new Error(`Expected float32 output, got ${logits.type}`);
|
| 357 |
+
}
|
| 358 |
+
}
|
| 359 |
+
getPredictions(logitsData, numPositions) {
|
| 360 |
+
const predictions = [];
|
| 361 |
+
for (let i = 0; i < numPositions; i++) {
|
| 362 |
+
let maxIdx = 0;
|
| 363 |
+
let maxVal = logitsData[i * this.config.vocabSize];
|
| 364 |
+
for (let j = 1; j < this.config.vocabSize; j++) {
|
| 365 |
+
const val = logitsData[i * this.config.vocabSize + j];
|
| 366 |
+
if (val > maxVal) {
|
| 367 |
+
maxVal = val;
|
| 368 |
+
maxIdx = j;
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
predictions.push(maxIdx);
|
| 372 |
+
}
|
| 373 |
+
return predictions;
|
| 374 |
+
}
|
| 375 |
+
}
|
| 376 |
+
exports.ModelInferencer = ModelInferencer;
|
| 377 |
+
//# sourceMappingURL=modelInferencer.js.map
|
trigo-web/backend/dist/inc/modelInferencer.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"modelInferencer.js","sourceRoot":"","sources":["../../../inc/modelInferencer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAmEH;;;GAGG;AACH,MAAa,eAAe;IAe3B,YAAY,WAA8B,EAAE,SAAoC,EAAE;QAd1E,YAAO,GAAuB,IAAI,CAAC;QAI3C,wEAAwE;QACxE,+CAA+C;QAC/C,+BAA+B;QAC/B,mBAAmB;QACnB,+DAA+D;QAC9C,cAAS,GAAG,CAAC,CAAC;QACd,gBAAW,GAAG,CAAC,CAAC;QAChB,cAAS,GAAG,CAAC,CAAC;QACd,gBAAW,GAAG,CAAC,CAAC;QAGhC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG;YACb,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,GAAG,EAAG,4BAA4B;YACjE,MAAM,EAAE,GAAG;YACX,GAAG,MAAM;SACT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
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
/* parser generated by jison 0.4.18 */
|
| 3 |
+
/*
|
| 4 |
+
Returns a Parser object of the following structure:
|
| 5 |
+
|
| 6 |
+
Parser: {
|
| 7 |
+
yy: {}
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
Parser.prototype: {
|
| 11 |
+
yy: {},
|
| 12 |
+
trace: function(),
|
| 13 |
+
symbols_: {associative list: name ==> number},
|
| 14 |
+
terminals_: {associative list: number ==> name},
|
| 15 |
+
productions_: [...],
|
| 16 |
+
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
|
| 17 |
+
table: [...],
|
| 18 |
+
defaultActions: {...},
|
| 19 |
+
parseError: function(str, hash),
|
| 20 |
+
parse: function(input),
|
| 21 |
+
|
| 22 |
+
lexer: {
|
| 23 |
+
EOF: 1,
|
| 24 |
+
parseError: function(str, hash),
|
| 25 |
+
setInput: function(input),
|
| 26 |
+
input: function(),
|
| 27 |
+
unput: function(str),
|
| 28 |
+
more: function(),
|
| 29 |
+
less: function(n),
|
| 30 |
+
pastInput: function(),
|
| 31 |
+
upcomingInput: function(),
|
| 32 |
+
showPosition: function(),
|
| 33 |
+
test_match: function(regex_match_array, rule_index),
|
| 34 |
+
next: function(),
|
| 35 |
+
lex: function(),
|
| 36 |
+
begin: function(condition),
|
| 37 |
+
popState: function(),
|
| 38 |
+
_currentRules: function(),
|
| 39 |
+
topState: function(),
|
| 40 |
+
pushState: function(condition),
|
| 41 |
+
|
| 42 |
+
options: {
|
| 43 |
+
ranges: boolean (optional: true ==> token location info will include a .range[] member)
|
| 44 |
+
flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
|
| 45 |
+
backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
|
| 46 |
+
},
|
| 47 |
+
|
| 48 |
+
performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
|
| 49 |
+
rules: [...],
|
| 50 |
+
conditions: {associative list: name ==> set},
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
token location info (@$, _$, etc.): {
|
| 56 |
+
first_line: n,
|
| 57 |
+
last_line: n,
|
| 58 |
+
first_column: n,
|
| 59 |
+
last_column: n,
|
| 60 |
+
range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
the parseError function receives a 'hash' object with these members for lexer and parser errors: {
|
| 65 |
+
text: (matched text)
|
| 66 |
+
token: (the produced terminal token, if any)
|
| 67 |
+
line: (yylineno)
|
| 68 |
+
}
|
| 69 |
+
while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
|
| 70 |
+
loc: (yylloc)
|
| 71 |
+
expected: (string describing the set of expected tokens)
|
| 72 |
+
recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
|
| 73 |
+
}
|
| 74 |
+
*/
|
| 75 |
+
var tgn = (function () {
|
| 76 |
+
var o = function (k, v, o, l) { for (o = o || {}, l = k.length; l--; o[k[l]] = v)
|
| 77 |
+
; return o; }, $V0 = [1, 7], $V1 = [2, 25], $V2 = [6, 8, 49], $V3 = [1, 32], $V4 = [6, 49], $V5 = [11, 49], $V6 = [11, 48], $V7 = [1, 51], $V8 = [1, 52], $V9 = [1, 53], $Va = [6, 36, 37, 38, 49];
|
| 78 |
+
var parser = { trace: function trace() { },
|
| 79 |
+
yy: {},
|
| 80 |
+
symbols_: { "error": 2, "game": 3, "tag_section": 4, "move_section": 5, "EOF": 6, "tag_pair": 7, "[": 8, "tag_name": 9, "STRING": 10, "]": 11, "TAG_RESULT": 12, "game_result": 13, "TAG_BOARD": 14, "board_shape": 15, "TAG_EVENT": 16, "TAG_SITE": 17, "TAG_DATE": 18, "TAG_ROUND": 19, "TAG_BLACK": 20, "TAG_WHITE": 21, "TAG_HANDICAP": 22, "TAG_RULES": 23, "TAG_TIMECONTROL": 24, "TAG_ANNOTATOR": 25, "TAG_APPLICATION": 26, "TAG_NAME": 27, "move_sequence": 28, "move_sequence_intact": 29, "move_sequence_truncated": 30, "move_round": 31, "move_round_half": 32, "number": 33, "DOT": 34, "move_action": 35, "PASS": 36, "RESIGN": 37, "COORDINATE": 38, "win": 39, "conquer": 40, "=": 41, "*": 42, "RESULT_BLACK": 43, "RESULT_WHITE": 44, "conquer_unit": 45, "POINTS": 46, "STONES": 47, "TIMES": 48, "NUMBER": 49, "$accept": 0, "$end": 1 },
|
| 81 |
+
terminals_: { 2: "error", 6: "EOF", 8: "[", 10: "STRING", 11: "]", 12: "TAG_RESULT", 14: "TAG_BOARD", 16: "TAG_EVENT", 17: "TAG_SITE", 18: "TAG_DATE", 19: "TAG_ROUND", 20: "TAG_BLACK", 21: "TAG_WHITE", 22: "TAG_HANDICAP", 23: "TAG_RULES", 24: "TAG_TIMECONTROL", 25: "TAG_ANNOTATOR", 26: "TAG_APPLICATION", 27: "TAG_NAME", 34: "DOT", 36: "PASS", 37: "RESIGN", 38: "COORDINATE", 41: "=", 42: "*", 43: "RESULT_BLACK", 44: "RESULT_WHITE", 46: "POINTS", 47: "STONES", 48: "TIMES", 49: "NUMBER" },
|
| 82 |
+
productions_: [0, [3, 3], [3, 2], [3, 2], [3, 1], [4, 1], [4, 2], [7, 4], [7, 4], [7, 4], [9, 1], [9, 1], [9, 1], [9, 1], [9, 1], [9, 1], [9, 1], [9, 1], [9, 1], [9, 1], [9, 1], [9, 1], [5, 1], [28, 1], [28, 1], [29, 0], [29, 2], [30, 2], [31, 4], [32, 3], [35, 1], [35, 1], [35, 1], [13, 1], [13, 2], [13, 1], [13, 1], [39, 1], [39, 1], [40, 2], [45, 1], [45, 1], [15, 1], [15, 3], [33, 1]],
|
| 83 |
+
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
|
| 84 |
+
/* this == yyval */
|
| 85 |
+
var $0 = $$.length - 1;
|
| 86 |
+
switch (yystate) {
|
| 87 |
+
case 1:
|
| 88 |
+
return {
|
| 89 |
+
tags: $$[$0 - 2],
|
| 90 |
+
moves: $$[$0 - 1],
|
| 91 |
+
success: true
|
| 92 |
+
};
|
| 93 |
+
break;
|
| 94 |
+
case 2:
|
| 95 |
+
return {
|
| 96 |
+
tags: $$[$0 - 1],
|
| 97 |
+
moves: null,
|
| 98 |
+
success: true
|
| 99 |
+
};
|
| 100 |
+
break;
|
| 101 |
+
case 3:
|
| 102 |
+
return {
|
| 103 |
+
tags: {},
|
| 104 |
+
moves: $$[$0 - 1],
|
| 105 |
+
success: true
|
| 106 |
+
};
|
| 107 |
+
break;
|
| 108 |
+
case 4:
|
| 109 |
+
return {
|
| 110 |
+
tags: {},
|
| 111 |
+
moves: null,
|
| 112 |
+
success: true
|
| 113 |
+
};
|
| 114 |
+
break;
|
| 115 |
+
case 5:
|
| 116 |
+
case 23:
|
| 117 |
+
case 24:
|
| 118 |
+
this.$ = $$[$0];
|
| 119 |
+
break;
|
| 120 |
+
case 6:
|
| 121 |
+
this.$ = Object.assign({}, $$[$0 - 1], $$[$0]);
|
| 122 |
+
break;
|
| 123 |
+
case 7:
|
| 124 |
+
const tagName = $$[$0 - 2];
|
| 125 |
+
const tagValue = $$[$0 - 1].slice(1, -1); // Remove quotes
|
| 126 |
+
this.$ = { [tagName]: tagValue };
|
| 127 |
+
break;
|
| 128 |
+
case 8:
|
| 129 |
+
this.$ = $$[$0 - 1];
|
| 130 |
+
break;
|
| 131 |
+
case 9:
|
| 132 |
+
this.$ = ({ [$$[$0 - 2]]: $$[$0 - 1] });
|
| 133 |
+
break;
|
| 134 |
+
case 21:
|
| 135 |
+
this.$ = yytext;
|
| 136 |
+
break;
|
| 137 |
+
case 25:
|
| 138 |
+
this.$ = [];
|
| 139 |
+
break;
|
| 140 |
+
case 26:
|
| 141 |
+
case 27:
|
| 142 |
+
this.$ = $$[$0 - 1].concat([$$[$0]]);
|
| 143 |
+
break;
|
| 144 |
+
case 28:
|
| 145 |
+
this.$ = ({ round: $$[$0 - 3], action_black: $$[$0 - 1], action_white: $$[$0] });
|
| 146 |
+
break;
|
| 147 |
+
case 29:
|
| 148 |
+
this.$ = ({ round: $$[$0 - 2], action_black: $$[$0] });
|
| 149 |
+
break;
|
| 150 |
+
case 30:
|
| 151 |
+
this.$ = ({ type: 'pass' });
|
| 152 |
+
break;
|
| 153 |
+
case 31:
|
| 154 |
+
this.$ = ({ type: 'resign' });
|
| 155 |
+
break;
|
| 156 |
+
case 32:
|
| 157 |
+
// Placeholder: Parse coordinate notation
|
| 158 |
+
this.$ = {
|
| 159 |
+
type: 'move',
|
| 160 |
+
position: yytext
|
| 161 |
+
};
|
| 162 |
+
break;
|
| 163 |
+
case 33:
|
| 164 |
+
this.$ = ({ Result: $$[$0] });
|
| 165 |
+
break;
|
| 166 |
+
case 34:
|
| 167 |
+
this.$ = ({ Result: $$[$0 - 1], Conquer: $$[$0] });
|
| 168 |
+
break;
|
| 169 |
+
case 35:
|
| 170 |
+
this.$ = ({ Result: "draw" });
|
| 171 |
+
break;
|
| 172 |
+
case 36:
|
| 173 |
+
this.$ = ({ Result: "unknown" });
|
| 174 |
+
break;
|
| 175 |
+
case 37:
|
| 176 |
+
this.$ = "black win";
|
| 177 |
+
break;
|
| 178 |
+
case 38:
|
| 179 |
+
this.$ = "white win";
|
| 180 |
+
break;
|
| 181 |
+
case 39:
|
| 182 |
+
this.$ = ({ n: $$[$0 - 1], unit: $$[$0] });
|
| 183 |
+
break;
|
| 184 |
+
case 42:
|
| 185 |
+
this.$ = [$$[$0]];
|
| 186 |
+
break;
|
| 187 |
+
case 43:
|
| 188 |
+
this.$ = $$[$0 - 2].concat($$[$0]);
|
| 189 |
+
break;
|
| 190 |
+
case 44:
|
| 191 |
+
this.$ = parseInt($$[$0]);
|
| 192 |
+
break;
|
| 193 |
+
}
|
| 194 |
+
},
|
| 195 |
+
table: [{ 3: 1, 4: 2, 5: 3, 6: [1, 4], 7: 5, 8: $V0, 28: 6, 29: 8, 30: 9, 49: $V1 }, { 1: [3] }, { 5: 10, 6: [1, 11], 7: 12, 8: $V0, 28: 6, 29: 8, 30: 9, 49: $V1 }, { 6: [1, 13] }, { 1: [2, 4] }, o($V2, [2, 5]), { 6: [2, 22] }, { 9: 14, 12: [1, 15], 14: [1, 16], 16: [1, 17], 17: [1, 18], 18: [1, 19], 19: [1, 20], 20: [1, 21], 21: [1, 22], 22: [1, 23], 23: [1, 24], 24: [1, 25], 25: [1, 26], 26: [1, 27], 27: [1, 28] }, { 6: [2, 23], 31: 29, 32: 30, 33: 31, 49: $V3 }, { 6: [2, 24] }, { 6: [1, 33] }, { 1: [2, 2] }, o($V2, [2, 6]), { 1: [2, 3] }, { 10: [1, 34] }, { 13: 35, 39: 36, 41: [1, 37], 42: [1, 38], 43: [1, 39], 44: [1, 40] }, { 15: 41, 33: 42, 49: $V3 }, { 10: [2, 10] }, { 10: [2, 11] }, { 10: [2, 12] }, { 10: [2, 13] }, { 10: [2, 14] }, { 10: [2, 15] }, { 10: [2, 16] }, { 10: [2, 17] }, { 10: [2, 18] }, { 10: [2, 19] }, { 10: [2, 20] }, { 10: [2, 21] }, o($V4, [2, 26]), { 6: [2, 27] }, { 34: [1, 43] }, o([11, 34, 46, 47, 48], [2, 44]), { 1: [2, 1] }, { 11: [1, 44] }, { 11: [1, 45] }, { 11: [2, 33], 33: 47, 40: 46, 49: $V3 }, { 11: [2, 35] }, { 11: [2, 36] }, o($V5, [2, 37]), o($V5, [2, 38]), { 11: [1, 48], 48: [1, 49] }, o($V6, [2, 42]), { 35: 50, 36: $V7, 37: $V8, 38: $V9 }, o($V2, [2, 7]), o($V2, [2, 8]), { 11: [2, 34] }, { 45: 54, 46: [1, 55], 47: [1, 56] }, o($V2, [2, 9]), { 33: 57, 49: $V3 }, { 6: [2, 29], 35: 58, 36: $V7, 37: $V8, 38: $V9 }, o($Va, [2, 30]), o($Va, [2, 31]), o($Va, [2, 32]), { 11: [2, 39] }, { 11: [2, 40] }, { 11: [2, 41] }, o($V6, [2, 43]), o($V4, [2, 28])],
|
| 196 |
+
defaultActions: { 4: [2, 4], 6: [2, 22], 9: [2, 24], 11: [2, 2], 13: [2, 3], 17: [2, 10], 18: [2, 11], 19: [2, 12], 20: [2, 13], 21: [2, 14], 22: [2, 15], 23: [2, 16], 24: [2, 17], 25: [2, 18], 26: [2, 19], 27: [2, 20], 28: [2, 21], 30: [2, 27], 33: [2, 1], 37: [2, 35], 38: [2, 36], 46: [2, 34], 54: [2, 39], 55: [2, 40], 56: [2, 41] },
|
| 197 |
+
parseError: function parseError(str, hash) {
|
| 198 |
+
if (hash.recoverable) {
|
| 199 |
+
this.trace(str);
|
| 200 |
+
}
|
| 201 |
+
else {
|
| 202 |
+
var error = new Error(str);
|
| 203 |
+
error.hash = hash;
|
| 204 |
+
throw error;
|
| 205 |
+
}
|
| 206 |
+
},
|
| 207 |
+
parse: function parse(input) {
|
| 208 |
+
var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
|
| 209 |
+
var args = lstack.slice.call(arguments, 1);
|
| 210 |
+
var lexer = Object.create(this.lexer);
|
| 211 |
+
var sharedState = { yy: {} };
|
| 212 |
+
for (var k in this.yy) {
|
| 213 |
+
if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
|
| 214 |
+
sharedState.yy[k] = this.yy[k];
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
lexer.setInput(input, sharedState.yy);
|
| 218 |
+
sharedState.yy.lexer = lexer;
|
| 219 |
+
sharedState.yy.parser = this;
|
| 220 |
+
if (typeof lexer.yylloc == 'undefined') {
|
| 221 |
+
lexer.yylloc = {};
|
| 222 |
+
}
|
| 223 |
+
var yyloc = lexer.yylloc;
|
| 224 |
+
lstack.push(yyloc);
|
| 225 |
+
var ranges = lexer.options && lexer.options.ranges;
|
| 226 |
+
if (typeof sharedState.yy.parseError === 'function') {
|
| 227 |
+
this.parseError = sharedState.yy.parseError;
|
| 228 |
+
}
|
| 229 |
+
else {
|
| 230 |
+
this.parseError = Object.getPrototypeOf(this).parseError;
|
| 231 |
+
}
|
| 232 |
+
function popStack(n) {
|
| 233 |
+
stack.length = stack.length - 2 * n;
|
| 234 |
+
vstack.length = vstack.length - n;
|
| 235 |
+
lstack.length = lstack.length - n;
|
| 236 |
+
}
|
| 237 |
+
_token_stack: var lex = function () {
|
| 238 |
+
var token;
|
| 239 |
+
token = lexer.lex() || EOF;
|
| 240 |
+
if (typeof token !== 'number') {
|
| 241 |
+
token = self.symbols_[token] || token;
|
| 242 |
+
}
|
| 243 |
+
return token;
|
| 244 |
+
};
|
| 245 |
+
var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
|
| 246 |
+
while (true) {
|
| 247 |
+
state = stack[stack.length - 1];
|
| 248 |
+
if (this.defaultActions[state]) {
|
| 249 |
+
action = this.defaultActions[state];
|
| 250 |
+
}
|
| 251 |
+
else {
|
| 252 |
+
if (symbol === null || typeof symbol == 'undefined') {
|
| 253 |
+
symbol = lex();
|
| 254 |
+
}
|
| 255 |
+
action = table[state] && table[state][symbol];
|
| 256 |
+
}
|
| 257 |
+
if (typeof action === 'undefined' || !action.length || !action[0]) {
|
| 258 |
+
var errStr = '';
|
| 259 |
+
expected = [];
|
| 260 |
+
for (p in table[state]) {
|
| 261 |
+
if (this.terminals_[p] && p > TERROR) {
|
| 262 |
+
expected.push('\'' + this.terminals_[p] + '\'');
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
if (lexer.showPosition) {
|
| 266 |
+
errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
|
| 267 |
+
}
|
| 268 |
+
else {
|
| 269 |
+
errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
|
| 270 |
+
}
|
| 271 |
+
this.parseError(errStr, {
|
| 272 |
+
text: lexer.match,
|
| 273 |
+
token: this.terminals_[symbol] || symbol,
|
| 274 |
+
line: lexer.yylineno,
|
| 275 |
+
loc: yyloc,
|
| 276 |
+
expected: expected
|
| 277 |
+
});
|
| 278 |
+
}
|
| 279 |
+
if (action[0] instanceof Array && action.length > 1) {
|
| 280 |
+
throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
|
| 281 |
+
}
|
| 282 |
+
switch (action[0]) {
|
| 283 |
+
case 1:
|
| 284 |
+
stack.push(symbol);
|
| 285 |
+
vstack.push(lexer.yytext);
|
| 286 |
+
lstack.push(lexer.yylloc);
|
| 287 |
+
stack.push(action[1]);
|
| 288 |
+
symbol = null;
|
| 289 |
+
if (!preErrorSymbol) {
|
| 290 |
+
yyleng = lexer.yyleng;
|
| 291 |
+
yytext = lexer.yytext;
|
| 292 |
+
yylineno = lexer.yylineno;
|
| 293 |
+
yyloc = lexer.yylloc;
|
| 294 |
+
if (recovering > 0) {
|
| 295 |
+
recovering--;
|
| 296 |
+
}
|
| 297 |
+
}
|
| 298 |
+
else {
|
| 299 |
+
symbol = preErrorSymbol;
|
| 300 |
+
preErrorSymbol = null;
|
| 301 |
+
}
|
| 302 |
+
break;
|
| 303 |
+
case 2:
|
| 304 |
+
len = this.productions_[action[1]][1];
|
| 305 |
+
yyval.$ = vstack[vstack.length - len];
|
| 306 |
+
yyval._$ = {
|
| 307 |
+
first_line: lstack[lstack.length - (len || 1)].first_line,
|
| 308 |
+
last_line: lstack[lstack.length - 1].last_line,
|
| 309 |
+
first_column: lstack[lstack.length - (len || 1)].first_column,
|
| 310 |
+
last_column: lstack[lstack.length - 1].last_column
|
| 311 |
+
};
|
| 312 |
+
if (ranges) {
|
| 313 |
+
yyval._$.range = [
|
| 314 |
+
lstack[lstack.length - (len || 1)].range[0],
|
| 315 |
+
lstack[lstack.length - 1].range[1]
|
| 316 |
+
];
|
| 317 |
+
}
|
| 318 |
+
r = this.performAction.apply(yyval, [
|
| 319 |
+
yytext,
|
| 320 |
+
yyleng,
|
| 321 |
+
yylineno,
|
| 322 |
+
sharedState.yy,
|
| 323 |
+
action[1],
|
| 324 |
+
vstack,
|
| 325 |
+
lstack
|
| 326 |
+
].concat(args));
|
| 327 |
+
if (typeof r !== 'undefined') {
|
| 328 |
+
return r;
|
| 329 |
+
}
|
| 330 |
+
if (len) {
|
| 331 |
+
stack = stack.slice(0, -1 * len * 2);
|
| 332 |
+
vstack = vstack.slice(0, -1 * len);
|
| 333 |
+
lstack = lstack.slice(0, -1 * len);
|
| 334 |
+
}
|
| 335 |
+
stack.push(this.productions_[action[1]][0]);
|
| 336 |
+
vstack.push(yyval.$);
|
| 337 |
+
lstack.push(yyval._$);
|
| 338 |
+
newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
|
| 339 |
+
stack.push(newState);
|
| 340 |
+
break;
|
| 341 |
+
case 3:
|
| 342 |
+
return true;
|
| 343 |
+
}
|
| 344 |
+
}
|
| 345 |
+
return true;
|
| 346 |
+
} };
|
| 347 |
+
/* ========== Additional JavaScript Code ========== */
|
| 348 |
+
// Parser configuration
|
| 349 |
+
parser.yy = {
|
| 350 |
+
// Helper functions can be added here
|
| 351 |
+
parseError: function (str, hash) {
|
| 352 |
+
throw new Error('Parse error: ' + str);
|
| 353 |
+
}
|
| 354 |
+
};
|
| 355 |
+
/* generated by jison-lex 0.3.4 */
|
| 356 |
+
var lexer = (function () {
|
| 357 |
+
var lexer = ({
|
| 358 |
+
EOF: 1,
|
| 359 |
+
parseError: function parseError(str, hash) {
|
| 360 |
+
if (this.yy.parser) {
|
| 361 |
+
this.yy.parser.parseError(str, hash);
|
| 362 |
+
}
|
| 363 |
+
else {
|
| 364 |
+
throw new Error(str);
|
| 365 |
+
}
|
| 366 |
+
},
|
| 367 |
+
// resets the lexer, sets new input
|
| 368 |
+
setInput: function (input, yy) {
|
| 369 |
+
this.yy = yy || this.yy || {};
|
| 370 |
+
this._input = input;
|
| 371 |
+
this._more = this._backtrack = this.done = false;
|
| 372 |
+
this.yylineno = this.yyleng = 0;
|
| 373 |
+
this.yytext = this.matched = this.match = '';
|
| 374 |
+
this.conditionStack = ['INITIAL'];
|
| 375 |
+
this.yylloc = {
|
| 376 |
+
first_line: 1,
|
| 377 |
+
first_column: 0,
|
| 378 |
+
last_line: 1,
|
| 379 |
+
last_column: 0
|
| 380 |
+
};
|
| 381 |
+
if (this.options.ranges) {
|
| 382 |
+
this.yylloc.range = [0, 0];
|
| 383 |
+
}
|
| 384 |
+
this.offset = 0;
|
| 385 |
+
return this;
|
| 386 |
+
},
|
| 387 |
+
// consumes and returns one char from the input
|
| 388 |
+
input: function () {
|
| 389 |
+
var ch = this._input[0];
|
| 390 |
+
this.yytext += ch;
|
| 391 |
+
this.yyleng++;
|
| 392 |
+
this.offset++;
|
| 393 |
+
this.match += ch;
|
| 394 |
+
this.matched += ch;
|
| 395 |
+
var lines = ch.match(/(?:\r\n?|\n).*/g);
|
| 396 |
+
if (lines) {
|
| 397 |
+
this.yylineno++;
|
| 398 |
+
this.yylloc.last_line++;
|
| 399 |
+
}
|
| 400 |
+
else {
|
| 401 |
+
this.yylloc.last_column++;
|
| 402 |
+
}
|
| 403 |
+
if (this.options.ranges) {
|
| 404 |
+
this.yylloc.range[1]++;
|
| 405 |
+
}
|
| 406 |
+
this._input = this._input.slice(1);
|
| 407 |
+
return ch;
|
| 408 |
+
},
|
| 409 |
+
// unshifts one char (or a string) into the input
|
| 410 |
+
unput: function (ch) {
|
| 411 |
+
var len = ch.length;
|
| 412 |
+
var lines = ch.split(/(?:\r\n?|\n)/g);
|
| 413 |
+
this._input = ch + this._input;
|
| 414 |
+
this.yytext = this.yytext.substr(0, this.yytext.length - len);
|
| 415 |
+
//this.yyleng -= len;
|
| 416 |
+
this.offset -= len;
|
| 417 |
+
var oldLines = this.match.split(/(?:\r\n?|\n)/g);
|
| 418 |
+
this.match = this.match.substr(0, this.match.length - 1);
|
| 419 |
+
this.matched = this.matched.substr(0, this.matched.length - 1);
|
| 420 |
+
if (lines.length - 1) {
|
| 421 |
+
this.yylineno -= lines.length - 1;
|
| 422 |
+
}
|
| 423 |
+
var r = this.yylloc.range;
|
| 424 |
+
this.yylloc = {
|
| 425 |
+
first_line: this.yylloc.first_line,
|
| 426 |
+
last_line: this.yylineno + 1,
|
| 427 |
+
first_column: this.yylloc.first_column,
|
| 428 |
+
last_column: lines ?
|
| 429 |
+
(lines.length === oldLines.length ? this.yylloc.first_column : 0)
|
| 430 |
+
+ oldLines[oldLines.length - lines.length].length - lines[0].length :
|
| 431 |
+
this.yylloc.first_column - len
|
| 432 |
+
};
|
| 433 |
+
if (this.options.ranges) {
|
| 434 |
+
this.yylloc.range = [r[0], r[0] + this.yyleng - len];
|
| 435 |
+
}
|
| 436 |
+
this.yyleng = this.yytext.length;
|
| 437 |
+
return this;
|
| 438 |
+
},
|
| 439 |
+
// When called from action, caches matched text and appends it on next action
|
| 440 |
+
more: function () {
|
| 441 |
+
this._more = true;
|
| 442 |
+
return this;
|
| 443 |
+
},
|
| 444 |
+
// When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
|
| 445 |
+
reject: function () {
|
| 446 |
+
if (this.options.backtrack_lexer) {
|
| 447 |
+
this._backtrack = true;
|
| 448 |
+
}
|
| 449 |
+
else {
|
| 450 |
+
return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
|
| 451 |
+
text: "",
|
| 452 |
+
token: null,
|
| 453 |
+
line: this.yylineno
|
| 454 |
+
});
|
| 455 |
+
}
|
| 456 |
+
return this;
|
| 457 |
+
},
|
| 458 |
+
// retain first n characters of the match
|
| 459 |
+
less: function (n) {
|
| 460 |
+
this.unput(this.match.slice(n));
|
| 461 |
+
},
|
| 462 |
+
// displays already matched input, i.e. for error messages
|
| 463 |
+
pastInput: function () {
|
| 464 |
+
var past = this.matched.substr(0, this.matched.length - this.match.length);
|
| 465 |
+
return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
|
| 466 |
+
},
|
| 467 |
+
// displays upcoming input, i.e. for error messages
|
| 468 |
+
upcomingInput: function () {
|
| 469 |
+
var next = this.match;
|
| 470 |
+
if (next.length < 20) {
|
| 471 |
+
next += this._input.substr(0, 20 - next.length);
|
| 472 |
+
}
|
| 473 |
+
return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
|
| 474 |
+
},
|
| 475 |
+
// displays the character position where the lexing error occurred, i.e. for error messages
|
| 476 |
+
showPosition: function () {
|
| 477 |
+
var pre = this.pastInput();
|
| 478 |
+
var c = new Array(pre.length + 1).join("-");
|
| 479 |
+
return pre + this.upcomingInput() + "\n" + c + "^";
|
| 480 |
+
},
|
| 481 |
+
// test the lexed token: return FALSE when not a match, otherwise return token
|
| 482 |
+
test_match: function (match, indexed_rule) {
|
| 483 |
+
var token, lines, backup;
|
| 484 |
+
if (this.options.backtrack_lexer) {
|
| 485 |
+
// save context
|
| 486 |
+
backup = {
|
| 487 |
+
yylineno: this.yylineno,
|
| 488 |
+
yylloc: {
|
| 489 |
+
first_line: this.yylloc.first_line,
|
| 490 |
+
last_line: this.last_line,
|
| 491 |
+
first_column: this.yylloc.first_column,
|
| 492 |
+
last_column: this.yylloc.last_column
|
| 493 |
+
},
|
| 494 |
+
yytext: this.yytext,
|
| 495 |
+
match: this.match,
|
| 496 |
+
matches: this.matches,
|
| 497 |
+
matched: this.matched,
|
| 498 |
+
yyleng: this.yyleng,
|
| 499 |
+
offset: this.offset,
|
| 500 |
+
_more: this._more,
|
| 501 |
+
_input: this._input,
|
| 502 |
+
yy: this.yy,
|
| 503 |
+
conditionStack: this.conditionStack.slice(0),
|
| 504 |
+
done: this.done
|
| 505 |
+
};
|
| 506 |
+
if (this.options.ranges) {
|
| 507 |
+
backup.yylloc.range = this.yylloc.range.slice(0);
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
lines = match[0].match(/(?:\r\n?|\n).*/g);
|
| 511 |
+
if (lines) {
|
| 512 |
+
this.yylineno += lines.length;
|
| 513 |
+
}
|
| 514 |
+
this.yylloc = {
|
| 515 |
+
first_line: this.yylloc.last_line,
|
| 516 |
+
last_line: this.yylineno + 1,
|
| 517 |
+
first_column: this.yylloc.last_column,
|
| 518 |
+
last_column: lines ?
|
| 519 |
+
lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length :
|
| 520 |
+
this.yylloc.last_column + match[0].length
|
| 521 |
+
};
|
| 522 |
+
this.yytext += match[0];
|
| 523 |
+
this.match += match[0];
|
| 524 |
+
this.matches = match;
|
| 525 |
+
this.yyleng = this.yytext.length;
|
| 526 |
+
if (this.options.ranges) {
|
| 527 |
+
this.yylloc.range = [this.offset, this.offset += this.yyleng];
|
| 528 |
+
}
|
| 529 |
+
this._more = false;
|
| 530 |
+
this._backtrack = false;
|
| 531 |
+
this._input = this._input.slice(match[0].length);
|
| 532 |
+
this.matched += match[0];
|
| 533 |
+
token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
|
| 534 |
+
if (this.done && this._input) {
|
| 535 |
+
this.done = false;
|
| 536 |
+
}
|
| 537 |
+
if (token) {
|
| 538 |
+
return token;
|
| 539 |
+
}
|
| 540 |
+
else if (this._backtrack) {
|
| 541 |
+
// recover context
|
| 542 |
+
for (var k in backup) {
|
| 543 |
+
this[k] = backup[k];
|
| 544 |
+
}
|
| 545 |
+
return false; // rule action called reject() implying the next rule should be tested instead.
|
| 546 |
+
}
|
| 547 |
+
return false;
|
| 548 |
+
},
|
| 549 |
+
// return next match in input
|
| 550 |
+
next: function () {
|
| 551 |
+
if (this.done) {
|
| 552 |
+
return this.EOF;
|
| 553 |
+
}
|
| 554 |
+
if (!this._input) {
|
| 555 |
+
this.done = true;
|
| 556 |
+
}
|
| 557 |
+
var token, match, tempMatch, index;
|
| 558 |
+
if (!this._more) {
|
| 559 |
+
this.yytext = '';
|
| 560 |
+
this.match = '';
|
| 561 |
+
}
|
| 562 |
+
var rules = this._currentRules();
|
| 563 |
+
for (var i = 0; i < rules.length; i++) {
|
| 564 |
+
tempMatch = this._input.match(this.rules[rules[i]]);
|
| 565 |
+
if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
|
| 566 |
+
match = tempMatch;
|
| 567 |
+
index = i;
|
| 568 |
+
if (this.options.backtrack_lexer) {
|
| 569 |
+
token = this.test_match(tempMatch, rules[i]);
|
| 570 |
+
if (token !== false) {
|
| 571 |
+
return token;
|
| 572 |
+
}
|
| 573 |
+
else if (this._backtrack) {
|
| 574 |
+
match = false;
|
| 575 |
+
continue; // rule action called reject() implying a rule MISmatch.
|
| 576 |
+
}
|
| 577 |
+
else {
|
| 578 |
+
// else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
|
| 579 |
+
return false;
|
| 580 |
+
}
|
| 581 |
+
}
|
| 582 |
+
else if (!this.options.flex) {
|
| 583 |
+
break;
|
| 584 |
+
}
|
| 585 |
+
}
|
| 586 |
+
}
|
| 587 |
+
if (match) {
|
| 588 |
+
token = this.test_match(match, rules[index]);
|
| 589 |
+
if (token !== false) {
|
| 590 |
+
return token;
|
| 591 |
+
}
|
| 592 |
+
// else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
|
| 593 |
+
return false;
|
| 594 |
+
}
|
| 595 |
+
if (this._input === "") {
|
| 596 |
+
return this.EOF;
|
| 597 |
+
}
|
| 598 |
+
else {
|
| 599 |
+
return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
|
| 600 |
+
text: "",
|
| 601 |
+
token: null,
|
| 602 |
+
line: this.yylineno
|
| 603 |
+
});
|
| 604 |
+
}
|
| 605 |
+
},
|
| 606 |
+
// return next match that has a token
|
| 607 |
+
lex: function lex() {
|
| 608 |
+
var r = this.next();
|
| 609 |
+
if (r) {
|
| 610 |
+
return r;
|
| 611 |
+
}
|
| 612 |
+
else {
|
| 613 |
+
return this.lex();
|
| 614 |
+
}
|
| 615 |
+
},
|
| 616 |
+
// activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
|
| 617 |
+
begin: function begin(condition) {
|
| 618 |
+
this.conditionStack.push(condition);
|
| 619 |
+
},
|
| 620 |
+
// pop the previously active lexer condition state off the condition stack
|
| 621 |
+
popState: function popState() {
|
| 622 |
+
var n = this.conditionStack.length - 1;
|
| 623 |
+
if (n > 0) {
|
| 624 |
+
return this.conditionStack.pop();
|
| 625 |
+
}
|
| 626 |
+
else {
|
| 627 |
+
return this.conditionStack[0];
|
| 628 |
+
}
|
| 629 |
+
},
|
| 630 |
+
// produce the lexer rule set which is active for the currently active lexer condition state
|
| 631 |
+
_currentRules: function _currentRules() {
|
| 632 |
+
if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
|
| 633 |
+
return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
|
| 634 |
+
}
|
| 635 |
+
else {
|
| 636 |
+
return this.conditions["INITIAL"].rules;
|
| 637 |
+
}
|
| 638 |
+
},
|
| 639 |
+
// return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
|
| 640 |
+
topState: function topState(n) {
|
| 641 |
+
n = this.conditionStack.length - 1 - Math.abs(n || 0);
|
| 642 |
+
if (n >= 0) {
|
| 643 |
+
return this.conditionStack[n];
|
| 644 |
+
}
|
| 645 |
+
else {
|
| 646 |
+
return "INITIAL";
|
| 647 |
+
}
|
| 648 |
+
},
|
| 649 |
+
// alias for begin(condition)
|
| 650 |
+
pushState: function pushState(condition) {
|
| 651 |
+
this.begin(condition);
|
| 652 |
+
},
|
| 653 |
+
// return the number of states currently on the stack
|
| 654 |
+
stateStackSize: function stateStackSize() {
|
| 655 |
+
return this.conditionStack.length;
|
| 656 |
+
},
|
| 657 |
+
options: {},
|
| 658 |
+
performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
|
| 659 |
+
var YYSTATE = YY_START;
|
| 660 |
+
switch ($avoiding_name_collisions) {
|
| 661 |
+
case 0: /* skip whitespace */
|
| 662 |
+
break;
|
| 663 |
+
case 1: /* skip newlines */
|
| 664 |
+
break;
|
| 665 |
+
case 2: /* skip line comments */
|
| 666 |
+
break;
|
| 667 |
+
case 3: /* skip block comments */
|
| 668 |
+
break;
|
| 669 |
+
case 4:
|
| 670 |
+
return 8;
|
| 671 |
+
break;
|
| 672 |
+
case 5:
|
| 673 |
+
return 11;
|
| 674 |
+
break;
|
| 675 |
+
case 6:
|
| 676 |
+
return 10;
|
| 677 |
+
break;
|
| 678 |
+
case 7:
|
| 679 |
+
return 16;
|
| 680 |
+
break;
|
| 681 |
+
case 8:
|
| 682 |
+
return 17;
|
| 683 |
+
break;
|
| 684 |
+
case 9:
|
| 685 |
+
return 18;
|
| 686 |
+
break;
|
| 687 |
+
case 10:
|
| 688 |
+
return 19;
|
| 689 |
+
break;
|
| 690 |
+
case 11:
|
| 691 |
+
return 20;
|
| 692 |
+
break;
|
| 693 |
+
case 12:
|
| 694 |
+
return 21;
|
| 695 |
+
break;
|
| 696 |
+
case 13:
|
| 697 |
+
return 12;
|
| 698 |
+
break;
|
| 699 |
+
case 14:
|
| 700 |
+
return 14;
|
| 701 |
+
break;
|
| 702 |
+
case 15:
|
| 703 |
+
return 22;
|
| 704 |
+
break;
|
| 705 |
+
case 16:
|
| 706 |
+
return 23;
|
| 707 |
+
break;
|
| 708 |
+
case 17:
|
| 709 |
+
return 24;
|
| 710 |
+
break;
|
| 711 |
+
case 18:
|
| 712 |
+
return 25;
|
| 713 |
+
break;
|
| 714 |
+
case 19:
|
| 715 |
+
return 26;
|
| 716 |
+
break;
|
| 717 |
+
case 20:
|
| 718 |
+
return 43;
|
| 719 |
+
break;
|
| 720 |
+
case 21:
|
| 721 |
+
return 44;
|
| 722 |
+
break;
|
| 723 |
+
case 22:
|
| 724 |
+
return 41; /* draw */
|
| 725 |
+
break;
|
| 726 |
+
case 23:
|
| 727 |
+
return 42; /* unknown */
|
| 728 |
+
break;
|
| 729 |
+
case 24:
|
| 730 |
+
return 49;
|
| 731 |
+
break;
|
| 732 |
+
case 25:
|
| 733 |
+
return 34;
|
| 734 |
+
break;
|
| 735 |
+
case 26:
|
| 736 |
+
return 36;
|
| 737 |
+
break;
|
| 738 |
+
case 27:
|
| 739 |
+
return 37;
|
| 740 |
+
break;
|
| 741 |
+
case 28:
|
| 742 |
+
return 46;
|
| 743 |
+
break;
|
| 744 |
+
case 29:
|
| 745 |
+
return 47;
|
| 746 |
+
break;
|
| 747 |
+
case 30:
|
| 748 |
+
return 48;
|
| 749 |
+
break;
|
| 750 |
+
case 31:
|
| 751 |
+
return 38;
|
| 752 |
+
break;
|
| 753 |
+
case 32:
|
| 754 |
+
return 27;
|
| 755 |
+
break;
|
| 756 |
+
case 33:
|
| 757 |
+
return 6;
|
| 758 |
+
break;
|
| 759 |
+
case 34:
|
| 760 |
+
return 'INVALID';
|
| 761 |
+
break;
|
| 762 |
+
}
|
| 763 |
+
},
|
| 764 |
+
rules: [/^(?:\s+)/, /^(?:\n)/, /^(?:;[^\n]*)/, /^(?:\{[^}]*\})/, /^(?:\[)/, /^(?:\])/, /^(?:"([^\\\"]|\\.)*")/, /^(?:Event\b)/, /^(?:Site\b)/, /^(?:Date\b)/, /^(?:Round\b)/, /^(?:Black\b)/, /^(?:White\b)/, /^(?:Result\b)/, /^(?:Board\b)/, /^(?:Handicap\b)/, /^(?:Rules\b)/, /^(?:TimeControl\b)/, /^(?:Annotator\b)/, /^(?:Application\b)/, /^(?:B\+)/, /^(?:W\+)/, /^(?:=)/, /^(?:\*)/, /^(?:[1-9][0-9]*)/, /^(?:\.)/, /^(?:pass\b)/, /^(?:resign\b)/, /^(?:points\b)/, /^(?:stones\b)/, /^(?:[x](?=[1-9]))/, /^(?:[a-z0]+)/, /^(?:[A-Z][A-Za-z0-9_]*)/, /^(?:$)/, /^(?:.)/],
|
| 765 |
+
conditions: { "INITIAL": { "rules": [0, 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], "inclusive": true } }
|
| 766 |
+
});
|
| 767 |
+
return lexer;
|
| 768 |
+
})();
|
| 769 |
+
parser.lexer = lexer;
|
| 770 |
+
function Parser() {
|
| 771 |
+
this.yy = {};
|
| 772 |
+
}
|
| 773 |
+
Parser.prototype = parser;
|
| 774 |
+
parser.Parser = Parser;
|
| 775 |
+
return new Parser;
|
| 776 |
+
})();
|
| 777 |
+
if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
|
| 778 |
+
exports.parser = tgn;
|
| 779 |
+
exports.Parser = tgn.Parser;
|
| 780 |
+
exports.parse = function () { return tgn.parse.apply(tgn, arguments); };
|
| 781 |
+
exports.main = function commonjsMain(args) {
|
| 782 |
+
if (!args[1]) {
|
| 783 |
+
console.log('Usage: ' + args[0] + ' FILE');
|
| 784 |
+
process.exit(1);
|
| 785 |
+
}
|
| 786 |
+
var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
|
| 787 |
+
return exports.parser.parse(source);
|
| 788 |
+
};
|
| 789 |
+
if (typeof module !== 'undefined' && require.main === module) {
|
| 790 |
+
exports.main(process.argv.slice(1));
|
| 791 |
+
}
|
| 792 |
+
}
|
| 793 |
+
//# sourceMappingURL=tgn.jison.cjs.map
|
trigo-web/backend/dist/inc/tgn/tgn.jison.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"tgn.jison.cjs","sourceRoot":"","sources":["../../../../inc/tgn/tgn.jison.cjs"],"names":[],"mappings":";AAAA,sCAAsC;AACtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuEE;AACF,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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* TGN Parser TypeScript Wrapper
|
| 3 |
+
*
|
| 4 |
+
* Wraps the jison-generated parser with TypeScript types
|
| 5 |
+
*
|
| 6 |
+
* Based on lotus project architecture:
|
| 7 |
+
* - Use jison npm package for grammar compilation at build time
|
| 8 |
+
* - Generate parser to .js file in build phase
|
| 9 |
+
* - Use synchronous parsing (no async needed)
|
| 10 |
+
* - Works in both browser and Node.js environments
|
| 11 |
+
*/
|
| 12 |
+
/**
|
| 13 |
+
* Parsed move action - represents a single player's action in a round
|
| 14 |
+
*/
|
| 15 |
+
export interface ParsedMoveAction {
|
| 16 |
+
type: "move" | "pass" | "resign";
|
| 17 |
+
position?: string;
|
| 18 |
+
}
|
| 19 |
+
/**
|
| 20 |
+
* Parsed move round - contains both black and white moves
|
| 21 |
+
*/
|
| 22 |
+
export interface ParsedMoveRound {
|
| 23 |
+
round: number;
|
| 24 |
+
action_black: ParsedMoveAction;
|
| 25 |
+
action_white?: ParsedMoveAction;
|
| 26 |
+
}
|
| 27 |
+
/**
|
| 28 |
+
* Parsed game result
|
| 29 |
+
*/
|
| 30 |
+
export interface ParsedGameResult {
|
| 31 |
+
Result: string;
|
| 32 |
+
Conquer?: {
|
| 33 |
+
n: number;
|
| 34 |
+
unit: string;
|
| 35 |
+
};
|
| 36 |
+
}
|
| 37 |
+
/**
|
| 38 |
+
* Parsed TGN tags (metadata)
|
| 39 |
+
*/
|
| 40 |
+
export interface ParsedTags {
|
| 41 |
+
Event?: string;
|
| 42 |
+
Site?: string;
|
| 43 |
+
Date?: string;
|
| 44 |
+
Round?: string;
|
| 45 |
+
Black?: string;
|
| 46 |
+
White?: string;
|
| 47 |
+
Result?: string;
|
| 48 |
+
Board?: number[];
|
| 49 |
+
Handicap?: string;
|
| 50 |
+
Rules?: string;
|
| 51 |
+
TimeControl?: string;
|
| 52 |
+
Annotator?: string;
|
| 53 |
+
Application?: string;
|
| 54 |
+
[key: string]: string | number[] | ParsedGameResult | undefined;
|
| 55 |
+
}
|
| 56 |
+
/**
|
| 57 |
+
* Parser output structure
|
| 58 |
+
*/
|
| 59 |
+
export interface TGNParseResult {
|
| 60 |
+
tags: ParsedTags;
|
| 61 |
+
moves: ParsedMoveRound[] | null;
|
| 62 |
+
success: boolean;
|
| 63 |
+
}
|
| 64 |
+
/**
|
| 65 |
+
* Parser error with position information
|
| 66 |
+
*/
|
| 67 |
+
export declare class TGNParseError extends Error {
|
| 68 |
+
line?: number;
|
| 69 |
+
column?: number;
|
| 70 |
+
hash?: any;
|
| 71 |
+
constructor(message: string, line?: number, column?: number, hash?: any);
|
| 72 |
+
}
|
| 73 |
+
/**
|
| 74 |
+
* Set the parser module (called by initialization code)
|
| 75 |
+
* This allows the pre-built parser to be used
|
| 76 |
+
*/
|
| 77 |
+
export declare function setParserModule(module: any): void;
|
| 78 |
+
/**
|
| 79 |
+
* Parse TGN string and return structured data
|
| 80 |
+
* Synchronous parsing (no async needed)
|
| 81 |
+
*
|
| 82 |
+
* @param tgnString - TGN formatted game notation
|
| 83 |
+
* @returns Parsed game data with tags and moves
|
| 84 |
+
* @throws TGNParseError if parsing fails
|
| 85 |
+
*/
|
| 86 |
+
export declare function parseTGN(tgnString: string): TGNParseResult;
|
| 87 |
+
/**
|
| 88 |
+
* Validate TGN string without fully parsing
|
| 89 |
+
* Synchronous validation (no async needed)
|
| 90 |
+
*
|
| 91 |
+
* @param tgnString - TGN formatted game notation
|
| 92 |
+
* @returns Object with valid flag and error message if invalid
|
| 93 |
+
*/
|
| 94 |
+
export declare function validateTGN(tgnString: string): {
|
| 95 |
+
valid: boolean;
|
| 96 |
+
error?: string;
|
| 97 |
+
};
|
| 98 |
+
//# sourceMappingURL=tgnParser.d.ts.map
|
trigo-web/backend/dist/inc/tgn/tgnParser.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"tgnParser.d.ts","sourceRoot":"","sources":["../../../../inc/tgn/tgnParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,CAAC,EAAE,gBAAgB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE;QACT,CAAC,EAAE,MAAM,CAAC;QACV,IAAI,EAAE,MAAM,CAAC;KACb,CAAC;CACF;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,E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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
/**
|
| 3 |
+
* TGN Parser TypeScript Wrapper
|
| 4 |
+
*
|
| 5 |
+
* Wraps the jison-generated parser with TypeScript types
|
| 6 |
+
*
|
| 7 |
+
* Based on lotus project architecture:
|
| 8 |
+
* - Use jison npm package for grammar compilation at build time
|
| 9 |
+
* - Generate parser to .js file in build phase
|
| 10 |
+
* - Use synchronous parsing (no async needed)
|
| 11 |
+
* - Works in both browser and Node.js environments
|
| 12 |
+
*/
|
| 13 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 14 |
+
exports.TGNParseError = void 0;
|
| 15 |
+
exports.setParserModule = setParserModule;
|
| 16 |
+
exports.parseTGN = parseTGN;
|
| 17 |
+
exports.validateTGN = validateTGN;
|
| 18 |
+
/**
|
| 19 |
+
* Parser error with position information
|
| 20 |
+
*/
|
| 21 |
+
class TGNParseError extends Error {
|
| 22 |
+
constructor(message, line, column, hash) {
|
| 23 |
+
super(message);
|
| 24 |
+
this.line = line;
|
| 25 |
+
this.column = column;
|
| 26 |
+
this.hash = hash;
|
| 27 |
+
this.name = "TGNParseError";
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
exports.TGNParseError = TGNParseError;
|
| 31 |
+
// Will be set by initialization code or build process
|
| 32 |
+
let parserModule = null;
|
| 33 |
+
/**
|
| 34 |
+
* Set the parser module (called by initialization code)
|
| 35 |
+
* This allows the pre-built parser to be used
|
| 36 |
+
*/
|
| 37 |
+
function setParserModule(module) {
|
| 38 |
+
parserModule = module;
|
| 39 |
+
}
|
| 40 |
+
/**
|
| 41 |
+
* Get the parser module
|
| 42 |
+
* Throws error if parser not loaded
|
| 43 |
+
*/
|
| 44 |
+
function getParser() {
|
| 45 |
+
if (!parserModule) {
|
| 46 |
+
throw new Error("TGN parser not loaded. Please ensure the parser has been built.\n" +
|
| 47 |
+
"Run: npm run build:parsers");
|
| 48 |
+
}
|
| 49 |
+
return parserModule;
|
| 50 |
+
}
|
| 51 |
+
/**
|
| 52 |
+
* Parse TGN string and return structured data
|
| 53 |
+
* Synchronous parsing (no async needed)
|
| 54 |
+
*
|
| 55 |
+
* @param tgnString - TGN formatted game notation
|
| 56 |
+
* @returns Parsed game data with tags and moves
|
| 57 |
+
* @throws TGNParseError if parsing fails
|
| 58 |
+
*/
|
| 59 |
+
function parseTGN(tgnString) {
|
| 60 |
+
const parser = getParser();
|
| 61 |
+
if (!parser.parse) {
|
| 62 |
+
throw new Error("TGN parser parse method not available");
|
| 63 |
+
}
|
| 64 |
+
try {
|
| 65 |
+
const result = parser.parse(tgnString);
|
| 66 |
+
return result;
|
| 67 |
+
}
|
| 68 |
+
catch (error) {
|
| 69 |
+
// Wrap jison errors with our custom error type
|
| 70 |
+
throw new TGNParseError(error.message || "Unknown parse error", error.hash?.line, error.hash?.loc?.first_column, error.hash);
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
/**
|
| 74 |
+
* Validate TGN string without fully parsing
|
| 75 |
+
* Synchronous validation (no async needed)
|
| 76 |
+
*
|
| 77 |
+
* @param tgnString - TGN formatted game notation
|
| 78 |
+
* @returns Object with valid flag and error message if invalid
|
| 79 |
+
*/
|
| 80 |
+
function validateTGN(tgnString) {
|
| 81 |
+
try {
|
| 82 |
+
parseTGN(tgnString);
|
| 83 |
+
return { valid: true };
|
| 84 |
+
}
|
| 85 |
+
catch (error) {
|
| 86 |
+
return {
|
| 87 |
+
valid: false,
|
| 88 |
+
error: error.message || "Unknown validation error"
|
| 89 |
+
};
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
//# sourceMappingURL=tgnParser.js.map
|
trigo-web/backend/dist/inc/tgn/tgnParser.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"tgnParser.js","sourceRoot":"","sources":["../../../../inc/tgn/tgnParser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAiFH,0CAEC;AAwBD,4BAmBC;AASD,kCAUC;AAtFD;;GAEG;AACH,MAAa,aAAc,SAAQ,KAAK;IACvC,YACC,OAAe,EACR,IAAa,EACb,MAAe,EACf,IAAU;QAEjB,KAAK,CAAC,OAAO,CAAC,CAAC;QAJR,SAAI,GAAJ,IAAI,CAAS;QACb,WAAM,GAAN,MAAM,CAAS;QACf,SAAI,GAAJ,IAAI,CAAM;QAGjB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC7B,CAAC;CACD;AAVD,sCAUC;AAED,sDAAsD;AACtD,IAAI,YAAY,GAAQ,IAAI,CAAC;AAE7B;;;GAGG;AACH,SAAgB,eAAe,CAAC,MAAW;IAC1C,YAAY,GAAG,MAAM,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,SAAS,SAAS;IACjB,IAAI,CAAC,YAAY,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACd,mEAAmE;YAClE,4BAA4B,CAC7B,CAAC;IACH,CAAC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
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Encode a position to TGN coordinate string.
|
| 3 |
+
*
|
| 4 |
+
* Coordinate system:
|
| 5 |
+
* - '0' represents the center position on an axis
|
| 6 |
+
* - 'a', 'b', 'c', ... from one edge toward center
|
| 7 |
+
* - 'z', 'y', 'x', ... from opposite edge toward center
|
| 8 |
+
*
|
| 9 |
+
* @param pos - Position array [x, y, z, ...] with 0-based indices
|
| 10 |
+
* @param boardShape - Board dimensions [sizeX, sizeY, sizeZ, ...]
|
| 11 |
+
* @returns TGN coordinate string (e.g., "000", "aa0", "bzz", "aa", "0")
|
| 12 |
+
*
|
| 13 |
+
* @example
|
| 14 |
+
* encodeAb0yz([2, 2, 2], [5, 5, 5]) // "000" - center of 5x5x5 board
|
| 15 |
+
* encodeAb0yz([0, 0, 2], [5, 5, 5]) // "aa0" - corner
|
| 16 |
+
* encodeAb0yz([4, 2, 2], [5, 5, 5]) // "z00"
|
| 17 |
+
* encodeAb0yz([0, 0, 0], [19, 19, 1]) // "aa" - 2D board (trailing 1 ignored)
|
| 18 |
+
*/
|
| 19 |
+
declare const encodeAb0yz: (pos: number[], boardShape: number[]) => string;
|
| 20 |
+
/**
|
| 21 |
+
* Decode a TGN coordinate string to position array.
|
| 22 |
+
*
|
| 23 |
+
* @param code - TGN coordinate string (e.g., "000", "aa0", "bzz", "aa", "0")
|
| 24 |
+
* @param boardShape - Board dimensions [sizeX, sizeY, sizeZ, ...]
|
| 25 |
+
* @returns Position array [x, y, z, ...] with 0-based indices
|
| 26 |
+
*
|
| 27 |
+
* @example
|
| 28 |
+
* decodeAb0yz("000", [5, 5, 5]) // [2, 2, 2] - center
|
| 29 |
+
* decodeAb0yz("aa0", [5, 5, 5]) // [0, 0, 2]
|
| 30 |
+
* decodeAb0yz("z00", [5, 5, 5]) // [4, 2, 2]
|
| 31 |
+
* decodeAb0yz("aa", [19, 19, 1]) // [0, 0, 0] - 2D board
|
| 32 |
+
*/
|
| 33 |
+
declare const decodeAb0yz: (code: string, boardShape: number[]) => number[];
|
| 34 |
+
export { encodeAb0yz, decodeAb0yz };
|
| 35 |
+
//# sourceMappingURL=ab0yz.d.ts.map
|
trigo-web/backend/dist/inc/trigo/ab0yz.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"ab0yz.d.ts","sourceRoot":"","sources":["../../../../inc/trigo/ab0yz.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,EAAE,YAAY,MAAM,EAAE,KAAG,MAuB1D,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,YAAY,MAAM,EAAE,KAAG,MAAM,EA+D/D,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC"}
|
trigo-web/backend/dist/inc/trigo/ab0yz.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
exports.decodeAb0yz = exports.encodeAb0yz = void 0;
|
| 4 |
+
// remove ones at tail
|
| 5 |
+
const compactShape = (shape) => shape[shape.length - 1] === 1 ? compactShape(shape.slice(0, shape.length - 1)) : shape;
|
| 6 |
+
/**
|
| 7 |
+
* Encode a position to TGN coordinate string.
|
| 8 |
+
*
|
| 9 |
+
* Coordinate system:
|
| 10 |
+
* - '0' represents the center position on an axis
|
| 11 |
+
* - 'a', 'b', 'c', ... from one edge toward center
|
| 12 |
+
* - 'z', 'y', 'x', ... from opposite edge toward center
|
| 13 |
+
*
|
| 14 |
+
* @param pos - Position array [x, y, z, ...] with 0-based indices
|
| 15 |
+
* @param boardShape - Board dimensions [sizeX, sizeY, sizeZ, ...]
|
| 16 |
+
* @returns TGN coordinate string (e.g., "000", "aa0", "bzz", "aa", "0")
|
| 17 |
+
*
|
| 18 |
+
* @example
|
| 19 |
+
* encodeAb0yz([2, 2, 2], [5, 5, 5]) // "000" - center of 5x5x5 board
|
| 20 |
+
* encodeAb0yz([0, 0, 2], [5, 5, 5]) // "aa0" - corner
|
| 21 |
+
* encodeAb0yz([4, 2, 2], [5, 5, 5]) // "z00"
|
| 22 |
+
* encodeAb0yz([0, 0, 0], [19, 19, 1]) // "aa" - 2D board (trailing 1 ignored)
|
| 23 |
+
*/
|
| 24 |
+
const encodeAb0yz = (pos, boardShape) => {
|
| 25 |
+
const compactedShape = compactShape(boardShape);
|
| 26 |
+
const result = [];
|
| 27 |
+
for (let i = 0; i < compactedShape.length; i++) {
|
| 28 |
+
const size = compactedShape[i];
|
| 29 |
+
const center = (size - 1) / 2;
|
| 30 |
+
const index = pos[i];
|
| 31 |
+
if (index === center) {
|
| 32 |
+
// Center position
|
| 33 |
+
result.push("0");
|
| 34 |
+
}
|
| 35 |
+
else if (index < center) {
|
| 36 |
+
// Left side: a, b, c, ...
|
| 37 |
+
result.push(String.fromCharCode(97 + index)); // 'a' = 97
|
| 38 |
+
}
|
| 39 |
+
else {
|
| 40 |
+
// Right side: z, y, x, ...
|
| 41 |
+
const offset = size - 1 - index;
|
| 42 |
+
result.push(String.fromCharCode(122 - offset)); // 'z' = 122
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
return result.join("");
|
| 46 |
+
};
|
| 47 |
+
exports.encodeAb0yz = encodeAb0yz;
|
| 48 |
+
/**
|
| 49 |
+
* Decode a TGN coordinate string to position array.
|
| 50 |
+
*
|
| 51 |
+
* @param code - TGN coordinate string (e.g., "000", "aa0", "bzz", "aa", "0")
|
| 52 |
+
* @param boardShape - Board dimensions [sizeX, sizeY, sizeZ, ...]
|
| 53 |
+
* @returns Position array [x, y, z, ...] with 0-based indices
|
| 54 |
+
*
|
| 55 |
+
* @example
|
| 56 |
+
* decodeAb0yz("000", [5, 5, 5]) // [2, 2, 2] - center
|
| 57 |
+
* decodeAb0yz("aa0", [5, 5, 5]) // [0, 0, 2]
|
| 58 |
+
* decodeAb0yz("z00", [5, 5, 5]) // [4, 2, 2]
|
| 59 |
+
* decodeAb0yz("aa", [19, 19, 1]) // [0, 0, 0] - 2D board
|
| 60 |
+
*/
|
| 61 |
+
const decodeAb0yz = (code, boardShape) => {
|
| 62 |
+
const compactedShape = compactShape(boardShape);
|
| 63 |
+
if (code.length !== compactedShape.length) {
|
| 64 |
+
throw new Error(`Invalid TGN coordinate: "${code}" (must be ${compactedShape.length} characters for board shape ${boardShape.join("x")})`);
|
| 65 |
+
}
|
| 66 |
+
const result = [];
|
| 67 |
+
for (let i = 0; i < compactedShape.length; i++) {
|
| 68 |
+
const char = code[i];
|
| 69 |
+
const size = compactedShape[i];
|
| 70 |
+
const center = (size - 1) / 2;
|
| 71 |
+
if (char === "0") {
|
| 72 |
+
// Center position
|
| 73 |
+
console.assert(Number.isInteger(center));
|
| 74 |
+
result.push(center);
|
| 75 |
+
}
|
| 76 |
+
else {
|
| 77 |
+
const charCode = char.charCodeAt(0);
|
| 78 |
+
if (charCode >= 97 && charCode <= 122) {
|
| 79 |
+
// 'a' to 'z'
|
| 80 |
+
// Calculate distance from 'a' and 'z'
|
| 81 |
+
const distFromA = charCode - 97;
|
| 82 |
+
const distFromZ = 122 - charCode;
|
| 83 |
+
// Determine if it's left side (closer to 'a') or right side (closer to 'z')
|
| 84 |
+
if (distFromA < distFromZ) {
|
| 85 |
+
// Left side: a=0, b=1, c=2, ...
|
| 86 |
+
const index = distFromA;
|
| 87 |
+
if (index >= center) {
|
| 88 |
+
throw new Error(`Invalid TGN coordinate: "${code}" (position ${index} >= center ${center} on axis ${i})`);
|
| 89 |
+
}
|
| 90 |
+
result.push(index);
|
| 91 |
+
}
|
| 92 |
+
else {
|
| 93 |
+
// Right side: z=size-1, y=size-2, x=size-3, ...
|
| 94 |
+
const index = size - 1 - distFromZ;
|
| 95 |
+
if (index <= center) {
|
| 96 |
+
throw new Error(`Invalid TGN coordinate: "${code}" (position ${index} <= center ${center} on axis ${i})`);
|
| 97 |
+
}
|
| 98 |
+
result.push(index);
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
else {
|
| 102 |
+
throw new Error(`Invalid TGN coordinate: "${code}" (character '${char}' at position ${i} must be '0' or a-z)`);
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
// Fill remaining dimensions with 0 if boardShape has trailing 1s
|
| 107 |
+
while (result.length < boardShape.length) {
|
| 108 |
+
result.push(0);
|
| 109 |
+
}
|
| 110 |
+
return result;
|
| 111 |
+
};
|
| 112 |
+
exports.decodeAb0yz = decodeAb0yz;
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* TrigoGame Class - Main Game State Management
|
| 3 |
+
*
|
| 4 |
+
* Modern reimplementation of prototype's trigo.Game
|
| 5 |
+
* Integrates game state, move history, and game logic in a single class
|
| 6 |
+
*
|
| 7 |
+
* Equivalent to: third_party/klstrigo/Source/static/js/trigo.game.js:75-601
|
| 8 |
+
*/
|
| 9 |
+
import type { Position, Stone, BoardShape } from "./types";
|
| 10 |
+
import { type TerritoryResult } from "./gameUtils";
|
| 11 |
+
export { StoneType } from "./gameUtils";
|
| 12 |
+
/**
|
| 13 |
+
* Step Types - Different types of moves in the game
|
| 14 |
+
* Equivalent to trigo.Game.StepType in prototype
|
| 15 |
+
*/
|
| 16 |
+
export declare enum StepType {
|
| 17 |
+
DROP = 0,// Place a stone
|
| 18 |
+
PASS = 1,// Pass turn
|
| 19 |
+
SURRENDER = 2,// Resign/surrender
|
| 20 |
+
UNDO = 3
|
| 21 |
+
}
|
| 22 |
+
/**
|
| 23 |
+
* Game Status enumeration
|
| 24 |
+
*/
|
| 25 |
+
export type GameStatus = "idle" | "playing" | "paused" | "finished";
|
| 26 |
+
/**
|
| 27 |
+
* Game Result information
|
| 28 |
+
*/
|
| 29 |
+
export interface GameResult {
|
| 30 |
+
winner: "black" | "white" | "draw";
|
| 31 |
+
reason: "resignation" | "timeout" | "completion" | "double-pass";
|
| 32 |
+
score?: TerritoryResult;
|
| 33 |
+
}
|
| 34 |
+
/**
|
| 35 |
+
* Step - Represents a single move in the game
|
| 36 |
+
* Equivalent to step objects in prototype's StepHistory
|
| 37 |
+
*/
|
| 38 |
+
export interface Step {
|
| 39 |
+
type: StepType;
|
| 40 |
+
position?: Position;
|
| 41 |
+
player: Stone;
|
| 42 |
+
capturedPositions?: Position[];
|
| 43 |
+
timestamp: number;
|
| 44 |
+
}
|
| 45 |
+
/**
|
| 46 |
+
* Game Callbacks - Event handlers for game state changes
|
| 47 |
+
* Equivalent to Callbacks in prototype's trigo.Game constructor
|
| 48 |
+
*/
|
| 49 |
+
export interface GameCallbacks {
|
| 50 |
+
onStepAdvance?: (step: Step, history: Step[]) => void;
|
| 51 |
+
onStepBack?: (step: Step, history: Step[]) => void;
|
| 52 |
+
onCapture?: (capturedPositions: Position[]) => void;
|
| 53 |
+
onWin?: (winner: Stone) => void;
|
| 54 |
+
onTerritoryChange?: (territory: TerritoryResult) => void;
|
| 55 |
+
}
|
| 56 |
+
/**
|
| 57 |
+
* TrigoGame - Main game class managing state, history, and logic
|
| 58 |
+
*
|
| 59 |
+
* Equivalent to trigo.Game in prototype (lines 75-395)
|
| 60 |
+
*
|
| 61 |
+
* Key features:
|
| 62 |
+
* - Maintains game board state
|
| 63 |
+
* - Tracks complete move history
|
| 64 |
+
* - Implements Go rules (capture, Ko, suicide)
|
| 65 |
+
* - Supports undo/redo functionality
|
| 66 |
+
* - Territory calculation
|
| 67 |
+
*/
|
| 68 |
+
export declare class TrigoGame {
|
| 69 |
+
private shape;
|
| 70 |
+
private callbacks;
|
| 71 |
+
private board;
|
| 72 |
+
private currentPlayer;
|
| 73 |
+
private stepHistory;
|
| 74 |
+
private currentStepIndex;
|
| 75 |
+
private gameStatus;
|
| 76 |
+
private gameResult?;
|
| 77 |
+
private passCount;
|
| 78 |
+
private lastCapturedPositions;
|
| 79 |
+
private territoryDirty;
|
| 80 |
+
private cachedTerritory;
|
| 81 |
+
/**
|
| 82 |
+
* Constructor
|
| 83 |
+
* Equivalent to trigo.Game constructor (lines 75-85)
|
| 84 |
+
*/
|
| 85 |
+
constructor(shape?: BoardShape, callbacks?: GameCallbacks);
|
| 86 |
+
/**
|
| 87 |
+
* Create an empty board
|
| 88 |
+
*/
|
| 89 |
+
private createEmptyBoard;
|
| 90 |
+
/**
|
| 91 |
+
* Reset the game to initial state
|
| 92 |
+
* Equivalent to Game.reset() (lines 153-163)
|
| 93 |
+
*/
|
| 94 |
+
reset(): void;
|
| 95 |
+
/**
|
| 96 |
+
* Clone the game state (deep copy)
|
| 97 |
+
* Creates an independent copy with all state preserved
|
| 98 |
+
*/
|
| 99 |
+
clone(): TrigoGame;
|
| 100 |
+
/**
|
| 101 |
+
* Get current board state (read-only)
|
| 102 |
+
*/
|
| 103 |
+
getBoard(): Stone[][][];
|
| 104 |
+
/**
|
| 105 |
+
* Get stone at specific position
|
| 106 |
+
* Equivalent to Game.stone() (lines 95-97)
|
| 107 |
+
*/
|
| 108 |
+
getStone(pos: Position): Stone;
|
| 109 |
+
/**
|
| 110 |
+
* Get current player
|
| 111 |
+
*/
|
| 112 |
+
getCurrentPlayer(): Stone;
|
| 113 |
+
/**
|
| 114 |
+
* Get current step number
|
| 115 |
+
* Equivalent to Game.currentStep() (lines 99-101)
|
| 116 |
+
*/
|
| 117 |
+
getCurrentStep(): number;
|
| 118 |
+
/**
|
| 119 |
+
* Get move history
|
| 120 |
+
* Equivalent to Game.routine() (lines 103-105)
|
| 121 |
+
*/
|
| 122 |
+
getHistory(): Step[];
|
| 123 |
+
/**
|
| 124 |
+
* Get last move
|
| 125 |
+
* Equivalent to Game.lastStep() (lines 107-110)
|
| 126 |
+
*/
|
| 127 |
+
getLastStep(): Step | null;
|
| 128 |
+
/**
|
| 129 |
+
* Get board shape
|
| 130 |
+
* Equivalent to Game.shape() (lines 87-89)
|
| 131 |
+
*/
|
| 132 |
+
getShape(): BoardShape;
|
| 133 |
+
/**
|
| 134 |
+
* Get game status
|
| 135 |
+
*/
|
| 136 |
+
getGameStatus(): GameStatus;
|
| 137 |
+
/**
|
| 138 |
+
* Set game status
|
| 139 |
+
*/
|
| 140 |
+
setGameStatus(status: GameStatus): void;
|
| 141 |
+
/**
|
| 142 |
+
* Get game result
|
| 143 |
+
*/
|
| 144 |
+
getGameResult(): GameResult | undefined;
|
| 145 |
+
/**
|
| 146 |
+
* Get consecutive pass count
|
| 147 |
+
*/
|
| 148 |
+
getPassCount(): number;
|
| 149 |
+
/**
|
| 150 |
+
* Recalculate consecutive pass count based on current history
|
| 151 |
+
* Counts consecutive PASS steps from the end of current history
|
| 152 |
+
*/
|
| 153 |
+
private recalculatePassCount;
|
| 154 |
+
/**
|
| 155 |
+
* Start the game
|
| 156 |
+
*/
|
| 157 |
+
startGame(): void;
|
| 158 |
+
/**
|
| 159 |
+
* Check if game is active
|
| 160 |
+
*/
|
| 161 |
+
isGameActive(): boolean;
|
| 162 |
+
/**
|
| 163 |
+
* Check if a move is valid
|
| 164 |
+
* Equivalent to Game.isDropable() and Game.isValidStep() (lines 112-151)
|
| 165 |
+
*/
|
| 166 |
+
isValidMove(pos: Position, player?: Stone): {
|
| 167 |
+
valid: boolean;
|
| 168 |
+
reason?: string;
|
| 169 |
+
};
|
| 170 |
+
/**
|
| 171 |
+
* Get all valid move positions for current player (efficient batch query)
|
| 172 |
+
*
|
| 173 |
+
* This method is optimized to avoid repeated validation checks by:
|
| 174 |
+
* 1. Only checking empty positions
|
| 175 |
+
* 2. Skipping bounds checking (iterator is already within bounds)
|
| 176 |
+
* 3. Using low-level validation functions directly
|
| 177 |
+
* 4. Batching board state access
|
| 178 |
+
*
|
| 179 |
+
* @param player - Optional player color (defaults to current player)
|
| 180 |
+
* @returns Array of all valid move positions
|
| 181 |
+
*/
|
| 182 |
+
validMovePositions(player?: Stone): Position[];
|
| 183 |
+
/**
|
| 184 |
+
* Reset pass count (called when a stone is placed)
|
| 185 |
+
*/
|
| 186 |
+
private resetPassCount;
|
| 187 |
+
/**
|
| 188 |
+
* Place a stone (drop move)
|
| 189 |
+
* Equivalent to Game.drop() and Game.appendStone() (lines 181-273)
|
| 190 |
+
*
|
| 191 |
+
* @returns true if move was successful, false otherwise
|
| 192 |
+
*/
|
| 193 |
+
drop(pos: Position): boolean;
|
| 194 |
+
/**
|
| 195 |
+
* Pass turn
|
| 196 |
+
* Equivalent to PASS step type in prototype
|
| 197 |
+
*/
|
| 198 |
+
pass(): boolean;
|
| 199 |
+
/**
|
| 200 |
+
* Surrender/resign
|
| 201 |
+
* Equivalent to Game.step() with SURRENDER type (lines 176-178)
|
| 202 |
+
*/
|
| 203 |
+
surrender(): boolean;
|
| 204 |
+
/**
|
| 205 |
+
* Undo last move
|
| 206 |
+
* Equivalent to Game.repent() (lines 197-230)
|
| 207 |
+
*
|
| 208 |
+
* @returns true if undo was successful, false if no moves to undo
|
| 209 |
+
*/
|
| 210 |
+
undo(): boolean;
|
| 211 |
+
/**
|
| 212 |
+
* Redo next move (after undo)
|
| 213 |
+
*
|
| 214 |
+
* @returns true if redo was successful, false if no moves to redo
|
| 215 |
+
*/
|
| 216 |
+
redo(): boolean;
|
| 217 |
+
/**
|
| 218 |
+
* Check if redo is available
|
| 219 |
+
*/
|
| 220 |
+
canRedo(): boolean;
|
| 221 |
+
/**
|
| 222 |
+
* Jump to specific step in history
|
| 223 |
+
* Rebuilds board state after applying the first 'index' moves
|
| 224 |
+
*
|
| 225 |
+
* @param index Number of moves to apply from history (0 for initial state, 1 for after first move, etc.)
|
| 226 |
+
* @returns true if jump was successful
|
| 227 |
+
*/
|
| 228 |
+
jumpToStep(index: number): boolean;
|
| 229 |
+
/**
|
| 230 |
+
* Advance to next step
|
| 231 |
+
* Equivalent to Game.stepAdvance() (lines 279-287)
|
| 232 |
+
*/
|
| 233 |
+
private advanceStep;
|
| 234 |
+
/**
|
| 235 |
+
* Get territory calculation
|
| 236 |
+
* Equivalent to Game.blackDomain() and Game.whiteDomain() (lines 232-244)
|
| 237 |
+
*
|
| 238 |
+
* Returns cached result if territory hasn't changed
|
| 239 |
+
*/
|
| 240 |
+
getTerritory(): TerritoryResult;
|
| 241 |
+
/**
|
| 242 |
+
* Get captured stone counts up to current position in history
|
| 243 |
+
* Only counts captures that have been played (up to currentStepIndex)
|
| 244 |
+
*/
|
| 245 |
+
getCapturedCounts(): {
|
| 246 |
+
black: number;
|
| 247 |
+
white: number;
|
| 248 |
+
};
|
| 249 |
+
/**
|
| 250 |
+
* Serialize game state to JSON
|
| 251 |
+
* Equivalent to Game.serialize() (lines 250-252)
|
| 252 |
+
*/
|
| 253 |
+
toJSON(): object;
|
| 254 |
+
/**
|
| 255 |
+
* Load game state from JSON
|
| 256 |
+
*/
|
| 257 |
+
fromJSON(data: any): boolean;
|
| 258 |
+
/**
|
| 259 |
+
* Get game statistics
|
| 260 |
+
*/
|
| 261 |
+
getStats(): {
|
| 262 |
+
totalMoves: number;
|
| 263 |
+
blackMoves: number;
|
| 264 |
+
whiteMoves: number;
|
| 265 |
+
capturedByBlack: number;
|
| 266 |
+
capturedByWhite: number;
|
| 267 |
+
territory: TerritoryResult;
|
| 268 |
+
};
|
| 269 |
+
/**
|
| 270 |
+
* Save game state to sessionStorage
|
| 271 |
+
*
|
| 272 |
+
* @param key Storage key (default: "trigoGameState")
|
| 273 |
+
* @returns true if save was successful
|
| 274 |
+
*/
|
| 275 |
+
saveToSessionStorage(key?: string): boolean;
|
| 276 |
+
/**
|
| 277 |
+
* Load game state from sessionStorage
|
| 278 |
+
*
|
| 279 |
+
* @param key Storage key (default: "trigoGameState")
|
| 280 |
+
* @returns true if load was successful
|
| 281 |
+
*/
|
| 282 |
+
loadFromSessionStorage(key?: string): boolean;
|
| 283 |
+
/**
|
| 284 |
+
* Clear saved game state from sessionStorage
|
| 285 |
+
*
|
| 286 |
+
* @param key Storage key (default: "trigoGameState")
|
| 287 |
+
*/
|
| 288 |
+
clearSessionStorage(key?: string): void;
|
| 289 |
+
/**
|
| 290 |
+
* Export game to TGN (Trigo Game Notation) format
|
| 291 |
+
*
|
| 292 |
+
* TGN format is similar to PGN (Portable Game Notation) for chess.
|
| 293 |
+
* It includes metadata tags and move sequence using ab0yz coordinate notation.
|
| 294 |
+
*
|
| 295 |
+
* @param metadata Optional metadata for the game (Event, Site, Date, Players, etc.)
|
| 296 |
+
* @returns TGN-formatted string
|
| 297 |
+
*
|
| 298 |
+
* @example
|
| 299 |
+
* const tgn = game.toTGN({
|
| 300 |
+
* event: "World Championship",
|
| 301 |
+
* site: "Tokyo",
|
| 302 |
+
* date: "2025.10.31",
|
| 303 |
+
* black: "Alice",
|
| 304 |
+
* white: "Bob"
|
| 305 |
+
* });
|
| 306 |
+
*/
|
| 307 |
+
toTGN(metadata?: {
|
| 308 |
+
event?: string;
|
| 309 |
+
site?: string;
|
| 310 |
+
date?: string;
|
| 311 |
+
round?: string;
|
| 312 |
+
black?: string;
|
| 313 |
+
white?: string;
|
| 314 |
+
rules?: string;
|
| 315 |
+
timeControl?: string;
|
| 316 |
+
application?: string;
|
| 317 |
+
[key: string]: string | undefined;
|
| 318 |
+
}, { markResult }?: {
|
| 319 |
+
markResult?: boolean;
|
| 320 |
+
}): string;
|
| 321 |
+
/**
|
| 322 |
+
* Import game from TGN (Trigo Game Notation) format
|
| 323 |
+
*
|
| 324 |
+
* Static factory method that parses a TGN string and creates a new TrigoGame instance
|
| 325 |
+
* with the board configuration and moves from the TGN file.
|
| 326 |
+
*
|
| 327 |
+
* Synchronous operation - requires parser to be loaded via setParserModule()
|
| 328 |
+
*
|
| 329 |
+
* @param tgnString TGN-formatted game notation string
|
| 330 |
+
* @param callbacks Optional game callbacks
|
| 331 |
+
* @returns New TrigoGame instance with the imported game state
|
| 332 |
+
* @throws TGNParseError if the TGN string is invalid
|
| 333 |
+
*
|
| 334 |
+
* @example
|
| 335 |
+
* const tgnString = `
|
| 336 |
+
* [Event "World Championship"]
|
| 337 |
+
* [Board "5x5x5"]
|
| 338 |
+
* [Black "Alice"]
|
| 339 |
+
* [White "Bob"]
|
| 340 |
+
*
|
| 341 |
+
* 1. 000 y00
|
| 342 |
+
* 2. 0y0 pass
|
| 343 |
+
* `;
|
| 344 |
+
* const game = TrigoGame.fromTGN(tgnString);
|
| 345 |
+
*/
|
| 346 |
+
static fromTGN(tgnString: string, callbacks?: GameCallbacks): TrigoGame;
|
| 347 |
+
/**
|
| 348 |
+
* Apply a parsed move action to the game
|
| 349 |
+
* Private helper method for fromTGN
|
| 350 |
+
*
|
| 351 |
+
* @param action Parsed move action from TGN parser
|
| 352 |
+
* @param boardShape Board dimensions for coordinate decoding
|
| 353 |
+
*/
|
| 354 |
+
private _applyParsedMove;
|
| 355 |
+
}
|
| 356 |
+
export { validateTGN, TGNParseError } from "../tgn/tgnParser";
|
| 357 |
+
//# sourceMappingURL=game.d.ts.map
|
trigo-web/backend/dist/inc/trigo/game.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"game.d.ts","sourceRoot":"","sources":["../../../../inc/trigo/game.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EASN,KAAK,eAAe,EACpB,MAAM,aAAa,CAAC;AAKrB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,oBAAY,QAAQ;IACnB,IAAI,IAAI,CAAE,gBAAgB;IAC1B,IAAI,IAAI,CAAE,YAAY;IACtB,SAAS,IAAI,CAAE,mBAAmB;IAClC,IAAI,IAAI;CACR;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;IACnC,MAAM,EAAE,aAAa,GAAG,SAAS,GAAG,YAAY,GAAG,aAAa,CAAC;IACjE,KAAK,CAAC,EAAE,eAAe,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,IAAI;IACpB,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,KAAK,CAAC;IACd,iBAAiB,CAAC,EAAE,QAAQ,EAAE,CAAC;IAC/B,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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
/**
|
| 3 |
+
* TrigoGame Class - Main Game State Management
|
| 4 |
+
*
|
| 5 |
+
* Modern reimplementation of prototype's trigo.Game
|
| 6 |
+
* Integrates game state, move history, and game logic in a single class
|
| 7 |
+
*
|
| 8 |
+
* Equivalent to: third_party/klstrigo/Source/static/js/trigo.game.js:75-601
|
| 9 |
+
*/
|
| 10 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 11 |
+
exports.TGNParseError = exports.validateTGN = exports.TrigoGame = exports.StepType = exports.StoneType = void 0;
|
| 12 |
+
const gameUtils_1 = require("./gameUtils");
|
| 13 |
+
const ab0yz_1 = require("./ab0yz");
|
| 14 |
+
const tgnParser_1 = require("../tgn/tgnParser");
|
| 15 |
+
// Re-export StoneType for convenient access with TrigoGame
|
| 16 |
+
var gameUtils_2 = require("./gameUtils");
|
| 17 |
+
Object.defineProperty(exports, "StoneType", { enumerable: true, get: function () { return gameUtils_2.StoneType; } });
|
| 18 |
+
/**
|
| 19 |
+
* Step Types - Different types of moves in the game
|
| 20 |
+
* Equivalent to trigo.Game.StepType in prototype
|
| 21 |
+
*/
|
| 22 |
+
var StepType;
|
| 23 |
+
(function (StepType) {
|
| 24 |
+
StepType[StepType["DROP"] = 0] = "DROP";
|
| 25 |
+
StepType[StepType["PASS"] = 1] = "PASS";
|
| 26 |
+
StepType[StepType["SURRENDER"] = 2] = "SURRENDER";
|
| 27 |
+
StepType[StepType["UNDO"] = 3] = "UNDO"; // Undo last move (called "REPENT" in prototype)
|
| 28 |
+
})(StepType || (exports.StepType = StepType = {}));
|
| 29 |
+
/**
|
| 30 |
+
* TrigoGame - Main game class managing state, history, and logic
|
| 31 |
+
*
|
| 32 |
+
* Equivalent to trigo.Game in prototype (lines 75-395)
|
| 33 |
+
*
|
| 34 |
+
* Key features:
|
| 35 |
+
* - Maintains game board state
|
| 36 |
+
* - Tracks complete move history
|
| 37 |
+
* - Implements Go rules (capture, Ko, suicide)
|
| 38 |
+
* - Supports undo/redo functionality
|
| 39 |
+
* - Territory calculation
|
| 40 |
+
*/
|
| 41 |
+
class TrigoGame {
|
| 42 |
+
/**
|
| 43 |
+
* Constructor
|
| 44 |
+
* Equivalent to trigo.Game constructor (lines 75-85)
|
| 45 |
+
*/
|
| 46 |
+
constructor(shape = { x: 5, y: 5, z: 5 }, callbacks = {}) {
|
| 47 |
+
// Last captured stones for Ko rule detection
|
| 48 |
+
this.lastCapturedPositions = null;
|
| 49 |
+
// Territory cache
|
| 50 |
+
this.territoryDirty = true;
|
| 51 |
+
this.cachedTerritory = null;
|
| 52 |
+
this.shape = shape;
|
| 53 |
+
this.callbacks = callbacks;
|
| 54 |
+
this.board = this.createEmptyBoard();
|
| 55 |
+
this.currentPlayer = gameUtils_1.StoneType.BLACK;
|
| 56 |
+
this.stepHistory = [];
|
| 57 |
+
this.currentStepIndex = 0;
|
| 58 |
+
this.gameStatus = "idle";
|
| 59 |
+
this.gameResult = undefined;
|
| 60 |
+
this.passCount = 0;
|
| 61 |
+
}
|
| 62 |
+
/**
|
| 63 |
+
* Create an empty board
|
| 64 |
+
*/
|
| 65 |
+
createEmptyBoard() {
|
| 66 |
+
const board = [];
|
| 67 |
+
for (let x = 0; x < this.shape.x; x++) {
|
| 68 |
+
board[x] = [];
|
| 69 |
+
for (let y = 0; y < this.shape.y; y++) {
|
| 70 |
+
board[x][y] = [];
|
| 71 |
+
for (let z = 0; z < this.shape.z; z++) {
|
| 72 |
+
board[x][y][z] = gameUtils_1.StoneType.EMPTY;
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
return board;
|
| 77 |
+
}
|
| 78 |
+
/**
|
| 79 |
+
* Reset the game to initial state
|
| 80 |
+
* Equivalent to Game.reset() (lines 153-163)
|
| 81 |
+
*/
|
| 82 |
+
reset() {
|
| 83 |
+
this.board = this.createEmptyBoard();
|
| 84 |
+
this.currentPlayer = gameUtils_1.StoneType.BLACK;
|
| 85 |
+
this.stepHistory = [];
|
| 86 |
+
this.currentStepIndex = 0;
|
| 87 |
+
this.lastCapturedPositions = null;
|
| 88 |
+
this.territoryDirty = true;
|
| 89 |
+
this.cachedTerritory = null;
|
| 90 |
+
this.gameStatus = "idle";
|
| 91 |
+
this.gameResult = undefined;
|
| 92 |
+
this.passCount = 0;
|
| 93 |
+
}
|
| 94 |
+
/**
|
| 95 |
+
* Clone the game state (deep copy)
|
| 96 |
+
* Creates an independent copy with all state preserved
|
| 97 |
+
*/
|
| 98 |
+
clone() {
|
| 99 |
+
const cloned = new TrigoGame(this.shape, {});
|
| 100 |
+
// Deep copy board
|
| 101 |
+
cloned.board = this.board.map((plane) => plane.map((row) => [...row]));
|
| 102 |
+
// Copy game state
|
| 103 |
+
cloned.currentPlayer = this.currentPlayer;
|
| 104 |
+
cloned.currentStepIndex = this.currentStepIndex;
|
| 105 |
+
cloned.gameStatus = this.gameStatus;
|
| 106 |
+
cloned.passCount = this.passCount;
|
| 107 |
+
// Deep copy step history
|
| 108 |
+
cloned.stepHistory = this.stepHistory.map((step) => ({
|
| 109 |
+
...step,
|
| 110 |
+
position: step.position ? { ...step.position } : undefined,
|
| 111 |
+
capturedPositions: step.capturedPositions
|
| 112 |
+
? step.capturedPositions.map((pos) => ({ ...pos }))
|
| 113 |
+
: []
|
| 114 |
+
}));
|
| 115 |
+
// Deep copy last captured positions
|
| 116 |
+
cloned.lastCapturedPositions = this.lastCapturedPositions
|
| 117 |
+
? this.lastCapturedPositions.map((pos) => ({ ...pos }))
|
| 118 |
+
: null;
|
| 119 |
+
// Copy game result
|
| 120 |
+
if (this.gameResult) {
|
| 121 |
+
cloned.gameResult = {
|
| 122 |
+
...this.gameResult,
|
| 123 |
+
score: this.gameResult.score ? { ...this.gameResult.score } : undefined
|
| 124 |
+
};
|
| 125 |
+
}
|
| 126 |
+
// Territory cache will be recalculated on demand
|
| 127 |
+
cloned.territoryDirty = true;
|
| 128 |
+
cloned.cachedTerritory = null;
|
| 129 |
+
return cloned;
|
| 130 |
+
}
|
| 131 |
+
/**
|
| 132 |
+
* Get current board state (read-only)
|
| 133 |
+
*/
|
| 134 |
+
getBoard() {
|
| 135 |
+
// Return a deep copy to prevent external modification
|
| 136 |
+
return this.board.map((plane) => plane.map((row) => [...row]));
|
| 137 |
+
}
|
| 138 |
+
/**
|
| 139 |
+
* Get stone at specific position
|
| 140 |
+
* Equivalent to Game.stone() (lines 95-97)
|
| 141 |
+
*/
|
| 142 |
+
getStone(pos) {
|
| 143 |
+
return this.board[pos.x][pos.y][pos.z];
|
| 144 |
+
}
|
| 145 |
+
/**
|
| 146 |
+
* Get current player
|
| 147 |
+
*/
|
| 148 |
+
getCurrentPlayer() {
|
| 149 |
+
return this.currentPlayer;
|
| 150 |
+
}
|
| 151 |
+
/**
|
| 152 |
+
* Get current step number
|
| 153 |
+
* Equivalent to Game.currentStep() (lines 99-101)
|
| 154 |
+
*/
|
| 155 |
+
getCurrentStep() {
|
| 156 |
+
return this.currentStepIndex;
|
| 157 |
+
}
|
| 158 |
+
/**
|
| 159 |
+
* Get move history
|
| 160 |
+
* Equivalent to Game.routine() (lines 103-105)
|
| 161 |
+
*/
|
| 162 |
+
getHistory() {
|
| 163 |
+
return [...this.stepHistory];
|
| 164 |
+
}
|
| 165 |
+
/**
|
| 166 |
+
* Get last move
|
| 167 |
+
* Equivalent to Game.lastStep() (lines 107-110)
|
| 168 |
+
*/
|
| 169 |
+
getLastStep() {
|
| 170 |
+
if (this.currentStepIndex > 0) {
|
| 171 |
+
return this.stepHistory[this.currentStepIndex - 1];
|
| 172 |
+
}
|
| 173 |
+
return null;
|
| 174 |
+
}
|
| 175 |
+
/**
|
| 176 |
+
* Get board shape
|
| 177 |
+
* Equivalent to Game.shape() (lines 87-89)
|
| 178 |
+
*/
|
| 179 |
+
getShape() {
|
| 180 |
+
return { ...this.shape };
|
| 181 |
+
}
|
| 182 |
+
/**
|
| 183 |
+
* Get game status
|
| 184 |
+
*/
|
| 185 |
+
getGameStatus() {
|
| 186 |
+
return this.gameStatus;
|
| 187 |
+
}
|
| 188 |
+
/**
|
| 189 |
+
* Set game status
|
| 190 |
+
*/
|
| 191 |
+
setGameStatus(status) {
|
| 192 |
+
this.gameStatus = status;
|
| 193 |
+
}
|
| 194 |
+
/**
|
| 195 |
+
* Get game result
|
| 196 |
+
*/
|
| 197 |
+
getGameResult() {
|
| 198 |
+
return this.gameResult;
|
| 199 |
+
}
|
| 200 |
+
/**
|
| 201 |
+
* Get consecutive pass count
|
| 202 |
+
*/
|
| 203 |
+
getPassCount() {
|
| 204 |
+
return this.passCount;
|
| 205 |
+
}
|
| 206 |
+
/**
|
| 207 |
+
* Recalculate consecutive pass count based on current history
|
| 208 |
+
* Counts consecutive PASS steps from the end of current history
|
| 209 |
+
*/
|
| 210 |
+
recalculatePassCount() {
|
| 211 |
+
this.passCount = 0;
|
| 212 |
+
// Count backwards from current position to find consecutive passes
|
| 213 |
+
for (let i = this.currentStepIndex - 1; i >= 0; i--) {
|
| 214 |
+
if (this.stepHistory[i].type === StepType.PASS) {
|
| 215 |
+
this.passCount++;
|
| 216 |
+
}
|
| 217 |
+
else {
|
| 218 |
+
break; // Stop at first non-pass move
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
/**
|
| 223 |
+
* Start the game
|
| 224 |
+
*/
|
| 225 |
+
startGame() {
|
| 226 |
+
if (this.gameStatus === "idle") {
|
| 227 |
+
this.gameStatus = "playing";
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
/**
|
| 231 |
+
* Check if game is active
|
| 232 |
+
*/
|
| 233 |
+
isGameActive() {
|
| 234 |
+
return this.gameStatus === "playing";
|
| 235 |
+
}
|
| 236 |
+
/**
|
| 237 |
+
* Check if a move is valid
|
| 238 |
+
* Equivalent to Game.isDropable() and Game.isValidStep() (lines 112-151)
|
| 239 |
+
*/
|
| 240 |
+
isValidMove(pos, player) {
|
| 241 |
+
const playerColor = player || this.currentPlayer;
|
| 242 |
+
return (0, gameUtils_1.validateMove)(pos, playerColor, this.board, this.shape, this.lastCapturedPositions);
|
| 243 |
+
}
|
| 244 |
+
/**
|
| 245 |
+
* Get all valid move positions for current player (efficient batch query)
|
| 246 |
+
*
|
| 247 |
+
* This method is optimized to avoid repeated validation checks by:
|
| 248 |
+
* 1. Only checking empty positions
|
| 249 |
+
* 2. Skipping bounds checking (iterator is already within bounds)
|
| 250 |
+
* 3. Using low-level validation functions directly
|
| 251 |
+
* 4. Batching board state access
|
| 252 |
+
*
|
| 253 |
+
* @param player - Optional player color (defaults to current player)
|
| 254 |
+
* @returns Array of all valid move positions
|
| 255 |
+
*/
|
| 256 |
+
validMovePositions(player) {
|
| 257 |
+
const playerColor = player || this.currentPlayer;
|
| 258 |
+
const validPositions = [];
|
| 259 |
+
// Iterate through all board positions (bounds are guaranteed)
|
| 260 |
+
for (let x = 0; x < this.shape.x; x++) {
|
| 261 |
+
for (let y = 0; y < this.shape.y; y++) {
|
| 262 |
+
for (let z = 0; z < this.shape.z; z++) {
|
| 263 |
+
// Skip occupied positions (quick filter)
|
| 264 |
+
if (this.board[x][y][z] !== gameUtils_1.StoneType.EMPTY) {
|
| 265 |
+
continue;
|
| 266 |
+
}
|
| 267 |
+
const pos = { x, y, z };
|
| 268 |
+
// Check Ko violation (using low-level function)
|
| 269 |
+
if ((0, gameUtils_1.isKoViolation)(pos, playerColor, this.board, this.shape, this.lastCapturedPositions)) {
|
| 270 |
+
continue;
|
| 271 |
+
}
|
| 272 |
+
// Check suicide rule (using low-level function)
|
| 273 |
+
if ((0, gameUtils_1.isSuicideMove)(pos, playerColor, this.board, this.shape)) {
|
| 274 |
+
continue;
|
| 275 |
+
}
|
| 276 |
+
// Position is valid
|
| 277 |
+
validPositions.push(pos);
|
| 278 |
+
}
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
+
return validPositions;
|
| 282 |
+
}
|
| 283 |
+
/**
|
| 284 |
+
* Reset pass count (called when a stone is placed)
|
| 285 |
+
*/
|
| 286 |
+
resetPassCount() {
|
| 287 |
+
this.passCount = 0;
|
| 288 |
+
}
|
| 289 |
+
/**
|
| 290 |
+
* Place a stone (drop move)
|
| 291 |
+
* Equivalent to Game.drop() and Game.appendStone() (lines 181-273)
|
| 292 |
+
*
|
| 293 |
+
* @returns true if move was successful, false otherwise
|
| 294 |
+
*/
|
| 295 |
+
drop(pos) {
|
| 296 |
+
// Validate the move
|
| 297 |
+
const validation = this.isValidMove(pos);
|
| 298 |
+
if (!validation.valid) {
|
| 299 |
+
console.warn(`Invalid move at (${pos.x}, ${pos.y}, ${pos.z}): ${validation.reason}`);
|
| 300 |
+
return false;
|
| 301 |
+
}
|
| 302 |
+
// Find captured groups BEFORE placing the stone
|
| 303 |
+
const capturedGroups = (0, gameUtils_1.findCapturedGroups)(pos, this.currentPlayer, this.board, this.shape);
|
| 304 |
+
// Place the stone on the board
|
| 305 |
+
this.board[pos.x][pos.y][pos.z] = this.currentPlayer;
|
| 306 |
+
// Execute captures
|
| 307 |
+
const capturedPositions = (0, gameUtils_1.executeCaptures)(capturedGroups, this.board);
|
| 308 |
+
// Store captured positions for Ko rule
|
| 309 |
+
this.lastCapturedPositions = capturedPositions.length > 0 ? capturedPositions : null;
|
| 310 |
+
// Mark territory as dirty
|
| 311 |
+
this.territoryDirty = true;
|
| 312 |
+
// Reset pass count when a stone is placed
|
| 313 |
+
this.resetPassCount();
|
| 314 |
+
// Create step record
|
| 315 |
+
const step = {
|
| 316 |
+
type: StepType.DROP,
|
| 317 |
+
position: pos,
|
| 318 |
+
player: this.currentPlayer,
|
| 319 |
+
capturedPositions: capturedPositions.length > 0 ? capturedPositions : undefined,
|
| 320 |
+
timestamp: Date.now()
|
| 321 |
+
};
|
| 322 |
+
// Advance to next step
|
| 323 |
+
this.advanceStep(step);
|
| 324 |
+
// Trigger callbacks
|
| 325 |
+
if (capturedPositions.length > 0 && this.callbacks.onCapture) {
|
| 326 |
+
this.callbacks.onCapture(capturedPositions);
|
| 327 |
+
}
|
| 328 |
+
if (this.territoryDirty && this.callbacks.onTerritoryChange) {
|
| 329 |
+
this.callbacks.onTerritoryChange(this.getTerritory());
|
| 330 |
+
}
|
| 331 |
+
return true;
|
| 332 |
+
}
|
| 333 |
+
/**
|
| 334 |
+
* Pass turn
|
| 335 |
+
* Equivalent to PASS step type in prototype
|
| 336 |
+
*/
|
| 337 |
+
pass() {
|
| 338 |
+
const step = {
|
| 339 |
+
type: StepType.PASS,
|
| 340 |
+
player: this.currentPlayer,
|
| 341 |
+
timestamp: Date.now()
|
| 342 |
+
};
|
| 343 |
+
this.lastCapturedPositions = null;
|
| 344 |
+
// Increment pass count
|
| 345 |
+
this.passCount++;
|
| 346 |
+
// Advance step
|
| 347 |
+
this.advanceStep(step);
|
| 348 |
+
// Check for double pass (game end condition)
|
| 349 |
+
if (this.passCount >= 2) {
|
| 350 |
+
// Calculate territory to determine winner
|
| 351 |
+
const territory = this.getTerritory();
|
| 352 |
+
const capturedCounts = this.getCapturedCounts();
|
| 353 |
+
const blackTotal = territory.black + capturedCounts.white; // black's territory + white stones captured
|
| 354 |
+
const whiteTotal = territory.white + capturedCounts.black; // white's territory + black stones captured
|
| 355 |
+
let winner;
|
| 356 |
+
if (blackTotal > whiteTotal) {
|
| 357 |
+
winner = "black";
|
| 358 |
+
}
|
| 359 |
+
else if (whiteTotal > blackTotal) {
|
| 360 |
+
winner = "white";
|
| 361 |
+
}
|
| 362 |
+
else {
|
| 363 |
+
winner = "draw";
|
| 364 |
+
}
|
| 365 |
+
this.gameResult = {
|
| 366 |
+
winner,
|
| 367 |
+
reason: "double-pass",
|
| 368 |
+
score: territory
|
| 369 |
+
};
|
| 370 |
+
this.gameStatus = "finished";
|
| 371 |
+
// Trigger win callback
|
| 372 |
+
if (this.callbacks.onWin) {
|
| 373 |
+
const winnerStone = winner === "black"
|
| 374 |
+
? gameUtils_1.StoneType.BLACK
|
| 375 |
+
: winner === "white"
|
| 376 |
+
? gameUtils_1.StoneType.WHITE
|
| 377 |
+
: gameUtils_1.StoneType.EMPTY;
|
| 378 |
+
this.callbacks.onWin(winnerStone);
|
| 379 |
+
}
|
| 380 |
+
}
|
| 381 |
+
return true;
|
| 382 |
+
}
|
| 383 |
+
/**
|
| 384 |
+
* Surrender/resign
|
| 385 |
+
* Equivalent to Game.step() with SURRENDER type (lines 176-178)
|
| 386 |
+
*/
|
| 387 |
+
surrender() {
|
| 388 |
+
const surrenderingPlayer = this.currentPlayer; // Remember who surrendered
|
| 389 |
+
const step = {
|
| 390 |
+
type: StepType.SURRENDER,
|
| 391 |
+
player: this.currentPlayer,
|
| 392 |
+
timestamp: Date.now()
|
| 393 |
+
};
|
| 394 |
+
this.advanceStep(step);
|
| 395 |
+
// Set game result - opponent of surrendering player wins
|
| 396 |
+
const winner = surrenderingPlayer === gameUtils_1.StoneType.BLACK ? "white" : "black";
|
| 397 |
+
this.gameResult = {
|
| 398 |
+
winner,
|
| 399 |
+
reason: "resignation"
|
| 400 |
+
};
|
| 401 |
+
this.gameStatus = "finished";
|
| 402 |
+
// Trigger win callback for the opponent
|
| 403 |
+
const winnerStone = (0, gameUtils_1.getEnemyColor)(surrenderingPlayer);
|
| 404 |
+
if (this.callbacks.onWin) {
|
| 405 |
+
this.callbacks.onWin(winnerStone);
|
| 406 |
+
}
|
| 407 |
+
return true;
|
| 408 |
+
}
|
| 409 |
+
/**
|
| 410 |
+
* Undo last move
|
| 411 |
+
* Equivalent to Game.repent() (lines 197-230)
|
| 412 |
+
*
|
| 413 |
+
* @returns true if undo was successful, false if no moves to undo
|
| 414 |
+
*/
|
| 415 |
+
undo() {
|
| 416 |
+
if (this.currentStepIndex === 0 || this.stepHistory.length === 0) {
|
| 417 |
+
return false;
|
| 418 |
+
}
|
| 419 |
+
const lastStep = this.stepHistory[this.currentStepIndex - 1];
|
| 420 |
+
// Revert the move
|
| 421 |
+
if (lastStep.type === StepType.DROP && lastStep.position) {
|
| 422 |
+
// Remove the placed stone
|
| 423 |
+
this.board[lastStep.position.x][lastStep.position.y][lastStep.position.z] =
|
| 424 |
+
gameUtils_1.StoneType.EMPTY;
|
| 425 |
+
// Restore captured stones
|
| 426 |
+
if (lastStep.capturedPositions) {
|
| 427 |
+
const enemyColor = (0, gameUtils_1.getEnemyColor)(lastStep.player);
|
| 428 |
+
for (const pos of lastStep.capturedPositions) {
|
| 429 |
+
this.board[pos.x][pos.y][pos.z] = enemyColor;
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
}
|
| 433 |
+
// Move back in history
|
| 434 |
+
this.currentStepIndex--;
|
| 435 |
+
this.currentPlayer = lastStep.player; // Restore player who made that move
|
| 436 |
+
// Recalculate pass count based on new history position
|
| 437 |
+
this.recalculatePassCount();
|
| 438 |
+
// Update last captured positions for Ko rule
|
| 439 |
+
// Need to check the step before this one
|
| 440 |
+
if (this.currentStepIndex > 0) {
|
| 441 |
+
const previousStep = this.stepHistory[this.currentStepIndex - 1];
|
| 442 |
+
this.lastCapturedPositions = previousStep.capturedPositions || null;
|
| 443 |
+
}
|
| 444 |
+
else {
|
| 445 |
+
this.lastCapturedPositions = null;
|
| 446 |
+
}
|
| 447 |
+
// Mark territory as dirty
|
| 448 |
+
this.territoryDirty = true;
|
| 449 |
+
// Trigger callback
|
| 450 |
+
if (this.callbacks.onStepBack) {
|
| 451 |
+
this.callbacks.onStepBack(lastStep, this.stepHistory.slice(0, this.currentStepIndex));
|
| 452 |
+
}
|
| 453 |
+
return true;
|
| 454 |
+
}
|
| 455 |
+
/**
|
| 456 |
+
* Redo next move (after undo)
|
| 457 |
+
*
|
| 458 |
+
* @returns true if redo was successful, false if no moves to redo
|
| 459 |
+
*/
|
| 460 |
+
redo() {
|
| 461 |
+
// Check if we can redo (not at the end of history)
|
| 462 |
+
if (this.currentStepIndex >= this.stepHistory.length) {
|
| 463 |
+
return false;
|
| 464 |
+
}
|
| 465 |
+
const nextStep = this.stepHistory[this.currentStepIndex];
|
| 466 |
+
// Re-apply the move
|
| 467 |
+
if (nextStep.type === StepType.DROP && nextStep.position) {
|
| 468 |
+
// Place the stone
|
| 469 |
+
this.board[nextStep.position.x][nextStep.position.y][nextStep.position.z] =
|
| 470 |
+
nextStep.player;
|
| 471 |
+
// Re-execute captures if there were any
|
| 472 |
+
if (nextStep.capturedPositions) {
|
| 473 |
+
for (const pos of nextStep.capturedPositions) {
|
| 474 |
+
this.board[pos.x][pos.y][pos.z] = gameUtils_1.StoneType.EMPTY;
|
| 475 |
+
}
|
| 476 |
+
}
|
| 477 |
+
// Update last captured positions
|
| 478 |
+
this.lastCapturedPositions = nextStep.capturedPositions || null;
|
| 479 |
+
}
|
| 480 |
+
else if (nextStep.type === StepType.PASS) {
|
| 481 |
+
this.lastCapturedPositions = null;
|
| 482 |
+
}
|
| 483 |
+
// Move forward in history
|
| 484 |
+
this.currentStepIndex++;
|
| 485 |
+
this.currentPlayer = (0, gameUtils_1.getEnemyColor)(nextStep.player); // Switch to next player
|
| 486 |
+
// Mark territory as dirty
|
| 487 |
+
this.territoryDirty = true;
|
| 488 |
+
// Trigger callback
|
| 489 |
+
if (this.callbacks.onStepAdvance) {
|
| 490 |
+
this.callbacks.onStepAdvance(nextStep, this.stepHistory.slice(0, this.currentStepIndex));
|
| 491 |
+
}
|
| 492 |
+
return true;
|
| 493 |
+
}
|
| 494 |
+
/**
|
| 495 |
+
* Check if redo is available
|
| 496 |
+
*/
|
| 497 |
+
canRedo() {
|
| 498 |
+
return this.currentStepIndex < this.stepHistory.length;
|
| 499 |
+
}
|
| 500 |
+
/**
|
| 501 |
+
* Jump to specific step in history
|
| 502 |
+
* Rebuilds board state after applying the first 'index' moves
|
| 503 |
+
*
|
| 504 |
+
* @param index Number of moves to apply from history (0 for initial state, 1 for after first move, etc.)
|
| 505 |
+
* @returns true if jump was successful
|
| 506 |
+
*/
|
| 507 |
+
jumpToStep(index) {
|
| 508 |
+
// Validate index: allow 0 (initial state) up to stepHistory.length (all moves applied)
|
| 509 |
+
if (index < 0 || index > this.stepHistory.length) {
|
| 510 |
+
return false;
|
| 511 |
+
}
|
| 512 |
+
// If already at target index, return false (no change made)
|
| 513 |
+
if (index === this.currentStepIndex) {
|
| 514 |
+
return false;
|
| 515 |
+
}
|
| 516 |
+
// Rebuild board from scratch
|
| 517 |
+
this.board = this.createEmptyBoard();
|
| 518 |
+
this.lastCapturedPositions = null;
|
| 519 |
+
// Replay all moves up to (but not including) target index
|
| 520 |
+
// After this loop, we'll have applied 'index' number of moves
|
| 521 |
+
for (let i = 0; i < index; i++) {
|
| 522 |
+
const step = this.stepHistory[i];
|
| 523 |
+
if (step.type === StepType.DROP && step.position) {
|
| 524 |
+
const pos = step.position;
|
| 525 |
+
// Place the stone
|
| 526 |
+
this.board[pos.x][pos.y][pos.z] = step.player;
|
| 527 |
+
// Re-execute captures
|
| 528 |
+
if (step.capturedPositions) {
|
| 529 |
+
for (const capturedPos of step.capturedPositions) {
|
| 530 |
+
this.board[capturedPos.x][capturedPos.y][capturedPos.z] = gameUtils_1.StoneType.EMPTY;
|
| 531 |
+
}
|
| 532 |
+
}
|
| 533 |
+
}
|
| 534 |
+
}
|
| 535 |
+
// Set last captured positions from the last applied move (if any)
|
| 536 |
+
if (index > 0) {
|
| 537 |
+
const lastAppliedStep = this.stepHistory[index - 1];
|
| 538 |
+
if (lastAppliedStep.type === StepType.DROP) {
|
| 539 |
+
this.lastCapturedPositions = lastAppliedStep.capturedPositions || null;
|
| 540 |
+
}
|
| 541 |
+
else if (lastAppliedStep.type === StepType.PASS) {
|
| 542 |
+
this.lastCapturedPositions = null;
|
| 543 |
+
}
|
| 544 |
+
}
|
| 545 |
+
else {
|
| 546 |
+
this.lastCapturedPositions = null;
|
| 547 |
+
}
|
| 548 |
+
// Update current index
|
| 549 |
+
const oldStepIndex = this.currentStepIndex;
|
| 550 |
+
this.currentStepIndex = index;
|
| 551 |
+
// Set current player based on number of moves played
|
| 552 |
+
// currentStepIndex represents the number of moves applied
|
| 553 |
+
const movesPlayed = index;
|
| 554 |
+
this.currentPlayer = movesPlayed % 2 === 0 ? gameUtils_1.StoneType.BLACK : gameUtils_1.StoneType.WHITE;
|
| 555 |
+
// Recalculate pass count based on new history position
|
| 556 |
+
this.recalculatePassCount();
|
| 557 |
+
// Mark territory as dirty
|
| 558 |
+
this.territoryDirty = true;
|
| 559 |
+
// Trigger callback based on direction
|
| 560 |
+
if (index < oldStepIndex && this.callbacks.onStepBack) {
|
| 561 |
+
const currentStep = this.stepHistory[index];
|
| 562 |
+
this.callbacks.onStepBack(currentStep, this.stepHistory.slice(0, index + 1));
|
| 563 |
+
}
|
| 564 |
+
else if (index > oldStepIndex && this.callbacks.onStepAdvance) {
|
| 565 |
+
const currentStep = this.stepHistory[index];
|
| 566 |
+
this.callbacks.onStepAdvance(currentStep, this.stepHistory.slice(0, index + 1));
|
| 567 |
+
}
|
| 568 |
+
return true;
|
| 569 |
+
}
|
| 570 |
+
/**
|
| 571 |
+
* Advance to next step
|
| 572 |
+
* Equivalent to Game.stepAdvance() (lines 279-287)
|
| 573 |
+
*/
|
| 574 |
+
advanceStep(step) {
|
| 575 |
+
// If we're not at the end of history, truncate future steps
|
| 576 |
+
if (this.currentStepIndex < this.stepHistory.length) {
|
| 577 |
+
this.stepHistory = this.stepHistory.slice(0, this.currentStepIndex);
|
| 578 |
+
}
|
| 579 |
+
// Add the new step
|
| 580 |
+
this.stepHistory.push(step);
|
| 581 |
+
this.currentStepIndex++;
|
| 582 |
+
// Switch player
|
| 583 |
+
this.currentPlayer = (0, gameUtils_1.getEnemyColor)(this.currentPlayer);
|
| 584 |
+
// Trigger callback
|
| 585 |
+
if (this.callbacks.onStepAdvance) {
|
| 586 |
+
this.callbacks.onStepAdvance(step, this.stepHistory);
|
| 587 |
+
}
|
| 588 |
+
}
|
| 589 |
+
/**
|
| 590 |
+
* Get territory calculation
|
| 591 |
+
* Equivalent to Game.blackDomain() and Game.whiteDomain() (lines 232-244)
|
| 592 |
+
*
|
| 593 |
+
* Returns cached result if territory hasn't changed
|
| 594 |
+
*/
|
| 595 |
+
getTerritory() {
|
| 596 |
+
if (this.territoryDirty || !this.cachedTerritory) {
|
| 597 |
+
this.cachedTerritory = (0, gameUtils_1.calculateTerritory)(this.board, this.shape);
|
| 598 |
+
this.territoryDirty = false;
|
| 599 |
+
}
|
| 600 |
+
return this.cachedTerritory;
|
| 601 |
+
}
|
| 602 |
+
/**
|
| 603 |
+
* Get captured stone counts up to current position in history
|
| 604 |
+
* Only counts captures that have been played (up to currentStepIndex)
|
| 605 |
+
*/
|
| 606 |
+
getCapturedCounts() {
|
| 607 |
+
const counts = { black: 0, white: 0 };
|
| 608 |
+
// Only count captures up to current step index
|
| 609 |
+
for (let i = 0; i < this.currentStepIndex; i++) {
|
| 610 |
+
const step = this.stepHistory[i];
|
| 611 |
+
if (step.capturedPositions && step.capturedPositions.length > 0) {
|
| 612 |
+
// Captured stones belong to the enemy of the player who made the move
|
| 613 |
+
const enemyColor = (0, gameUtils_1.getEnemyColor)(step.player);
|
| 614 |
+
if (enemyColor === gameUtils_1.StoneType.BLACK) {
|
| 615 |
+
counts.black += step.capturedPositions.length;
|
| 616 |
+
}
|
| 617 |
+
else if (enemyColor === gameUtils_1.StoneType.WHITE) {
|
| 618 |
+
counts.white += step.capturedPositions.length;
|
| 619 |
+
}
|
| 620 |
+
}
|
| 621 |
+
}
|
| 622 |
+
return counts;
|
| 623 |
+
}
|
| 624 |
+
/**
|
| 625 |
+
* Serialize game state to JSON
|
| 626 |
+
* Equivalent to Game.serialize() (lines 250-252)
|
| 627 |
+
*/
|
| 628 |
+
toJSON() {
|
| 629 |
+
return {
|
| 630 |
+
shape: this.shape,
|
| 631 |
+
currentPlayer: this.currentPlayer,
|
| 632 |
+
currentStepIndex: this.currentStepIndex,
|
| 633 |
+
history: this.stepHistory,
|
| 634 |
+
board: this.board,
|
| 635 |
+
gameStatus: this.gameStatus,
|
| 636 |
+
gameResult: this.gameResult,
|
| 637 |
+
passCount: this.passCount
|
| 638 |
+
};
|
| 639 |
+
}
|
| 640 |
+
/**
|
| 641 |
+
* Load game state from JSON
|
| 642 |
+
*/
|
| 643 |
+
fromJSON(data) {
|
| 644 |
+
try {
|
| 645 |
+
// Validate required fields
|
| 646 |
+
if (!data || typeof data !== "object") {
|
| 647 |
+
return false;
|
| 648 |
+
}
|
| 649 |
+
if (!data.shape || !data.board || !Array.isArray(data.history)) {
|
| 650 |
+
return false;
|
| 651 |
+
}
|
| 652 |
+
this.shape = data.shape;
|
| 653 |
+
this.currentPlayer = data.currentPlayer;
|
| 654 |
+
this.currentStepIndex = data.currentStepIndex;
|
| 655 |
+
this.stepHistory = data.history || [];
|
| 656 |
+
this.board = data.board;
|
| 657 |
+
this.gameStatus = data.gameStatus || "idle";
|
| 658 |
+
this.gameResult = data.gameResult;
|
| 659 |
+
this.passCount = data.passCount || 0;
|
| 660 |
+
// Recalculate last captured positions
|
| 661 |
+
if (this.currentStepIndex > 0) {
|
| 662 |
+
const lastStep = this.stepHistory[this.currentStepIndex - 1];
|
| 663 |
+
this.lastCapturedPositions = lastStep.capturedPositions || null;
|
| 664 |
+
}
|
| 665 |
+
else {
|
| 666 |
+
this.lastCapturedPositions = null;
|
| 667 |
+
}
|
| 668 |
+
this.territoryDirty = true;
|
| 669 |
+
this.cachedTerritory = null;
|
| 670 |
+
return true;
|
| 671 |
+
}
|
| 672 |
+
catch (error) {
|
| 673 |
+
console.error("Failed to load game state:", error);
|
| 674 |
+
return false;
|
| 675 |
+
}
|
| 676 |
+
}
|
| 677 |
+
/**
|
| 678 |
+
* Get game statistics
|
| 679 |
+
*/
|
| 680 |
+
getStats() {
|
| 681 |
+
const captured = this.getCapturedCounts();
|
| 682 |
+
const territory = this.getTerritory();
|
| 683 |
+
let blackMoves = 0;
|
| 684 |
+
let whiteMoves = 0;
|
| 685 |
+
for (const step of this.stepHistory.slice(0, this.currentStepIndex)) {
|
| 686 |
+
if (step.type === StepType.DROP) {
|
| 687 |
+
if (step.player === gameUtils_1.StoneType.BLACK) {
|
| 688 |
+
blackMoves++;
|
| 689 |
+
}
|
| 690 |
+
else if (step.player === gameUtils_1.StoneType.WHITE) {
|
| 691 |
+
whiteMoves++;
|
| 692 |
+
}
|
| 693 |
+
}
|
| 694 |
+
}
|
| 695 |
+
return {
|
| 696 |
+
totalMoves: this.currentStepIndex,
|
| 697 |
+
blackMoves,
|
| 698 |
+
whiteMoves,
|
| 699 |
+
capturedByBlack: captured.white, // Black captures white stones
|
| 700 |
+
capturedByWhite: captured.black, // White captures black stones
|
| 701 |
+
territory
|
| 702 |
+
};
|
| 703 |
+
}
|
| 704 |
+
/**
|
| 705 |
+
* Save game state to sessionStorage
|
| 706 |
+
*
|
| 707 |
+
* @param key Storage key (default: "trigoGameState")
|
| 708 |
+
* @returns true if save was successful
|
| 709 |
+
*/
|
| 710 |
+
saveToSessionStorage(key = "trigoGameState") {
|
| 711 |
+
// Check if sessionStorage is available (browser environment)
|
| 712 |
+
if (typeof globalThis !== "undefined" && globalThis.sessionStorage) {
|
| 713 |
+
try {
|
| 714 |
+
const gameState = this.toJSON();
|
| 715 |
+
globalThis.sessionStorage.setItem(key, JSON.stringify(gameState));
|
| 716 |
+
return true;
|
| 717 |
+
}
|
| 718 |
+
catch (error) {
|
| 719 |
+
console.error("Failed to save game state to sessionStorage:", error);
|
| 720 |
+
return false;
|
| 721 |
+
}
|
| 722 |
+
}
|
| 723 |
+
console.warn("sessionStorage is not available");
|
| 724 |
+
return false;
|
| 725 |
+
}
|
| 726 |
+
/**
|
| 727 |
+
* Load game state from sessionStorage
|
| 728 |
+
*
|
| 729 |
+
* @param key Storage key (default: "trigoGameState")
|
| 730 |
+
* @returns true if load was successful
|
| 731 |
+
*/
|
| 732 |
+
loadFromSessionStorage(key = "trigoGameState") {
|
| 733 |
+
// Check if sessionStorage is available (browser environment)
|
| 734 |
+
if (typeof globalThis !== "undefined" && globalThis.sessionStorage) {
|
| 735 |
+
try {
|
| 736 |
+
const savedState = globalThis.sessionStorage.getItem(key);
|
| 737 |
+
if (!savedState) {
|
| 738 |
+
console.log("No saved game state found");
|
| 739 |
+
return false;
|
| 740 |
+
}
|
| 741 |
+
const data = JSON.parse(savedState);
|
| 742 |
+
return this.fromJSON(data);
|
| 743 |
+
}
|
| 744 |
+
catch (error) {
|
| 745 |
+
console.error("Failed to load game state from sessionStorage:", error);
|
| 746 |
+
return false;
|
| 747 |
+
}
|
| 748 |
+
}
|
| 749 |
+
console.warn("sessionStorage is not available");
|
| 750 |
+
return false;
|
| 751 |
+
}
|
| 752 |
+
/**
|
| 753 |
+
* Clear saved game state from sessionStorage
|
| 754 |
+
*
|
| 755 |
+
* @param key Storage key (default: "trigoGameState")
|
| 756 |
+
*/
|
| 757 |
+
clearSessionStorage(key = "trigoGameState") {
|
| 758 |
+
// Check if sessionStorage is available (browser environment)
|
| 759 |
+
if (typeof globalThis !== "undefined" && globalThis.sessionStorage) {
|
| 760 |
+
try {
|
| 761 |
+
globalThis.sessionStorage.removeItem(key);
|
| 762 |
+
}
|
| 763 |
+
catch (error) {
|
| 764 |
+
console.error("Failed to clear sessionStorage:", error);
|
| 765 |
+
}
|
| 766 |
+
}
|
| 767 |
+
else {
|
| 768 |
+
console.warn("sessionStorage is not available");
|
| 769 |
+
}
|
| 770 |
+
}
|
| 771 |
+
/**
|
| 772 |
+
* Export game to TGN (Trigo Game Notation) format
|
| 773 |
+
*
|
| 774 |
+
* TGN format is similar to PGN (Portable Game Notation) for chess.
|
| 775 |
+
* It includes metadata tags and move sequence using ab0yz coordinate notation.
|
| 776 |
+
*
|
| 777 |
+
* @param metadata Optional metadata for the game (Event, Site, Date, Players, etc.)
|
| 778 |
+
* @returns TGN-formatted string
|
| 779 |
+
*
|
| 780 |
+
* @example
|
| 781 |
+
* const tgn = game.toTGN({
|
| 782 |
+
* event: "World Championship",
|
| 783 |
+
* site: "Tokyo",
|
| 784 |
+
* date: "2025.10.31",
|
| 785 |
+
* black: "Alice",
|
| 786 |
+
* white: "Bob"
|
| 787 |
+
* });
|
| 788 |
+
*/
|
| 789 |
+
toTGN(metadata, { markResult } = {}) {
|
| 790 |
+
const lines = [];
|
| 791 |
+
// Add metadata tags
|
| 792 |
+
if (metadata) {
|
| 793 |
+
if (metadata.event)
|
| 794 |
+
lines.push(`[Event "${metadata.event}"]`);
|
| 795 |
+
if (metadata.site)
|
| 796 |
+
lines.push(`[Site "${metadata.site}"]`);
|
| 797 |
+
if (metadata.date)
|
| 798 |
+
lines.push(`[Date "${metadata.date}"]`);
|
| 799 |
+
if (metadata.round)
|
| 800 |
+
lines.push(`[Round "${metadata.round}"]`);
|
| 801 |
+
if (metadata.black)
|
| 802 |
+
lines.push(`[Black "${metadata.black}"]`);
|
| 803 |
+
if (metadata.white)
|
| 804 |
+
lines.push(`[White "${metadata.white}"]`);
|
| 805 |
+
}
|
| 806 |
+
// Add result if game is finished
|
| 807 |
+
if (this.gameStatus === "finished" && this.gameResult) {
|
| 808 |
+
let resultStr = "";
|
| 809 |
+
if (this.gameResult.winner === "black") {
|
| 810 |
+
resultStr = "B+";
|
| 811 |
+
}
|
| 812 |
+
else if (this.gameResult.winner === "white") {
|
| 813 |
+
resultStr = "W+";
|
| 814 |
+
}
|
| 815 |
+
else {
|
| 816 |
+
resultStr = "=";
|
| 817 |
+
}
|
| 818 |
+
// Add score information if available
|
| 819 |
+
if (this.gameResult.score) {
|
| 820 |
+
const { black, white } = this.gameResult.score;
|
| 821 |
+
const diff = Math.abs(black - white);
|
| 822 |
+
resultStr += `${diff}points`;
|
| 823 |
+
}
|
| 824 |
+
else if (this.gameResult.reason === "resignation") {
|
| 825 |
+
resultStr += "Resign";
|
| 826 |
+
}
|
| 827 |
+
//lines.push(`[Result "${resultStr}"]`);
|
| 828 |
+
}
|
| 829 |
+
// Add board size (without quotes - parser expects unquoted board shape)
|
| 830 |
+
const boardStr = this.shape.z === 1
|
| 831 |
+
? `${this.shape.x}x${this.shape.y}` // 2D board
|
| 832 |
+
: `${this.shape.x}x${this.shape.y}x${this.shape.z}`; // 3D board
|
| 833 |
+
lines.push(`[Board ${boardStr}]`);
|
| 834 |
+
// Add optional metadata
|
| 835 |
+
if (metadata) {
|
| 836 |
+
if (metadata.rules)
|
| 837 |
+
lines.push(`[Rules "${metadata.rules}"]`);
|
| 838 |
+
if (metadata.timeControl)
|
| 839 |
+
lines.push(`[TimeControl "${metadata.timeControl}"]`);
|
| 840 |
+
if (metadata.application)
|
| 841 |
+
lines.push(`[Application "${metadata.application}"]`);
|
| 842 |
+
}
|
| 843 |
+
// Add empty line after metadata
|
| 844 |
+
lines.push("");
|
| 845 |
+
// Generate move sequence
|
| 846 |
+
const moves = [];
|
| 847 |
+
let moveNumber = 1;
|
| 848 |
+
for (let i = 0; i < this.stepHistory.length; i++) {
|
| 849 |
+
const step = this.stepHistory[i];
|
| 850 |
+
let moveStr = "";
|
| 851 |
+
// Add move number at the start of each round (black's move)
|
| 852 |
+
if (step.player === gameUtils_1.StoneType.BLACK) {
|
| 853 |
+
moveStr = `${moveNumber}. `;
|
| 854 |
+
}
|
| 855 |
+
// Format the move
|
| 856 |
+
if (step.type === StepType.DROP && step.position) {
|
| 857 |
+
// Convert position to TGN coordinate
|
| 858 |
+
const pos = [step.position.x, step.position.y, step.position.z];
|
| 859 |
+
const boardShape = [this.shape.x, this.shape.y, this.shape.z];
|
| 860 |
+
const coord = (0, ab0yz_1.encodeAb0yz)(pos, boardShape);
|
| 861 |
+
moveStr += coord;
|
| 862 |
+
}
|
| 863 |
+
else if (step.type === StepType.PASS) {
|
| 864 |
+
moveStr += "Pass";
|
| 865 |
+
}
|
| 866 |
+
else if (step.type === StepType.SURRENDER) {
|
| 867 |
+
moveStr += "Resign";
|
| 868 |
+
}
|
| 869 |
+
moves.push(moveStr);
|
| 870 |
+
// Increment move number after white's move
|
| 871 |
+
if (step.player === gameUtils_1.StoneType.WHITE) {
|
| 872 |
+
moveNumber++;
|
| 873 |
+
}
|
| 874 |
+
}
|
| 875 |
+
// Format moves with proper line breaks
|
| 876 |
+
// Group moves in pairs (black, white) on the same line
|
| 877 |
+
let currentLine = "";
|
| 878 |
+
for (let i = 0; i < moves.length; i++) {
|
| 879 |
+
const move = moves[i];
|
| 880 |
+
if (move.match(/^\d+\./)) {
|
| 881 |
+
// Start of a new round (black's move)
|
| 882 |
+
if (currentLine) {
|
| 883 |
+
lines.push(currentLine);
|
| 884 |
+
}
|
| 885 |
+
currentLine = move;
|
| 886 |
+
}
|
| 887 |
+
else {
|
| 888 |
+
// White's move - add to current line
|
| 889 |
+
currentLine += " " + move;
|
| 890 |
+
}
|
| 891 |
+
}
|
| 892 |
+
// Add the last line if it exists
|
| 893 |
+
if (currentLine) {
|
| 894 |
+
lines.push(currentLine);
|
| 895 |
+
}
|
| 896 |
+
// Add score result if game has finished
|
| 897 |
+
if (markResult) {
|
| 898 |
+
// Calculate territory to get final score
|
| 899 |
+
const territory = this.getTerritory();
|
| 900 |
+
const scoreDiff = territory.black - territory.white;
|
| 901 |
+
// Add score comment: negative means black wins, positive means white wins
|
| 902 |
+
lines.push(`; ${scoreDiff > 0 ? '-' : scoreDiff < 0 ? '+' : ''}${Math.abs(scoreDiff)}`);
|
| 903 |
+
}
|
| 904 |
+
// Add empty line at the end
|
| 905 |
+
lines.push("");
|
| 906 |
+
return lines.join("\n");
|
| 907 |
+
}
|
| 908 |
+
/**
|
| 909 |
+
* Import game from TGN (Trigo Game Notation) format
|
| 910 |
+
*
|
| 911 |
+
* Static factory method that parses a TGN string and creates a new TrigoGame instance
|
| 912 |
+
* with the board configuration and moves from the TGN file.
|
| 913 |
+
*
|
| 914 |
+
* Synchronous operation - requires parser to be loaded via setParserModule()
|
| 915 |
+
*
|
| 916 |
+
* @param tgnString TGN-formatted game notation string
|
| 917 |
+
* @param callbacks Optional game callbacks
|
| 918 |
+
* @returns New TrigoGame instance with the imported game state
|
| 919 |
+
* @throws TGNParseError if the TGN string is invalid
|
| 920 |
+
*
|
| 921 |
+
* @example
|
| 922 |
+
* const tgnString = `
|
| 923 |
+
* [Event "World Championship"]
|
| 924 |
+
* [Board "5x5x5"]
|
| 925 |
+
* [Black "Alice"]
|
| 926 |
+
* [White "Bob"]
|
| 927 |
+
*
|
| 928 |
+
* 1. 000 y00
|
| 929 |
+
* 2. 0y0 pass
|
| 930 |
+
* `;
|
| 931 |
+
* const game = TrigoGame.fromTGN(tgnString);
|
| 932 |
+
*/
|
| 933 |
+
static fromTGN(tgnString, callbacks) {
|
| 934 |
+
// Parse the TGN string (synchronous)
|
| 935 |
+
const parsed = (0, tgnParser_1.parseTGN)(tgnString);
|
| 936 |
+
// Extract board shape from tags
|
| 937 |
+
let boardShape;
|
| 938 |
+
if (parsed.tags.Board && Array.isArray(parsed.tags.Board)) {
|
| 939 |
+
const shape = parsed.tags.Board;
|
| 940 |
+
// Ensure we have at least 2 dimensions, default to 1 for z if not 3D
|
| 941 |
+
boardShape = {
|
| 942 |
+
x: shape[0] || 5,
|
| 943 |
+
y: shape[1] || 5,
|
| 944 |
+
z: shape[2] || 1
|
| 945 |
+
};
|
| 946 |
+
}
|
| 947 |
+
else {
|
| 948 |
+
// Default to 5x5x5 if no board shape specified
|
| 949 |
+
boardShape = { x: 5, y: 5, z: 5 };
|
| 950 |
+
}
|
| 951 |
+
// Create new game instance using 'this' constructor
|
| 952 |
+
// This allows subclasses to automatically get their own type
|
| 953 |
+
const game = new this(boardShape, callbacks);
|
| 954 |
+
game.startGame();
|
| 955 |
+
// Replay all moves from the parsed data
|
| 956 |
+
if (parsed.moves && parsed.moves.length > 0) {
|
| 957 |
+
for (const round of parsed.moves) {
|
| 958 |
+
// Play black's move
|
| 959 |
+
if (round.action_black) {
|
| 960 |
+
game._applyParsedMove(round.action_black, boardShape);
|
| 961 |
+
}
|
| 962 |
+
// Play white's move if it exists
|
| 963 |
+
if (round.action_white) {
|
| 964 |
+
game._applyParsedMove(round.action_white, boardShape);
|
| 965 |
+
}
|
| 966 |
+
}
|
| 967 |
+
}
|
| 968 |
+
return game;
|
| 969 |
+
}
|
| 970 |
+
/**
|
| 971 |
+
* Apply a parsed move action to the game
|
| 972 |
+
* Private helper method for fromTGN
|
| 973 |
+
*
|
| 974 |
+
* @param action Parsed move action from TGN parser
|
| 975 |
+
* @param boardShape Board dimensions for coordinate decoding
|
| 976 |
+
*/
|
| 977 |
+
_applyParsedMove(action, boardShape) {
|
| 978 |
+
if (action.type === "pass") {
|
| 979 |
+
this.pass();
|
| 980 |
+
}
|
| 981 |
+
else if (action.type === "resign") {
|
| 982 |
+
this.surrender();
|
| 983 |
+
}
|
| 984 |
+
else if (action.type === "move" && action.position) {
|
| 985 |
+
// Decode ab0yz coordinate to Position
|
| 986 |
+
const coords = (0, ab0yz_1.decodeAb0yz)(action.position, [boardShape.x, boardShape.y, boardShape.z]);
|
| 987 |
+
const position = {
|
| 988 |
+
x: coords[0],
|
| 989 |
+
y: coords[1],
|
| 990 |
+
z: coords[2]
|
| 991 |
+
};
|
| 992 |
+
// Make the move
|
| 993 |
+
this.drop(position);
|
| 994 |
+
}
|
| 995 |
+
}
|
| 996 |
+
}
|
| 997 |
+
exports.TrigoGame = TrigoGame;
|
| 998 |
+
// Re-export parser utilities for convenience
|
| 999 |
+
var tgnParser_2 = require("../tgn/tgnParser");
|
| 1000 |
+
Object.defineProperty(exports, "validateTGN", { enumerable: true, get: function () { return tgnParser_2.validateTGN; } });
|
| 1001 |
+
Object.defineProperty(exports, "TGNParseError", { enumerable: true, get: function () { return tgnParser_2.TGNParseError; } });
|
| 1002 |
+
//# sourceMappingURL=game.js.map
|
trigo-web/backend/dist/inc/trigo/game.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"game.js","sourceRoot":"","sources":["../../../../inc/trigo/game.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAGH,2CAUqB;AACrB,mCAAmD;AACnD,gDAAwE;AAExE,2DAA2D;AAC3D,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAElB;;;GAGG;AACH,IAAY,QAKX;AALD,WAAY,QAAQ;IACnB,uCAAQ,CAA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Logic Service - Core Go Rules Implementation
|
| 3 |
+
*
|
| 4 |
+
* Implements capture detection, Ko rule, and territory counting
|
| 5 |
+
* Ported from prototype trigo.game.js to modern TypeScript
|
| 6 |
+
*/
|
| 7 |
+
import type { Position, Stone, BoardShape } from "./types";
|
| 8 |
+
export declare const StoneType: {
|
| 9 |
+
EMPTY: Stone;
|
| 10 |
+
BLACK: Stone;
|
| 11 |
+
WHITE: Stone;
|
| 12 |
+
};
|
| 13 |
+
/**
|
| 14 |
+
* Get the enemy color of a given stone
|
| 15 |
+
*
|
| 16 |
+
* Equivalent to trigo.enemyColor() in prototype
|
| 17 |
+
*/
|
| 18 |
+
export declare function getEnemyColor(color: Stone): Stone;
|
| 19 |
+
/**
|
| 20 |
+
* Check if a position is within board bounds
|
| 21 |
+
*/
|
| 22 |
+
export declare function isInBounds(pos: Position, shape: BoardShape): boolean;
|
| 23 |
+
/**
|
| 24 |
+
* Get all neighboring positions (up to 6 in 3D: ±x, ±y, ±z)
|
| 25 |
+
*
|
| 26 |
+
* Equivalent to StoneArray.stoneNeighbors() in prototype
|
| 27 |
+
*/
|
| 28 |
+
export declare function getNeighbors(pos: Position, shape: BoardShape): Position[];
|
| 29 |
+
/**
|
| 30 |
+
* Compare two positions for equality
|
| 31 |
+
*/
|
| 32 |
+
export declare function positionsEqual(p1: Position, p2: Position): boolean;
|
| 33 |
+
/**
|
| 34 |
+
* Coordinate Set - manages a set of positions (stones in a group or liberties)
|
| 35 |
+
*/
|
| 36 |
+
export declare class CoordSet {
|
| 37 |
+
private positions;
|
| 38 |
+
has(pos: Position): boolean;
|
| 39 |
+
insert(pos: Position): boolean;
|
| 40 |
+
remove(pos: Position): void;
|
| 41 |
+
size(): number;
|
| 42 |
+
empty(): boolean;
|
| 43 |
+
forEach(callback: (pos: Position, index: number) => void): void;
|
| 44 |
+
toArray(): Position[];
|
| 45 |
+
clear(): void;
|
| 46 |
+
}
|
| 47 |
+
/**
|
| 48 |
+
* Patch - represents a connected group of same-colored stones
|
| 49 |
+
*
|
| 50 |
+
* Note: Called "Patch" in the original prototype (trigo.game.js)
|
| 51 |
+
* Equivalent to trigo.Game.Patch which extends trigo.CoordSet
|
| 52 |
+
*/
|
| 53 |
+
export declare class Patch {
|
| 54 |
+
positions: CoordSet;
|
| 55 |
+
color: Stone;
|
| 56 |
+
constructor(color?: Stone);
|
| 57 |
+
addStone(pos: Position): void;
|
| 58 |
+
size(): number;
|
| 59 |
+
/**
|
| 60 |
+
* Get all liberties (empty adjacent positions) for this group
|
| 61 |
+
*
|
| 62 |
+
* Equivalent to StoneArray.patchAir() in prototype
|
| 63 |
+
* Returns a CoordSet of empty positions adjacent to this patch
|
| 64 |
+
*/
|
| 65 |
+
getLiberties(board: Stone[][][], shape: BoardShape): CoordSet;
|
| 66 |
+
}
|
| 67 |
+
/**
|
| 68 |
+
* Find the connected group of stones at a given position
|
| 69 |
+
*/
|
| 70 |
+
export declare function findGroup(pos: Position, board: Stone[][][], shape: BoardShape): Patch;
|
| 71 |
+
/**
|
| 72 |
+
* Get all neighboring groups (different from current position's color)
|
| 73 |
+
*/
|
| 74 |
+
export declare function getNeighborGroups(pos: Position, board: Stone[][][], shape: BoardShape, excludeEmpty?: boolean): Patch[];
|
| 75 |
+
/**
|
| 76 |
+
* Check if a group would be captured (has no liberties)
|
| 77 |
+
*/
|
| 78 |
+
export declare function isGroupCaptured(group: Patch, board: Stone[][][], shape: BoardShape): boolean;
|
| 79 |
+
/**
|
| 80 |
+
* Find all groups that would be captured by placing a stone at position
|
| 81 |
+
*
|
| 82 |
+
* Equivalent to Game.killedPatches() in prototype
|
| 83 |
+
*
|
| 84 |
+
* Note: Prototype checks patchAir <= 1 BEFORE placement.
|
| 85 |
+
* We create a temp board with stone placed, then check for 0 liberties AFTER.
|
| 86 |
+
* Both approaches produce the same result.
|
| 87 |
+
*/
|
| 88 |
+
export declare function findCapturedGroups(pos: Position, playerColor: Stone, board: Stone[][][], shape: BoardShape): Patch[];
|
| 89 |
+
/**
|
| 90 |
+
* Check if placing a stone at position would result in self-capture (suicide)
|
| 91 |
+
*
|
| 92 |
+
* Equivalent to Game.isDeadStone() in prototype
|
| 93 |
+
*
|
| 94 |
+
* Exception: Move is allowed if it captures enemy stones first
|
| 95 |
+
*/
|
| 96 |
+
export declare function isSuicideMove(pos: Position, playerColor: Stone, board: Stone[][][], shape: BoardShape): boolean;
|
| 97 |
+
/**
|
| 98 |
+
* Ko Detection - check if move would recreate previous board state
|
| 99 |
+
*
|
| 100 |
+
* Equivalent to "rob" check in Game.isDropable() (lines 127-132)
|
| 101 |
+
* Note: Ko rule is called "rob" (打劫 dǎjié) in the prototype
|
| 102 |
+
*
|
| 103 |
+
* Ko rule: Cannot immediately recapture a single stone if it would
|
| 104 |
+
* return the board to the previous position
|
| 105 |
+
*/
|
| 106 |
+
export declare function isKoViolation(pos: Position, playerColor: Stone, board: Stone[][][], shape: BoardShape, lastCapturedPositions: Position[] | null): boolean;
|
| 107 |
+
/**
|
| 108 |
+
* Execute captures on the board
|
| 109 |
+
* Returns the positions of captured stones
|
| 110 |
+
*/
|
| 111 |
+
export declare function executeCaptures(capturedGroups: Patch[], board: Stone[][][]): Position[];
|
| 112 |
+
/**
|
| 113 |
+
* Territory Calculation
|
| 114 |
+
*
|
| 115 |
+
* Determines which empty regions belong to which player
|
| 116 |
+
* An empty region belongs to a player if it's completely surrounded
|
| 117 |
+
* by that player's stones
|
| 118 |
+
*/
|
| 119 |
+
export interface TerritoryResult {
|
| 120 |
+
black: number;
|
| 121 |
+
white: number;
|
| 122 |
+
neutral: number;
|
| 123 |
+
blackTerritory: Position[];
|
| 124 |
+
whiteTerritory: Position[];
|
| 125 |
+
neutralTerritory: Position[];
|
| 126 |
+
}
|
| 127 |
+
/**
|
| 128 |
+
* Calculate territory for both players
|
| 129 |
+
*
|
| 130 |
+
* Equivalent to Game.calculateDomainSize() in prototype (lines 305-343)
|
| 131 |
+
* Uses PatchList.spaceDomain() logic to determine region ownership
|
| 132 |
+
*
|
| 133 |
+
* Algorithm:
|
| 134 |
+
* 1. First pass: Add all stones to their player's territory, collect empty regions
|
| 135 |
+
* 2. Second pass: Determine ownership of each empty region
|
| 136 |
+
*/
|
| 137 |
+
export declare function calculateTerritory(board: Stone[][][], shape: BoardShape): TerritoryResult;
|
| 138 |
+
/**
|
| 139 |
+
* Validate if a move is legal
|
| 140 |
+
*
|
| 141 |
+
* Equivalent to Game.isDropable() in prototype
|
| 142 |
+
* Checks: bounds, occupation, Ko rule ("rob"), suicide rule
|
| 143 |
+
*/
|
| 144 |
+
export interface MoveValidation {
|
| 145 |
+
valid: boolean;
|
| 146 |
+
reason?: string;
|
| 147 |
+
}
|
| 148 |
+
export declare function validateMove(pos: Position, playerColor: Stone, board: Stone[][][], shape: BoardShape, lastCapturedPositions?: Position[] | null): MoveValidation;
|
| 149 |
+
//# sourceMappingURL=gameUtils.d.ts.map
|
trigo-web/backend/dist/inc/trigo/gameUtils.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"gameUtils.d.ts","sourceRoot":"","sources":["../../../../inc/trigo/gameUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE3D,eAAO,MAAM,SAAS;WACT,KAAK;WACL,KAAK;WACL,KAAK;CACjB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAIjD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CASpE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,QAAQ,EAAE,CA0BzE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,QAAQ,EAAE,EAA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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
/**
|
| 3 |
+
* Game Logic Service - Core Go Rules Implementation
|
| 4 |
+
*
|
| 5 |
+
* Implements capture detection, Ko rule, and territory counting
|
| 6 |
+
* Ported from prototype trigo.game.js to modern TypeScript
|
| 7 |
+
*/
|
| 8 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 9 |
+
exports.Patch = exports.CoordSet = exports.StoneType = void 0;
|
| 10 |
+
exports.getEnemyColor = getEnemyColor;
|
| 11 |
+
exports.isInBounds = isInBounds;
|
| 12 |
+
exports.getNeighbors = getNeighbors;
|
| 13 |
+
exports.positionsEqual = positionsEqual;
|
| 14 |
+
exports.findGroup = findGroup;
|
| 15 |
+
exports.getNeighborGroups = getNeighborGroups;
|
| 16 |
+
exports.isGroupCaptured = isGroupCaptured;
|
| 17 |
+
exports.findCapturedGroups = findCapturedGroups;
|
| 18 |
+
exports.isSuicideMove = isSuicideMove;
|
| 19 |
+
exports.isKoViolation = isKoViolation;
|
| 20 |
+
exports.executeCaptures = executeCaptures;
|
| 21 |
+
exports.calculateTerritory = calculateTerritory;
|
| 22 |
+
exports.validateMove = validateMove;
|
| 23 |
+
exports.StoneType = {
|
| 24 |
+
EMPTY: 0,
|
| 25 |
+
BLACK: 1,
|
| 26 |
+
WHITE: 2
|
| 27 |
+
};
|
| 28 |
+
/**
|
| 29 |
+
* Get the enemy color of a given stone
|
| 30 |
+
*
|
| 31 |
+
* Equivalent to trigo.enemyColor() in prototype
|
| 32 |
+
*/
|
| 33 |
+
function getEnemyColor(color) {
|
| 34 |
+
if (color === exports.StoneType.BLACK)
|
| 35 |
+
return exports.StoneType.WHITE;
|
| 36 |
+
if (color === exports.StoneType.WHITE)
|
| 37 |
+
return exports.StoneType.BLACK;
|
| 38 |
+
return exports.StoneType.EMPTY;
|
| 39 |
+
}
|
| 40 |
+
/**
|
| 41 |
+
* Check if a position is within board bounds
|
| 42 |
+
*/
|
| 43 |
+
function isInBounds(pos, shape) {
|
| 44 |
+
return (pos.x >= 0 &&
|
| 45 |
+
pos.x < shape.x &&
|
| 46 |
+
pos.y >= 0 &&
|
| 47 |
+
pos.y < shape.y &&
|
| 48 |
+
pos.z >= 0 &&
|
| 49 |
+
pos.z < shape.z);
|
| 50 |
+
}
|
| 51 |
+
/**
|
| 52 |
+
* Get all neighboring positions (up to 6 in 3D: ±x, ±y, ±z)
|
| 53 |
+
*
|
| 54 |
+
* Equivalent to StoneArray.stoneNeighbors() in prototype
|
| 55 |
+
*/
|
| 56 |
+
function getNeighbors(pos, shape) {
|
| 57 |
+
const neighbors = [];
|
| 58 |
+
// Check all 6 directions in 3D space
|
| 59 |
+
const directions = [
|
| 60 |
+
{ x: 1, y: 0, z: 0 },
|
| 61 |
+
{ x: -1, y: 0, z: 0 },
|
| 62 |
+
{ x: 0, y: 1, z: 0 },
|
| 63 |
+
{ x: 0, y: -1, z: 0 },
|
| 64 |
+
{ x: 0, y: 0, z: 1 },
|
| 65 |
+
{ x: 0, y: 0, z: -1 }
|
| 66 |
+
];
|
| 67 |
+
for (const dir of directions) {
|
| 68 |
+
const neighbor = {
|
| 69 |
+
x: pos.x + dir.x,
|
| 70 |
+
y: pos.y + dir.y,
|
| 71 |
+
z: pos.z + dir.z
|
| 72 |
+
};
|
| 73 |
+
if (isInBounds(neighbor, shape)) {
|
| 74 |
+
neighbors.push(neighbor);
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
return neighbors;
|
| 78 |
+
}
|
| 79 |
+
/**
|
| 80 |
+
* Compare two positions for equality
|
| 81 |
+
*/
|
| 82 |
+
function positionsEqual(p1, p2) {
|
| 83 |
+
return p1.x === p2.x && p1.y === p2.y && p1.z === p2.z;
|
| 84 |
+
}
|
| 85 |
+
/**
|
| 86 |
+
* Coordinate Set - manages a set of positions (stones in a group or liberties)
|
| 87 |
+
*/
|
| 88 |
+
class CoordSet {
|
| 89 |
+
constructor() {
|
| 90 |
+
this.positions = [];
|
| 91 |
+
}
|
| 92 |
+
has(pos) {
|
| 93 |
+
return this.positions.some((p) => positionsEqual(p, pos));
|
| 94 |
+
}
|
| 95 |
+
insert(pos) {
|
| 96 |
+
if (!this.has(pos)) {
|
| 97 |
+
this.positions.push(pos);
|
| 98 |
+
return true;
|
| 99 |
+
}
|
| 100 |
+
return false;
|
| 101 |
+
}
|
| 102 |
+
remove(pos) {
|
| 103 |
+
this.positions = this.positions.filter((p) => !positionsEqual(p, pos));
|
| 104 |
+
}
|
| 105 |
+
size() {
|
| 106 |
+
return this.positions.length;
|
| 107 |
+
}
|
| 108 |
+
empty() {
|
| 109 |
+
return this.positions.length === 0;
|
| 110 |
+
}
|
| 111 |
+
forEach(callback) {
|
| 112 |
+
this.positions.forEach(callback);
|
| 113 |
+
}
|
| 114 |
+
toArray() {
|
| 115 |
+
return [...this.positions];
|
| 116 |
+
}
|
| 117 |
+
clear() {
|
| 118 |
+
this.positions = [];
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
exports.CoordSet = CoordSet;
|
| 122 |
+
/**
|
| 123 |
+
* Patch - represents a connected group of same-colored stones
|
| 124 |
+
*
|
| 125 |
+
* Note: Called "Patch" in the original prototype (trigo.game.js)
|
| 126 |
+
* Equivalent to trigo.Game.Patch which extends trigo.CoordSet
|
| 127 |
+
*/
|
| 128 |
+
class Patch {
|
| 129 |
+
constructor(color = exports.StoneType.EMPTY) {
|
| 130 |
+
this.positions = new CoordSet();
|
| 131 |
+
this.color = exports.StoneType.EMPTY;
|
| 132 |
+
this.color = color;
|
| 133 |
+
}
|
| 134 |
+
addStone(pos) {
|
| 135 |
+
this.positions.insert(pos);
|
| 136 |
+
}
|
| 137 |
+
size() {
|
| 138 |
+
return this.positions.size();
|
| 139 |
+
}
|
| 140 |
+
/**
|
| 141 |
+
* Get all liberties (empty adjacent positions) for this group
|
| 142 |
+
*
|
| 143 |
+
* Equivalent to StoneArray.patchAir() in prototype
|
| 144 |
+
* Returns a CoordSet of empty positions adjacent to this patch
|
| 145 |
+
*/
|
| 146 |
+
getLiberties(board, shape) {
|
| 147 |
+
const liberties = new CoordSet();
|
| 148 |
+
this.positions.forEach((stonePos) => {
|
| 149 |
+
const neighbors = getNeighbors(stonePos, shape);
|
| 150 |
+
for (const neighbor of neighbors) {
|
| 151 |
+
if (board[neighbor.x][neighbor.y][neighbor.z] === exports.StoneType.EMPTY) {
|
| 152 |
+
liberties.insert(neighbor);
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
});
|
| 156 |
+
return liberties;
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
exports.Patch = Patch;
|
| 160 |
+
/**
|
| 161 |
+
* Find the connected group of stones at a given position
|
| 162 |
+
*/
|
| 163 |
+
function findGroup(pos, board, shape) {
|
| 164 |
+
const color = board[pos.x][pos.y][pos.z];
|
| 165 |
+
const group = new Patch(color);
|
| 166 |
+
if (color === exports.StoneType.EMPTY) {
|
| 167 |
+
return group;
|
| 168 |
+
}
|
| 169 |
+
// Flood fill to find all connected stones of the same color
|
| 170 |
+
const visited = new CoordSet();
|
| 171 |
+
const stack = [pos];
|
| 172 |
+
while (stack.length > 0) {
|
| 173 |
+
const current = stack.pop();
|
| 174 |
+
if (visited.has(current)) {
|
| 175 |
+
continue;
|
| 176 |
+
}
|
| 177 |
+
visited.insert(current);
|
| 178 |
+
if (board[current.x][current.y][current.z] === color) {
|
| 179 |
+
group.addStone(current);
|
| 180 |
+
const neighbors = getNeighbors(current, shape);
|
| 181 |
+
for (const neighbor of neighbors) {
|
| 182 |
+
if (!visited.has(neighbor)) {
|
| 183 |
+
stack.push(neighbor);
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
return group;
|
| 189 |
+
}
|
| 190 |
+
/**
|
| 191 |
+
* Get all neighboring groups (different from current position's color)
|
| 192 |
+
*/
|
| 193 |
+
function getNeighborGroups(pos, board, shape, excludeEmpty = false) {
|
| 194 |
+
const neighbors = getNeighbors(pos, shape);
|
| 195 |
+
const groups = [];
|
| 196 |
+
const processedPositions = new CoordSet();
|
| 197 |
+
for (const neighbor of neighbors) {
|
| 198 |
+
if (processedPositions.has(neighbor)) {
|
| 199 |
+
continue;
|
| 200 |
+
}
|
| 201 |
+
const stone = board[neighbor.x][neighbor.y][neighbor.z];
|
| 202 |
+
if (excludeEmpty && stone === exports.StoneType.EMPTY) {
|
| 203 |
+
continue;
|
| 204 |
+
}
|
| 205 |
+
if (stone !== exports.StoneType.EMPTY) {
|
| 206 |
+
const group = findGroup(neighbor, board, shape);
|
| 207 |
+
group.positions.forEach((p) => processedPositions.insert(p));
|
| 208 |
+
groups.push(group);
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
return groups;
|
| 212 |
+
}
|
| 213 |
+
/**
|
| 214 |
+
* Check if a group would be captured (has no liberties)
|
| 215 |
+
*/
|
| 216 |
+
function isGroupCaptured(group, board, shape) {
|
| 217 |
+
const liberties = group.getLiberties(board, shape);
|
| 218 |
+
return liberties.size() === 0;
|
| 219 |
+
}
|
| 220 |
+
/**
|
| 221 |
+
* Find all groups that would be captured by placing a stone at position
|
| 222 |
+
*
|
| 223 |
+
* Equivalent to Game.killedPatches() in prototype
|
| 224 |
+
*
|
| 225 |
+
* Note: Prototype checks patchAir <= 1 BEFORE placement.
|
| 226 |
+
* We create a temp board with stone placed, then check for 0 liberties AFTER.
|
| 227 |
+
* Both approaches produce the same result.
|
| 228 |
+
*/
|
| 229 |
+
function findCapturedGroups(pos, playerColor, board, shape) {
|
| 230 |
+
const enemyColor = getEnemyColor(playerColor);
|
| 231 |
+
const captured = [];
|
| 232 |
+
// Create a temporary board with the new stone placed
|
| 233 |
+
const tempBoard = board.map((plane) => plane.map((row) => [...row]));
|
| 234 |
+
tempBoard[pos.x][pos.y][pos.z] = playerColor;
|
| 235 |
+
// Check all neighboring enemy groups
|
| 236 |
+
const neighborGroups = getNeighborGroups(pos, tempBoard, shape, true);
|
| 237 |
+
for (const group of neighborGroups) {
|
| 238 |
+
if (group.color === enemyColor) {
|
| 239 |
+
if (isGroupCaptured(group, tempBoard, shape)) {
|
| 240 |
+
captured.push(group);
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
return captured;
|
| 245 |
+
}
|
| 246 |
+
/**
|
| 247 |
+
* Check if placing a stone at position would result in self-capture (suicide)
|
| 248 |
+
*
|
| 249 |
+
* Equivalent to Game.isDeadStone() in prototype
|
| 250 |
+
*
|
| 251 |
+
* Exception: Move is allowed if it captures enemy stones first
|
| 252 |
+
*/
|
| 253 |
+
function isSuicideMove(pos, playerColor, board, shape) {
|
| 254 |
+
// Create temporary board with the new stone
|
| 255 |
+
const tempBoard = board.map((plane) => plane.map((row) => [...row]));
|
| 256 |
+
tempBoard[pos.x][pos.y][pos.z] = playerColor;
|
| 257 |
+
// If this move captures enemy stones, it's not suicide
|
| 258 |
+
const capturedGroups = findCapturedGroups(pos, playerColor, board, shape);
|
| 259 |
+
if (capturedGroups.length > 0) {
|
| 260 |
+
return false;
|
| 261 |
+
}
|
| 262 |
+
// Check if the placed stone's group has any liberties
|
| 263 |
+
const placedGroup = findGroup(pos, tempBoard, shape);
|
| 264 |
+
const liberties = placedGroup.getLiberties(tempBoard, shape);
|
| 265 |
+
return liberties.size() === 0;
|
| 266 |
+
}
|
| 267 |
+
/**
|
| 268 |
+
* Ko Detection - check if move would recreate previous board state
|
| 269 |
+
*
|
| 270 |
+
* Equivalent to "rob" check in Game.isDropable() (lines 127-132)
|
| 271 |
+
* Note: Ko rule is called "rob" (打劫 dǎjié) in the prototype
|
| 272 |
+
*
|
| 273 |
+
* Ko rule: Cannot immediately recapture a single stone if it would
|
| 274 |
+
* return the board to the previous position
|
| 275 |
+
*/
|
| 276 |
+
function isKoViolation(pos, playerColor, board, shape, lastCapturedPositions) {
|
| 277 |
+
// Ko only applies when:
|
| 278 |
+
// 1. We would capture exactly one stone
|
| 279 |
+
// 2. The previous move also captured exactly one stone
|
| 280 |
+
// 3. We're placing at the position of the previously captured stone
|
| 281 |
+
if (!lastCapturedPositions || lastCapturedPositions.length !== 1) {
|
| 282 |
+
return false;
|
| 283 |
+
}
|
| 284 |
+
const capturedGroups = findCapturedGroups(pos, playerColor, board, shape);
|
| 285 |
+
// Check if this move would capture exactly one stone
|
| 286 |
+
if (capturedGroups.length !== 1 || capturedGroups[0].size() !== 1) {
|
| 287 |
+
return false;
|
| 288 |
+
}
|
| 289 |
+
// Check if we're placing at the position that was just captured
|
| 290 |
+
const previouslyCaptured = lastCapturedPositions[0];
|
| 291 |
+
if (positionsEqual(pos, previouslyCaptured)) {
|
| 292 |
+
return true;
|
| 293 |
+
}
|
| 294 |
+
return false;
|
| 295 |
+
}
|
| 296 |
+
/**
|
| 297 |
+
* Execute captures on the board
|
| 298 |
+
* Returns the positions of captured stones
|
| 299 |
+
*/
|
| 300 |
+
function executeCaptures(capturedGroups, board) {
|
| 301 |
+
const capturedPositions = [];
|
| 302 |
+
for (const group of capturedGroups) {
|
| 303 |
+
group.positions.forEach((pos) => {
|
| 304 |
+
board[pos.x][pos.y][pos.z] = exports.StoneType.EMPTY;
|
| 305 |
+
capturedPositions.push(pos);
|
| 306 |
+
});
|
| 307 |
+
}
|
| 308 |
+
return capturedPositions;
|
| 309 |
+
}
|
| 310 |
+
/**
|
| 311 |
+
* Find all connected empty positions starting from a position
|
| 312 |
+
*/
|
| 313 |
+
function findEmptyRegion(startPos, board, shape, visited) {
|
| 314 |
+
const region = new CoordSet();
|
| 315 |
+
const stack = [startPos];
|
| 316 |
+
while (stack.length > 0) {
|
| 317 |
+
const pos = stack.pop();
|
| 318 |
+
if (visited.has(pos)) {
|
| 319 |
+
continue;
|
| 320 |
+
}
|
| 321 |
+
visited.insert(pos);
|
| 322 |
+
if (board[pos.x][pos.y][pos.z] === exports.StoneType.EMPTY) {
|
| 323 |
+
region.insert(pos);
|
| 324 |
+
const neighbors = getNeighbors(pos, shape);
|
| 325 |
+
for (const neighbor of neighbors) {
|
| 326 |
+
if (!visited.has(neighbor)) {
|
| 327 |
+
stack.push(neighbor);
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
}
|
| 332 |
+
return region;
|
| 333 |
+
}
|
| 334 |
+
/**
|
| 335 |
+
* Determine which player owns an empty region
|
| 336 |
+
* Returns BLACK, WHITE, or EMPTY (neutral/dame)
|
| 337 |
+
*
|
| 338 |
+
* Equivalent to PatchList.spaceDomain() in prototype (lines 561-585)
|
| 339 |
+
* An empty region belongs to a player if ALL bordering stones are that color
|
| 340 |
+
*/
|
| 341 |
+
function determineRegionOwner(region, board, shape) {
|
| 342 |
+
let owner = exports.StoneType.EMPTY;
|
| 343 |
+
let solved = false; // Flag to break out when we find mixed colors
|
| 344 |
+
region.forEach((pos) => {
|
| 345 |
+
if (solved)
|
| 346 |
+
return; // Skip if already determined to be neutral
|
| 347 |
+
const neighbors = getNeighbors(pos, shape);
|
| 348 |
+
for (const neighbor of neighbors) {
|
| 349 |
+
if (solved)
|
| 350 |
+
break; // Skip if already determined to be neutral
|
| 351 |
+
const stone = board[neighbor.x][neighbor.y][neighbor.z];
|
| 352 |
+
if (stone !== exports.StoneType.EMPTY) {
|
| 353 |
+
if (owner === exports.StoneType.EMPTY) {
|
| 354 |
+
// First colored stone we've found
|
| 355 |
+
owner = stone;
|
| 356 |
+
}
|
| 357 |
+
else if (owner !== stone) {
|
| 358 |
+
// Found a different colored stone - region is neutral
|
| 359 |
+
owner = exports.StoneType.EMPTY;
|
| 360 |
+
solved = true; // Mark as solved so we stop checking
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
});
|
| 365 |
+
return owner;
|
| 366 |
+
}
|
| 367 |
+
/**
|
| 368 |
+
* Calculate territory for both players
|
| 369 |
+
*
|
| 370 |
+
* Equivalent to Game.calculateDomainSize() in prototype (lines 305-343)
|
| 371 |
+
* Uses PatchList.spaceDomain() logic to determine region ownership
|
| 372 |
+
*
|
| 373 |
+
* Algorithm:
|
| 374 |
+
* 1. First pass: Add all stones to their player's territory, collect empty regions
|
| 375 |
+
* 2. Second pass: Determine ownership of each empty region
|
| 376 |
+
*/
|
| 377 |
+
function calculateTerritory(board, shape) {
|
| 378 |
+
const result = {
|
| 379 |
+
black: 0,
|
| 380 |
+
white: 0,
|
| 381 |
+
neutral: 0,
|
| 382 |
+
blackTerritory: [],
|
| 383 |
+
whiteTerritory: [],
|
| 384 |
+
neutralTerritory: []
|
| 385 |
+
};
|
| 386 |
+
const visited = new CoordSet();
|
| 387 |
+
const emptyRegions = [];
|
| 388 |
+
// FIRST PASS: Count all stones and find all empty regions
|
| 389 |
+
for (let x = 0; x < shape.x; x++) {
|
| 390 |
+
for (let y = 0; y < shape.y; y++) {
|
| 391 |
+
for (let z = 0; z < shape.z; z++) {
|
| 392 |
+
const pos = { x, y, z };
|
| 393 |
+
const stone = board[x][y][z];
|
| 394 |
+
if (stone === exports.StoneType.BLACK) {
|
| 395 |
+
result.black++;
|
| 396 |
+
result.blackTerritory.push(pos);
|
| 397 |
+
}
|
| 398 |
+
else if (stone === exports.StoneType.WHITE) {
|
| 399 |
+
result.white++;
|
| 400 |
+
result.whiteTerritory.push(pos);
|
| 401 |
+
}
|
| 402 |
+
else if (!visited.has(pos)) {
|
| 403 |
+
// Found an empty position - explore the region and save it
|
| 404 |
+
const region = findEmptyRegion(pos, board, shape, visited);
|
| 405 |
+
emptyRegions.push(region);
|
| 406 |
+
}
|
| 407 |
+
}
|
| 408 |
+
}
|
| 409 |
+
}
|
| 410 |
+
// SECOND PASS: Determine ownership of each empty region
|
| 411 |
+
for (const region of emptyRegions) {
|
| 412 |
+
const owner = determineRegionOwner(region, board, shape);
|
| 413 |
+
const regionArray = region.toArray();
|
| 414 |
+
if (owner === exports.StoneType.BLACK) {
|
| 415 |
+
result.black += region.size();
|
| 416 |
+
result.blackTerritory.push(...regionArray);
|
| 417 |
+
}
|
| 418 |
+
else if (owner === exports.StoneType.WHITE) {
|
| 419 |
+
result.white += region.size();
|
| 420 |
+
result.whiteTerritory.push(...regionArray);
|
| 421 |
+
}
|
| 422 |
+
else {
|
| 423 |
+
result.neutral += region.size();
|
| 424 |
+
result.neutralTerritory.push(...regionArray);
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
return result;
|
| 428 |
+
}
|
| 429 |
+
function validateMove(pos, playerColor, board, shape, lastCapturedPositions = null) {
|
| 430 |
+
// Check bounds
|
| 431 |
+
if (!isInBounds(pos, shape)) {
|
| 432 |
+
return { valid: false, reason: "Position out of bounds" };
|
| 433 |
+
}
|
| 434 |
+
// Check if position is empty
|
| 435 |
+
if (board[pos.x][pos.y][pos.z] !== exports.StoneType.EMPTY) {
|
| 436 |
+
return { valid: false, reason: "Position already occupied" };
|
| 437 |
+
}
|
| 438 |
+
// Check for Ko violation
|
| 439 |
+
if (isKoViolation(pos, playerColor, board, shape, lastCapturedPositions)) {
|
| 440 |
+
return { valid: false, reason: "Ko rule violation" };
|
| 441 |
+
}
|
| 442 |
+
// Check for suicide (self-capture)
|
| 443 |
+
if (isSuicideMove(pos, playerColor, board, shape)) {
|
| 444 |
+
return { valid: false, reason: "suicide move not allowed" };
|
| 445 |
+
}
|
| 446 |
+
return { valid: true };
|
| 447 |
+
}
|
| 448 |
+
//# sourceMappingURL=gameUtils.js.map
|
trigo-web/backend/dist/inc/trigo/gameUtils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"gameUtils.js","sourceRoot":"","sources":["../../../../inc/trigo/gameUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAeH,sCAIC;AAKD,gCASC;AAOD,oCA0BC;AAKD,wCAEC;AA4FD,8BAkCC;AAKD,8CA6BC;AAKD,0CAGC;AAWD,gDAyBC;AASD,sCAqBC;AAWD,sCA8BC;AAMD,0CAWC;AAqGD,gDAqDC;AAaD,oCA4BC;AA5iBY,QAAA,SAAS,GAAG;IACxB,KAAK,EAAE,CAAU;IACjB,KAAK,EAAE,CAAU;IACjB,KAAK,EAAE,CAAU;CACjB,CAAC;AAEF;;;;GAIG;AACH,SAAgB,aAAa,CAAC,KAAY;IACzC,IAAI,KAAK,KAAK,iBAAS,CAAC,KAAK;QAAE,OAAO,iBAAS,CAAC,KAAK,CAAC;IACtD,IAAI,KAAK,KAAK,iBAAS,CAAC,KAAK;QAAE,OAAO,iBAAS,CAAC,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CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,iBAAS,CAAC,KAAK,EAAE,CAAC;QACpD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,2BAA2B,EAAE,CAAC;IAC9D,CAAC;IAED,yBAAyB;IACzB,IAAI,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,qBAAqB,CAAC,EAAE,CAAC;QAC1E,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;IACtD,CAAC;IAED,mCAAmC;IACnC,IAAI,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC;QACnD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,0BAA0B,EAAE,CAAC;IAC7D,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACxB,CAAC"}
|
trigo-web/backend/dist/inc/trigo/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export * from "./types";
|
| 2 |
+
export * from "./gameUtils";
|
| 3 |
+
export * from "./game";
|
| 4 |
+
export * from "./typeAdapters";
|
| 5 |
+
//# sourceMappingURL=index.d.ts.map
|
trigo-web/backend/dist/inc/trigo/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../inc/trigo/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC"}
|
trigo-web/backend/dist/inc/trigo/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
| 3 |
+
if (k2 === undefined) k2 = k;
|
| 4 |
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
| 5 |
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
| 6 |
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
| 7 |
+
}
|
| 8 |
+
Object.defineProperty(o, k2, desc);
|
| 9 |
+
}) : (function(o, m, k, k2) {
|
| 10 |
+
if (k2 === undefined) k2 = k;
|
| 11 |
+
o[k2] = m[k];
|
| 12 |
+
}));
|
| 13 |
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
| 14 |
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
| 15 |
+
};
|
| 16 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 17 |
+
__exportStar(require("./types"), exports);
|
| 18 |
+
__exportStar(require("./gameUtils"), exports);
|
| 19 |
+
__exportStar(require("./game"), exports);
|
| 20 |
+
__exportStar(require("./typeAdapters"), exports);
|
| 21 |
+
//# sourceMappingURL=index.js.map
|
trigo-web/backend/dist/inc/trigo/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../inc/trigo/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,8CAA4B;AAC5B,yCAAuB;AACvB,iDAA+B"}
|
trigo-web/backend/dist/inc/trigo/parserInit.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Initialize all parsers for use in the application
|
| 3 |
+
* Should be called once at application startup
|
| 4 |
+
*
|
| 5 |
+
* In browser: Dynamically imports from /lib/
|
| 6 |
+
* In Node.js: Loads from project's public/lib directory
|
| 7 |
+
*/
|
| 8 |
+
export function initializeParsers(): Promise<void>;
|
| 9 |
+
//# sourceMappingURL=parserInit.d.ts.map
|
trigo-web/backend/dist/inc/trigo/parserInit.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"parserInit.d.ts","sourceRoot":"","sources":["../../../../inc/trigo/parserInit.js"],"names":[],"mappings":"AA4BA;;;;;;GAMG;AACH,mDAgBC"}
|
trigo-web/backend/dist/inc/trigo/parserInit.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
| 3 |
+
if (k2 === undefined) k2 = k;
|
| 4 |
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
| 5 |
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
| 6 |
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
| 7 |
+
}
|
| 8 |
+
Object.defineProperty(o, k2, desc);
|
| 9 |
+
}) : (function(o, m, k, k2) {
|
| 10 |
+
if (k2 === undefined) k2 = k;
|
| 11 |
+
o[k2] = m[k];
|
| 12 |
+
}));
|
| 13 |
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
| 14 |
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
| 15 |
+
}) : function(o, v) {
|
| 16 |
+
o["default"] = v;
|
| 17 |
+
});
|
| 18 |
+
var __importStar = (this && this.__importStar) || (function () {
|
| 19 |
+
var ownKeys = function(o) {
|
| 20 |
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
| 21 |
+
var ar = [];
|
| 22 |
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
| 23 |
+
return ar;
|
| 24 |
+
};
|
| 25 |
+
return ownKeys(o);
|
| 26 |
+
};
|
| 27 |
+
return function (mod) {
|
| 28 |
+
if (mod && mod.__esModule) return mod;
|
| 29 |
+
var result = {};
|
| 30 |
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
| 31 |
+
__setModuleDefault(result, mod);
|
| 32 |
+
return result;
|
| 33 |
+
};
|
| 34 |
+
})();
|
| 35 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 36 |
+
exports.initializeParsers = initializeParsers;
|
| 37 |
+
/**
|
| 38 |
+
* Parser Initialization Module
|
| 39 |
+
*
|
| 40 |
+
* Loads pre-built parsers from public/lib and injects them into parser wrappers
|
| 41 |
+
* This allows the same synchronous API to work in both browser and Node.js
|
| 42 |
+
*
|
| 43 |
+
* Usage in Node.js tests:
|
| 44 |
+
* ```
|
| 45 |
+
* import { initializeParsers } from "@inc/trigo/parserInit"
|
| 46 |
+
* await initializeParsers()
|
| 47 |
+
* ```
|
| 48 |
+
*
|
| 49 |
+
* Usage in Vue app:
|
| 50 |
+
* Add to main.ts before using any game functionality
|
| 51 |
+
*/
|
| 52 |
+
const tgnParser_1 = require("../tgn/tgnParser");
|
| 53 |
+
/**
|
| 54 |
+
* Check if we're in a browser environment
|
| 55 |
+
*/
|
| 56 |
+
function isBrowser() {
|
| 57 |
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
| 58 |
+
}
|
| 59 |
+
/**
|
| 60 |
+
* Check if we're in a Node.js environment
|
| 61 |
+
*/
|
| 62 |
+
function isNode() {
|
| 63 |
+
return typeof process !== "undefined" && !!process.versions && !!process.versions.node;
|
| 64 |
+
}
|
| 65 |
+
/**
|
| 66 |
+
* Initialize all parsers for use in the application
|
| 67 |
+
* Should be called once at application startup
|
| 68 |
+
*
|
| 69 |
+
* In browser: Dynamically imports from /lib/
|
| 70 |
+
* In Node.js: Loads from project's public/lib directory
|
| 71 |
+
*/
|
| 72 |
+
async function initializeParsers() {
|
| 73 |
+
try {
|
| 74 |
+
if (isBrowser()) {
|
| 75 |
+
await initializeParsersForBrowser();
|
| 76 |
+
}
|
| 77 |
+
else if (isNode()) {
|
| 78 |
+
await initializeParsersForNode();
|
| 79 |
+
}
|
| 80 |
+
else {
|
| 81 |
+
throw new Error("Unable to determine runtime environment");
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
catch (error) {
|
| 85 |
+
console.error("❌ Failed to initialize parsers:", error);
|
| 86 |
+
throw error;
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
/**
|
| 90 |
+
* Initialize parsers for browser environment
|
| 91 |
+
* Loads parsers from /lib/ which is served by Vite in dev and included in build
|
| 92 |
+
*/
|
| 93 |
+
async function initializeParsersForBrowser() {
|
| 94 |
+
try {
|
| 95 |
+
// In browser, fetch the parser from the public directory
|
| 96 |
+
// Vite serves /public as / so /lib/tgnParser.cjs maps to public/lib/tgnParser.cjs
|
| 97 |
+
const libPath = "/" + "lib/tgnParser.cjs";
|
| 98 |
+
const response = await fetch(libPath);
|
| 99 |
+
if (!response.ok) {
|
| 100 |
+
throw new Error(`Failed to fetch parser: ${response.status} ${response.statusText}`);
|
| 101 |
+
}
|
| 102 |
+
const code = await response.text();
|
| 103 |
+
// Create a CommonJS module environment
|
| 104 |
+
// The jison parser checks: if (typeof require !== 'undefined' && typeof exports !== 'undefined')
|
| 105 |
+
// So we need to make these available as variables in the eval scope
|
| 106 |
+
const module = { exports: {} };
|
| 107 |
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
| 108 |
+
const exports = module.exports;
|
| 109 |
+
// We need 'require' to be defined (but can be a dummy)
|
| 110 |
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
| 111 |
+
const require = function () { throw new Error("require not available in browser"); };
|
| 112 |
+
// Eval in a scope where module, exports, and require are defined
|
| 113 |
+
// eslint-disable-next-line no-eval
|
| 114 |
+
eval(code);
|
| 115 |
+
// The jison parser exports: exports.parser = tgnParser
|
| 116 |
+
// So module.exports.parser is the actual parser instance
|
| 117 |
+
const parser = module.exports.parser;
|
| 118 |
+
if (!parser || typeof parser.parse !== 'function') {
|
| 119 |
+
throw new Error("Parser loaded but parse method not available");
|
| 120 |
+
}
|
| 121 |
+
(0, tgnParser_1.setParserModule)(parser);
|
| 122 |
+
}
|
| 123 |
+
catch (error) {
|
| 124 |
+
console.error("✗ Failed to load TGN parser:", error);
|
| 125 |
+
throw error;
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
/**
|
| 129 |
+
* Initialize parsers for Node.js environment
|
| 130 |
+
* Loads parsers from project's public/lib directory
|
| 131 |
+
*/
|
| 132 |
+
async function initializeParsersForNode() {
|
| 133 |
+
try {
|
| 134 |
+
// Import Node.js modules dynamically
|
| 135 |
+
const pathModule = await Promise.resolve().then(() => __importStar(require("path")));
|
| 136 |
+
const urlModule = await Promise.resolve().then(() => __importStar(require("url")));
|
| 137 |
+
const path = pathModule.default;
|
| 138 |
+
const { fileURLToPath, pathToFileURL } = urlModule;
|
| 139 |
+
// Get project root directory
|
| 140 |
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
| 141 |
+
const projectRoot = path.resolve(__dirname, "../..");
|
| 142 |
+
const libPath = path.resolve(projectRoot, "public/lib");
|
| 143 |
+
// Load TGN parser
|
| 144 |
+
const tgnParserPath = path.resolve(libPath, "tgnParser.cjs");
|
| 145 |
+
const tgnParserModule = await Promise.resolve(`${pathToFileURL(tgnParserPath).href}`).then(s => __importStar(require(s)));
|
| 146 |
+
const tgnParser = tgnParserModule.parser;
|
| 147 |
+
(0, tgnParser_1.setParserModule)(tgnParser);
|
| 148 |
+
}
|
| 149 |
+
catch (error) {
|
| 150 |
+
console.error("✗ Failed to load TGN parser:", error);
|
| 151 |
+
throw error;
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
//# sourceMappingURL=parserInit.js.map
|