// piece type attacks which one.
const Score ThreatBonus[8][8] = {
{}, {},
- { S(0, 0), S(18,37), S( 0, 0), S(37,47), S(55,97), S(55,97) }, // KNIGHT
- { S(0, 0), S(18,37), S(37,47), S( 0, 0), S(55,97), S(55,97) }, // BISHOP
- { S(0, 0), S( 9,27), S(27,47), S(27,47), S( 0, 0), S(37,47) }, // ROOK
- { S(0, 0), S(27,37), S(27,37), S(27,37), S(27,37), S( 0, 0) } // QUEEN
+ { S(0, 0), S( 7, 39), S( 0, 0), S(24, 49), S(41,100), S(41,100) }, // KNIGHT
+ { S(0, 0), S( 7, 39), S(24, 49), S( 0, 0), S(41,100), S(41,100) }, // BISHOP
+ { S(0, 0), S(-1, 29), S(15, 49), S(15, 49), S( 0, 0), S(24, 49) }, // ROOK
+ { S(0, 0), S(15, 39), S(15, 39), S(15, 39), S(15, 39), S( 0, 0) } // QUEEN
};
// ThreatedByPawnPenalty[] contains a penalty according to which piece
ei.value -= Sign[Us] * ThreatedByPawnPenalty[Piece];
// Bishop and knight outposts squares
- if ((Piece == BISHOP || Piece == KNIGHT) && pos.square_is_weak(s, Them))
+ if ((Piece == BISHOP || Piece == KNIGHT) && pos.square_is_weak(s, Us))
evaluate_outposts<Piece, Us>(pos, ei, s);
// Special patterns: trapped bishops on a7/h7/a2/h2
assert(pos.pawn_is_passed(Us, s));
int r = int(relative_rank(Us, s) - RANK_2);
- int tr = Max(0, r * (r - 1));
+ int tr = r * (r - 1);
// Base bonus based on rank
Value mbonus = Value(20 * tr);
void init_safety() {
- int maxSlope = 30;
- int peak = 0x500;
- double a = 0.4;
- double b = 0.0;
+ const Value MaxSlope = Value(30);
+ const Value Peak = Value(1280);
Value t[100];
// First setup the base table
for (int i = 0; i < 100; i++)
{
- if (i < b)
- t[i] = Value(0);
- else
- t[i] = Value((int)(a * (i - b) * (i - b)));
- }
+ t[i] = Value(int(0.4 * i * i));
- for (int i = 1; i < 100; i++)
- {
- if (t[i] - t[i - 1] > maxSlope)
- t[i] = t[i - 1] + Value(maxSlope);
+ if (i > 0)
+ t[i] = Min(t[i], t[i - 1] + MaxSlope);
- if (t[i] > Value(peak))
- t[i] = Value(peak);
+ t[i] = Min(t[i], Peak);
}
// Then apply the weights and get the final KingDangerTable[] array