Skip to content

Commit 53fa482

Browse files
Merge pull request #96 from DeveloperPaul123/feature/code-cleanup
bench: 3997113
2 parents 8ab0770 + 4a596d8 commit 53fa482

27 files changed

+366
-188
lines changed

Cargo.lock

Lines changed: 8 additions & 9 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
@@ -12,13 +12,13 @@ members = ["engine", "chess"]
1212
[dependencies]
1313
engine = { path = "engine" }
1414
chess = { path = "chess" }
15-
anyhow = "1.0.97"
16-
clap = { version = "4.5.32", features = ["derive"] }
15+
anyhow = "1.0.98"
16+
clap = { version = "4.5.37", features = ["derive"] }
1717
colored = "3.0.0"
1818
console = { version = "0.15.11", features = ["windows-console-colors"] }
1919
csv = "1.3.1"
2020
indicatif = { version = "0.17.11", features = ["rayon"] }
21-
rand = { version = "0.9.0", features = ["small_rng"] }
21+
rand = { version = "0.9.1", features = ["small_rng"] }
2222
rand_chacha = "0.9.0"
2323
rayon = "1.10.0"
2424
serde = { version = "1.0.219", features = ["derive"] }

Justfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ make_dir := if os_family() == "windows" {
88
}
99
env_var_prefix := if os_family() == "windows" { "$env:" } else { "" }
1010
env_var_postfix := if os_family() == "windows" { ";" } else { "" }
11-
default: (build)
11+
default:
12+
@just -l
13+
14+
build-engine:
15+
cargo rustc --release --bin byte-knight -- -C target-cpu=native
1216

1317
[group('dev')]
1418
[doc('Build the project (default is debug)')]
@@ -64,9 +68,8 @@ lint:
6468
[group('chess')]
6569
[group('performance')]
6670
[doc('Run sarch benchmark - required before committing for OpenBench.')]
67-
search-bench:
71+
search-bench: build-engine
6872
echo "Running search benchmark..."
69-
cargo rustc --release --bin byte-knight -- -C target-cpu=native
7073
./target/release/byte-knight bench
7174

7275
[group('chess')]

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
`byte-knight` is a UCI compliant chess engine written in Rust. It started as a port of the chess engine I submitted for Sebatian Lague's [Chess Engine Challenge](https://github.com/DeveloperPaul123/Leonidas) where it placed in the top 32 out of 600+ entries.
66

