mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 11:39:15 +00:00
Assorted trivial cleanups June 2019
No functional change.
This commit is contained in:
parent
c83cbe42f3
commit
4ae5a7b45a
5 changed files with 29 additions and 22 deletions
|
@ -142,7 +142,7 @@ namespace {
|
||||||
constexpr Score KnightOnQueen = S( 16, 12);
|
constexpr Score KnightOnQueen = S( 16, 12);
|
||||||
constexpr Score LongDiagonalBishop = S( 45, 0);
|
constexpr Score LongDiagonalBishop = S( 45, 0);
|
||||||
constexpr Score MinorBehindPawn = S( 18, 3);
|
constexpr Score MinorBehindPawn = S( 18, 3);
|
||||||
constexpr Score Outpost = S( 36, 12);
|
constexpr Score Outpost = S( 18, 6);
|
||||||
constexpr Score PawnlessFlank = S( 17, 95);
|
constexpr Score PawnlessFlank = S( 17, 95);
|
||||||
constexpr Score RestrictedPiece = S( 7, 7);
|
constexpr Score RestrictedPiece = S( 7, 7);
|
||||||
constexpr Score RookOnPawn = S( 10, 32);
|
constexpr Score RookOnPawn = S( 10, 32);
|
||||||
|
@ -222,7 +222,7 @@ namespace {
|
||||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||||
constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
|
constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
|
||||||
constexpr Bitboard LowRanks = (Us == WHITE ? Rank2BB | Rank3BB: Rank7BB | Rank6BB);
|
constexpr Bitboard LowRanks = (Us == WHITE ? Rank2BB | Rank3BB : Rank7BB | Rank6BB);
|
||||||
|
|
||||||
const Square ksq = pos.square<KING>(Us);
|
const Square ksq = pos.square<KING>(Us);
|
||||||
|
|
||||||
|
@ -305,10 +305,10 @@ namespace {
|
||||||
// Bonus if piece is on an outpost square or can reach one
|
// Bonus if piece is on an outpost square or can reach one
|
||||||
bb = OutpostRanks & attackedBy[Us][PAWN] & ~pe->pawn_attacks_span(Them);
|
bb = OutpostRanks & attackedBy[Us][PAWN] & ~pe->pawn_attacks_span(Them);
|
||||||
if (bb & s)
|
if (bb & s)
|
||||||
score += Outpost * (Pt == KNIGHT ? 2 : 1);
|
score += Outpost * (Pt == KNIGHT ? 4 : 2);
|
||||||
|
|
||||||
else if (bb & b & ~pos.pieces(Us))
|
else if (bb & b & ~pos.pieces(Us))
|
||||||
score += Outpost / (Pt == KNIGHT ? 1 : 2);
|
score += Outpost * (Pt == KNIGHT ? 2 : 1);
|
||||||
|
|
||||||
// Knight and Bishop bonus for being right behind a pawn
|
// Knight and Bishop bonus for being right behind a pawn
|
||||||
if (shift<Down>(pos.pieces(PAWN)) & s)
|
if (shift<Down>(pos.pieces(PAWN)) & s)
|
||||||
|
@ -561,7 +561,7 @@ namespace {
|
||||||
b &= ~attackedBy[Them][PAWN] & safe;
|
b &= ~attackedBy[Them][PAWN] & safe;
|
||||||
|
|
||||||
// Bonus for safe pawn threats on the next move
|
// Bonus for safe pawn threats on the next move
|
||||||
b = pawn_attacks_bb<Us>(b) & pos.pieces(Them);
|
b = pawn_attacks_bb<Us>(b) & nonPawnEnemies;
|
||||||
score += ThreatByPawnPush * popcount(b);
|
score += ThreatByPawnPush * popcount(b);
|
||||||
|
|
||||||
// Our safe or protected pawns
|
// Our safe or protected pawns
|
||||||
|
|
|
@ -32,9 +32,9 @@ namespace {
|
||||||
#define S(mg, eg) make_score(mg, eg)
|
#define S(mg, eg) make_score(mg, eg)
|
||||||
|
|
||||||
// Pawn penalties
|
// Pawn penalties
|
||||||
constexpr Score Backward = S( 9, 24);
|
constexpr Score Backward = S( 9, 24);
|
||||||
constexpr Score Doubled = S(11, 56);
|
constexpr Score Doubled = S(11, 56);
|
||||||
constexpr Score Isolated = S( 5, 15);
|
constexpr Score Isolated = S( 5, 15);
|
||||||
constexpr Score WeakUnopposed = S( 13, 27);
|
constexpr Score WeakUnopposed = S( 13, 27);
|
||||||
constexpr Score Attacked2Unsupported = S( 0, 20);
|
constexpr Score Attacked2Unsupported = S( 0, 20);
|
||||||
|
|
||||||
|
@ -108,17 +108,18 @@ namespace {
|
||||||
phalanx = neighbours & rank_bb(s);
|
phalanx = neighbours & rank_bb(s);
|
||||||
support = neighbours & rank_bb(s - Up);
|
support = neighbours & rank_bb(s - Up);
|
||||||
|
|
||||||
// A pawn is backward when it is behind all pawns of the same color
|
// A pawn is backward when it is behind all pawns of the same color on
|
||||||
// on the adjacent files and cannot be safely advanced.
|
// the adjacent files and cannot safely advance. Phalanx and isolated
|
||||||
backward = !(ourPawns & pawn_attack_span(Them, s + Up))
|
// pawns will be excluded when the pawn is scored.
|
||||||
|
backward = !(neighbours & forward_ranks_bb(Them, s))
|
||||||
&& (stoppers & (leverPush | (s + Up)));
|
&& (stoppers & (leverPush | (s + Up)));
|
||||||
|
|
||||||
// Passed pawns will be properly scored in evaluation because we need
|
// Passed pawns will be properly scored in evaluation because we need
|
||||||
// full attack info to evaluate them. Include also not passed pawns
|
// full attack info to evaluate them. Include also not passed pawns
|
||||||
// which could become passed after one or two pawn pushes when are
|
// which could become passed after one or two pawn pushes when are
|
||||||
// not attacked more times than defended.
|
// not attacked more times than defended.
|
||||||
if ( !(stoppers ^ lever) ||
|
if ( !(stoppers ^ lever) ||
|
||||||
(!(stoppers ^ leverPush) && popcount(phalanx) >= popcount(leverPush)))
|
(!(stoppers ^ leverPush) && popcount(phalanx) >= popcount(leverPush)))
|
||||||
e->passedPawns[Us] |= s;
|
e->passedPawns[Us] |= s;
|
||||||
|
|
||||||
else if (stoppers == square_bb(s + Up) && r >= RANK_5)
|
else if (stoppers == square_bb(s + Up) && r >= RANK_5)
|
||||||
|
@ -137,6 +138,7 @@ namespace {
|
||||||
|
|
||||||
score += make_score(v, v * (r - 2) / 4);
|
score += make_score(v, v * (r - 2) / 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!neighbours)
|
else if (!neighbours)
|
||||||
score -= Isolated + WeakUnopposed * int(!opposed);
|
score -= Isolated + WeakUnopposed * int(!opposed);
|
||||||
|
|
||||||
|
|
|
@ -55,13 +55,13 @@ constexpr Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING
|
||||||
// valuable attacker for the side to move, remove the attacker we just found
|
// valuable attacker for the side to move, remove the attacker we just found
|
||||||
// from the bitboards and scan for new X-ray attacks behind it.
|
// from the bitboards and scan for new X-ray attacks behind it.
|
||||||
|
|
||||||
template<int Pt>
|
template<PieceType Pt>
|
||||||
PieceType min_attacker(const Bitboard* byTypeBB, Square to, Bitboard stmAttackers,
|
PieceType min_attacker(const Bitboard* byTypeBB, Square to, Bitboard stmAttackers,
|
||||||
Bitboard& occupied, Bitboard& attackers) {
|
Bitboard& occupied, Bitboard& attackers) {
|
||||||
|
|
||||||
Bitboard b = stmAttackers & byTypeBB[Pt];
|
Bitboard b = stmAttackers & byTypeBB[Pt];
|
||||||
if (!b)
|
if (!b)
|
||||||
return min_attacker<Pt + 1>(byTypeBB, to, stmAttackers, occupied, attackers);
|
return min_attacker<PieceType(Pt + 1)>(byTypeBB, to, stmAttackers, occupied, attackers);
|
||||||
|
|
||||||
occupied ^= lsb(b); // Remove the attacker from occupied
|
occupied ^= lsb(b); // Remove the attacker from occupied
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ PieceType min_attacker(const Bitboard* byTypeBB, Square to, Bitboard stmAttacker
|
||||||
// X-ray may add already processed pieces because byTypeBB[] is constant: in
|
// X-ray may add already processed pieces because byTypeBB[] is constant: in
|
||||||
// the rook example, now attackers contains _again_ rook in a7, so remove it.
|
// the rook example, now attackers contains _again_ rook in a7, so remove it.
|
||||||
attackers &= occupied;
|
attackers &= occupied;
|
||||||
return (PieceType)Pt;
|
return Pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
|
@ -108,6 +108,7 @@ public:
|
||||||
Bitboard checkers() const;
|
Bitboard checkers() const;
|
||||||
Bitboard blockers_for_king(Color c) const;
|
Bitboard blockers_for_king(Color c) const;
|
||||||
Bitboard check_squares(PieceType pt) const;
|
Bitboard check_squares(PieceType pt) const;
|
||||||
|
bool is_discovery_check_on_king(Color c, Move m) const;
|
||||||
|
|
||||||
// Attacks to/from a given square
|
// Attacks to/from a given square
|
||||||
Bitboard attackers_to(Square s) const;
|
Bitboard attackers_to(Square s) const;
|
||||||
|
@ -316,6 +317,10 @@ inline Bitboard Position::check_squares(PieceType pt) const {
|
||||||
return st->checkSquares[pt];
|
return st->checkSquares[pt];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool Position::is_discovery_check_on_king(Color c, Move m) const {
|
||||||
|
return st->blockersForKing[c] & from_sq(m);
|
||||||
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_passed(Color c, Square s) const {
|
inline bool Position::pawn_passed(Color c, Square s) const {
|
||||||
return !(pieces(~c, PAWN) & passed_pawn_span(c, s));
|
return !(pieces(~c, PAWN) & passed_pawn_span(c, s));
|
||||||
}
|
}
|
||||||
|
|
|
@ -739,7 +739,7 @@ namespace {
|
||||||
}
|
}
|
||||||
else if (ttHit)
|
else if (ttHit)
|
||||||
{
|
{
|
||||||
// Never assume anything on values stored in TT
|
// Never assume anything about values stored in TT
|
||||||
ss->staticEval = eval = tte->eval();
|
ss->staticEval = eval = tte->eval();
|
||||||
if (eval == VALUE_NONE)
|
if (eval == VALUE_NONE)
|
||||||
ss->staticEval = eval = evaluate(pos);
|
ss->staticEval = eval = evaluate(pos);
|
||||||
|
@ -978,7 +978,7 @@ moves_loop: // When in check, search starts from here
|
||||||
|
|
||||||
// Check extension (~2 Elo)
|
// Check extension (~2 Elo)
|
||||||
else if ( givesCheck
|
else if ( givesCheck
|
||||||
&& (pos.blockers_for_king(~us) & from_sq(move) || pos.see_ge(move)))
|
&& (pos.is_discovery_check_on_king(~us, move) || pos.see_ge(move)))
|
||||||
extension = ONE_PLY;
|
extension = ONE_PLY;
|
||||||
|
|
||||||
// Castling extension
|
// Castling extension
|
||||||
|
@ -1013,7 +1013,7 @@ moves_loop: // When in check, search starts from here
|
||||||
&& !givesCheck
|
&& !givesCheck
|
||||||
&& (!pos.advanced_pawn_push(move) || pos.non_pawn_material(~us) > BishopValueMg))
|
&& (!pos.advanced_pawn_push(move) || pos.non_pawn_material(~us) > BishopValueMg))
|
||||||
{
|
{
|
||||||
// Move count based pruning (~30 Elo)
|
// Move count based pruning
|
||||||
if (moveCountPruning)
|
if (moveCountPruning)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -1037,8 +1037,8 @@ moves_loop: // When in check, search starts from here
|
||||||
if (!pos.see_ge(move, Value(-29 * lmrDepth * lmrDepth)))
|
if (!pos.see_ge(move, Value(-29 * lmrDepth * lmrDepth)))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if ((!givesCheck || !extension)
|
else if ( (!givesCheck || !extension)
|
||||||
&& !pos.see_ge(move, -PawnValueEg * (depth / ONE_PLY))) // (~20 Elo)
|
&& !pos.see_ge(move, -PawnValueEg * (depth / ONE_PLY))) // (~20 Elo)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1341,7 +1341,7 @@ moves_loop: // When in check, search starts from here
|
||||||
{
|
{
|
||||||
if (ttHit)
|
if (ttHit)
|
||||||
{
|
{
|
||||||
// Never assume anything on values stored in TT
|
// Never assume anything about values stored in TT
|
||||||
if ((ss->staticEval = bestValue = tte->eval()) == VALUE_NONE)
|
if ((ss->staticEval = bestValue = tte->eval()) == VALUE_NONE)
|
||||||
ss->staticEval = bestValue = evaluate(pos);
|
ss->staticEval = bestValue = evaluate(pos);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue