aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-01-29 03:26:39 +0300
committereug-vs <eugene@eug-vs.xyz>2023-01-29 03:26:39 +0300
commit482cea1ebd9a43963fe0160fd081c97367534b7a (patch)
tree9ebf239ff8eaf9b6c0beb4c35a562cb4fd9daa57
parent0d8860bd88c49641093434d2f96299b27a0ff641 (diff)
downloadchessnost-482cea1ebd9a43963fe0160fd081c97367534b7a.tar.gz
fix: correclty count legal moves
-rw-r--r--src/board/engine.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs
index 2ebbd7d..a710efb 100644
--- a/src/board/engine.rs
+++ b/src/board/engine.rs
@@ -267,6 +267,7 @@ impl Board {
return (self.quiscence(alpha, beta), principal_variation);
}
+ 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();
@@ -274,6 +275,7 @@ impl Board {
let captured_piece = self.make_move(mov);
if !self.is_king_in_check(color) {
+ legal_move_found = true;
let (mut score, mut subtree_pv) = self.negamax_search(-beta, -alpha, depth_left - 1, deadline);
score *= -1.;
self.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before);
@@ -321,7 +323,7 @@ impl Board {
}
}
- if principal_variation.len() == 0 {
+ if !legal_move_found {
if self.is_king_in_check(color) {
return (-VALUE_WIN, principal_variation);
}