mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Assorted trivial cleanups (#1894)
To address https://github.com/official-stockfish/Stockfish/issues/1862 No functional change.
This commit is contained in:
parent
79c97625a4
commit
eb6d7f537d
10 changed files with 63 additions and 60 deletions
|
@ -184,8 +184,8 @@ namespace {
|
|||
|
||||
// init_magics() computes all rook and bishop attacks at startup. Magic
|
||||
// bitboards are used to look up attacks of sliding pieces. As a reference see
|
||||
// chessprogramming.wikispaces.com/Magic+Bitboards. In particular, here we
|
||||
// use the so called "fancy" approach.
|
||||
// www.chessprogramming.org/Magic_Bitboards. In particular, here we use the so
|
||||
// called "fancy" approach.
|
||||
|
||||
void init_magics(Bitboard table[], Magic magics[], Direction directions[]) {
|
||||
|
||||
|
|
|
@ -724,6 +724,9 @@ ScaleFactor Endgame<KNPK>::operator()(const Position& pos) const {
|
|||
template<>
|
||||
ScaleFactor Endgame<KNPKB>::operator()(const Position& pos) const {
|
||||
|
||||
assert(verify_material(pos, strongSide, KnightValueMg, 1));
|
||||
assert(verify_material(pos, weakSide, BishopValueMg, 0));
|
||||
|
||||
Square pawnSq = pos.square<PAWN>(strongSide);
|
||||
Square bishopSq = pos.square<BISHOP>(weakSide);
|
||||
Square weakKingSq = pos.square<KING>(weakSide);
|
||||
|
|
|
@ -213,7 +213,7 @@ namespace {
|
|||
// kingRing[color] are the squares adjacent to the king, plus (only for a
|
||||
// king on its first rank) the squares two ranks in front. For instance,
|
||||
// if black's king is on g8, kingRing[BLACK] is f8, h8, f7, g7, h7, f6, g6
|
||||
// and h6. It is set to 0 when king safety evaluation is skipped.
|
||||
// and h6.
|
||||
Bitboard kingRing[COLOR_NB];
|
||||
|
||||
// kingAttackersCount[color] is the number of pieces of the given color
|
||||
|
@ -505,7 +505,7 @@ namespace {
|
|||
Score score = SCORE_ZERO;
|
||||
|
||||
// Non-pawn enemies
|
||||
nonPawnEnemies = pos.pieces(Them) & ~pos.pieces(Them, PAWN);
|
||||
nonPawnEnemies = pos.pieces(Them) & ~pos.pieces(PAWN);
|
||||
|
||||
// Squares strongly protected by the enemy, either because they defend the
|
||||
// square with a pawn, or because they defend the square twice and we don't.
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace {
|
|||
template<Color Us, CastlingSide Cs, bool Checks, bool Chess960>
|
||||
ExtMove* generate_castling(const Position& pos, ExtMove* moveList) {
|
||||
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr CastlingRight Cr = Us | Cs;
|
||||
constexpr bool KingSide = (Cs == KING_SIDE);
|
||||
|
||||
|
@ -39,7 +40,7 @@ namespace {
|
|||
Square kfrom = pos.square<KING>(Us);
|
||||
Square rfrom = pos.castling_rook_square(Cr);
|
||||
Square kto = relative_square(Us, KingSide ? SQ_G1 : SQ_C1);
|
||||
Bitboard enemies = pos.pieces(~Us);
|
||||
Bitboard enemies = pos.pieces(Them);
|
||||
|
||||
assert(!pos.checkers());
|
||||
|
||||
|
@ -53,7 +54,7 @@ namespace {
|
|||
// Because we generate only legal castling moves we need to verify that
|
||||
// when moving the castling rook we do not discover some hidden checker.
|
||||
// For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
|
||||
if (Chess960 && (attacks_bb<ROOK>(kto, pos.pieces() ^ rfrom) & pos.pieces(~Us, ROOK, QUEEN)))
|
||||
if (Chess960 && (attacks_bb<ROOK>(kto, pos.pieces() ^ rfrom) & pos.pieces(Them, ROOK, QUEEN)))
|
||||
return moveList;
|
||||
|
||||
Move m = make<CASTLING>(kfrom, rfrom);
|
||||
|
@ -93,8 +94,7 @@ namespace {
|
|||
template<Color Us, GenType Type>
|
||||
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||
|
||||
// Compute our parametrized parameters at compile time, named according to
|
||||
// the point of view of white side.
|
||||
// Compute some compile time parameters relative to the white side
|
||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||
constexpr Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
||||
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||
|
|
|
@ -85,11 +85,11 @@ enum StatsParams { NOT_USED = 0 };
|
|||
/// ButterflyHistory records how often quiet moves have been successful or
|
||||
/// unsuccessful during the current search, and is used for reduction and move
|
||||
/// ordering decisions. It uses 2 tables (one for each color) indexed by
|
||||
/// the move's from and to squares, see chessprogramming.wikispaces.com/Butterfly+Boards
|
||||
/// the move's from and to squares, see www.chessprogramming.org/Butterfly_Boards
|
||||
typedef Stats<int16_t, 10692, COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)> ButterflyHistory;
|
||||
|
||||
/// CounterMoveHistory stores counter moves indexed by [piece][to] of the previous
|
||||
/// move, see chessprogramming.wikispaces.com/Countermove+Heuristic
|
||||
/// move, see www.chessprogramming.org/Countermove_Heuristic
|
||||
typedef Stats<Move, NOT_USED, PIECE_NB, SQUARE_NB> CounterMoveHistory;
|
||||
|
||||
/// CapturePieceToHistory is addressed by a move's [piece][to][captured piece type]
|
||||
|
|
|
@ -183,7 +183,7 @@ void Position::init() {
|
|||
{
|
||||
std::swap(cuckoo[i], key);
|
||||
std::swap(cuckooMove[i], move);
|
||||
if (move == 0) // Arrived at empty slot ?
|
||||
if (move == MOVE_NONE) // Arrived at empty slot?
|
||||
break;
|
||||
i = (i == H1(key)) ? H2(key) : H1(key); // Push victim to alternative slot
|
||||
}
|
||||
|
@ -465,16 +465,16 @@ const string Position::fen() const {
|
|||
ss << (sideToMove == WHITE ? " w " : " b ");
|
||||
|
||||
if (can_castle(WHITE_OO))
|
||||
ss << (chess960 ? char('A' + file_of(castling_rook_square(WHITE | KING_SIDE))) : 'K');
|
||||
ss << (chess960 ? char('A' + file_of(castling_rook_square(WHITE_OO ))) : 'K');
|
||||
|
||||
if (can_castle(WHITE_OOO))
|
||||
ss << (chess960 ? char('A' + file_of(castling_rook_square(WHITE | QUEEN_SIDE))) : 'Q');
|
||||
ss << (chess960 ? char('A' + file_of(castling_rook_square(WHITE_OOO))) : 'Q');
|
||||
|
||||
if (can_castle(BLACK_OO))
|
||||
ss << (chess960 ? char('a' + file_of(castling_rook_square(BLACK | KING_SIDE))) : 'k');
|
||||
ss << (chess960 ? char('a' + file_of(castling_rook_square(BLACK_OO ))) : 'k');
|
||||
|
||||
if (can_castle(BLACK_OOO))
|
||||
ss << (chess960 ? char('a' + file_of(castling_rook_square(BLACK | QUEEN_SIDE))) : 'q');
|
||||
ss << (chess960 ? char('a' + file_of(castling_rook_square(BLACK_OOO))) : 'q');
|
||||
|
||||
if (!can_castle(ANY_CASTLING))
|
||||
ss << '-';
|
||||
|
|
|
@ -91,8 +91,8 @@ constexpr Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
|
|||
};
|
||||
|
||||
constexpr Score PBonus[RANK_NB][FILE_NB] =
|
||||
{ // Pawn
|
||||
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) },
|
||||
{ // Pawn (asymmetric distribution)
|
||||
{ },
|
||||
{ S( 0,-11), S( -3,-4), S(13, -1), S( 19, -4), S(16, 17), S(13, 7), S( 4, 4), S( -4,-13) },
|
||||
{ S(-16, -8), S(-12,-6), S(20, -3), S( 21, 0), S(25,-11), S(29, 3), S( 0, 0), S(-27, -1) },
|
||||
{ S(-11, 3), S(-17, 6), S(11,-10), S( 21, 1), S(32, -6), S(19,-11), S( -5, 0), S(-14, -2) },
|
||||
|
|
|
@ -113,8 +113,8 @@ namespace {
|
|||
Value value_from_tt(Value v, int ply);
|
||||
void update_pv(Move* pv, Move move, Move* childPv);
|
||||
void update_continuation_histories(Stack* ss, Piece pc, Square to, int bonus);
|
||||
void update_quiet_stats(const Position& pos, Stack* ss, Move move, Move* quiets, int quietsCnt, int bonus);
|
||||
void update_capture_stats(const Position& pos, Move move, Move* captures, int captureCnt, int bonus);
|
||||
void update_quiet_stats(const Position& pos, Stack* ss, Move move, Move* quiets, int quietCount, int bonus);
|
||||
void update_capture_stats(const Position& pos, Move move, Move* captures, int captureCount, int bonus);
|
||||
|
||||
inline bool gives_check(const Position& pos, Move move) {
|
||||
Color us = pos.side_to_move();
|
||||
|
@ -1481,7 +1481,7 @@ moves_loop: // When in check, search starts from here
|
|||
// update_capture_stats() updates move sorting heuristics when a new capture best move is found
|
||||
|
||||
void update_capture_stats(const Position& pos, Move move,
|
||||
Move* captures, int captureCnt, int bonus) {
|
||||
Move* captures, int captureCount, int bonus) {
|
||||
|
||||
CapturePieceToHistory& captureHistory = pos.this_thread()->captureHistory;
|
||||
Piece moved_piece = pos.moved_piece(move);
|
||||
|
@ -1491,7 +1491,7 @@ moves_loop: // When in check, search starts from here
|
|||
captureHistory[moved_piece][to_sq(move)][captured] << bonus;
|
||||
|
||||
// Decrease all the other played capture moves
|
||||
for (int i = 0; i < captureCnt; ++i)
|
||||
for (int i = 0; i < captureCount; ++i)
|
||||
{
|
||||
moved_piece = pos.moved_piece(captures[i]);
|
||||
captured = type_of(pos.piece_on(to_sq(captures[i])));
|
||||
|
@ -1503,7 +1503,7 @@ moves_loop: // When in check, search starts from here
|
|||
// update_quiet_stats() updates move sorting heuristics when a new quiet best move is found
|
||||
|
||||
void update_quiet_stats(const Position& pos, Stack* ss, Move move,
|
||||
Move* quiets, int quietsCnt, int bonus) {
|
||||
Move* quiets, int quietCount, int bonus) {
|
||||
|
||||
if (ss->killers[0] != move)
|
||||
{
|
||||
|
@ -1523,7 +1523,7 @@ moves_loop: // When in check, search starts from here
|
|||
}
|
||||
|
||||
// Decrease all the other played quiet moves
|
||||
for (int i = 0; i < quietsCnt; ++i)
|
||||
for (int i = 0; i < quietCount; ++i)
|
||||
{
|
||||
thisThread->mainHistory[us][from_to(quiets[i])] << -bonus;
|
||||
update_continuation_histories(ss, pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
|
||||
|
@ -1666,7 +1666,7 @@ bool RootMove::extract_ponder_from_tt(Position& pos) {
|
|||
|
||||
assert(pv.size() == 1);
|
||||
|
||||
if (!pv[0])
|
||||
if (pv[0] == MOVE_NONE)
|
||||
return false;
|
||||
|
||||
pos.do_move(pv[0], st);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
# verify perft numbers (positions from https://chessprogramming.wikispaces.com/Perft+Results)
|
||||
# verify perft numbers (positions from www.chessprogramming.org/Perft_Results)
|
||||
|
||||
error()
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue