diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-01-26 20:27:35 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-01-26 20:28:28 +0300 |
commit | 1eeda0725263aa1cab7c8f5a81773896ad8bda4f (patch) | |
tree | a14bd988f2a592545ce5e57cbaaaeb4303c8b708 /src | |
parent | 587378bc98797ae0b7d8befbd0da1543e138d973 (diff) | |
download | chessnost-1eeda0725263aa1cab7c8f5a81773896ad8bda4f.tar.gz |
fix: correct castle validations
Diffstat (limited to 'src')
-rw-r--r-- | src/board/engine.rs | 4 | ||||
-rw-r--r-- | src/board/mod.rs | 27 |
2 files changed, 19 insertions, 12 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs index 06369f5..2aa8e28 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -335,8 +335,7 @@ mod tests { assert_eq!(board.perft(2, false), PerftResult { leaf_nodes: 400, captures: 0, en_passants: 0, castles: 0 , checks: 0 }); assert_eq!(board.perft(3, false), PerftResult { leaf_nodes: 8902, captures: 34, en_passants: 0, castles: 0 , checks: 12 }); assert_eq!(board.perft(4, false), PerftResult { leaf_nodes: 197281, captures: 1576, en_passants: 0, castles: 0 , checks: 469 }); - // assert_eq!(board.perft(5, false), (4865609, 82719, 27351, 0, 258)); - // assert_eq!(board.perft(6, false), (119060324, 2812008, 809099, 0, 5248)); + // assert_eq!(board.perft(5, false), PerftResult { leaf_nodes: 4865609, captures: 82719, en_passants: 258, castles: 0, checks: 27351 }); } #[test] @@ -347,6 +346,7 @@ mod tests { assert_eq!(board.perft(1, false), PerftResult { leaf_nodes: 48, captures: 8, en_passants: 0, castles: 2 , checks: 0 }); assert_eq!(board.perft(2, false), PerftResult { leaf_nodes: 2039, captures: 351, en_passants: 1, castles: 91 , checks: 3 }); assert_eq!(board.perft(3, false), PerftResult { leaf_nodes: 97862, captures: 17102, en_passants: 45, castles: 3162, checks: 993 }); + // assert_eq!(board.perft(4, false), PerftResult { leaf_nodes: 4085603, captures: 757163, en_passants: 1929, castles: 128013, checks: 25523 }); } #[test] diff --git a/src/board/mod.rs b/src/board/mod.rs index 76ebd59..589da8a 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -316,14 +316,18 @@ impl Board { { match rook_square.file() { 0 => { - let castle_line = [ - king_home_position, + let all_empty = [ king_home_position.west_one(), king_home_position.west_one().west_one(), - ]; + king_home_position.west_one().west_one().west_one(), - let all_empty = castle_line.iter().skip(1).all(|square| empty & square.to_bitboard() > 0); - let any_checks = castle_line.iter().any(|square| self.is_square_attacked(*square, color.flip())); + ].iter().all(|square| empty & square.to_bitboard() > 0); + + let any_checks = [ + king_home_position, + king_home_position.west_one(), + king_home_position.west_one().west_one(), + ].iter().any(|square| self.is_square_attacked(*square, color.flip())); if all_empty && !any_checks && self.castling_rights[color as usize][CastlingSide::Queen as usize] { moves.push(Move { @@ -334,14 +338,17 @@ impl Board { } }, 7 => { - let castle_line = [ - king_home_position, + let all_empty = [ king_home_position.east_one(), king_home_position.east_one().east_one(), - ]; - let all_empty = castle_line.iter().skip(1).all(|square| empty & square.to_bitboard() > 0); - let any_checks = castle_line.iter().any(|square| self.is_square_attacked(*square, color.flip())); + ].iter().all(|square| empty & square.to_bitboard() > 0); + + let any_checks = [ + king_home_position, + king_home_position.east_one(), + king_home_position.east_one().east_one(), + ].iter().any(|square| self.is_square_attacked(*square, color.flip())); if all_empty && !any_checks && self.castling_rights[color as usize][CastlingSide::King as usize] { moves.push(Move { |