@@ -453,25 +453,32 @@ impl<'a, Log: LogLevel> Search<'a, Log> {
453453 // sort moves by MVV/LVA
454454 let move_iter = InplaceIncrementalSort :: new ( move_list. as_mut_slice ( ) , & mut order_list) ;
455455
456- // initialize best move and best score
457- // we ensured we have moves earlier
458- // let mut best_move = Some(*sorted_moves[0]);
459-
460- // really "bad" initial score
456+ // Really "bad" initial score
461457 let mut best_score = -Score :: INF ;
462458 let mut best_move = tt_move;
463459
464- let lmr_reduction = 1 ;
465- // loop through all moves
460+ // Loop through all moves
466461 for ( i, mv) in move_iter. into_iter ( ) . enumerate ( ) {
462+ // Calculate the LMR reduction and depth which will be used later in FP
463+ let lmr_table_value = self . lmr_table . at ( depth as usize , i) ;
464+ let base_reduction = if let Some ( table_val) = lmr_table_value {
465+ * table_val
466+ } else {
467+ 1f64
468+ } ;
469+ let lmr_reduction = ( 1f64 + base_reduction) . floor ( ) as i16 ;
470+ let _lmr_depth = depth. saturating_sub ( lmr_reduction) ;
471+ let is_in_check = board. is_in_check ( & self . move_gen ) ;
472+ let is_root = Node :: ROOT ;
473+ let is_pv = Node :: PV ;
474+
467475 // Move-loop pruning techniques
468476
469477 // LMP - Late Move Pruning
470478 // We assume our move ordering is just too good, so if we're under a certain depth
471479 // and have made more than a certain number of moves, we can assume that later moves
472480 // won't be as good, so we prune them.
473- if !Node :: ROOT && !Node :: PV && !board. is_in_check ( & self . move_gen ) && !best_score. mated ( )
474- {
481+ if !is_root && !is_pv && !is_in_check && !best_score. mated ( ) {
475482 let min_lmp_moves =
476483 LMP_MIN_THRESHOLD_DEPTH as usize + depth as usize * depth as usize ;
477484 if i >= min_lmp_moves {
@@ -491,9 +498,7 @@ impl<'a, Log: LogLevel> Search<'a, Log> {
491498 -self . negamax :: < PvNode > ( board, depth - 1 , ply + 1 , -beta, -alpha_use, & mut local_pv)
492499 } else {
493500 let reduction = if mv. is_quiet ( ) && depth >= 3 && board. full_move_number ( ) >= 3 {
494- let lmr_table_val = self . lmr_table . at ( depth as usize , i) ;
495- assert ! ( lmr_table_val. is_some( ) , "LMR table not initialized." ) ;
496- ( lmr_reduction as f64 + lmr_table_val. unwrap ( ) ) . floor ( ) as i16
501+ lmr_reduction
497502 } else {
498503 1
499504 } ;
0 commit comments