Skip to content

Commit

Permalink
Add razoring (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenphuminh authored Jul 28, 2024
1 parent 8964d9e commit 0a59d3e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ Note that the config file is compiled with the engine itself, so if you are usin
* Countermove heuristic.
* Transposition table.
* Pruning:
* Reverse futility pruning.
* Null-move pruning.
* Razoring.
* 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.11.0",
version: "v0.12.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.11.0",
"version": "0.12.0",
"description": "The Catto chess engine",
"main": "index.js",
"scripts": {
Expand Down
20 changes: 19 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ export class Engine {
if (depth === 0) return this.quiescence(alpha, beta);

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

if (currentEval - rfpMargin >= beta) return currentEval - rfpMargin;
Expand Down Expand Up @@ -363,6 +364,23 @@ export class Engine {
possibleMoves = this.sortMoves(possibleMoves);
let searchedMoves = 0, bestMoveSoFar: Move;

// Razoring, skipping an entire subtree
if (!isPv && !inCheck && depth <= 3) {
// Prepare score for first phase
let scaledScore = currentEval + mgMaterial[0];

if (scaledScore < beta) {
const qScore = this.quiescence(alpha, beta);

if (depth === 1) return Math.max(qScore, scaledScore);

// Second phase for depth 2 and depth 3
scaledScore += mgMaterial[0];

if (scaledScore < beta && qScore < beta) return Math.max(qScore, scaledScore);
}
}

// Futility pruning
let fpEnabled = false;
if (depth < 4 && Math.abs(alpha) < 48000) {
Expand Down

0 comments on commit 0a59d3e

Please sign in to comment.