mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Assorted trivial cleanups
- Cleanups by Alain - Group king attacks and king defenses - Signature of futility_move_count() - Use is_discovery_check_on_king() - Simplify backward definition - Use static asserts in move generator - Factor a statement in move generator No functional change
This commit is contained in:
parent
7e89a71624
commit
90c0385724
9 changed files with 30 additions and 35 deletions
|
@ -448,16 +448,16 @@ namespace {
|
||||||
int kingFlankAttacks = popcount(b1) + popcount(b2);
|
int kingFlankAttacks = popcount(b1) + popcount(b2);
|
||||||
|
|
||||||
kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them]
|
kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them]
|
||||||
+ 69 * kingAttacksCount[Them]
|
|
||||||
+ 185 * popcount(kingRing[Us] & weak)
|
+ 185 * popcount(kingRing[Us] & weak)
|
||||||
- 100 * bool(attackedBy[Us][KNIGHT] & attackedBy[Us][KING])
|
|
||||||
- 35 * bool(attackedBy[Us][BISHOP] & attackedBy[Us][KING])
|
|
||||||
+ 148 * popcount(unsafeChecks)
|
+ 148 * popcount(unsafeChecks)
|
||||||
+ 98 * popcount(pos.blockers_for_king(Us))
|
+ 98 * popcount(pos.blockers_for_king(Us))
|
||||||
- 873 * !pos.count<QUEEN>(Them)
|
+ 69 * kingAttacksCount[Them]
|
||||||
- 6 * mg_value(score) / 8
|
|
||||||
+ mg_value(mobility[Them] - mobility[Us])
|
|
||||||
+ 3 * kingFlankAttacks * kingFlankAttacks / 8
|
+ 3 * kingFlankAttacks * kingFlankAttacks / 8
|
||||||
|
+ mg_value(mobility[Them] - mobility[Us])
|
||||||
|
- 873 * !pos.count<QUEEN>(Them)
|
||||||
|
- 100 * bool(attackedBy[Us][KNIGHT] & attackedBy[Us][KING])
|
||||||
|
- 35 * bool(attackedBy[Us][BISHOP] & attackedBy[Us][KING])
|
||||||
|
- 6 * mg_value(score) / 8
|
||||||
- 7;
|
- 7;
|
||||||
|
|
||||||
// Transform the kingDanger units into a Score, and subtract it from the evaluation
|
// Transform the kingDanger units into a Score, and subtract it from the evaluation
|
||||||
|
@ -596,7 +596,6 @@ namespace {
|
||||||
assert(!(pos.pieces(Them, PAWN) & forward_file_bb(Us, s + Up)));
|
assert(!(pos.pieces(Them, PAWN) & forward_file_bb(Us, s + Up)));
|
||||||
|
|
||||||
int r = relative_rank(Us, s);
|
int r = relative_rank(Us, s);
|
||||||
File f = file_of(s);
|
|
||||||
|
|
||||||
Score bonus = PassedRank[r];
|
Score bonus = PassedRank[r];
|
||||||
|
|
||||||
|
@ -646,7 +645,7 @@ namespace {
|
||||||
|| (pos.pieces(PAWN) & (s + Up)))
|
|| (pos.pieces(PAWN) & (s + Up)))
|
||||||
bonus = bonus / 2;
|
bonus = bonus / 2;
|
||||||
|
|
||||||
score += bonus - PassedFile * map_to_queenside(f);
|
score += bonus - PassedFile * map_to_queenside(file_of(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (T)
|
if (T)
|
||||||
|
|
|
@ -60,6 +60,7 @@ namespace {
|
||||||
constexpr Direction UpRight = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
constexpr Direction UpRight = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||||
constexpr Direction UpLeft = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
constexpr Direction UpLeft = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||||
|
|
||||||
|
const Square ksq = pos.square<KING>(Them);
|
||||||
Bitboard emptySquares;
|
Bitboard emptySquares;
|
||||||
|
|
||||||
Bitboard pawnsOn7 = pos.pieces(Us, PAWN) & TRank7BB;
|
Bitboard pawnsOn7 = pos.pieces(Us, PAWN) & TRank7BB;
|
||||||
|
@ -84,8 +85,6 @@ namespace {
|
||||||
|
|
||||||
if (Type == QUIET_CHECKS)
|
if (Type == QUIET_CHECKS)
|
||||||
{
|
{
|
||||||
Square ksq = pos.square<KING>(Them);
|
|
||||||
|
|
||||||
b1 &= pos.attacks_from<PAWN>(ksq, Them);
|
b1 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||||
b2 &= pos.attacks_from<PAWN>(ksq, Them);
|
b2 &= pos.attacks_from<PAWN>(ksq, Them);
|
||||||
|
|
||||||
|
@ -130,8 +129,6 @@ namespace {
|
||||||
Bitboard b2 = shift<UpLeft >(pawnsOn7) & enemies;
|
Bitboard b2 = shift<UpLeft >(pawnsOn7) & enemies;
|
||||||
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
|
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
|
||||||
|
|
||||||
Square ksq = pos.square<KING>(Them);
|
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
moveList = make_promotions<Type, UpRight>(moveList, pop_lsb(&b1), ksq);
|
moveList = make_promotions<Type, UpRight>(moveList, pop_lsb(&b1), ksq);
|
||||||
|
|
||||||
|
@ -187,7 +184,7 @@ namespace {
|
||||||
ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us,
|
ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us,
|
||||||
Bitboard target) {
|
Bitboard target) {
|
||||||
|
|
||||||
assert(Pt != KING && Pt != PAWN);
|
static_assert(Pt != KING && Pt != PAWN, "Unsupported piece type in generate_moves()");
|
||||||
|
|
||||||
const Square* pl = pos.squares<Pt>(us);
|
const Square* pl = pos.squares<Pt>(us);
|
||||||
|
|
||||||
|
@ -261,7 +258,7 @@ namespace {
|
||||||
template<GenType Type>
|
template<GenType Type>
|
||||||
ExtMove* generate(const Position& pos, ExtMove* moveList) {
|
ExtMove* generate(const Position& pos, ExtMove* moveList) {
|
||||||
|
|
||||||
assert(Type == CAPTURES || Type == QUIETS || Type == NON_EVASIONS);
|
static_assert(Type == CAPTURES || Type == QUIETS || Type == NON_EVASIONS, "Unsupported type in generate()");
|
||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
|
|
|
@ -108,7 +108,7 @@ namespace {
|
||||||
// A pawn is backward when it is behind all pawns of the same color on
|
// A pawn is backward when it is behind all pawns of the same color on
|
||||||
// the adjacent files and cannot safely advance.
|
// the adjacent files and cannot safely advance.
|
||||||
backward = !(neighbours & forward_ranks_bb(Them, s + Up))
|
backward = !(neighbours & forward_ranks_bb(Them, s + Up))
|
||||||
&& (stoppers & (leverPush | blocked));
|
&& (leverPush | blocked);
|
||||||
|
|
||||||
// Compute additional span if pawn is not backward nor blocked
|
// Compute additional span if pawn is not backward nor blocked
|
||||||
if (!backward && !blocked)
|
if (!backward && !blocked)
|
||||||
|
|
|
@ -286,7 +286,8 @@ inline Square Position::castling_rook_square(CastlingRights cr) const {
|
||||||
|
|
||||||
template<PieceType Pt>
|
template<PieceType Pt>
|
||||||
inline Bitboard Position::attacks_from(Square s) const {
|
inline Bitboard Position::attacks_from(Square s) const {
|
||||||
assert(Pt != PAWN);
|
static_assert(Pt != PAWN, "Pawn attacks need color");
|
||||||
|
|
||||||
return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, byTypeBB[ALL_PIECES])
|
return Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, byTypeBB[ALL_PIECES])
|
||||||
: Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
|
: Pt == QUEEN ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
|
||||||
: PseudoAttacks[Pt][s];
|
: PseudoAttacks[Pt][s];
|
||||||
|
|
|
@ -75,7 +75,7 @@ namespace {
|
||||||
return (r + 520) / 1024 + (!i && r > 999);
|
return (r + 520) / 1024 + (!i && r > 999);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr int futility_move_count(bool improving, int depth) {
|
constexpr int futility_move_count(bool improving, Depth depth) {
|
||||||
return (5 + depth * depth) * (1 + improving) / 2;
|
return (5 + depth * depth) * (1 + improving) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,7 +594,7 @@ namespace {
|
||||||
Move ttMove, move, excludedMove, bestMove;
|
Move ttMove, move, excludedMove, bestMove;
|
||||||
Depth extension, newDepth;
|
Depth extension, newDepth;
|
||||||
Value bestValue, value, ttValue, eval, maxValue;
|
Value bestValue, value, ttValue, eval, maxValue;
|
||||||
bool ttHit, ttPv, inCheck, givesCheck, improving, doLMR, priorCapture;
|
bool ttHit, ttPv, inCheck, givesCheck, improving, didLMR, priorCapture;
|
||||||
bool captureOrPromotion, doFullDepthSearch, moveCountPruning, ttCapture, singularLMR;
|
bool captureOrPromotion, doFullDepthSearch, moveCountPruning, ttCapture, singularLMR;
|
||||||
Piece movedPiece;
|
Piece movedPiece;
|
||||||
int moveCount, captureCount, quietCount;
|
int moveCount, captureCount, quietCount;
|
||||||
|
@ -1151,17 +1151,17 @@ moves_loop: // When in check, search starts from here
|
||||||
|
|
||||||
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
|
||||||
|
|
||||||
doFullDepthSearch = (value > alpha && d != newDepth), doLMR = true;
|
doFullDepthSearch = (value > alpha && d != newDepth), didLMR = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
doFullDepthSearch = !PvNode || moveCount > 1, doLMR = false;
|
doFullDepthSearch = !PvNode || moveCount > 1, didLMR = false;
|
||||||
|
|
||||||
// Step 17. Full depth search when LMR is skipped or fails high
|
// Step 17. Full depth search when LMR is skipped or fails high
|
||||||
if (doFullDepthSearch)
|
if (doFullDepthSearch)
|
||||||
{
|
{
|
||||||
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode);
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode);
|
||||||
|
|
||||||
if (doLMR && !captureOrPromotion)
|
if (didLMR && !captureOrPromotion)
|
||||||
{
|
{
|
||||||
int bonus = value > alpha ? stat_bonus(newDepth)
|
int bonus = value > alpha ? stat_bonus(newDepth)
|
||||||
: -stat_bonus(newDepth);
|
: -stat_bonus(newDepth);
|
||||||
|
@ -1466,7 +1466,7 @@ moves_loop: // When in check, search starts from here
|
||||||
|
|
||||||
// Don't search moves with negative SEE values
|
// Don't search moves with negative SEE values
|
||||||
if ( (!inCheck || evasionPrunable)
|
if ( (!inCheck || evasionPrunable)
|
||||||
&& (!givesCheck || !(pos.blockers_for_king(~pos.side_to_move()) & from_sq(move)))
|
&& !(givesCheck && pos.is_discovery_check_on_king(~pos.side_to_move(), move))
|
||||||
&& !pos.see_ge(move))
|
&& !pos.see_ge(move))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -706,9 +706,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
|
||||||
|
|
||||||
std::swap(squares[0], *std::max_element(squares, squares + leadPawnsCnt, pawns_comp));
|
std::swap(squares[0], *std::max_element(squares, squares + leadPawnsCnt, pawns_comp));
|
||||||
|
|
||||||
tbFile = file_of(squares[0]);
|
tbFile = map_to_queenside(file_of(squares[0]));
|
||||||
if (tbFile > FILE_D)
|
|
||||||
tbFile = file_of(squares[0] ^ 7); // Horizontal flip: SQ_H1 -> SQ_A1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DTZ tables are one-sided, i.e. they store positions only for white to
|
// DTZ tables are one-sided, i.e. they store positions only for white to
|
||||||
|
@ -1062,8 +1060,8 @@ void set(T& e, uint8_t* data) {
|
||||||
|
|
||||||
enum { Split = 1, HasPawns = 2 };
|
enum { Split = 1, HasPawns = 2 };
|
||||||
|
|
||||||
assert(e.hasPawns == !!(*data & HasPawns));
|
assert(e.hasPawns == bool(*data & HasPawns));
|
||||||
assert((e.key != e.key2) == !!(*data & Split));
|
assert((e.key != e.key2) == bool(*data & Split));
|
||||||
|
|
||||||
data++; // First byte stores flags
|
data++; // First byte stores flags
|
||||||
|
|
||||||
|
|
|
@ -341,7 +341,7 @@ inline Score operator*(Score s, int i) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Multiplication of a Score by an boolean
|
/// Multiplication of a Score by a boolean
|
||||||
inline Score operator*(Score s, bool b) {
|
inline Score operator*(Score s, bool b) {
|
||||||
return Score(int(s) * int(b));
|
return Score(int(s) * int(b));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue