aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-02-14 17:45:10 +0300
committereug-vs <eugene@eug-vs.xyz>2023-02-14 17:45:10 +0300
commitfa6f6c3f5f8f872a216ccdb593492775c0d265a1 (patch)
tree85bb3c711d2774b131601887a90496766e3258d8 /src
parentcae14cd6f19c40be2c30b638a51a02c4da0959ea (diff)
downloadchessnost-stable.tar.gz
feat: consider checks in quiscencestable
Diffstat (limited to 'src')
-rw-r--r--src/board/engine.rs40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs
index 46cf8ed..1516784 100644
--- a/src/board/engine.rs
+++ b/src/board/engine.rs
@@ -472,26 +472,36 @@ impl Board {
let mut moves = self.generate_pseudolegal_moves(color);
moves = self.order_moves(moves, Vec::new());
- let stand_pat = self.evaluate();
+ if !self.is_king_in_check(color) {
+ // If we are not in check, we can evaluate stand pat
+ let stand_pat = self.evaluate();
- if stand_pat >= beta {
- return beta;
- }
- if alpha < stand_pat {
- alpha = stand_pat;
- }
+ if stand_pat >= beta {
+ return beta;
+ }
+ if alpha < stand_pat {
+ alpha = stand_pat;
+ }
- let tactical_moves = moves.iter().filter(|m| m.is_tactical());
+ // If we are not in check, we can only search tactical moves
+ moves = moves
+ .iter()
+ .filter(|m| m.is_tactical())
+ .map(|m| *m)
+ .collect()
+ }
- for mov in tactical_moves {
+ let mut legal_move_found = false;
+ for mov in moves {
let ep_target_before = self.ep_target.clone();
let castling_rights_before = self.castling_rights.clone();
let hash_before = self.hash.clone();
- let captured_piece = self.make_move(*mov);
+ let captured_piece = self.make_move(mov);
if !self.is_king_in_check(color) {
+ legal_move_found = true;
let evaluation = -self.quiscence(-beta, -alpha);
- self.unmake_move(*mov, captured_piece, ep_target_before, castling_rights_before, hash_before);
+ self.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before);
if evaluation >= beta {
return beta; // Fail-hard beta-cutoff
@@ -500,7 +510,13 @@ impl Board {
alpha = evaluation;
}
} else {
- self.unmake_move(*mov, captured_piece, ep_target_before, castling_rights_before, hash_before);
+ self.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before);
+ }
+ }
+
+ if !legal_move_found {
+ if self.is_king_in_check(color) {
+ return -VALUE_WIN
}
}