Skip to content

Commit

Permalink
Account for enemy pawn attacks in mobility
Browse files Browse the repository at this point in the history
Elo   | 14.90 +- 7.93 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=16MB
LLR   | 2.96 (-2.94, 2.94) [0.00, 5.00]
Games | N: 4084 W: 1379 L: 1204 D: 1501
Penta | [135, 442, 776, 491, 198]
  • Loading branch information
jgilchrist committed Dec 9, 2024
1 parent 7e90d67 commit 104fdd0
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 143 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

* Evaluate passed pawns (38.30 +- 13.27)
* Don't consider mobility for squares that are attacked by opponent pawns (14.90 +- 7.93)

## [5.0]

Expand Down
20 changes: 16 additions & 4 deletions src/engine/eval/mobility_and_king_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,42 @@ fn mobility_and_opp_king_safety_for(game: &Game, player: Player) -> PhasedEval {
let mut eval = PhasedEval::ZERO;
let blockers = game.board.occupancy();

let their_pawns = game.board.pawns(player.other()).forward(player.other());
let their_pawn_attacks = their_pawns.west() | their_pawns.east();
let mobility_safe_squares = !their_pawn_attacks;

let mut attacked_squares = Bitboard::EMPTY;

for p in game.board.knights(player) {
let moves = tables::knight_attacks(p);
attacked_squares |= moves;
eval += KNIGHT_MOBILITY[moves.count() as usize];

let mobility_squares = (moves & mobility_safe_squares).count() as usize;
eval += KNIGHT_MOBILITY[mobility_squares];
}

for p in game.board.bishops(player) {
let moves = tables::bishop_attacks(p, blockers);
attacked_squares |= moves;
eval += BISHOP_MOBILITY[moves.count() as usize];

let mobility_squares = (moves & mobility_safe_squares).count() as usize;
eval += BISHOP_MOBILITY[mobility_squares];
}

for p in game.board.rooks(player) {
let moves = tables::rook_attacks(p, blockers);
attacked_squares |= moves;
eval += ROOK_MOBILITY[moves.count() as usize];

let mobility_squares = (moves & mobility_safe_squares).count() as usize;
eval += ROOK_MOBILITY[mobility_squares];
}

for p in game.board.queens(player) {
let moves = tables::bishop_attacks(p, blockers) | tables::rook_attacks(p, blockers);
attacked_squares |= moves;
eval += QUEEN_MOBILITY[moves.count() as usize];

let mobility_squares = (moves & mobility_safe_squares).count() as usize;
eval += QUEEN_MOBILITY[mobility_squares];
}

let enemy_king = game.board.king(player.other()).single();
Expand Down
Loading

0 comments on commit 104fdd0

Please sign in to comment.