|
@@ -24,6 +24,7 @@ pub struct SearchControl {
|
|
|
|
|
|
pub board: Board,
|
|
|
pub hash: Arc<RwLock<Cache>>,
|
|
|
+ pub move_history: Arc<RwLock<RepetitionTable>>,
|
|
|
|
|
|
/// depth the current iteration was started at
|
|
|
initial_depth: i32,
|
|
@@ -64,11 +65,12 @@ pub enum SearchResult {
|
|
|
}
|
|
|
|
|
|
impl SearchControl {
|
|
|
- pub fn new(board: &Board, stop_channel: mpsc::Receiver<SearchMessage>, hash: Arc<RwLock<Cache>>) -> Self {
|
|
|
+ pub fn new(board: &Board, stop_channel: mpsc::Receiver<SearchMessage>, hash: Arc<RwLock<Cache>>, move_history: Arc<RwLock<RepetitionTable>>) -> Self {
|
|
|
SearchControl {
|
|
|
nodes: 0,
|
|
|
board: board.clone(),
|
|
|
hash,
|
|
|
+ move_history,
|
|
|
killer_moves: Vec::new(),
|
|
|
last_move: None,
|
|
|
countermoves: Arc::new(Mutex::new(CountermoveTable::new())),
|
|
@@ -316,10 +318,16 @@ pub fn search(mut board: Board, sc: &mut SearchControl, hashs: Arc<RwLock<Cache>
|
|
|
for mov in moves {
|
|
|
let undo = board.apply(mov);
|
|
|
|
|
|
- let val = increase_mate_in(
|
|
|
+
|
|
|
+ let mut val = increase_mate_in(
|
|
|
-negamax(&mut board, sc, &mut hash, decrease_mate_in(-beta), decrease_mate_in(-alpha), depth - 1)
|
|
|
);
|
|
|
|
|
|
+ if sc.move_history.read().unwrap().lookup(board.zobrist.as_ref().unwrap().1) >= 2 {
|
|
|
+ println!("mov {} hit", mov.to_string());
|
|
|
+ val = 0;
|
|
|
+ }
|
|
|
+
|
|
|
//info!("moveval {} -> {}\n", mov.to_string(), val);
|
|
|
|
|
|
board.undo_move(undo);
|
|
@@ -372,7 +380,11 @@ pub fn negamax(game: &mut Board, sc: &mut SearchControl, hash: &mut Cache, mut a
|
|
|
if e.depth() as i32 >= depth {
|
|
|
//println!("TABLE HIT!");
|
|
|
match e.entry_type {
|
|
|
- EntryType::Value => { return e.value(); },
|
|
|
+ EntryType::Value => {
|
|
|
+ if e.halfmove_age as u16 != sc.halfmove_age {
|
|
|
+ return e.value();
|
|
|
+ }
|
|
|
+ },
|
|
|
EntryType::LowerBound => {
|
|
|
if e.value() >= beta { return beta; }
|
|
|
},
|
|
@@ -487,6 +499,11 @@ pub fn negamax(game: &mut Board, sc: &mut SearchControl, hash: &mut Cache, mut a
|
|
|
let mut val = increase_mate_in(
|
|
|
-negamax(game, sc, hash, -decrease_mate_in(beta), -decrease_mate_in(alpha), depth - 1 - reduce)
|
|
|
);
|
|
|
+
|
|
|
+ if depth > 3 && sc.move_history.read().unwrap().lookup(game.zobrist.as_ref().unwrap().1) >= 1 {
|
|
|
+ val = 0;
|
|
|
+ }
|
|
|
+
|
|
|
game.undo_move(undo);
|
|
|
sc.reductions_allowed = reductions_allowed_before;
|
|
|
|
|
@@ -644,6 +661,7 @@ impl SearchControl {
|
|
|
nodes: 0,
|
|
|
board: board.clone(),
|
|
|
hash: Arc::new(RwLock::new(Cache::new(0))),
|
|
|
+ move_history: Arc::new(RwLock::new(RepetitionTable::new())),
|
|
|
initial_depth: depth,
|
|
|
killer_moves: Vec::new(),
|
|
|
last_move: None,
|