aboutsummaryrefslogtreecommitdiff
path: root/src/board/mod.rs
diff options
context:
space:
mode:
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;