### Install Dependencies Source: https://github.com/franciscobsalgueiro/en-croissant/blob/master/CONTRIBUTING.md Install all project dependencies using pnpm. This command should be run after cloning the repository and entering the project directory. ```bash pnpm i ``` -------------------------------- ### Start Development Server Source: https://github.com/franciscobsalgueiro/en-croissant/blob/master/CONTRIBUTING.md Starts the application in development mode, allowing you to see changes in real time. This is useful for active development. ```bash pnpm dev ``` -------------------------------- ### Build En Croissant from Source Source: https://github.com/franciscobsalgueiro/en-croissant/blob/master/README.md Follow these commands to clone the repository, install dependencies using pnpm, and build the application. The built app will be located in `src-tauri/target/release`. ```bash git clone https://github.com/franciscoBSalgueiro/en-croissant cd en-croissant pnpm install pnpm build ``` -------------------------------- ### Configure and Start Human vs. Engine Chess Game Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Set up a game against a UCI engine with custom time controls, opening books, and engine options. Listen for game events like moves, clock updates, and game over. ```typescript import { commands, events, type GameConfig, type PlayerConfig, type GoMode } from "@/bindings"; // Configure human vs engine game const config: GameConfig = { white: { type: "human", name: "Player" }, black: { type: "engine", name: "Stockfish 16", path: "/path/to/stockfish", options: [ { name: "Skill Level", value: "10" }, { name: "Threads", value: "2" } ], go: { t: "Depth", c: 15 } // or null for time-based }, whiteTimeControl: { initialTime: 600000, increment: 5000 }, // 10+5 blackTimeControl: { initialTime: 600000, increment: 5000 }, initialFen: null, // standard starting position initialMoves: [], openingBook: { path: "/path/to/openings.bin", // Polyglot, PGN, or EPD maxPly: 20 } }; // Start the game const gameId = "game-" + Date.now(); const state = await commands.startGame(gameId, config); console.log(`Game started: ${state.whitePlayer} vs ${state.blackPlayer}`); // Listen for moves and clock updates events.gameMoveEvent.listen((event) => { if (event.payload.gameId === gameId) { const lastMove = event.payload.moves[event.payload.moves.length - 1]; console.log(`Move played: ${lastMove.san}`); console.log(`Position: ${event.payload.fen}`); } }); events.clockUpdateEvent.listen((event) => { if (event.payload.gameId === gameId) { console.log(`White: ${event.payload.whiteTime}ms, Black: ${event.payload.blackTime}ms`); } }); events.gameOverEvent.listen((event) => { if (event.payload.gameId === gameId) { const result = event.payload.result; if (result.type === "whiteWins") { console.log(`White wins by ${result.reason}`); } else if (result.type === "blackWins") { console.log(`Black wins by ${result.reason}`); } else { console.log(`Draw by ${result.reason}`); } } }); // Make a move (only on human's turn) const newState = await commands.makeGameMove(gameId, "e2e4"); // Take back move await commands.takeBackGameMove(gameId); // Resign await commands.resignGame(gameId, "white"); // Abort game await commands.abortGame(gameId); ``` -------------------------------- ### Get Available Puzzle Themes Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Fetch a list of all available themes from a Lichess puzzle database. This helps in filtering puzzles by specific criteria. ```typescript // Get available puzzle themes const themes = await commands.getPuzzleThemes("/path/to/puzzles.db"); console.log(`Available themes: ${themes.join(", ")}`); ``` -------------------------------- ### Get Database Information Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Retrieves metadata about a chess database, including its title, game and player counts, and indexing status. ```typescript const dbInfo = await commands.getDbInfo("/path/to/database.db3"); console.log(`Database: ${dbInfo.title}`); console.log(`Games: ${dbInfo.game_count}, Players: ${dbInfo.player_count}`); console.log(`Indexed: ${dbInfo.indexed}`); ``` -------------------------------- ### Get UCI Engine Configuration Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Retrieve the configuration details and available options for a UCI chess engine. This allows for dynamic inspection and potential modification of engine settings. ```typescript import { commands, type EngineConfig } from "@/bindings"; // Get engine configuration and available options const config: EngineConfig = await commands.getEngineConfig("/path/to/stockfish"); console.log(`Engine: ${config.name}`); config.options.forEach(option => { if (option.type === "spin") { console.log(`${option.value.name}: ${option.value.default} (${option.value.min}-${option.value.max})`); } else if (option.type === "check") { console.log(`${option.value.name}: ${option.value.default ? "on" : "off"}`); } else if (option.type === "combo") { console.log(`${option.value.name}: ${option.value.default} [${option.value.var.join(", ")}]`); } else if (option.type === "string") { console.log(`${option.value.name}: "${option.value.default}"`); } }); ``` -------------------------------- ### Get FEN for Specific Opening Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Retrieve the FEN string for a specific chess opening by its name. Useful for setting up a board to a known opening position. ```typescript // Get FEN for a specific opening const fen = await commands.getOpeningFromName("Italian Game"); console.log(`Italian Game FEN: ${fen}`); ``` -------------------------------- ### Get Themes for a Specific Puzzle Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Retrieve the themes associated with a particular chess puzzle, identified by its ID. Useful for understanding the characteristics of a puzzle. ```typescript // Get themes for a specific puzzle const puzzleThemes = await commands.getThemesForPuzzle("/path/to/puzzles.db", puzzle.id); ``` -------------------------------- ### Get Opening Name from FEN Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Retrieve the name of a chess opening given its FEN string. This is useful for identifying openings during game analysis or playback. ```typescript import { commands } from "@/bindings"; // Get opening name from FEN const openingName = await commands.getOpeningFromFen( "rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2" ); console.log(`Opening: ${openingName}`); // "Sicilian Defense" ``` -------------------------------- ### Get Puzzle Database Information Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Retrieve information about a Lichess puzzle database, including the total number of puzzles available. Requires the path to the puzzle database file. ```typescript import { commands } from "@/bindings"; // Get puzzle database info const dbInfo = await commands.getPuzzleDbInfo("/path/to/puzzles.db"); console.log(`Total puzzles: ${dbInfo.puzzleCount}`); ``` -------------------------------- ### Get Random Puzzle with Filters Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Retrieve a random chess puzzle from a database, with options to filter by minimum and maximum rating, and by theme. The solution is provided as space-separated UCI moves. ```typescript // Get a random puzzle with filters const puzzle = await commands.getPuzzle( "/path/to/puzzles.db", 1200, // minimum rating 1600, // maximum rating "mateIn2" // theme filter (null for any) ); console.log(`Puzzle FEN: ${puzzle.fen}`); console.log(`Solution: ${puzzle.moves}`); // space-separated UCI moves console.log(`Rating: ${puzzle.rating} (RD: ${puzzle.rating_deviation})`); console.log(`Popularity: ${puzzle.popularity}, Plays: ${puzzle.nb_plays}`); ``` -------------------------------- ### Get Deepest Opening Match from FEN Sequence Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Find the deepest matching chess opening from a sequence of FEN strings. This is useful for identifying openings in complex game states. ```typescript // Get opening from sequence of FENs (finds deepest match) const fens = [ "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1", "rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 2", "rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2" ]; const deepestOpening = await commands.getOpeningFromFens(fens); ``` -------------------------------- ### Build the Application Source: https://github.com/franciscobsalgueiro/en-croissant/blob/master/CONTRIBUTING.md Builds the entire application from source. The compiled application will be located at `src-tauri/target/release/`. This is a required step before submitting a pull request. ```bash pnpm build ``` -------------------------------- ### Format Project Code Source: https://github.com/franciscobsalgueiro/en-croissant/blob/master/CONTRIBUTING.md Formats the entire project according to the established project guidelines. This should be run before submitting code. ```bash pnpm format ``` -------------------------------- ### Download File with Progress Tracking Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Initiate a file download and track its progress. This is useful for downloading large files like chess engines or database updates. Progress updates are received via event listeners. ```typescript import { commands, events } from "@/bindings"; const downloadId = "stockfish-download"; // Listen for progress updates events.progressEvent.listen((event) => { if (event.payload.id === downloadId) { console.log(`Download progress: ${event.payload.progress.toFixed(1)}%`); if (event.payload.finished) { console.log("Download complete!"); } } }); // Start download await commands.downloadFile( downloadId, "https://github.com/official-stockfish/Stockfish/releases/latest/download/stockfish-ubuntu-x86-64-avx2.tar", "/path/to/stockfish.tar", null, // auth token (for private downloads) true, // finalize (decompress if archive) null // total size (null = unknown) ); ``` -------------------------------- ### Configure and Run Continuous Engine Analysis Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Set up analysis options, including FEN, moves, and UCI parameters. Listen for real-time updates on best moves and scores. Stop or kill the engine process as needed. ```typescript import { commands, events, type GoMode, type EngineOptions } from "@/bindings"; // Configure engine analysis options const options: EngineOptions = { fen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", moves: ["e2e4", "e7e5", "g1f3"], extraOptions: [ { name: "MultiPV", value: "3" }, { name: "Threads", value: "4" }, { name: "Hash", value: "256" } ] }; // Analysis modes: depth, time, nodes, or infinite const goMode: GoMode = { t: "Depth", c: 20 }; // Start continuous analysis (returns cached result if unchanged) const result = await commands.getBestMoves( "analysis-1", // unique ID for this analysis instance "/path/to/stockfish", // engine path "tab-1", // tab identifier for grouping engines goMode, options ); // Listen for real-time analysis updates const unlisten = await events.bestMovesPayload.listen((event) => { const { bestLines, engine, fen, progress } = event.payload; console.log(`Progress: ${progress}%, Best move: ${bestLines[0]?.sanMoves[0]}`); console.log(`Score: ${bestLines[0]?.score.value}`); }); // Stop engine without killing await commands.stopEngine("/path/to/stockfish", "tab-1"); // Kill engine process await commands.killEngine("analysis-1", "tab-1"); ``` -------------------------------- ### Set File Executable (Linux/macOS) Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Make a downloaded file executable. This is typically required for engine binaries on Linux and macOS systems. ```typescript // Make downloaded file executable (Linux/macOS) await commands.setFileAsExecutable("/path/to/stockfish"); ``` -------------------------------- ### Clone the Repository Source: https://github.com/franciscobsalgueiro/en-croissant/blob/master/CONTRIBUTING.md Clone your forked repository to your local machine. Replace `{your_username}` with your GitHub username. ```bash git clone git@github.com:{your_username}/en-croissant.git ``` -------------------------------- ### Run All Tests Source: https://github.com/franciscobsalgueiro/en-croissant/blob/master/CONTRIBUTING.md Executes all tests within the project and generates a report. This command is used to ensure code quality and correctness. ```bash pnpm test ``` -------------------------------- ### Search Openings by Name Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Search for chess openings by name. Returns a list of openings matching the search query, including their names and FEN strings. ```typescript // Search openings by name const results = await commands.searchOpeningName("Sicilian"); results.forEach(opening => { console.log(`${opening.name}: ${opening.fen}`); }); ``` -------------------------------- ### Convert PGN to Database Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Imports chess games from PGN files (including compressed formats) into a database file. Specify input files, output database path, an optional timestamp filter, and database title/description. ```typescript import { commands, type GameQuery, type PlayerQuery, type QueryOptions } from "@/bindings"; // Convert PGN files to database await commands.convertPgn( ["/path/to/games.pgn", "/path/to/more-games.pgn.bz2"], "/path/to/output.db3", null, // timestamp filter (null = import all) "My Games", // database title "Imported from lichess" // description ); ``` -------------------------------- ### Preload Reference Database Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Loads a reference database into memory for faster subsequent searches. Useful for frequently accessed databases. ```typescript await commands.preloadReferenceDb("/path/to/masters.db3"); ``` -------------------------------- ### Export Database to PGN Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Exports all games from a database file back into a PGN format file. ```typescript await commands.exportToPgn("/path/to/database.db3", "/path/to/export.pgn"); ``` -------------------------------- ### Lint and Fix Code Source: https://github.com/franciscobsalgueiro/en-croissant/blob/master/CONTRIBUTING.md Lints the project according to the guidelines and automatically fixes any linting issues. Run this after formatting. ```bash pnpm lint:fix ``` -------------------------------- ### Check CPU Compatibility for BMI2 Instructions Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Verify if the current CPU architecture supports BMI2 instructions. This is important for utilizing optimized chess engine builds. ```typescript // Check CPU compatibility for optimized engines const hasBmi2 = await commands.isBmi2Compatible(); console.log(`BMI2 support: ${hasBmi2}`); ``` -------------------------------- ### Engine Analysis API Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Provides multi-engine position analysis with support for all UCI-compatible engines. The `getBestMoves` command runs continuous analysis that emits real-time updates, while `analyzeGame` performs batch analysis of entire games. ```APIDOC ## Engine Analysis API ### Description The engine analysis commands provide multi-engine position analysis with support for all UCI-compatible engines. The `getBestMoves` command runs continuous analysis that emits real-time updates, while `analyzeGame` performs batch analysis of entire games. ### Method `POST` (Tauri IPC command) ### Endpoint `/commands/getBestMoves` `/commands/stopEngine` `/commands/killEngine` ### Parameters #### `getBestMoves` Parameters - **analysisId** (string) - Required - A unique identifier for this analysis instance. - **enginePath** (string) - Required - The absolute path to the UCI-compatible chess engine executable. - **tabId** (string) - Required - The identifier for the tab or group to which this engine belongs. - **goMode** (object) - Required - Specifies the analysis mode (e.g., Depth, Time, Nodes, Infinite). - **t** (string) - Required - Type of analysis mode (e.g., "Depth", "Time", "Nodes", "Infinite"). - **c** (number) - Required - The value for the specified analysis mode (e.g., depth, time in seconds, node count). - **options** (object) - Required - Configuration options for the analysis. - **fen** (string) - Optional - The FEN string representing the starting position for analysis. - **moves** (array of strings) - Optional - An array of moves in SAN notation to play from the FEN position. - **extraOptions** (array of objects) - Optional - Additional UCI options to set for the engine. - **name** (string) - Required - The name of the UCI option. - **value** (string) - Required - The value of the UCI option. #### `stopEngine` Parameters - **enginePath** (string) - Required - The absolute path to the UCI-compatible chess engine executable. - **tabId** (string) - Required - The identifier for the tab or group to which this engine belongs. #### `killEngine` Parameters - **analysisId** (string) - Required - The unique identifier for the analysis instance to kill. - **tabId** (string) - Required - The identifier for the tab or group to which this engine belongs. ### Events - **`bestMovesPayload`**: Emitted in real-time during analysis. Payload includes `bestLines`, `engine`, `fen`, and `progress`. ### Request Example (getBestMoves) ```typescript import { commands, events, type GoMode, type EngineOptions } from "@/bindings"; const options: EngineOptions = { fen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", moves: ["e2e4", "e7e5", "g1f3"], extraOptions: [ { name: "MultiPV", value: "3" }, { name: "Threads", value: "4" }, { name: "Hash", value: "256" } ] }; const goMode: GoMode = { t: "Depth", c: 20 }; const result = await commands.getBestMoves( "analysis-1", "/path/to/stockfish", "tab-1", goMode, options ); const unlisten = await events.bestMovesPayload.listen((event) => { const { bestLines, engine, fen, progress } = event.payload; console.log(`Progress: ${progress}%, Best move: ${bestLines[0]?.sanMoves[0]}`); console.log(`Score: ${bestLines[0]?.score.value}`); }); await commands.stopEngine("/path/to/stockfish", "tab-1"); await commands.killEngine("analysis-1", "tab-1"); ``` ### Response (getBestMoves) - **`bestLines`** (array) - An array of the best move lines found. - **`engine`** (object) - Information about the engine used. - **`fen`** (string) - The FEN string of the current position. - **`progress`** (number) - The analysis progress percentage. ### Response Example (getBestMoves) ```json { "bestLines": [ { "sanMoves": ["e4"], "score": { "value": { "type": "cp", "value": 30 } } } ], "engine": { "name": "Stockfish", "version": "15.1" }, "fen": "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1", "progress": 50 } ``` ``` -------------------------------- ### Check System Memory Size Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Determine the available system memory in megabytes. This information is crucial for configuring the hash table size in chess engines. ```typescript // Check system memory for Hash configuration const memoryMB = await commands.memorySize(); console.log(`System memory: ${memoryMB} MB`); ``` -------------------------------- ### Manage Download Progress Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Check the progress of an ongoing download and clear its status once completed. This helps in managing download states and resources. ```typescript // Check and clear progress const progress = await commands.getProgress(downloadId); if (progress?.finished) { await commands.clearProgress(downloadId); } ``` -------------------------------- ### Extract Translations Source: https://github.com/franciscobsalgueiro/en-croissant/blob/master/CONTRIBUTING.md Extracts all translation keys from the code and updates the translation files located in `src/translation/`. Run this if you modify or add any translation keys. ```bash pnpm i18n:extract ``` -------------------------------- ### Perform Full Game Analysis with Novelty Detection Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Analyze an entire game, optionally comparing it against a reference database for novelty and sacrifice detection. Includes progress tracking and cancellation. ```typescript import { commands, type AnalysisOptions, type GoMode } from "@/bindings"; const analysisOptions: AnalysisOptions = { fen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", moves: ["e2e4", "c7c5", "g1f3", "d7d6", "d2d4", "c5d4", "f3d4"], annotateNovelties: true, referenceDb: "/path/to/masters.db3", reversed: false // analyze from start to end }; const goMode: GoMode = { t: "Depth", c: 18 }; const uciOptions = [ { name: "MultiPV", value: "2" }, { name: "Threads", value: "8" } ]; // Full game analysis with progress tracking const analysisId = "game-analysis-1"; const unlisten = await events.progressEvent.listen((event) => { if (event.payload.id === analysisId) { console.log(`Analysis progress: ${event.payload.progress.toFixed(1)}%`); } }); try { const analysis = await commands.analyzeGame( analysisId, "/path/to/stockfish", goMode, analysisOptions, uciOptions ); // Process analysis results analysis.forEach((move, index) => { const bestMove = move.best[0]; console.log(`Move ${index + 1}: Best was ${bestMove?.sanMoves[0]}`); console.log(` Score: ${bestMove?.score.value.type === 'cp' ? (bestMove.score.value.value / 100).toFixed(2) : `#${bestMove?.score.value.value}`}`); if (move.novelty) console.log(" NOVELTY!"); if (move.is_sacrifice) console.log(" Sacrifice!"); }); } catch (error) { if (error === "Analysis cancelled") { console.log("Analysis was cancelled"); } } // Cancel ongoing analysis await commands.cancelAnalysis(analysisId); unlisten(); ``` -------------------------------- ### Query Games from Database Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Retrieves games from a database file based on specified criteria. Supports filtering by players, ELO range, dates, and outcomes. The results include game data and a total count. ```typescript const gameQuery: GameQuery = { options: { skipCount: false, page: 1, pageSize: 25, sort: "date", direction: "desc" }, player1: 42, // player ID (from getPlayers) sides: "Any", // "WhiteBlack", "BlackWhite", or "Any" range1: [2000, 2400], // ELO range for player1 startDate: "2023.01.01", endDate: "2024.12.31", outcome: "1-0" // filter by result }; const { data: games, count } = await commands.getGames("/path/to/database.db3", gameQuery); console.log(`Found ${count} games matching criteria`); games.forEach(game => { console.log(`${game.white} (${game.white_elo}) vs ${game.black} (${game.black_elo})`); console.log(` ${game.date} - ${game.result}`); console.log(` Opening: ${game.eco}`); }); ``` -------------------------------- ### Search Players in Database Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Finds players within a database based on name and ELO range. Results are paginated and sorted by ELO. ```typescript const playerQuery: PlayerQuery = { options: { skipCount: false, page: 1, pageSize: 20, sort: "elo", direction: "desc" }, name: "Carlsen", range: [2700, 2900] }; const { data: players } = await commands.getPlayers("/path/to/database.db3", playerQuery); ``` -------------------------------- ### Parse and Navigate PGN Tree Structure Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Convert PGN strings into a navigable tree for analysis and manipulation. Supports variations, annotations, and comments. Export the tree back to PGN format. ```typescript import { commands } from "@/bindings"; import { parsePGN, getPGN, getMainLine, getMoveText, type TreeState } from "@/utils/chess"; import { getNodeAtPath, treeIterator, type TreeNode } from "@/utils/treeReducer"; // Parse PGN string into tree structure const pgn = `[Event "World Championship"] [White "Carlsen"] [Black "Nepomniachtchi"] [Result "1-0"] 1. e4 e5 2. Nf3 Nc6 3. Bb5 {The Ruy Lopez} a6 4. Ba4 Nf6 5. O-O *`; const tree: TreeState = await parsePGN(pgn); console.log(`${tree.headers.white} vs ${tree.headers.black}`); // Navigate the tree const currentNode = getNodeAtPath(tree.root, tree.position); console.log(`Current FEN: ${currentNode.fen}`); console.log(`Comment: ${currentNode.comment}`); // Get mainline as UCI moves const mainLine = getMainLine(tree.root); console.log(`Mainline: ${mainLine.join(" ")}`); // Iterate through all positions (including variations) for (const { position, node } of treeIterator(tree.root)) { if (node.san) { console.log(`${position.join(".")}: ${node.san}`); } } // Export back to PGN with options const exportedPgn = getPGN(tree.root, { headers: tree.headers, glyphs: true, // include annotations like !, ?, etc. comments: true, // include comments variations: true, // include variation lines extraMarkups: true // include eval, clock, arrows }); // Tokenize PGN for custom processing const tokens = await commands.lexPgn(pgn); tokens.forEach(token => { if (token.type === "San") { console.log(`Move: ${token.value}`); } else if (token.type === "Comment") { console.log(`Comment: ${token.value}`); } }); ``` -------------------------------- ### Full Game Analysis API Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Analyzes an entire game with novelty detection, sacrifice detection, and annotation of theoretical departures. ```APIDOC ## Full Game Analysis API ### Description Analyze an entire game with novelty detection by comparing against a reference database. The analysis includes sacrifice detection and can annotate where the game departs from known theory. ### Method `POST` (Tauri IPC command) ### Endpoint `/commands/analyzeGame` `/commands/cancelAnalysis` ### Parameters #### `analyzeGame` Parameters - **analysisId** (string) - Required - A unique identifier for this analysis instance. - **enginePath** (string) - Required - The absolute path to the UCI-compatible chess engine executable. - **goMode** (object) - Required - Specifies the analysis mode (e.g., Depth, Time, Nodes, Infinite). - **t** (string) - Required - Type of analysis mode (e.g., "Depth", "Time", "Nodes", "Infinite"). - **c** (number) - Required - The value for the specified analysis mode (e.g., depth, time in seconds, node count). - **analysisOptions** (object) - Required - Configuration options for the game analysis. - **fen** (string) - Optional - The FEN string representing the starting position for analysis. - **moves** (array of strings) - Required - An array of moves in SAN notation representing the game to analyze. - **annotateNovelties** (boolean) - Optional - Whether to annotate novelties (departures from theory). - **referenceDb** (string) - Optional - Path to a reference PGN or database file for novelty detection. - **reversed** (boolean) - Optional - Whether to analyze the game in reverse (from end to start). Defaults to `false`. - **uciOptions** (array of objects) - Optional - Additional UCI options to set for the engine. - **name** (string) - Required - The name of the UCI option. - **value** (string) - Required - The value of the UCI option. #### `cancelAnalysis` Parameters - **analysisId** (string) - Required - The unique identifier of the analysis to cancel. ### Events - **`progressEvent`**: Emitted periodically during analysis. Payload includes `id` and `progress` percentage. ### Request Example (analyzeGame) ```typescript import { commands, type AnalysisOptions, type GoMode } from "@/bindings"; const analysisOptions: AnalysisOptions = { fen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", moves: ["e2e4", "c7c5", "g1f3", "d7d6", "d2d4", "c5d4", "f3d4"], annotateNovelties: true, referenceDb: "/path/to/masters.db3", reversed: false }; const goMode: GoMode = { t: "Depth", c: 18 }; const uciOptions = [ { name: "MultiPV", value: "2" }, { name: "Threads", value: "8" } ]; const analysisId = "game-analysis-1"; const unlisten = await events.progressEvent.listen((event) => { if (event.payload.id === analysisId) { console.log(`Analysis progress: ${event.payload.progress.toFixed(1)}%`); } }); try { const analysis = await commands.analyzeGame( analysisId, "/path/to/stockfish", goMode, analysisOptions, uciOptions ); analysis.forEach((move, index) => { const bestMove = move.best[0]; console.log(`Move ${index + 1}: Best was ${bestMove?.sanMoves[0]}`); console.log(` Score: ${bestMove?.score.value.type === 'cp' ? (bestMove.score.value.value / 100).toFixed(2) : `#${bestMove?.score.value.value}`}`); if (move.novelty) console.log(" NOVELTY!"); if (move.is_sacrifice) console.log(" Sacrifice!"); }); } catch (error) { if (error === "Analysis cancelled") { console.log("Analysis was cancelled"); } } await commands.cancelAnalysis(analysisId); unlisten(); ``` ### Response (analyzeGame) - **`analysis`** (array of objects) - An array where each object represents a move in the game and contains analysis details. - **`best`** (array of objects) - The best move lines for the current position. - **`sanMoves`** (array of strings) - The sequence of moves in SAN notation. - **`score`** (object) - The evaluation score of the position. - **`value`** (object) - The score value. - **`type`** (string) - Type of score ('cp' for centipawns, 'mate' for mate in X). - **`value`** (number) - The numerical score. - **`novelty`** (boolean) - Indicates if this move is a novelty. - **`is_sacrifice`** (boolean) - Indicates if this move is a sacrifice. ### Response Example (analyzeGame) ```json [ { "best": [ { "sanMoves": ["e4"], "score": { "value": { "type": "cp", "value": 30 } } } ], "novelty": false, "is_sacrifice": false }, { "best": [ { "sanMoves": ["c5"], "score": { "value": { "type": "cp", "value": 10 } } } ], "novelty": false, "is_sacrifice": false } ] ``` ``` -------------------------------- ### Search Exact Chess Position Source: https://context7.com/franciscobsalgueiro/en-croissant/llms.txt Searches a database for games containing an exact chess position. Returns position statistics and a list of matching games. ```typescript const positionQuery: PositionQueryJs = { fen: "rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2", type_: "exact" // or "partial" for flexible matching }; const gameQuery: GameQuery = { position: positionQuery, options: { skipCount: false, page: 1, pageSize: 50, sort: "date", direction: "desc" } }; // Returns position statistics and matching games const [positionStats, matchingGames] = await commands.searchPosition( "/path/to/database.db3", gameQuery, "search-tab-1" ); // Position statistics show move frequencies positionStats.forEach(stat => { const total = stat.white + stat.draw + stat.black; const whitePercent = ((stat.white / total) * 100).toFixed(1); const drawPercent = ((stat.draw / total) * 100).toFixed(1); const blackPercent = ((stat.black / total) * 100).toFixed(1); console.log(`${stat.move}: ${total} games (${whitePercent}%/${drawPercent}%/${blackPercent}%)`); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.