aboutsummaryrefslogtreecommitdiff
path: root/src/board/move_generation.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-08-31 14:03:07 +0300
committereug-vs <eugene@eug-vs.xyz>2023-08-31 14:03:07 +0300
commit02a87211a862e76a5fa7611fe1d1dcdc270a9d47 (patch)
tree46307a89b94d55bbd649f2e23469f7b0f4726adf /src/board/move_generation.rs
parent1891aed81193bd8913e806f58cfc802c13f9df1e (diff)
downloadchessnost-02a87211a862e76a5fa7611fe1d1dcdc270a9d47.tar.gz
perf: only generate moves needed for current stage
Diffstat (limited to 'src/board/move_generation.rs')
-rw-r--r--src/board/move_generation.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/board/move_generation.rs b/src/board/move_generation.rs
index 5a3650a..7669b85 100644
--- a/src/board/move_generation.rs
+++ b/src/board/move_generation.rs
@@ -195,5 +195,35 @@ mod tests {
println!("{:?}", board.castling_rights);
assert!(castle.is_none(), "Castle should not be allowed after king has moved");
}
+
+ #[test]
+ fn tactical_move_generation() {
+ let fen = String::from("4k2r/ppp1n3/8/4R1Pp/5P2/q1P5/P1P1BP2/1K1R4 b - - 2 22");
+ let board = Board::from_FEN(fen);
+
+ let all_moves = board.generate_pseudolegal_moves();
+
+ let tactical_only = board.generate_moves_core(true);
+ let quiet_only = board.generate_moves_core(false);
+
+ let true_tactical = all_moves.iter().filter(|m| m.is_tactical()).copied().collect::<MoveList>();
+ let true_quiet = all_moves.iter().filter(|m| !m.is_tactical()).copied().collect::<MoveList>();
+
+ // Make sure tactical_only and true_tactical are identical sets
+ for mov in tactical_only.iter() {
+ assert!(true_tactical.iter().any(|m| *m == *mov));
+ }
+ for mov in true_tactical {
+ assert!(tactical_only.iter().any(|m| *m == mov));
+ }
+
+ // Make sure quiet_only and true_quiet are identical sets
+ for mov in quiet_only.iter() {
+ assert!(true_quiet.iter().any(|m| *m == *mov));
+ }
+ for mov in true_quiet {
+ assert!(quiet_only.iter().any(|m| *m == mov));
+ }
+ }
}