Add TT lookups in quiescence, move TT inside Game, remove redundant occupancy and time limit functions
This commit is contained in:
@@ -9,7 +9,7 @@ use super::{
|
||||
move_ordering,
|
||||
quiescence::quiescence,
|
||||
time::{hard_limit, TimeInfo},
|
||||
transposition_table::{Bound, TTEntry, TranspositionTable},
|
||||
transposition_table::TTEntry,
|
||||
SearchResult,
|
||||
};
|
||||
|
||||
@@ -20,7 +20,6 @@ pub fn negamax(
|
||||
depth: u8,
|
||||
plies: u8,
|
||||
time_info: &TimeInfo,
|
||||
tt: &mut TranspositionTable,
|
||||
) -> Result<SearchResult> {
|
||||
if hard_limit(&time_info.time, time_info.remaining_time_in_ms) {
|
||||
bail!("Time is up! In Negamax");
|
||||
@@ -36,10 +35,9 @@ pub fn negamax(
|
||||
let mut best_score = MIN_SCORE;
|
||||
let mate_score = -MATE_SCORE + plies as i32;
|
||||
let mut legal_moves = 0;
|
||||
let mut bound = Bound::Alpha;
|
||||
let all_moves = game.board.pseudo_moves_all();
|
||||
|
||||
let tt_move = tt.lookup(game.hash).and_then(|entry| entry.mv);
|
||||
let tt_move = game.tt.lookup(game.hash).and_then(|entry| entry.mv);
|
||||
let moves = move_ordering::sort_moves(all_moves, &game.mailbox, tt_move);
|
||||
|
||||
for mv in moves {
|
||||
@@ -51,7 +49,7 @@ pub fn negamax(
|
||||
}
|
||||
|
||||
legal_moves += 1;
|
||||
let score = -negamax(game, -beta, -alpha, depth - 1, plies + 1, time_info, tt)?.best_score;
|
||||
let score = -negamax(game, -beta, -alpha, depth - 1, plies + 1, time_info)?.best_score;
|
||||
game.unmake_move();
|
||||
|
||||
if score > best_score {
|
||||
@@ -60,14 +58,12 @@ pub fn negamax(
|
||||
}
|
||||
|
||||
if score >= beta {
|
||||
bound = Bound::Beta;
|
||||
best_score = beta;
|
||||
best_move = Some(mv);
|
||||
break;
|
||||
}
|
||||
|
||||
if score > alpha {
|
||||
bound = Bound::Exact;
|
||||
alpha = score;
|
||||
}
|
||||
}
|
||||
@@ -79,7 +75,7 @@ pub fn negamax(
|
||||
return Ok(SearchResult::new(None, 0));
|
||||
}
|
||||
|
||||
tt.insert(TTEntry::new(game.hash, depth, best_score, best_move, bound));
|
||||
game.tt.insert(TTEntry::new(game.hash, best_move));
|
||||
Ok(SearchResult::new(best_move, best_score))
|
||||
}
|
||||
|
||||
@@ -91,8 +87,6 @@ mod tests {
|
||||
use crate::movegen::r#move::Move;
|
||||
use crate::search::negamax::negamax;
|
||||
use crate::search::time::TimeInfo;
|
||||
use crate::search::transposition_table::TranspositionTable;
|
||||
use crate::search::MAX_TT_SIZE;
|
||||
|
||||
const FEN_MATE_IN_1: [&str; 2] = [
|
||||
"8/8/8/8/8/4q1k1/8/5K2 b - - 0 1",
|
||||
@@ -104,10 +98,9 @@ mod tests {
|
||||
init_attacks();
|
||||
let mut game = from_fen(FEN_MATE_IN_1[0]).unwrap();
|
||||
|
||||
let mut tt = TranspositionTable::new(MAX_TT_SIZE);
|
||||
let e3f2 = Move::new(Square::E3, Square::F2);
|
||||
let time_info = TimeInfo::new(std::time::Instant::now(), 1000);
|
||||
let anointed_move = negamax(&mut game, MIN_SCORE, MAX_SCORE, 2, 0, &time_info, &mut tt)
|
||||
let anointed_move = negamax(&mut game, MIN_SCORE, MAX_SCORE, 2, 0, &time_info)
|
||||
.expect("Expected a search result")
|
||||
.best_move
|
||||
.expect("Expected a move");
|
||||
@@ -117,7 +110,7 @@ mod tests {
|
||||
let mut game = from_fen(FEN_MATE_IN_1[1]).unwrap();
|
||||
|
||||
let e3f2 = Move::new(Square::E3, Square::F2);
|
||||
let anointed_move = negamax(&mut game, MIN_SCORE, MAX_SCORE, 2, 0, &time_info, &mut tt)
|
||||
let anointed_move = negamax(&mut game, MIN_SCORE, MAX_SCORE, 2, 0, &time_info)
|
||||
.expect("Expected a search result")
|
||||
.best_move
|
||||
.expect("Expected a move");
|
||||
|
||||
Reference in New Issue
Block a user