aboutsummaryrefslogtreecommitdiff
path: root/src/board/mod.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-02-01 14:23:59 +0300
committereug-vs <eugene@eug-vs.xyz>2023-02-01 14:48:40 +0300
commit46abb37e60667445d10791553bdb307d52661180 (patch)
treea042ac6d97dfcd4282c9726a4a3539f9b82cac73 /src/board/mod.rs
parent7a8845f9d089d9b5b70c5842d1d77e157374ac75 (diff)
downloadchessnost-46abb37e60667445d10791553bdb307d52661180.tar.gz
fix: do not overcount EP square in move generation
Diffstat (limited to 'src/board/mod.rs')
-rw-r--r--src/board/mod.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/board/mod.rs b/src/board/mod.rs
index fd0ff25..3f37d62 100644
--- a/src/board/mod.rs
+++ b/src/board/mod.rs
@@ -269,7 +269,14 @@ impl Board {
PieceType::Pawn => {
for source in serialize_bitboard(*piece) {
let ep_bitboard = match self.ep_target {
- Some(square) => square.to_bitboard(),
+ Some(square) => {
+ let rank = square.rank();
+ if (rank == 2 && color == Color::Black) || (rank == 5 && color == Color::White) {
+ square.to_bitboard()
+ } else {
+ 0
+ }
+ }
None => 0,
};
for target in serialize_bitboard(self.attacks.pawn[color as usize][source as usize] & capture_targets) {
@@ -431,6 +438,7 @@ impl Board {
}
/// Count pseudo-legal moves without actually generating them
+ /// Also exclude all moves that put a piece under attack of a pawn - so called safe mobility
pub fn mobility(&self, color: Color) -> f32 {
let mut mobility = 0.;
let opponent_occupancy = self.color_occupancy(color.flip());
@@ -453,7 +461,14 @@ impl Board {
PieceType::Pawn => {
for source in serialize_bitboard(*piece) {
let ep_bitboard = match self.ep_target {
- Some(square) => square.to_bitboard(),
+ Some(square) => {
+ let rank = square.rank();
+ if (rank == 2 && color == Color::Black) || (rank == 5 && color == Color::White) {
+ square.to_bitboard()
+ } else {
+ 0
+ }
+ }
None => 0,
};
mobility += pop_count(self.attacks.pawn[color as usize][source as usize] & (opponent_occupancy | ep_bitboard)) as f32;