diff --git a/README.md b/README.md index 610e75b..10eaed2 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,6 @@ There are several configurations for Catto that you can change in `catto.config. module.exports = { // Search depth searchDepth: 4, - // Set to true to turn on debug mode, will log out useful info - debug: false, - // If you disable stable mode, features that are in-dev and might cause issues will be turned on - stable: true, // The starting position represented as a FEN string fen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", // Current version to show in UCI diff --git a/catto.config.js b/catto.config.js index 3104b2e..99c83fa 100644 --- a/catto.config.js +++ b/catto.config.js @@ -1,14 +1,10 @@ module.exports = { // Search depth searchDepth: 4, - // Set to true to turn on debug mode, will log out useful info - debug: false, - // If you disable stable mode, features that are in-dev and might cause issues will be turned on - stable: true, // The starting position represented as a FEN string fen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", // Current version to show in UCI - version: "v0.6.0", + version: "v0.6.1", // Late move reduction config lmrFullDepth: 4, // Number of moves to be searched in full depth lmrMaxReduction: 3, // Only apply LMR above this depth diff --git a/package.json b/package.json index e028ff3..7ff7505 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "catto", - "version": "0.6.0", + "version": "0.6.1", "description": "The Catto chess engine", "main": "index.js", "scripts": { diff --git a/src/core.ts b/src/core.ts index 6a3b7be..6786ff5 100644 --- a/src/core.ts +++ b/src/core.ts @@ -36,8 +36,6 @@ export interface HistoryMove { export class Engine { public chess: Chess; public fen: string; - public debug: boolean; - public stable: boolean; public searchDepth: number; public nodes: number = 0; public lmrMaxReduction: number; @@ -57,16 +55,19 @@ export class Engine { "w": [ {}, {}, {}, {}, {}, {} ] } + // PV table + public pvTable: string[]; + constructor(options: EngineOptions) { this.fen = options.fen; - this.debug = options.debug; this.searchDepth = options.searchDepth; this.chess = new Chess(this.fen); this.uci = options.uci; - this.stable = options.stable; this.lmrMaxReduction = options.lmrMaxReduction; this.lmrFullDepth = options.lmrFullDepth; this.maxExtensions = options.maxExtensions; + + this.pvTable = new Array(this.searchDepth).fill(""); } // Tranposition table @@ -384,6 +385,9 @@ export class Engine { if (this.ply === 0) { this.bestMove = move; } + + // Store pv move + this.pvTable[this.ply] = move.lan; } } @@ -393,16 +397,25 @@ export class Engine { return alpha; } - findMove() { + findMove(): { + bestMove: Move | undefined; + time: number; + depth: number; + nodes: number; + pvTable: string[]; + evaluation: number; + } { const start = Date.now(); - this.negamax(this.searchDepth, -50000, 50000, 0); + const evaluation = this.negamax(this.searchDepth, -50000, 50000, 0); - if (this.debug) { - console.log("Nodes searched:", this.nodes); - console.log(`Finished in: ${Date.now() - start}ms`); + return { + bestMove: this.bestMove, + time: Date.now() - start, + depth: this.searchDepth, + nodes: this.nodes, + pvTable: this.pvTable, + evaluation }; - - return this.bestMove; } } diff --git a/src/uci.ts b/src/uci.ts index 9fccc2b..faa6c51 100644 --- a/src/uci.ts +++ b/src/uci.ts @@ -71,15 +71,12 @@ export class UCI { } } } - // console.log(this.engine.chess.ascii()); } handleGo(command: string) { // To be updated - // const start = Date.now(); - const bestMove = this.engine.findMove(); + const result = this.engine.findMove(); - console.log(`bestmove ${bestMove?.lan}`); - // console.log(this.engine.nodes); - // console.log(Date.now() - start); + console.log(`info depth ${result.depth} score cp ${Math.round(result.evaluation)} time ${result.time} nodes ${result.nodes} pv ${result.pvTable.join(" ")}`); + console.log(`bestmove ${result.bestMove?.lan}`); } }