refactor: remove many transposition entry fields

seemingly having a smaller transposition table entry makes the engine
way faster (for example, position startpos - go now gets a depth of 6
compared to 5 before)
This commit is contained in:
dogeystamp 2024-12-21 21:23:08 -05:00
parent 4ee30bd278
commit 3dcdb892ab
No known key found for this signature in database

View File

@ -138,17 +138,13 @@ fn lvv_mva_eval(src_pc: Piece, cap_pc: Piece) -> EvalInt {
} }
/// Assign a priority to a move based on how promising it is. /// Assign a priority to a move based on how promising it is.
fn move_priority(board: &mut Board, mv: &Move, state: &mut EngineState) -> EvalInt { fn move_priority(board: &mut Board, mv: &Move) -> EvalInt {
// move eval // move eval
let mut eval: EvalInt = 0; let mut eval: EvalInt = 0;
let src_pc = board.get_piece(mv.src).unwrap(); let src_pc = board.get_piece(mv.src).unwrap();
let anti_mv = mv.make(board); let anti_mv = mv.make(board);
if state.config.enable_trans_table { if let Some(cap_pc) = anti_mv.cap {
if let Some(entry) = &state.cache[board.zobrist] {
eval = entry.eval.into();
}
} else if let Some(cap_pc) = anti_mv.cap {
// least valuable victim, most valuable attacker // least valuable victim, most valuable attacker
eval += lvv_mva_eval(src_pc.into(), cap_pc) eval += lvv_mva_eval(src_pc.into(), cap_pc)
} }
@ -239,19 +235,15 @@ fn minmax(board: &mut Board, state: &mut EngineState, mm: MinmaxState) -> (Vec<M
.into_iter() .into_iter()
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into_iter() .into_iter()
.map(|mv| (move_priority(board, &mv, state), mv)) .map(|mv| (move_priority(board, &mv), mv))
.collect(); .collect();
// get transposition table entry // get transposition table entry
if state.config.enable_trans_table { if state.config.enable_trans_table {
if let Some(entry) = &state.cache[board.zobrist] { if let Some(entry) = &state.cache[board.zobrist] {
if entry.is_qsearch == mm.quiesce && entry.depth >= mm.depth { if (entry.depth & 0x80 > 0) == mm.quiesce && (entry.depth & !0x80) >= (mm.depth as u8) {
if let SearchEval::Exact(_) | SearchEval::Upper(_) = entry.eval { mvs.push((EVAL_BEST, entry.best_mv))
// no point looking for a better move
return (vec![entry.best_move], entry.eval);
}
} }
mvs.push((EVAL_BEST, entry.best_move));
} }
} }
@ -336,10 +328,8 @@ fn minmax(board: &mut Board, state: &mut EngineState, mm: MinmaxState) -> (Vec<M
best_continuation.push(best_move); best_continuation.push(best_move);
if state.config.enable_trans_table { if state.config.enable_trans_table {
state.cache[board.zobrist] = Some(TranspositionEntry { state.cache[board.zobrist] = Some(TranspositionEntry {
best_move, best_mv: best_move,
eval: abs_best, depth: mm.depth as u8 | ((mm.quiesce as u8) << 7),
depth: mm.depth,
is_qsearch: mm.quiesce,
}); });
} }
} }
@ -350,14 +340,12 @@ fn minmax(board: &mut Board, state: &mut EngineState, mm: MinmaxState) -> (Vec<M
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct TranspositionEntry { pub struct TranspositionEntry {
/// best move found last time
best_move: Move,
/// last time's eval
eval: SearchEval,
/// depth of this entry /// depth of this entry
depth: usize, ///
/// is this score within the context of quiescence /// most significant bit marks if this is qsearch or not
is_qsearch: bool, depth: u8,
/// last time's best move
best_mv: Move,
} }
pub type TranspositionTable = ZobristTable<TranspositionEntry>; pub type TranspositionTable = ZobristTable<TranspositionEntry>;