BQP2M5YIF2R53XJSJXTZRSXMOAJ4UEJBCLFCZ2OHF27T4DOGWJJQC
J3BT4EXSBCDHSZDYYWZHEBGQLKODRKPLUOFRCAT7VNPWWPAUXSHQC
HSGLIJUNOPRWGA53IQNV7G2BOOPHI23WVYJSF5RE3HLEL63Z3OHQC
G4HJL4QLASCZBWYGCEXYYRBYL7UVX6ENELHRRBFB5UAXXGVVGZGQC
DKK2G2S3X7KFEJBHGLUEVTBBW6UBR36XR7ZBUWG5GO6JYXWGJOOAC
WSRRWTTVBE2K6NKPS54CXMY3QYK5YTDRGEH3YJ53VQ2XW5UM5O2QC
F7RLQRYDCN3Y3JJBCI7NH5RFMJUNIQVXOPZV7RUUIBSKMIYNNYLQC
CU3XNAGXZHXACBEDPM3THFT6AWAJ4HC5PXZM3Z72WWVMSHPOOXFQC
RNEXG5IFDKMHSUR6RMNTI3Y32ORLVMZ6UJYKHLV2XBMT2QONBTVQC
NCFUC2F34HIV6BZYYMMHIGQOD6G6BUJZYY4RINPCAKGCSVCC46DAC
4B26P4BBEABLLGDY4IQS7QK6OW67EROEIQMHS36D2Z4TWDEK5Z2AC
HNCUAGWTMX3UHH2KFTUM3M6Q4CC33M6PVE5DWZWFG5UM2Y7J2ZKAC
Z4PX3GURAMMW55R5KRP5WCO2CXFEI6LBULGBQRYTABBONCOZ5NHQC
V34YWVR66ERHUV6SOYQWJQLYMPLWEIJDXCR44B3SLPN2CRYIR45QC
XRCSCQWQKVYASIMAJO7JVUJXHXE44FZROCJPBW2BR7EE4RPEIBKAC
NK6IUUYQENJVKT3SDWOXH7NF6JGCSE66IRFAPJTTYPVVPI34X6RQC
3N3FYEBBZ6RLFCFKG2FNHHRDUZBOVBAAXAHBUPSOB3FN5HMWLVDAC
inline fn adjustTTgetScore(self: *const @This(), s: isize) isize {
if (s < -eval.CHECKMATE_SCORE) {
return s + @intCast(isize, self.ply);
} else if (s > eval.CHECKMATE_SCORE) {
return s - @intCast(isize, self.ply);
} else {
return s;
}
}
inline fn adjustTTsetScore(self: *const @This(), s: isize) isize {
if (s < -eval.CHECKMATE_SCORE) {
return s - @intCast(isize, self.ply);
} else if (s > eval.CHECKMATE_SCORE) {
return s + @intCast(isize, self.ply);
} else {
return s;
}
}
// TT probe
if (self.ply != 0) {
if (self.tt.get(self.state.hash)) |entry| {
if (entry.depth >= depth_orig) {
switch (entry.flag) {
.empty => unreachable,
.exact => return self.adjustTTgetScore(entry.score),
.lower => {
if (entry.score <= alpha_orig) return self.adjustTTgetScore(alpha_orig);
},
.upper => {
if (entry.score >= beta) return self.adjustTTgetScore(beta);
},
}
}
}
}
// TT probe
if (self.tt.get(self.state.hash)) |entry| {
if (entry.depth >= depth_orig) {
switch (entry.flag) {
.empty => unreachable,
.exact => return entry.value,
.lower => {
if (entry.value <= alpha_orig) return alpha_orig;
},
.upper => {
if (entry.value >= beta) return beta;
},
}
}
}
// fail-hard beta cutoff
if (scr >= beta) {
self.tt.set(.{
.key = self.state.hash,
.value = beta,
.depth = @intCast(u8, depth),
.flag = .upper,
});
// store killer moves
if (!mp.move.capture) {
score.killer_moves[1][self.ply] = score.killer_moves[0][self.ply];
score.killer_moves[0][self.ply] = mp.move;
}
// node (move) fails high
return beta;
}
// fail-hard beta cutoff
if (scr >= beta) {
self.tt.set(.{
.key = self.state.hash,
.score = self.adjustTTsetScore(beta),
.depth = @intCast(u8, depth),
.flag = .upper,
});
// store killer moves
if (!mp.move.capture) {
score.killer_moves[1][self.ply] = score.killer_moves[0][self.ply];
score.killer_moves[0][self.ply] = mp.move;
}
// node (move) fails high
return beta;
}