aboutsummaryrefslogtreecommitdiff
path: root/src/grossmeister/move_selector.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2024-01-25 11:24:36 +0100
committereug-vs <eugene@eug-vs.xyz>2024-01-25 11:24:36 +0100
commit746e3bf17463a377b6c54b291ebef9a736d6ceb7 (patch)
treea4e965669871084b98d3ce89ac95fa9d50131699 /src/grossmeister/move_selector.rs
parent299c6d6dee96a50f9366955192f922d449d11f20 (diff)
downloadchessnost-canary.tar.gz
chore: autoformat codecanary
Use #[rustfmt:skip] to preserve aligned blocks
Diffstat (limited to 'src/grossmeister/move_selector.rs')
-rw-r--r--src/grossmeister/move_selector.rs66
1 files changed, 37 insertions, 29 deletions
diff --git a/src/grossmeister/move_selector.rs b/src/grossmeister/move_selector.rs
index 08e5cf1..debaba5 100644
--- a/src/grossmeister/move_selector.rs
+++ b/src/grossmeister/move_selector.rs
@@ -1,8 +1,8 @@
use smallvec::SmallVec;
-use crate::{moves::Move, board::{Board, move_generation::MoveList}};
+use crate::{board::move_generation::MoveList, moves::Move};
-use super::{Grossmeister, ttable::NodeType};
+use super::{ttable::NodeType, Grossmeister};
pub type ScoredMove = (Move, f32);
pub type ScoredMoveList = SmallVec<[ScoredMove; 128]>;
@@ -28,7 +28,7 @@ impl Iterator for ScoredMoveIter {
}
self.index += 1;
- return Some(self.moves[self.index - 1])
+ return Some(self.moves[self.index - 1]);
}
None
}
@@ -65,7 +65,7 @@ impl MoveGenStage {
MoveGenStage::WinningOrEqualTactical => MoveGenStage::Killer,
MoveGenStage::Killer => MoveGenStage::Quiet,
MoveGenStage::Quiet => MoveGenStage::LosingTactical,
- MoveGenStage::LosingTactical => todo!()
+ MoveGenStage::LosingTactical => todo!(),
}
}
}
@@ -96,17 +96,21 @@ impl Grossmeister {
/// Register killer for ply-before
pub fn register_killer(&mut self, killer: Move) {
if self.board.ply > 1 {
- let parent_killers = &mut self.move_selectors[(self.board.ply - 2) as usize].killer_moves;
+ let parent_killers =
+ &mut self.move_selectors[(self.board.ply - 2) as usize].killer_moves;
match parent_killers.iter().find(|m| **m == killer) {
None => {
parent_killers.push(killer);
- debug_assert!(!parent_killers.spilled(), "Killer move list should remain on the stack");
+ debug_assert!(
+ !parent_killers.spilled(),
+ "Killer move list should remain on the stack"
+ );
// We want to have max 3 killers, so if we exceed the limit remove the oldest killer
if parent_killers.len() > 3 {
parent_killers.remove(0);
}
}
- Some(..) => {},
+ Some(..) => {}
}
}
}
@@ -117,22 +121,17 @@ impl Grossmeister {
if m.is_tactical() {
let [source_eval, target_eval] = [m.source, m.target]
.map(|sq| self.board.piece_by_square(sq))
- .map(|p| {
- match p {
- Some(p) => p.static_eval(),
- None => 0.,
- }
+ .map(|p| match p {
+ Some(p) => p.static_eval(),
+ None => 0.,
});
- return 2. * target_eval - source_eval
+ return 2. * target_eval - source_eval;
}
0.0
}
pub fn score_moves(&self, movelist: MoveList) -> ScoredMoveList {
- movelist
- .iter()
- .map(|&m| (m, self.eval_move(m)))
- .collect()
+ movelist.iter().map(|&m| (m, self.eval_move(m))).collect()
}
pub fn next_tactical(&mut self) -> Option<Move> {
@@ -146,10 +145,7 @@ impl Grossmeister {
}
fn init_stage(&mut self, moves: ScoredMoveList) {
- self.move_selector().stage_moves = ScoredMoveIter {
- moves,
- index: 0,
- }
+ self.move_selector().stage_moves = ScoredMoveIter { moves, index: 0 }
}
/// TODO: next stage
@@ -168,7 +164,7 @@ impl Grossmeister {
if let Some(transposition) = self.transposition() {
if transposition.node_type != NodeType::All {
if let Some(mov) = transposition.mov {
- return Some(mov)
+ return Some(mov);
}
}
}
@@ -181,8 +177,10 @@ impl Grossmeister {
self.move_selector().tactical_moves = self.score_moves(moves);
// But we only care about current stage now
- let new_stage =
- self.move_selector().tactical_moves.iter()
+ let new_stage = self
+ .move_selector()
+ .tactical_moves
+ .iter()
.filter(|(_, score)| *score >= 0.0)
.copied()
.collect();
@@ -197,9 +195,17 @@ impl Grossmeister {
}
MoveGenStage::Killer => {
if self.move_selector().stage_moves.moves.is_empty() {
- let new_stage = self.move_selector().killer_moves.clone()
+ let new_stage = self
+ .move_selector()
+ .killer_moves
+ .clone()
.iter()
- .filter(|&m| self.move_selector().tactical_moves.iter().any(|(m2, _)| m2 == m)) // Test if killer is in the movelist
+ .filter(|&m| {
+ self.move_selector()
+ .tactical_moves
+ .iter()
+ .any(|(m2, _)| m2 == m)
+ }) // Test if killer is in the movelist
.map(|&m| (m, 0.0))
.collect();
self.init_stage(new_stage);
@@ -223,8 +229,10 @@ impl Grossmeister {
}
MoveGenStage::LosingTactical => {
if self.move_selector().stage_moves.moves.is_empty() {
- let new_stage =
- self.move_selector().tactical_moves.iter()
+ let new_stage = self
+ .move_selector()
+ .tactical_moves
+ .iter()
.filter(|(_, score)| *score < 0.0)
.copied()
.collect();
@@ -232,7 +240,7 @@ impl Grossmeister {
}
match self.move_selector().stage_moves.next() {
Some((mov, _)) => return Some(mov),
- None => return None
+ None => return None,
}
}
}