aboutsummaryrefslogtreecommitdiff
path: root/src/grossmeister/search.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-02-23 13:21:57 +0300
committereug-vs <eugene@eug-vs.xyz>2023-02-23 14:01:19 +0300
commit43dc24718c442ef45f6cecf5790df0ab84a72cfc (patch)
tree16f446b1d5a3e0fdf638e0bcab16cf34ec338bd8 /src/grossmeister/search.rs
parentf60c573ba71207c18a28413e3940a4e21b07c73f (diff)
downloadchessnost-43dc24718c442ef45f6cecf5790df0ab84a72cfc.tar.gz
refactor: apply clippy suggestions
Diffstat (limited to 'src/grossmeister/search.rs')
-rw-r--r--src/grossmeister/search.rs73
1 files changed, 31 insertions, 42 deletions
diff --git a/src/grossmeister/search.rs b/src/grossmeister/search.rs
index 57ce672..3efa9f8 100644
--- a/src/grossmeister/search.rs
+++ b/src/grossmeister/search.rs
@@ -21,30 +21,27 @@ impl Grossmeister {
let mut killer_moves = Vec::new();
let color = self.board.color();
- match self.transposition() {
- Some(transposition) => {
- if transposition.depth == depth_left {
- match transposition.node_type {
- NodeType::PV => { // PV-nodes have exact score
+ if let Some(transposition) = self.transposition() {
+ if transposition.depth == depth_left {
+ match transposition.node_type {
+ NodeType::PV => { // PV-nodes have exact score
+ principal_variation.push(transposition.mov);
+ return (transposition.score, principal_variation);
+ }
+ NodeType::Cut => {
+ if transposition.score >= beta {
principal_variation.push(transposition.mov);
- return (transposition.score, principal_variation);
- }
- NodeType::Cut => {
- if transposition.score >= beta {
- principal_variation.push(transposition.mov);
- return (beta, principal_variation);
- }
+ return (beta, principal_variation);
}
- NodeType::All => {
- if transposition.score <= alpha {
- principal_variation.push(transposition.mov);
- return (alpha, principal_variation);
- }
+ }
+ NodeType::All => {
+ if transposition.score <= alpha {
+ principal_variation.push(transposition.mov);
+ return (alpha, principal_variation);
}
}
}
}
- None => {},
}
if depth_left == 0 {
@@ -57,9 +54,9 @@ impl Grossmeister {
let mut should_pv_search = true;
let mut legal_move_found = false;
for mov in moves {
- let ep_target_before = self.board.ep_target.clone();
- let castling_rights_before = self.board.castling_rights.clone();
- let hash_before = self.board.hash.clone();
+ let ep_target_before = self.board.ep_target;
+ let castling_rights_before = self.board.castling_rights;
+ let hash_before = self.board.hash;
let captured_piece = self.board.make_move(mov);
if !self.board.is_king_in_check(color) {
@@ -135,10 +132,8 @@ impl Grossmeister {
}
}
- if !legal_move_found {
- if self.board.is_king_in_check(color) {
- return (-VALUE_WIN, principal_variation);
- }
+ if !legal_move_found && self.board.is_king_in_check(color) {
+ return (-VALUE_WIN, principal_variation);
}
(alpha, principal_variation)
@@ -161,18 +156,14 @@ impl Grossmeister {
}
// If we are not in check, we can only search tactical moves
- moves = moves
- .iter()
- .filter(|m| m.is_tactical())
- .map(|m| *m)
- .collect()
+ moves.retain(|m| m.is_tactical())
}
let mut legal_move_found = false;
for mov in moves {
- let ep_target_before = self.board.ep_target.clone();
- let castling_rights_before = self.board.castling_rights.clone();
- let hash_before = self.board.hash.clone();
+ let ep_target_before = self.board.ep_target;
+ let castling_rights_before = self.board.castling_rights;
+ let hash_before = self.board.hash;
let captured_piece = self.board.make_move(mov);
if !self.board.is_king_in_check(color) {
@@ -191,10 +182,8 @@ impl Grossmeister {
}
}
- if !legal_move_found {
- if self.board.is_king_in_check(color) {
- return -VALUE_WIN
- }
+ if !legal_move_found && self.board.is_king_in_check(color) {
+ return -VALUE_WIN
}
alpha
@@ -252,7 +241,7 @@ impl Grossmeister {
continue;
}
- if search_result.1.len() > 0 {
+ if !search_result.1.is_empty() {
depth += 1;
gradual_widening_counter = 0;
alpha = search_result.0 - window_size;
@@ -265,7 +254,7 @@ impl Grossmeister {
}
match result {
- Some(r) => return r,
+ Some(r) => r,
None => panic!("Could not find a move in time"),
}
}
@@ -287,9 +276,9 @@ impl Grossmeister {
}
for mov in moves {
- let ep_target_before = self.board.ep_target.clone();
- let castling_rights_before = self.board.castling_rights.clone();
- let hash_before = self.board.hash.clone();
+ let ep_target_before = self.board.ep_target;
+ let castling_rights_before = self.board.castling_rights;
+ let hash_before = self.board.hash;
let captured_piece = self.board.make_move(mov);
// King can not be in check after our own move
if !self.board.is_king_in_check(color) {