Skip to content

Commit

Permalink
added quiescent search
Browse files Browse the repository at this point in the history
  • Loading branch information
TierynnB committed Sep 24, 2024
1 parent df320e9 commit 076e48f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/conversion.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::board;
// use crate::board;
use crate::board::Board;
use crate::constants;
use crate::constants::BLACK;
Expand Down
61 changes: 52 additions & 9 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::board::Board;
use crate::constants::*;
use crate::conversion;
use crate::evaluate;
use crate::evaluate::evaluate;
use crate::movegen;
use crate::moves::*;
use std::time::Instant;
Expand Down Expand Up @@ -84,11 +85,7 @@ impl SearchEngine {
depth_distance: depth_distance,
});
}
fn get_position_from_tt(
&self,
position_hash: u64,
depth_distance: i8,
) -> Option<&TranspositionTableEntry> {
fn get_position_from_tt(&self, position_hash: u64) -> Option<&TranspositionTableEntry> {
for entry in self.transposition_table.iter() {
if entry.position_hash == position_hash {
return Some(entry);
Expand Down Expand Up @@ -169,15 +166,62 @@ impl SearchEngine {
return min_eval;
}
}
fn queiscence_search(board: &mut Board) {}
pub fn quiescence_search(&mut self, board: &mut Board, mut alpha: i32, beta: i32) -> i32 {
// if in check, return.
// if evaluate::is_in_check(board, board.side_to_move, None) {
// return evaluate(board);
// }

// if evaluate::is_in_check(board, board.side_to_move * -1, None) {
// return evaluate(board);
// }
// searches the captures available
let stand_pat = evaluate(board);
if stand_pat >= beta {
return beta;
}
if alpha < stand_pat {
alpha = stand_pat;
}

// generate moves for current depth of board
let mut moves_for_current_depth =
movegen::generate_pseudo_legal_moves(board, board.side_to_move, false);

order_moves(&mut moves_for_current_depth);

for generated_move in moves_for_current_depth.iter() {
if generated_move.to_piece == EMPTY {
continue;
}
if generated_move.to_piece == KING {
return alpha;
}

board.make_move(generated_move);
let score = -self.quiescence_search(board, -beta, -alpha);
board.un_make_move(generated_move);

if score >= beta {
return beta;
}

if score > alpha {
alpha = score;
}
}

return alpha;
}
pub fn alpha_beta(&mut self, board: &mut Board, depth: i8, mut alpha: i32, beta: i32) -> i32 {
let mut best_value = i32::MIN;
if depth == 0 {
self.nodes += 1;
return evaluate::evaluate(&board);
return self.quiescence_search(board, alpha, beta); //
// return evaluate::evaluate(&board);
};

if let Some(entry) = self.get_position_from_tt(conversion::hash_board_state(board), depth) {
if let Some(entry) = self.get_position_from_tt(conversion::hash_board_state(board)) {
return entry.position_terminal_score;
}

Expand All @@ -189,7 +233,6 @@ impl SearchEngine {
for generated_move in moves_for_current_depth.iter() {
board.make_move(generated_move);

// negative alpha becomes the beta of the other player
let eval = -self.alpha_beta(board, depth - 1, -beta, -alpha);

// let position_hash = conversion::hash_board_state(board);
Expand Down

0 comments on commit 076e48f

Please sign in to comment.