1
- use crate :: chess:: { Move , Zobrist } ;
2
1
use crate :: nnue:: { Evaluator , Value } ;
3
- use crate :: search:: * ;
4
2
use crate :: util:: { Assume , Counter , Integer , Timer } ;
3
+ use crate :: { chess:: Move , search:: * } ;
5
4
use arrayvec:: ArrayVec ;
6
5
use derive_more:: { Display , Error } ;
7
6
use rayon:: { prelude:: * , ThreadPool , ThreadPoolBuilder } ;
@@ -66,15 +65,20 @@ impl Engine {
66
65
}
67
66
68
67
/// Records a `[Transposition`].
69
- fn record ( & self , key : Zobrist , bounds : Range < Score > , depth : Depth , ply : Ply , pv : Pv ) -> Pv {
68
+ fn record ( & self , pos : & Evaluator , bounds : Range < Score > , depth : Depth , ply : Ply , pv : Pv ) -> Pv {
69
+ let m = pv. best ( ) . assume ( ) ;
70
+ if pv >= bounds. end && m. is_quiet ( ) {
71
+ Self :: KILLERS . with_borrow_mut ( |ks| ks. insert ( ply, pos. turn ( ) , m) ) ;
72
+ }
73
+
70
74
self . tt . set (
71
- key ,
75
+ pos . zobrist ( ) ,
72
76
if pv. score ( ) >= bounds. end {
73
- Transposition :: lower ( depth - ply, pv. score ( ) . normalize ( -ply) , pv . best ( ) . assume ( ) )
77
+ Transposition :: lower ( depth - ply, pv. score ( ) . normalize ( -ply) , m )
74
78
} else if pv. score ( ) <= bounds. start {
75
- Transposition :: upper ( depth - ply, pv. score ( ) . normalize ( -ply) , pv . best ( ) . assume ( ) )
79
+ Transposition :: upper ( depth - ply, pv. score ( ) . normalize ( -ply) , m )
76
80
} else {
77
- Transposition :: exact ( depth - ply, pv. score ( ) . normalize ( -ply) , pv . best ( ) . assume ( ) )
81
+ Transposition :: exact ( depth - ply, pv. score ( ) . normalize ( -ply) , m )
78
82
} ,
79
83
) ;
80
84
@@ -246,18 +250,12 @@ impl Engine {
246
250
Some ( ( m, _) ) => {
247
251
let mut next = pos. clone ( ) ;
248
252
next. play ( m) ;
249
- let pv = m >> -self . pvs ( & next, -beta..-alpha, depth, ply + 1 , ctrl) ?;
250
-
251
- if pv >= beta && m. is_quiet ( ) {
252
- Self :: KILLERS . with_borrow_mut ( |ks| ks. insert ( ply, pos. turn ( ) , m) ) ;
253
- }
254
-
255
- pv
253
+ m >> -self . pvs ( & next, -beta..-alpha, depth, ply + 1 , ctrl) ?
256
254
}
257
255
} ;
258
256
259
257
if pv >= beta {
260
- return Ok ( self . record ( pos. zobrist ( ) , bounds, depth, ply, pv) ) ;
258
+ return Ok ( self . record ( pos, bounds, depth, ply, pv) ) ;
261
259
}
262
260
263
261
let cutoff = AtomicI16 :: new ( pv. score ( ) . max ( alpha) . get ( ) ) ;
@@ -290,10 +288,6 @@ impl Engine {
290
288
_ => m >> -self . pvs ( & next, -beta..-alpha, depth, ply + 1 , ctrl) ?,
291
289
} ;
292
290
293
- if pv >= beta && m. is_quiet ( ) {
294
- Self :: KILLERS . with_borrow_mut ( |ks| ks. insert ( ply, pos. turn ( ) , m) ) ;
295
- }
296
-
297
291
if pv > alpha {
298
292
cutoff. fetch_max ( pv. score ( ) . get ( ) , Ordering :: Relaxed ) ;
299
293
}
@@ -304,7 +298,7 @@ impl Engine {
304
298
. try_reduce ( || None , |a, b| Ok ( max ( a, b) ) ) ?
305
299
. assume ( ) ;
306
300
307
- Ok ( self . record ( pos. zobrist ( ) , bounds, depth, ply, pv) )
301
+ Ok ( self . record ( pos, bounds, depth, ply, pv) )
308
302
}
309
303
310
304
/// An implementation of [aspiration windows] with [iterative deepening].
0 commit comments