aboutsummaryrefslogtreecommitdiff
path: root/src/grossmeister/search.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-09-04 06:32:17 +0300
committereug-vs <eugene@eug-vs.xyz>2023-09-04 06:32:17 +0300
commit30326ce2dafb57fd1b6b46b8e7561383ed404641 (patch)
tree157f2f10ee856ba04a3a1796e8ec3dfca339f968 /src/grossmeister/search.rs
parentcc3f6674fa1662626a95995b32890c8ddd6255a0 (diff)
downloadchessnost-30326ce2dafb57fd1b6b46b8e7561383ed404641.tar.gz
feat: add grain of 1cp to the score
Diffstat (limited to 'src/grossmeister/search.rs')
-rw-r--r--src/grossmeister/search.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/grossmeister/search.rs b/src/grossmeister/search.rs
index d3dc0b4..455fb6f 100644
--- a/src/grossmeister/search.rs
+++ b/src/grossmeister/search.rs
@@ -2,9 +2,9 @@ use std::f32::INFINITY;
use crate::{moves::{Move, MoveKind}, board::io::IO};
-use super::{Grossmeister, ttable::{NodeType, TTABLE_SIZE, TranspositionTableItem}};
+use super::{Grossmeister, ttable::{NodeType, TTABLE_SIZE, TranspositionTableItem}, evaluation::Score};
-const SCORE_MATE: f32 = 20_000.0;
+const SCORE_MATE: Score = 20_000.0;
#[derive(Debug, Default, PartialEq)]
pub struct PerftResult {
@@ -18,9 +18,9 @@ pub struct PerftResult {
impl Grossmeister {
// Mate distance pruning
// If a non-zero value (mating score) is returned, branch could be safely pruned
- pub fn MDP(alpha: &mut f32, beta: &mut f32, root_distance: u8) -> f32 {
+ pub fn MDP(alpha: &mut Score, beta: &mut Score, root_distance: u8) -> Score {
{ // Update bound in case we are winning
- let mating_score = SCORE_MATE - root_distance as f32;
+ let mating_score = SCORE_MATE - root_distance as Score;
if mating_score < *beta {
*beta = mating_score;
if *alpha >= mating_score {
@@ -29,7 +29,7 @@ impl Grossmeister {
}
}
{ // Update bound in case we are losing
- let mating_score = -SCORE_MATE + root_distance as f32;
+ let mating_score = -SCORE_MATE + root_distance as Score;
if mating_score > *alpha {
*alpha = mating_score;
if *beta <= mating_score {
@@ -40,7 +40,7 @@ impl Grossmeister {
0.0
}
- pub fn negamax_search(&mut self, mut alpha: f32, mut beta: f32, depth_left: u8, root_distance: u8) -> (f32, Vec<Move>) {
+ pub fn negamax_search(&mut self, mut alpha: Score, mut beta: Score, depth_left: u8, root_distance: u8) -> (Score, Vec<Move>) {
let mut principal_variation = Vec::new();
let color = self.board.color();
@@ -163,7 +163,7 @@ impl Grossmeister {
if !legal_move_found {
if self.board.is_king_in_check(color) {
- return (-SCORE_MATE + root_distance as f32, principal_variation);
+ return (-SCORE_MATE + root_distance as Score, principal_variation);
} else {
return (0.0, principal_variation);
}
@@ -172,7 +172,7 @@ impl Grossmeister {
(alpha, principal_variation)
}
- pub fn quiscence(&mut self, mut alpha: f32, mut beta: f32, root_distance: u8) -> f32 {
+ pub fn quiscence(&mut self, mut alpha: Score, mut beta: Score, root_distance: u8) -> Score {
let color = self.board.color();
if self.board.threefold_repetition() {
@@ -227,13 +227,13 @@ impl Grossmeister {
}
if !legal_move_found && self.board.is_king_in_check(color) {
- return -SCORE_MATE + root_distance as f32
+ return -SCORE_MATE + root_distance as Score
}
alpha
}
- pub fn iterative_deepening(&mut self, max_depth: u8) -> Option<(f32, Vec<Move>)> {
+ pub fn iterative_deepening(&mut self, max_depth: u8) -> Option<(Score, Vec<Move>)> {
let mut result = None;
let mut depth = 1;
let mut alpha = -INFINITY;
@@ -291,7 +291,7 @@ impl Grossmeister {
println!();
// If our score is mate in N, we break at depth N
- if depth as f32 >= SCORE_MATE - search_result.0.abs() {
+ if depth as Score >= SCORE_MATE - search_result.0.abs() {
result = Some(search_result);
break;
}