Skip to content

Commit b0c529d

Browse files
committed
Exclude squares attacked by enemy pawns for knight mobility. Bench: 40224792
1 parent da3b6e8 commit b0c529d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Bit-Genie/src/eval.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ static constexpr int mobility_score(Callable F, Args... args)
116116
return mobility_scores[type - 1][popcount64(F(args...))];
117117
}
118118

119+
template<PieceType pt>
120+
static constexpr int safe_mobility_score(Position const& position, Color us, Square sq)
121+
{
122+
uint64_t enemy_pawns = position.pieces.get_piece_bb(make_piece(Pawn, !us));
123+
uint64_t forward = us == White ? shift<Direction::south>(enemy_pawns) : shift<Direction::north>(enemy_pawns);
124+
uint64_t enemy_pawn_attacks = shift<Direction::east>(forward) | shift<Direction::west>(forward);
125+
126+
uint64_t occupancy = position.total_occupancy();
127+
uint64_t attacks = Attacks::generate(pt, sq, occupancy) & ~enemy_pawn_attacks;
128+
129+
return mobility_scores[pt - 1][popcount64(attacks)];
130+
}
131+
119132
static constexpr int passed_pawn_scores[total_ranks] = {
120133
S(0, 0),
121134
S(-16, -16),
@@ -219,7 +232,7 @@ static int evaluate_knight(Position const &position, Square sq, Color us)
219232
int score = 0;
220233

221234
score += knight_psqt[psqt_sq(sq, us)];
222-
score += mobility_score<Knight>(Attacks::knight, sq);
235+
score += safe_mobility_score<Knight>(position, us, sq);
223236

224237
return score;
225238
}

Bit-Genie/src/uci.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "benchmark.h"
2626
#include "searchinit.h"
2727

28-
const char *version = "3.4.5";
28+
const char *version = "3.5";
2929

3030
namespace
3131
{

0 commit comments

Comments
 (0)