Skip to content

Commit

Permalink
Add SEE bench
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes committed May 13, 2024
1 parent 525a577 commit f3ed968
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ harness = false
[[bench]]
name = "eval"
harness = false

[[bench]]
name = "see"
harness = false
33 changes: 33 additions & 0 deletions benches/see.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use camel::{
moves::gen::MoveStage,
position::{fen::FromFen, Position},
search::see,
};
use criterion::{criterion_group, criterion_main, Criterion};

fn see_1(c: &mut Criterion) {
let position =
Position::from_fen("rnbqkb1r/1p1p1ppp/p3pn2/8/2PNP3/8/PP3PPP/RNBQKB1R w KQkq - 1 6")
.unwrap();
let moves = position.moves(MoveStage::All);
let mov = moves.iter().find(|mov| mov.to_string() == "d4e6").unwrap();

c.bench_function("see_1", |b| {
b.iter(|| see::see::<false>(*mov, &position.board));
});
}

fn see_2(c: &mut Criterion) {
let position =
Position::from_fen("rnbqkb1r/1p1p1ppp/p3p3/8/2PNn3/2N5/PP3PPP/R1BQKB1R w KQkq - 0 7")
.unwrap();
let moves = position.moves(MoveStage::All);
let mov = moves.iter().find(|mov| mov.to_string() == "c3e4").unwrap();

c.bench_function("see_2", |b| {
b.iter(|| see::see::<false>(*mov, &position.board));
});
}

criterion_group!(see, see_1, see_2,);
criterion_main!(see);
10 changes: 5 additions & 5 deletions src/search/see.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ pub fn see<const RETURN_EARLY: bool>(mov: Move, board: &Board) -> ValueScore {
}

// We need an auxiliary board to perform the search.
// We also store the max score when it is our turn.
// We also store a standing pat when it is our turn to move.
let mut board = *board;
let mut max_score = ValueScore::MIN;
let mut stand_pat = ValueScore::MIN;

// Make our move.
let mut on_square = piece;
Expand All @@ -41,8 +41,8 @@ pub fn see<const RETURN_EARLY: bool>(mov: Move, board: &Board) -> ValueScore {
if RETURN_EARLY && score >= 0 {
return score;
}
max_score = max_score.max(score);
} else if RETURN_EARLY && score < 0 {
stand_pat = stand_pat.max(score);
} else if RETURN_EARLY && score <= 0 {
return score;
}

Expand All @@ -66,7 +66,7 @@ pub fn see<const RETURN_EARLY: bool>(mov: Move, board: &Board) -> ValueScore {
}
}

max_score.max(score)
stand_pat.max(score)
}

#[cfg(test)]
Expand Down

0 comments on commit f3ed968

Please sign in to comment.