-
Notifications
You must be signed in to change notification settings - Fork 1
/
alpha_beta_benchmark.rs
52 lines (46 loc) · 1.66 KB
/
alpha_beta_benchmark.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use chess::alpha_beta_searcher::{alpha_beta_search, SearchContext};
use chess::board::castle_rights_bitmask::ALL_CASTLE_RIGHTS;
use chess::board::color::Color;
use chess::board::piece::Piece;
use chess::board::Board;
use chess::chess_position;
use chess::evaluate::{self, GameEnding};
use chess::move_generator::MoveGenerator;
use common::bitboard::bitboard::Bitboard;
use criterion::{criterion_group, criterion_main, Criterion};
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("alpha beta mate in 2", |b| {
b.iter(find_alpha_beta_mate_in_2)
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
fn find_alpha_beta_mate_in_2() {
let mut search_context = SearchContext::new(2);
let mut move_generator = MoveGenerator::new();
let mut board = chess_position! {
....r..k
....q...
........
........
........
........
.....PPP
R.....K.
};
board.set_turn(Color::Black);
board.lose_castle_rights(ALL_CASTLE_RIGHTS);
let move1 = alpha_beta_search(&mut search_context, &mut board, &mut move_generator).unwrap();
move1.apply(&mut board).unwrap();
board.toggle_turn();
let move2 = alpha_beta_search(&mut search_context, &mut board, &mut move_generator).unwrap();
move2.apply(&mut board).unwrap();
board.toggle_turn();
let move3 = alpha_beta_search(&mut search_context, &mut board, &mut move_generator).unwrap();
move3.apply(&mut board).unwrap();
let current_turn = board.toggle_turn();
matches!(
evaluate::game_ending(&mut board, &mut move_generator, current_turn),
Some(GameEnding::Checkmate)
);
}