|
@@ -74,7 +74,6 @@ pub fn search(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut alp
|
|
}
|
|
}
|
|
|
|
|
|
let mut moves = generate_legal_moves(game, game.turn);
|
|
let mut moves = generate_legal_moves(game, game.turn);
|
|
- let mut rng = rand::thread_rng();
|
|
|
|
let ply_depth = (sc.initial_depth - depth) as usize;
|
|
let ply_depth = (sc.initial_depth - depth) as usize;
|
|
sort_moves(game, hash, &sc.killer_moves[ply_depth], &mut moves);
|
|
sort_moves(game, hash, &sc.killer_moves[ply_depth], &mut moves);
|
|
|
|
|
|
@@ -92,45 +91,29 @@ pub fn search(game: &mut Game, sc: &mut SearchControl, hash: &mut Cache, mut alp
|
|
|
|
|
|
for mov in moves {
|
|
for mov in moves {
|
|
let undo = game.apply(mov);
|
|
let undo = game.apply(mov);
|
|
- //assert_eq!(new_game, *game, );
|
|
|
|
|
|
|
|
- //info!("searching {}", mov.to_string());
|
|
|
|
let val = -negamax(game, sc, hash, decrease_mate_in(-beta), decrease_mate_in(-alpha), depth - 1);
|
|
let val = -negamax(game, sc, hash, decrease_mate_in(-beta), decrease_mate_in(-alpha), depth - 1);
|
|
|
|
+
|
|
game.undo_move(undo);
|
|
game.undo_move(undo);
|
|
|
|
|
|
if sc.stopping {
|
|
if sc.stopping {
|
|
- //return (Move::default(), 0);
|
|
|
|
cancelled = true;
|
|
cancelled = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- if val >= mate_in_p1(1) {
|
|
|
|
- // mate in 1 --- can't get better than that
|
|
|
|
- info!("yay mate!");
|
|
|
|
- //return SearchResult::Finished(mov, increase_mate_in(val));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //info!("searched {} -> {}", mov.to_string(), val);
|
|
|
|
-
|
|
|
|
if increase_mate_in(val) > alpha {
|
|
if increase_mate_in(val) > alpha {
|
|
alpha = increase_mate_in(val) - ALPHA_OFFSET;
|
|
alpha = increase_mate_in(val) - ALPHA_OFFSET;
|
|
valued_moves.push((mov, -alpha));
|
|
valued_moves.push((mov, -alpha));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //info!("movvalues: {:?}", valued_moves.iter().map(|mv| mv.0.to_string() + " - " + &mv.1.to_string()).collect::<Vec<String>>());
|
|
|
|
-
|
|
|
|
valued_moves.sort_by_key(|mv| mv.1);
|
|
valued_moves.sort_by_key(|mv| mv.1);
|
|
|
|
|
|
- //info!("best movvalues: {:?}", valued_moves.iter().map(|mv| mv.0.to_string() + " - " + &mv.1.to_string()).collect::<Vec<String>>());
|
|
|
|
-
|
|
|
|
if valued_moves.len() > 0 {
|
|
if valued_moves.len() > 0 {
|
|
let min_val = valued_moves[0].1;
|
|
let min_val = valued_moves[0].1;
|
|
let best_moves = valued_moves.iter().filter(|mv| mv.1 == min_val).collect::<Vec<&(Move, PosValue)>>();
|
|
let best_moves = valued_moves.iter().filter(|mv| mv.1 == min_val).collect::<Vec<&(Move, PosValue)>>();
|
|
|
|
|
|
- //info!("bestmove value {}", -min_val);
|
|
|
|
|
|
+ let mut rng = rand::thread_rng();
|
|
let chosen_mov = best_moves[(rng.next_u64() % best_moves.len() as u64) as usize];
|
|
let chosen_mov = best_moves[(rng.next_u64() % best_moves.len() as u64) as usize];
|
|
if cancelled {
|
|
if cancelled {
|
|
return SearchResult::Cancelled(Some((chosen_mov.0, -chosen_mov.1)));
|
|
return SearchResult::Cancelled(Some((chosen_mov.0, -chosen_mov.1)));
|