Add uci movetime, hash and initialize TT based on size in MBs

This commit is contained in:
stefiosif
2025-02-04 23:53:18 +02:00
parent 908a87bd26
commit b98100aa71
5 changed files with 75 additions and 23 deletions

View File

@@ -1,5 +1,7 @@
use crate::{board::zobrist::ZobristHash, movegen::r#move::Move};
use super::TT_SIZE_IN_MB;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct TranspositionTable {
positions: Vec<Option<TTEntry>>,
@@ -7,10 +9,17 @@ pub struct TranspositionTable {
}
impl TranspositionTable {
pub fn new(size: u64) -> Self {
pub fn new() -> Self {
Self::new_with_mb_size(TT_SIZE_IN_MB)
}
pub fn new_with_mb_size(size_in_mega_bytes: usize) -> Self {
let size_in_bytes = size_in_mega_bytes * 1024 * 1024;
let num_of_entries = size_in_bytes / std::mem::size_of::<TTEntry>();
Self {
positions: vec![None; size as usize],
size,
positions: vec![None; num_of_entries],
size: num_of_entries as u64,
}
}
@@ -66,7 +75,7 @@ mod tests {
board::fen::from_fen,
evaluation::{MAX_SCORE, MIN_SCORE},
movegen::attack_generator::init_attacks,
search::{negamax::negamax, time::TimeInfo},
search::{negamax::negamax, time::TimeInfo, INC, TIME},
};
const FEN: &str = "1r2k2r/2P1pq1p/2npb3/1p3ppP/p3P3/P2B1Q2/1P1PNPP1/R3K2R w KQk g6 0 1";
@@ -77,10 +86,10 @@ mod tests {
fn test_transposition_table() -> anyhow::Result<()> {
init_attacks();
let mut game = from_fen(FEN).unwrap();
let time_info = TimeInfo::new(std::time::Instant::now(), 30000, 100);
let time_info = TimeInfo::new(std::time::Instant::now(), TIME, INC);
negamax(
&mut game, MIN_SCORE, MAX_SCORE, 2, 0, &time_info, &mut 0, true,
&mut game, MIN_SCORE, MAX_SCORE, 3, 0, &time_info, &mut 0, true,
)
.expect("Expected a search result");