7+
You can challenge `byte-knight` yourself on [Lichess](https://lichess.org/@/byte-knight)!
8+
79
# Overview
810

911
`byte-knight` is my first "real" Rust project. I'm a long time [C++ developer](https://github.com/DeveloperPaul123?tab=repositories&q=&type=source&language=c%2B%2B&sort=stargazers) and have been itching to learn Rust. I really enjoyed participating in the chess challenge a while back and thought that writing a new chess engine from scratch would be a good way to learn the language.
@@ -30,6 +32,7 @@ New features are tested via my [OpenBench](https://github.com/AndyGrant/OpenBenc
3032
- [Principle variation search](https://www.chessprogramming.org/Principal_Variation_Search)
3133
- [Aspiration windows](https://www.chessprogramming.org/Aspiration_Windows)
3234
- [Reverse futility pruning](https://www.chessprogramming.org/Reverse_Futility_Pruning)
35+
- [Late Move Reductions](https://www.chessprogramming.org/Late_Move_Reductions)
3336
- [Time control](https://www.chessprogramming.org/Time_Management)
3437
- Basic hard/soft limits
3538
- Move ordering

chess/src/board.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Created Date: Wednesday, August 21st 2024
55
* Author: Paul Tsouchlos (DeveloperPaul123) ([email protected])
66
* -----
7-
* Last Modified: Mon Apr 14 2025
7+
* Last Modified: Thu Apr 24 2025
88
* -----
99
* Copyright (c) 2024 Paul Tsouchlos (DeveloperPaul123)
1010
* GNU General Public License v3.0 or later
@@ -117,7 +117,6 @@ impl Board {
117117
match side {
118118
Side::White => self.initialize_white_bbs(),
119119
Side::Black => self.initialize_black_bbs(),
120-
_ => panic!("Invalid side"),
121120
}
122121
}
123122

@@ -325,7 +324,6 @@ impl Board {
325324

326325
/// Returns the bitboard for a specific piece and side.
327326
pub fn piece_bitboard(&self, piece: Piece, side: Side) -> &Bitboard {
328-
debug_assert!(side != Side::Both);
329327
&self.piece_bitboards[side as usize][piece as usize]
330328
}
331329

@@ -418,7 +416,6 @@ impl Board {
418416
match side {
419417
Side::White => castling_rights & CastlingAvailability::WHITE_KINGSIDE != 0,
420418
Side::Black => castling_rights & CastlingAvailability::BLACK_KINGSIDE != 0,
421-
Side::Both => panic!("Cannot check if both sides can castle kingside"),
422419
}
423420
}
424421

@@ -436,7 +433,6 @@ impl Board {
436433
match side {
437434
Side::White => castling_rights & CastlingAvailability::WHITE_QUEENSIDE != 0,
438435
Side::Black => castling_rights & CastlingAvailability::BLACK_QUEENSIDE != 0,
439-
Side::Both => panic!("Cannot check if both sides can castle queenside"),
440436
}
441437
}
442438

chess/src/fen.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Created Date: Tuesday, November 26th 2024
55
* Author: Paul Tsouchlos (DeveloperPaul123) ([email protected])
66
* -----
7-
* Last Modified: Wed Mar 19 2025
7+
* Last Modified: Thu Apr 24 2025
88
* -----
99
* Copyright (c) 2024 Paul Tsouchlos (DeveloperPaul123)
1010
* GNU General Public License v3.0 or later
@@ -270,7 +270,6 @@ pub(crate) fn active_color_to_fen(board: &Board) -> String {
270270
match board.side_to_move() {
271271
Side::White => "w".to_string(),
272272
Side::Black => "b".to_string(),
273-
_ => panic!("Invalid side"),
274273
}
275274
}
276275

chess/src/legal_move_generation.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Created Date: Tuesday, November 26th 2024
55
* Author: Paul Tsouchlos (DeveloperPaul123) ([email protected])
66
* -----
7-
* Last Modified: Tue Nov 26 2024
7+
* Last Modified: Thu Apr 24 2025
88
* -----
99
* Copyright (c) 2024 Paul Tsouchlos (DeveloperPaul123)
1010
* GNU General Public License v3.0 or later
@@ -180,7 +180,6 @@ impl MoveGenerator {
180180
capture_mask |= en_passant_bb;
181181
}
182182
}
183-
Side::Both => panic!("Both side not allowed"),
184183
}
185184

186185
(
@@ -268,7 +267,6 @@ impl MoveGenerator {
268267
let captured_sq = match board.side_to_move() {
269268
Side::White => sq - SOUTH as u8,
270269
Side::Black => sq + NORTH as u8,
271-
Side::Both => panic!("Both side not allowed"),
272270
};
273271
occupancy &= !(Bitboard::from_square(captured_sq));
274272
// get the squares attacked by the sliding pieces
@@ -337,7 +335,6 @@ impl MoveGenerator {
337335
let direction = match us {
338336
Side::White => NORTH as u8,
339337
Side::Black => SOUTH as u8,
340-
Side::Both => panic!("Both side not allowed"),
341338
};
342339
let from_square = square.to_square_index();
343340
let to_square = match us {
@@ -355,7 +352,6 @@ impl MoveGenerator {
355352
false => Some(result),
356353
}
357354
}
358-
Side::Both => panic!("Both side not allowed"),
359355
};
360356

361357
let mut pushes: Bitboard = match to_square {
@@ -369,7 +365,6 @@ impl MoveGenerator {
369365
let can_double_push = match us {
370366
Side::White => square::is_square_on_rank(from_square, Rank::R2 as u8),
371367
Side::Black => square::is_square_on_rank(from_square, Rank::R7 as u8),
372-
Side::Both => panic!("Both side not allowed"),
373368
};
374369

375370
// if single push is obstructed, we can't double push
@@ -389,7 +384,6 @@ impl MoveGenerator {
389384
false => Some(result),
390385
}
391386
}
392-
Side::Both => panic!("Both side not allowed"),
393387
};
394388

395389
if let Some(to) = double_push_sq {
@@ -559,7 +553,6 @@ impl MoveGenerator {
559553
let king_sq = match us {
560554
Side::White => Squares::E1,
561555
Side::Black => Squares::E8,
562-
Side::Both => panic!("Both side not allowed"),
563556
};
564557

565558
// sanity check
@@ -572,7 +565,6 @@ impl MoveGenerator {
572565
let king_side_rook = match us {
573566
Side::White => Squares::H1,
574567
Side::Black => Squares::H8,
575-
Side::Both => panic!("Both side not allowed"),
576568
};
577569
// sanity check for the rook placement
578570
let maybe_rook = board.piece_on_square(king_side_rook);
@@ -588,13 +580,11 @@ impl MoveGenerator {
588580
Side::Black => {
589581
Bitboard::from_square(Squares::F8) | Bitboard::from_square(Squares::G8)
590582
}
591-
Side::Both => panic!("Both side not allowed"),
592583
};
593584

594585
let king_side_target_sq = match us {
595586
Side::White => Squares::G1,
596587
Side::Black => Squares::G8,
597-
Side::Both => panic!("Both side not allowed"),
598588
};
599589

600590
let is_king_ray_empty = king_side_empty & occupancy == Bitboard::default();
@@ -608,7 +598,6 @@ impl MoveGenerator {
608598
let queen_side_rook = match us {
609599
Side::White => Squares::A1,
610600
Side::Black => Squares::A8,
611-
Side::Both => panic!("Both side not allowed"),
612601
};
613602
// sanity check for the rook placement
614603
let maybe_rook = board.piece_on_square(queen_side_rook);
@@ -624,18 +613,15 @@ impl MoveGenerator {
624613
Side::Black => {
625614
Bitboard::from_square(Squares::C8) | Bitboard::from_square(Squares::D8)
626615
}
627-
Side::Both => panic!("Both side not allowed"),
628616
};
629617
let queen_side_empty = match us {
630618
Side::White => queen_side_no_attack | Bitboard::from_square(Squares::B1),
631619
Side::Black => queen_side_no_attack | Bitboard::from_square(Squares::B8),
632-
Side::Both => panic!("Both side not allowed"),
633620
};
634621

635622
let queen_side_target_sq = match us {
636623
Side::White => Squares::C1,
637624
Side::Black => Squares::C8,
638-
Side::Both => panic!("Both side not allowed"),
639625
};
640626

641627
let is_king_ray_empty = queen_side_empty & occupancy == Bitboard::default();

chess/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
* Created Date: Friday, August 16th 2024
55
* Author: Paul Tsouchlos (DeveloperPaul123) ([email protected])
66
* -----
7-
* Last Modified: Wed Apr 23 2025
7+
* Last Modified: Thu Apr 24 2025
88
* -----
99
* Copyright (c) 2024 Paul Tsouchlos (DeveloperPaul123)
1010
* GNU General Public License v3.0 or later
1111
* https://www.gnu.org/licenses/gpl-3.0-standalone.html
1212
*
1313
*/
1414

15+
#![deny(clippy::unused_result_ok)]
16+
#![deny(clippy::panic)]
17+
#![deny(clippy::expect_used)]
18+
1519
pub mod bitboard;
1620
pub mod bitboard_helpers;
1721
pub mod board;
@@ -27,9 +31,12 @@ pub mod move_history;
2731
pub mod move_list;
2832
pub mod move_making;
2933
pub mod moves;
34+
pub mod non_slider_piece;
3035
pub mod perft;
36+
pub mod piece_category;
3137
pub mod pieces;
3238
pub mod rank;
3339
pub mod side;
40+
pub mod slider_pieces;
3441
pub mod square;
3542
pub mod zobrist;

0 commit comments

Comments
 (0)