S( 0, 0), S( 0, 0), S(0, 0), S(0, 0),
S(20,20), S(40,40), S(0, 0), S(0, 0) };
- // Bonus for file distance of the two outermost pawns
- const Score PawnsFileSpan = S(0, 15);
-
// Unsupported pawn penalty
const Score UnsupportedPawnPenalty = S(20, 10);
value -= UnsupportedPawnPenalty;
if (doubled)
- value -= Doubled[f] / rank_distance(s, lsb(doubled));
+ value -= Doubled[f] / distance<Rank>(s, frontmost_sq(Us, doubled));
if (backward)
value -= Backward[opposed][f];
b = e->semiopenFiles[Us] ^ 0xFF;
e->pawnSpan[Us] = b ? int(msb(b) - lsb(b)) : 0;
- // In endgame it's better to have pawns on both wings. So give a bonus according
- // to file distance between left and right outermost pawns.
- value += PawnsFileSpan * e->pawnSpan[Us];
-
return value;
}
namespace Pawns {
+/// init() initializes some tables used by evaluation. Instead of hard-coded
+/// tables, when makes sense, we prefer to calculate them with a formula to
+/// reduce independent parameters and to allow easier tuning and better insight.
+
void init()
{
- const int c[RANK_NB] = {0, 6, 15, 10, 57, 75, 135, 258};
+ static const int Seed[RANK_NB] = { 0, 6, 15, 10, 57, 75, 135, 258 };
- for (Rank r = RANK_2; r <= RANK_7; ++r)
- for (int opposed = false; opposed <= true; ++opposed)
- for (int phalanx = false; phalanx <= true; ++phalanx)
+ for (int opposed = 0; opposed <= 1; ++opposed)
+ for (int phalanx = 0; phalanx <= 1; ++phalanx)
+ for (Rank r = RANK_2; r < RANK_8; ++r)
{
- int bonus = c[r] + (phalanx ? (c[r + 1] - c[r]) / 2 : 0);
+ int bonus = Seed[r] + (phalanx ? (Seed[r + 1] - Seed[r]) / 2 : 0);
Connected[opposed][phalanx][r] = make_score(bonus / 2, bonus >> opposed);
}
}
+
/// probe() takes a position as input, computes a Entry object, and returns a
/// pointer to it. The result is also stored in a hash table, so we don't have
/// to recompute everything when the same pawn structure occurs again.
kingSquares[Us] = ksq;
castlingRights[Us] = pos.can_castle(Us);
- minKPdistance[Us] = 0;
+ minKingPawnDistance[Us] = 0;
Bitboard pawns = pos.pieces(Us, PAWN);
if (pawns)
- while (!(DistanceRingsBB[ksq][minKPdistance[Us]++] & pawns)) {}
+ while (!(DistanceRingsBB[ksq][minKingPawnDistance[Us]++] & pawns)) {}
if (relative_rank(Us, ksq) > RANK_4)
- return make_score(0, -16 * minKPdistance[Us]);
+ return make_score(0, -16 * minKingPawnDistance[Us]);
Value bonus = shelter_storm<Us>(pos, ksq);
if (pos.can_castle(MakeCastling<Us, QUEEN_SIDE>::right))
bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_C1)));
- return make_score(bonus, -16 * minKPdistance[Us]);
+ return make_score(bonus, -16 * minKingPawnDistance[Us]);
}
// Explicit template instantiation