Skip to content

Commit 1a885eb

Browse files
committed
Merge branch 'master' into feature/tui
2 parents 5b3e9e7 + aab5b94 commit 1a885eb

33 files changed

Lines changed: 1482 additions & 1771 deletions

Cargo.lock

Lines changed: 404 additions & 682 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "check-buddy"
3-
description = "Check buddy is a chess engine"
3+
description = "A WIP chess engine written in Rust."
44
license-file = "LICENSE.md"
5-
version = "0.1.0"
5+
version = "0.2.3"
66
edition = "2021"
77
authors = ["Ramon van Sprundel <ramonvansprundel@gmail.com>"]
88
categories = ["chess", "chess-engine", "gui"]
@@ -11,7 +11,7 @@ categories = ["chess", "chess-engine", "gui"]
1111
members = ["crates/*"]
1212

1313
[dependencies]
14-
check-buddy-core = { path = "crates/check-buddy-core", version = "0.1" }
14+
check-buddy-core = { path = "crates/check-buddy-core", version = "0.2.3" }
1515

1616
[profile.dev.package."*"]
1717
opt-level = 3
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
- [x] next move check
1616
- [x] illegal moves
1717
- [x] en passant
18+
- [x] castling
1819
- [ ] pawn trade
1920
- [ ] win check
20-
- [ ] fem string
21+
- [x] FEN string
2122
- [x] from
22-
- [ ] to
23+
- [x] to

crates/check-buddy-core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "check-buddy-core"
33
description = "The core system of check buddy, a chess engine"
44
license-file = "LICENSE.md"
5-
version = "0.1.0"
5+
version = "0.2.3"
66
edition = "2021"
77
authors = ["Ramon van Sprundel <ramonvansprundel@gmail.com>"]
88
categories = ["chess", "chess-engine"]
@@ -13,7 +13,7 @@ anyhow = "1"
1313
thiserror = "1"
1414

1515
[dev-dependencies]
16-
criterion = "0.4"
16+
criterion = "0.5"
1717
calamine = "0.19"
1818
csv = "1.1"
1919

crates/check-buddy-core/benches/generate_moves.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn generate_moves(c: &mut Criterion) {
66
let board = BoardMap::starting();
77
let mut group = c.benchmark_group("generate_moves");
88
group.bench_function("single_move", |b| {
9-
b.iter(|| board.gen_moves(black_box([0, 0])))
9+
b.iter(|| board.gen_to_positions(black_box([0, 0])))
1010
});
1111
group.bench_function("opponent_moves", |b| {
1212
b.iter(|| board.gen_all_opponent_positions())
@@ -15,7 +15,7 @@ fn generate_moves(c: &mut Criterion) {
1515
b.iter(|| {
1616
(0..8).flat_map(|rank| {
1717
(0..8)
18-
.map(|file| board.gen_moves(black_box([rank, file])))
18+
.map(|file| board.gen_to_positions(black_box([rank, file])))
1919
.collect::<Vec<_>>()
2020
})
2121
})

crates/check-buddy-core/src/algorithm.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(unused_must_use)]
2-
use crate::piece_move::PieceMove;
3-
use crate::{BoardMap, PieceColor};
2+
use crate::piece_color::PieceColor;
3+
use crate::position_move::PositionMove;
4+
use crate::BoardMap;
45
use rand::Rng;
56

67
#[derive(Default, Clone)]
@@ -10,17 +11,17 @@ impl ChessEngine {
1011
const MIN: f32 = -1000.;
1112
const MAX: f32 = 1000.;
1213

13-
pub fn find_best_move_minimax_ab(&mut self, board: BoardMap, depth: usize) -> PieceMove {
14+
pub fn find_best_move_minimax_ab(&mut self, board: BoardMap, depth: usize) -> PositionMove {
1415
let mut best_value = Self::MIN;
1516
let mut best_moves = vec![];
1617
for from in board.get_active_pieces() {
1718
let moves = board.gen_legal_positions(from);
1819
for to in moves {
19-
let piece_move = PieceMove::new(from, to);
20+
let piece_move = PositionMove::new(from, to);
2021
let piece_value = board.get_piece(from).0;
2122
let mut temp_board = board;
2223

23-
temp_board.move_turn(piece_move);
24+
temp_board.single_move_turn(piece_move);
2425
let move_value =
2526
self.ab_max(depth, temp_board, ChessEngine::MIN, ChessEngine::MAX, true);
2627
temp_board.undo_move(piece_move, piece_value);
@@ -49,17 +50,17 @@ impl ChessEngine {
4950
best_moves[index]
5051
}
5152

52-
pub fn find_best_move_negamax(&mut self, board: BoardMap, depth: usize) -> PieceMove {
53+
pub fn find_best_move_negamax(&mut self, board: BoardMap, depth: usize) -> PositionMove {
5354
let mut best_value = Self::MIN;
5455
let mut best_moves = vec![];
5556
for from in board.get_active_pieces() {
5657
let moves = board.gen_legal_positions(from);
5758
for to in moves {
58-
let piece_move = PieceMove::new(from, to);
59+
let piece_move = PositionMove::new(from, to);
5960
let piece_value = board.get_piece(from).0;
6061

6162
let mut temp_board = board;
62-
temp_board.move_turn(piece_move);
63+
temp_board.single_move_turn(piece_move);
6364
let move_value = self.nega_max(temp_board, depth);
6465
temp_board.undo_move(piece_move, piece_value);
6566

@@ -96,7 +97,7 @@ impl ChessEngine {
9697
mut beta: f32,
9798
is_maximizing_player: bool,
9899
) -> f32 {
99-
return if is_maximizing_player {
100+
if is_maximizing_player {
100101
// AB MAX
101102
if depth == 0 {
102103
return self.evaluate(board);
@@ -108,7 +109,7 @@ impl ChessEngine {
108109

109110
let piece_value = board.get_piece(piece_move.from).0;
110111

111-
temp_board.move_turn(*piece_move);
112+
temp_board.single_move_turn(*piece_move);
112113
let score = self.ab_max(depth - 1, temp_board, alpha, beta, !is_maximizing_player);
113114
temp_board.undo_move(*piece_move, piece_value);
114115

@@ -132,7 +133,7 @@ impl ChessEngine {
132133

133134
let piece_value = board.get_piece(piece_move.from).0;
134135

135-
temp_board.move_turn(*piece_move);
136+
temp_board.single_move_turn(*piece_move);
136137
let score = self.ab_max(depth - 1, temp_board, alpha, beta, !is_maximizing_player);
137138
temp_board.undo_move(*piece_move, piece_value);
138139

@@ -144,7 +145,7 @@ impl ChessEngine {
144145
}
145146
}
146147
beta
147-
};
148+
}
148149
}
149150

150151
fn nega_max(&mut self, board: BoardMap, depth: usize) -> f32 {
@@ -156,7 +157,7 @@ impl ChessEngine {
156157

157158
for piece_move in moves.iter() {
158159
let mut temp_board = board;
159-
temp_board.move_turn(*piece_move);
160+
temp_board.single_move_turn(*piece_move);
160161

161162
let value = -self.nega_max(board, depth - 1);
162163
if value > max {

0 commit comments

Comments
 (0)