mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Small cleanups
https://github.com/official-stockfish/Stockfish/pull/2584 No functional change.
This commit is contained in:
parent
b7ecdaada7
commit
209e94203f
9 changed files with 37 additions and 43 deletions
|
@ -78,11 +78,11 @@ void Bitboards::init() {
|
|||
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
|
||||
SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));
|
||||
|
||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||
{
|
||||
PawnAttacks[WHITE][s] = pawn_attacks_bb<WHITE>(square_bb(s));
|
||||
PawnAttacks[BLACK][s] = pawn_attacks_bb<BLACK>(square_bb(s));
|
||||
}
|
||||
Direction RookDirections[] = { NORTH, EAST, SOUTH, WEST };
|
||||
Direction BishopDirections[] = { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST };
|
||||
|
||||
init_magics(RookTable, RookMagics, RookDirections);
|
||||
init_magics(BishopTable, BishopMagics, BishopDirections);
|
||||
|
||||
// Helper returning the target bitboard of a step from a square
|
||||
auto landing_square_bb = [&](Square s, int step)
|
||||
|
@ -91,23 +91,17 @@ void Bitboards::init() {
|
|||
return is_ok(to) && distance(s, to) <= 2 ? square_bb(to) : Bitboard(0);
|
||||
};
|
||||
|
||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||
{
|
||||
for (int step : {-9, -8, -7, -1, 1, 7, 8, 9} )
|
||||
PseudoAttacks[KING][s] |= landing_square_bb(s, step);
|
||||
|
||||
for (int step : {-17, -15, -10, -6, 6, 10, 15, 17} )
|
||||
PseudoAttacks[KNIGHT][s] |= landing_square_bb(s, step);
|
||||
}
|
||||
|
||||
Direction RookDirections[] = { NORTH, EAST, SOUTH, WEST };
|
||||
Direction BishopDirections[] = { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST };
|
||||
|
||||
init_magics(RookTable, RookMagics, RookDirections);
|
||||
init_magics(BishopTable, BishopMagics, BishopDirections);
|
||||
|
||||
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
||||
{
|
||||
PawnAttacks[WHITE][s1] = pawn_attacks_bb<WHITE>(square_bb(s1));
|
||||
PawnAttacks[BLACK][s1] = pawn_attacks_bb<BLACK>(square_bb(s1));
|
||||
|
||||
for (int step : {-9, -8, -7, -1, 1, 7, 8, 9} )
|
||||
PseudoAttacks[KING][s1] |= landing_square_bb(s1, step);
|
||||
|
||||
for (int step : {-17, -15, -10, -6, 6, 10, 15, 17} )
|
||||
PseudoAttacks[KNIGHT][s1] |= landing_square_bb(s1, step);
|
||||
|
||||
PseudoAttacks[QUEEN][s1] = PseudoAttacks[BISHOP][s1] = attacks_bb<BISHOP>(s1, 0);
|
||||
PseudoAttacks[QUEEN][s1] |= PseudoAttacks[ ROOK][s1] = attacks_bb< ROOK>(s1, 0);
|
||||
|
||||
|
|
|
@ -91,15 +91,15 @@ namespace {
|
|||
// MobilityBonus[PieceType-2][attacked] contains bonuses for middle and end game,
|
||||
// indexed by piece type and number of attacked squares in the mobility area.
|
||||
constexpr Score MobilityBonus[][32] = {
|
||||
{ S(-62,-81), S(-53,-56), S(-12,-30), S( -4,-14), S( 3, 8), S( 13, 15), // Knights
|
||||
{ S(-62,-81), S(-53,-56), S(-12,-30), S( -4,-14), S( 3, 8), S( 13, 15), // Knight
|
||||
S( 22, 23), S( 28, 27), S( 33, 33) },
|
||||
{ S(-48,-59), S(-20,-23), S( 16, -3), S( 26, 13), S( 38, 24), S( 51, 42), // Bishops
|
||||
{ S(-48,-59), S(-20,-23), S( 16, -3), S( 26, 13), S( 38, 24), S( 51, 42), // Bishop
|
||||
S( 55, 54), S( 63, 57), S( 63, 65), S( 68, 73), S( 81, 78), S( 81, 86),
|
||||
S( 91, 88), S( 98, 97) },
|
||||
{ S(-58,-76), S(-27,-18), S(-15, 28), S(-10, 55), S( -5, 69), S( -2, 82), // Rooks
|
||||
{ S(-58,-76), S(-27,-18), S(-15, 28), S(-10, 55), S( -5, 69), S( -2, 82), // Rook
|
||||
S( 9,112), S( 16,118), S( 30,132), S( 29,142), S( 32,155), S( 38,165),
|
||||
S( 46,166), S( 48,169), S( 58,171) },
|
||||
{ S(-39,-36), S(-21,-15), S( 3, 8), S( 3, 18), S( 14, 34), S( 22, 54), // Queens
|
||||
{ S(-39,-36), S(-21,-15), S( 3, 8), S( 3, 18), S( 14, 34), S( 22, 54), // Queen
|
||||
S( 28, 61), S( 41, 73), S( 43, 79), S( 48, 92), S( 56, 94), S( 60,104),
|
||||
S( 60,113), S( 66,120), S( 67,123), S( 70,126), S( 71,133), S( 73,136),
|
||||
S( 79,140), S( 88,143), S( 88,148), S( 99,166), S(102,170), S(102,175),
|
||||
|
@ -213,7 +213,7 @@ namespace {
|
|||
template<Tracing T> template<Color Us>
|
||||
void Evaluation<T>::initialize() {
|
||||
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Color Them = ~Us;
|
||||
constexpr Direction Up = pawn_push(Us);
|
||||
constexpr Direction Down = -Up;
|
||||
constexpr Bitboard LowRanks = (Us == WHITE ? Rank2BB | Rank3BB : Rank7BB | Rank6BB);
|
||||
|
@ -252,7 +252,7 @@ namespace {
|
|||
template<Tracing T> template<Color Us, PieceType Pt>
|
||||
Score Evaluation<T>::pieces() {
|
||||
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Color Them = ~Us;
|
||||
constexpr Direction Down = -pawn_push(Us);
|
||||
constexpr Bitboard OutpostRanks = (Us == WHITE ? Rank4BB | Rank5BB | Rank6BB
|
||||
: Rank5BB | Rank4BB | Rank3BB);
|
||||
|
@ -298,12 +298,12 @@ namespace {
|
|||
else if (Pt == KNIGHT && bb & b & ~pos.pieces(Us))
|
||||
score += Outpost;
|
||||
|
||||
// Knight and Bishop bonus for being right behind a pawn
|
||||
// Bonus for a knight or bishop shielded by pawn
|
||||
if (shift<Down>(pos.pieces(PAWN)) & s)
|
||||
score += MinorBehindPawn;
|
||||
|
||||
// Penalty if the piece is far from the king
|
||||
score -= KingProtector * distance(s, pos.square<KING>(Us));
|
||||
score -= KingProtector * distance(pos.square<KING>(Us), s);
|
||||
|
||||
if (Pt == BISHOP)
|
||||
{
|
||||
|
@ -313,7 +313,7 @@ namespace {
|
|||
Bitboard blocked = pos.pieces(Us, PAWN) & shift<Down>(pos.pieces());
|
||||
|
||||
score -= BishopPawns * pos.pawns_on_same_color_squares(Us, s)
|
||||
* (!bool(attackedBy[Us][PAWN] & s) + popcount(blocked & CenterFiles));
|
||||
* (!(attackedBy[Us][PAWN] & s) + popcount(blocked & CenterFiles));
|
||||
|
||||
// Bonus for bishop on a long diagonal which can "see" both center squares
|
||||
if (more_than_one(attacks_bb<BISHOP>(s, pos.pieces(PAWN)) & Center))
|
||||
|
@ -372,7 +372,7 @@ namespace {
|
|||
template<Tracing T> template<Color Us>
|
||||
Score Evaluation<T>::king() const {
|
||||
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Color Them = ~Us;
|
||||
constexpr Bitboard Camp = (Us == WHITE ? AllSquares ^ Rank6BB ^ Rank7BB ^ Rank8BB
|
||||
: AllSquares ^ Rank1BB ^ Rank2BB ^ Rank3BB);
|
||||
|
||||
|
@ -480,7 +480,7 @@ namespace {
|
|||
template<Tracing T> template<Color Us>
|
||||
Score Evaluation<T>::threats() const {
|
||||
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Color Them = ~Us;
|
||||
constexpr Direction Up = pawn_push(Us);
|
||||
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||
|
||||
|
@ -576,7 +576,7 @@ namespace {
|
|||
template<Tracing T> template<Color Us>
|
||||
Score Evaluation<T>::passed() const {
|
||||
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Color Them = ~Us;
|
||||
constexpr Direction Up = pawn_push(Us);
|
||||
|
||||
auto king_proximity = [&](Color c, Square s) {
|
||||
|
@ -667,7 +667,7 @@ namespace {
|
|||
if (pos.non_pawn_material() < SpaceThreshold)
|
||||
return SCORE_ZERO;
|
||||
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Color Them = ~Us;
|
||||
constexpr Direction Down = -pawn_push(Us);
|
||||
constexpr Bitboard SpaceMask =
|
||||
Us == WHITE ? CenterFiles & (Rank2BB | Rank3BB | Rank4BB)
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace {
|
|||
template<Color Us>
|
||||
int imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
|
||||
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Color Them = ~Us;
|
||||
|
||||
int bonus = 0;
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace {
|
|||
template<Color Us, GenType Type>
|
||||
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Color Them = ~Us;
|
||||
constexpr Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
||||
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||
constexpr Direction Up = pawn_push(Us);
|
||||
|
@ -319,7 +319,7 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
|
|||
while (sliders)
|
||||
{
|
||||
Square checksq = pop_lsb(&sliders);
|
||||
sliderAttacks |= LineBB[checksq][ksq] ^ checksq;
|
||||
sliderAttacks |= LineBB[ksq][checksq] ^ checksq;
|
||||
}
|
||||
|
||||
// Generate evasions for king, capture and non capture moves
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace {
|
|||
template<Color Us>
|
||||
Score evaluate(const Position& pos, Pawns::Entry* e) {
|
||||
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Color Them = ~Us;
|
||||
constexpr Direction Up = pawn_push(Us);
|
||||
|
||||
Bitboard neighbours, stoppers, support, phalanx, opposed;
|
||||
|
@ -187,7 +187,7 @@ Entry* probe(const Position& pos) {
|
|||
template<Color Us>
|
||||
Score Entry::evaluate_shelter(const Position& pos, Square ksq) {
|
||||
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Color Them = ~Us;
|
||||
|
||||
Bitboard b = pos.pieces(PAWN) & ~forward_ranks_bb(Them, ksq);
|
||||
Bitboard ourPawns = b & pos.pieces(Us);
|
||||
|
|
|
@ -666,7 +666,7 @@ bool Position::gives_check(Move m) const {
|
|||
case CASTLING:
|
||||
{
|
||||
Square kfrom = from;
|
||||
Square rfrom = to; // Castling is encoded as 'King captures the rook'
|
||||
Square rfrom = to; // Castling is encoded as 'king captures the rook'
|
||||
Square kto = relative_square(sideToMove, rfrom > kfrom ? SQ_G1 : SQ_C1);
|
||||
Square rto = relative_square(sideToMove, rfrom > kfrom ? SQ_F1 : SQ_D1);
|
||||
|
||||
|
|
|
@ -292,7 +292,7 @@ void MainThread::search() {
|
|||
|
||||
if (bestThread->rootMoves[0].score >= VALUE_TB_WIN_IN_MAX_PLY)
|
||||
{
|
||||
// Make sure we pick the shortest mate
|
||||
// Make sure we pick the shortest mate / TB conversion
|
||||
if (th->rootMoves[0].score > bestThread->rootMoves[0].score)
|
||||
bestThread = th;
|
||||
}
|
||||
|
@ -867,7 +867,7 @@ namespace {
|
|||
|
||||
if (nullValue >= beta)
|
||||
{
|
||||
// Do not return unproven mate scores
|
||||
// Do not return unproven mate or TB scores
|
||||
if (nullValue >= VALUE_TB_WIN_IN_MAX_PLY)
|
||||
nullValue = beta;
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace {
|
|||
limits.startTime = now(); // As early as possible!
|
||||
|
||||
while (is >> token)
|
||||
if (token == "searchmoves")
|
||||
if (token == "searchmoves") // Needs to be the last command on the line
|
||||
while (is >> token)
|
||||
limits.searchmoves.push_back(UCI::to_move(pos, token));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue