Move make/unmake and History on Game

This commit is contained in:
stefiosif
2024-09-15 18:38:32 +03:00
parent 3383435af7
commit f128b35252
8 changed files with 172 additions and 159 deletions

View File

@@ -26,16 +26,16 @@ pub fn negamax(
pseudo_legal_moves.sort_unstable_by_key(|mv| score_by_mvv_lva(&game.board, *mv));
for mv in pseudo_legal_moves {
game.board.make_move(&mv);
game.make_move(&mv);
if game.board.king_under_check(color) {
game.board.unmake_move();
game.unmake_move();
continue;
}
legal_moves += 1;
let move_score = -negamax(game, -beta, -alpha, depth - 1, plies + 1).1;
game.board.unmake_move();
game.unmake_move();
if move_score > best_score {
best_score = move_score;

View File

@@ -11,7 +11,7 @@ pub fn driver(game: &mut Game, nodes: &mut u64, depth: u8) {
for mv in pseudo_moves {
let original_board = game.board.clone();
game.board.make_move(&mv);
game.make_move(&mv);
if game.board.king_under_check(color) {
game.board = original_board;

View File

@@ -33,15 +33,15 @@ pub fn quiescence(game: &mut Game, mut alpha: i32, beta: i32) -> (Option<Move>,
captures.sort_unstable_by_key(|mv| score_by_mvv_lva(&game.board, *mv));
for mv in captures {
game.board.make_move(&mv);
game.make_move(&mv);
if game.board.king_under_check(color) {
game.board.unmake_move();
game.unmake_move();
continue;
}
let move_score = -quiescence(game, -beta, -alpha).1;
game.board.unmake_move();
game.unmake_move();
if move_score >= beta {
return (Some(mv), beta);