Skip to content

Commit 610b213

Browse files
committed
feat: principal variation search
Basic PVS implemented, yielding provisionary 210 Elo improvement compared to last commit
1 parent 4c860a4 commit 610b213

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

config.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"pgn": {
2626
"event_name": "Fastchess Tournament",
2727
"site": "?",
28-
"file": "elo_20250817-231021.pgn",
28+
"file": "elo_20250818-094028.pgn",
2929
"notation": 0,
3030
"track_nodes": false,
3131
"track_seldepth": false,
@@ -48,7 +48,7 @@
4848
},
4949
"config_name": "",
5050
"output": 0,
51-
"seed": 6913807169441360982,
51+
"seed": 12012971255052956627,
5252
"variant": 0,
5353
"ratinginterval": 10,
5454
"scoreinterval": 1,
@@ -90,9 +90,9 @@
9090
"variant": 0
9191
},
9292
{
93-
"name": "engine.0.1.1.core-avx2",
93+
"name": "engine.old",
9494
"dir": "",
95-
"cmd": "build/engine.0.1.1.core-avx2.exe",
95+
"cmd": "build/engine.old.exe",
9696
"args": "",
9797
"options": [],
9898
"limit": {
@@ -110,26 +110,26 @@
110110
}
111111
],
112112
"stats": {
113-
"engine.0.1.1.core-avx2 vs engine": {
114-
"wins": 2,
115-
"losses": 10,
116-
"draws": 0,
113+
"engine.old vs engine": {
114+
"wins": 4,
115+
"losses": 15,
116+
"draws": 1,
117117
"penta_WW": 0,
118118
"penta_WD": 0,
119-
"penta_WL": 2,
119+
"penta_WL": 4,
120120
"penta_DD": 0,
121-
"penta_LD": 0,
122-
"penta_LL": 4
121+
"penta_LD": 1,
122+
"penta_LL": 5
123123
},
124-
"engine vs engine.0.1.1.core-avx2": {
125-
"wins": 4,
126-
"losses": 2,
127-
"draws": 2,
128-
"penta_WW": 1,
129-
"penta_WD": 1,
130-
"penta_WL": 1,
124+
"engine vs engine.old": {
125+
"wins": 0,
126+
"losses": 0,
127+
"draws": 0,
128+
"penta_WW": 0,
129+
"penta_WD": 0,
130+
"penta_WL": 0,
131131
"penta_DD": 0,
132-
"penta_LD": 1,
132+
"penta_LD": 0,
133133
"penta_LL": 0
134134
}
135135
}

src/search.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,18 @@ Value negamax(Position& pos, int depth, int ply, Value alpha, Value beta, bool c
241241

242242
// todo reductions and prunings
243243

244+
// Principal variation search
245+
Value score;
244246
pos.makeMove(m);
245-
// todo implement principal variation search
246-
Value score = -negamax<true>(pos, depth - 1, ply + 1, -beta, -alpha, false);
247+
if (moveSearched == 1) {
248+
score = -negamax<isPV>(pos, depth - 1, ply + 1, -beta, -alpha, false);
249+
} else {
250+
score = -negamax<false>(pos, depth - 1, ply + 1, -alpha - 1, -alpha, true);
251+
// If it improves alpha, re-search with full window
252+
if (score > alpha && isPV) {
253+
score = -negamax<true>(pos, depth - 1, ply + 1, -beta, -alpha, false);
254+
}
255+
}
247256
pos.unmakeMove(m);
248257

249258
// Stop searching if time control is hit
@@ -262,6 +271,10 @@ Value negamax(Position& pos, int depth, int ply, Value alpha, Value beta, bool c
262271
currSS->bestMove = m;
263272
if (score >= beta) {
264273
ttFlag = EntryType::LOWER_BOUND;
274+
// Record quiet killer moves
275+
if (!pos.isCapture(bestMove)) {
276+
searchHistory.killerTable[ply].add(bestMove);
277+
}
265278
break;
266279
}
267280
}

0 commit comments

Comments
 (0)