From f9ab353f1cff808cd1c05913447360f51b805203 Mon Sep 17 00:00:00 2001 From: "Phu Minh (Catto)" <53084840+nguyenphuminh@users.noreply.github.com> Date: Fri, 4 Oct 2024 00:25:21 +0700 Subject: [PATCH] Time bug fix (#23) Fixed an issue where we use the move of the current depth when not all moves of that depth were searched. --- catto.config.js | 2 +- package.json | 2 +- src/core.ts | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/catto.config.js b/catto.config.js index d938adc..efc12c9 100644 --- a/catto.config.js +++ b/catto.config.js @@ -1,6 +1,6 @@ module.exports = { // Current version to show in UCI - version: "v0.12.2", + version: "v0.12.3", // 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 87c4809..aa753e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "catto", - "version": "0.12.2", + "version": "0.12.3", "description": "The Catto chess engine", "main": "index.js", "scripts": { diff --git a/src/core.ts b/src/core.ts index 074d957..8260e7a 100644 --- a/src/core.ts +++ b/src/core.ts @@ -508,6 +508,8 @@ export class Engine { } findMove() { + let bestMove = ""; + // Iterative deepening with aspiration windows this.startTime = Date.now(); @@ -550,8 +552,12 @@ export class Engine { console.log(`info depth ${depth} score cp ${Math.round(score)} time ${Date.now() - this.startTime} nodes ${this.nodes} pv${pv}`); } } + + // This is used to prevent cases where moves at a depth is not completely searched. + // We will just use the best move of previous depth if time is up or forced-stopped. + bestMove = this.pvTable[0][0]; } - console.log(`bestmove ${this.pvTable[0][0]}`); + console.log(`bestmove ${bestMove}`); } }