Skip to content

Commit

Permalink
RFP and fix TT
Browse files Browse the repository at this point in the history
- Added reverse futility pruning.
- Fixed mate score adjustment in transposition table.
  • Loading branch information
nguyenphuminh authored Jul 27, 2024
1 parent 0f11a1d commit 8964d9e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Note that the config file is compiled with the engine itself, so if you are usin
* Pruning:
* Null-move pruning.
* Futility pruning.
* Reverse futility pruning.
* Delta pruning.
* Late move reductions.
* Search extensions:
Expand Down
2 changes: 1 addition & 1 deletion catto.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
// Current version to show in UCI
version: "v0.10.1",
version: "v0.11.0",
// 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.10.1",
"version": "0.11.0",
"description": "The Catto chess engine",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 12 additions & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export class Engine {

const hash = genZobristKey(this.chess).toString();
// const hash = this.chess.fen();

if (score < -48000) score -= this.ply;
if (score > 48000) score += this.ply;

this.hashTable[hash] = {
score,
Expand Down Expand Up @@ -299,6 +302,14 @@ export class Engine {
// Quiescence search
if (depth === 0) return this.quiescence(alpha, beta);

// Reverse futility pruning
const currentEval = evaluateBoard(this.chess);
if (depth < 3 && !inCheck && !(beta - alpha > 1) && Math.abs(beta - 1) > -48900) {
let rfpMargin = mgMaterial[0] * depth; // Scaled for each depth by a pawn

if (currentEval - rfpMargin >= beta) return currentEval - rfpMargin;
}

// Null move pruning
if (this.ply && depth >= 3 && !inCheck) {
// Preserve old moves to reconstruct chess obj
Expand Down Expand Up @@ -355,7 +366,6 @@ export class Engine {
// Futility pruning
let fpEnabled = false;
if (depth < 4 && Math.abs(alpha) < 48000) {
const currentEval = evaluateBoard(this.chess);
// Margin for each depth, the shallower the depth the more we reduce the margin
const futilityMargin = [ 0, mgMaterial[0], mgMaterial[1], mgMaterial[3] ];
fpEnabled = currentEval + futilityMargin[depth] <= alpha;
Expand Down Expand Up @@ -464,7 +474,7 @@ export class Engine {
// Copy move from deeper ply into a current ply's line
this.pvTable[this.ply][nextPly] = this.pvTable[this.ply + 1][nextPly];

// adjust PV length
// Adjust PV length
this.pvLength[this.ply] = this.pvLength[this.ply + 1];
}
}
Expand Down

0 comments on commit 8964d9e

Please sign in to comment.