Skip to content

Commit

Permalink
Add info to the uci client (#11)
Browse files Browse the repository at this point in the history
- Added "info" to uci client which currently includes depth, nodes, score cp, time, pv.
- Removed "debug" and "stable" options because they are currently useless. Debug info is in also uci's info now so no reason to have it.
  • Loading branch information
nguyenphuminh authored Jul 21, 2024
1 parent 73b6585 commit cb2e8af
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions catto.config.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "catto",
"version": "0.6.0",
"version": "0.6.1",
"description": "The Catto chess engine",
"main": "index.js",
"scripts": {
Expand Down
35 changes: 24 additions & 11 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -384,6 +385,9 @@ export class Engine {
if (this.ply === 0) {
this.bestMove = move;
}

// Store pv move
this.pvTable[this.ply] = move.lan;
}
}

Expand All @@ -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;
}
}
9 changes: 3 additions & 6 deletions src/uci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}

0 comments on commit cb2e8af

Please sign in to comment.