mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-06 10:53:50 +08:00
Various cleanups
Various simplifications, cleanups, consistancy improvements, and warning mitigations. Passed Non-Regression STC: https://tests.stockfishchess.org/tests/view/67e7dd2d6682f97da2178fd8 LLR: 2.94 (-2.94,2.94) <-1.75,0.25> Total: 386848 W: 99593 L: 99751 D: 187504 Ptnml(0-2): 1024, 41822, 107973, 41498, 1107 closes https://github.com/official-stockfish/Stockfish/pull/5948 No functional change
This commit is contained in:
@@ -102,17 +102,17 @@ constexpr Bitboard square_bb(Square s) {
|
||||
// Overloads of bitwise operators between a Bitboard and a Square for testing
|
||||
// whether a given bit is set in a bitboard, and for setting and clearing bits.
|
||||
|
||||
inline Bitboard operator&(Bitboard b, Square s) { return b & square_bb(s); }
|
||||
inline Bitboard operator|(Bitboard b, Square s) { return b | square_bb(s); }
|
||||
inline Bitboard operator^(Bitboard b, Square s) { return b ^ square_bb(s); }
|
||||
inline Bitboard& operator|=(Bitboard& b, Square s) { return b |= square_bb(s); }
|
||||
inline Bitboard& operator^=(Bitboard& b, Square s) { return b ^= square_bb(s); }
|
||||
constexpr Bitboard operator&(Bitboard b, Square s) { return b & square_bb(s); }
|
||||
constexpr Bitboard operator|(Bitboard b, Square s) { return b | square_bb(s); }
|
||||
constexpr Bitboard operator^(Bitboard b, Square s) { return b ^ square_bb(s); }
|
||||
constexpr Bitboard& operator|=(Bitboard& b, Square s) { return b |= square_bb(s); }
|
||||
constexpr Bitboard& operator^=(Bitboard& b, Square s) { return b ^= square_bb(s); }
|
||||
|
||||
inline Bitboard operator&(Square s, Bitboard b) { return b & s; }
|
||||
inline Bitboard operator|(Square s, Bitboard b) { return b | s; }
|
||||
inline Bitboard operator^(Square s, Bitboard b) { return b ^ s; }
|
||||
constexpr Bitboard operator&(Square s, Bitboard b) { return b & s; }
|
||||
constexpr Bitboard operator|(Square s, Bitboard b) { return b | s; }
|
||||
constexpr Bitboard operator^(Square s, Bitboard b) { return b ^ s; }
|
||||
|
||||
inline Bitboard operator|(Square s1, Square s2) { return square_bb(s1) | s2; }
|
||||
constexpr Bitboard operator|(Square s1, Square s2) { return square_bb(s1) | s2; }
|
||||
|
||||
constexpr bool more_than_one(Bitboard b) { return b & (b - 1); }
|
||||
|
||||
|
||||
@@ -38,17 +38,15 @@
|
||||
namespace Stockfish {
|
||||
|
||||
// Returns a static, purely materialistic evaluation of the position from
|
||||
// the point of view of the given color. It can be divided by PawnValue to get
|
||||
// the point of view of the side to move. It can be divided by PawnValue to get
|
||||
// an approximation of the material advantage on the board in terms of pawns.
|
||||
int Eval::simple_eval(const Position& pos, Color c) {
|
||||
int Eval::simple_eval(const Position& pos) {
|
||||
Color c = pos.side_to_move();
|
||||
return PawnValue * (pos.count<PAWN>(c) - pos.count<PAWN>(~c))
|
||||
+ (pos.non_pawn_material(c) - pos.non_pawn_material(~c));
|
||||
}
|
||||
|
||||
bool Eval::use_smallnet(const Position& pos) {
|
||||
int simpleEval = simple_eval(pos, pos.side_to_move());
|
||||
return std::abs(simpleEval) > 962;
|
||||
}
|
||||
bool Eval::use_smallnet(const Position& pos) { return std::abs(simple_eval(pos)) > 962; }
|
||||
|
||||
// Evaluate is the evaluator for the outer world. It returns a static evaluation
|
||||
// of the position from the point of view of the side to move.
|
||||
|
||||
@@ -44,7 +44,7 @@ class AccumulatorStack;
|
||||
|
||||
std::string trace(Position& pos, const Eval::NNUE::Networks& networks);
|
||||
|
||||
int simple_eval(const Position& pos, Color c);
|
||||
int simple_eval(const Position& pos);
|
||||
bool use_smallnet(const Position& pos);
|
||||
Value evaluate(const NNUE::Networks& networks,
|
||||
const Position& pos,
|
||||
|
||||
@@ -176,7 +176,7 @@ void MovePicker::score() {
|
||||
: 0;
|
||||
|
||||
// malus for putting piece en prise
|
||||
m.value -= (pt == QUEEN ? bool(to & threatenedByRook) * 49000
|
||||
m.value -= (pt == QUEEN && bool(to & threatenedByRook) ? 49000
|
||||
: pt == ROOK && bool(to & threatenedByMinor) ? 24335
|
||||
: 0);
|
||||
|
||||
|
||||
@@ -245,19 +245,16 @@ class AffineTransform {
|
||||
#if defined(USE_AVX2)
|
||||
using vec_t = __m256i;
|
||||
#define vec_setzero() _mm256_setzero_si256()
|
||||
#define vec_set_32 _mm256_set1_epi32
|
||||
#define vec_add_dpbusd_32 Simd::m256_add_dpbusd_epi32
|
||||
#define vec_hadd Simd::m256_hadd
|
||||
#elif defined(USE_SSSE3)
|
||||
using vec_t = __m128i;
|
||||
#define vec_setzero() _mm_setzero_si128()
|
||||
#define vec_set_32 _mm_set1_epi32
|
||||
#define vec_add_dpbusd_32 Simd::m128_add_dpbusd_epi32
|
||||
#define vec_hadd Simd::m128_hadd
|
||||
#elif defined(USE_NEON_DOTPROD)
|
||||
using vec_t = int32x4_t;
|
||||
#define vec_setzero() vdupq_n_s32(0)
|
||||
#define vec_set_32 vdupq_n_s32
|
||||
#define vec_add_dpbusd_32(acc, a, b) \
|
||||
Simd::dotprod_m128_add_dpbusd_epi32(acc, vreinterpretq_s8_s32(a), \
|
||||
vreinterpretq_s8_s32(b))
|
||||
@@ -282,7 +279,6 @@ class AffineTransform {
|
||||
output[0] = vec_hadd(sum0, biases[0]);
|
||||
|
||||
#undef vec_setzero
|
||||
#undef vec_set_32
|
||||
#undef vec_add_dpbusd_32
|
||||
#undef vec_hadd
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ namespace {
|
||||
|
||||
constexpr std::string_view PieceToChar(" PNBRQK pnbrqk");
|
||||
|
||||
constexpr Piece Pieces[] = {W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
|
||||
B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING};
|
||||
static constexpr Piece Pieces[] = {W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
|
||||
B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING};
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -733,8 +733,7 @@ DirtyPiece Position::do_move(Move m,
|
||||
st->nonPawnKey[us] ^= Zobrist::psq[captured][rfrom] ^ Zobrist::psq[captured][rto];
|
||||
captured = NO_PIECE;
|
||||
}
|
||||
|
||||
if (captured)
|
||||
else if (captured)
|
||||
{
|
||||
Square capsq = to;
|
||||
|
||||
|
||||
@@ -492,7 +492,8 @@ void Search::Worker::iterative_deepening() {
|
||||
// Do we have time for the next iteration? Can we stop searching now?
|
||||
if (limits.use_time_management() && !threads.stop && !mainThread->stopOnPonderhit)
|
||||
{
|
||||
int nodesEffort = rootMoves[0].effort * 100000 / std::max(size_t(1), size_t(nodes));
|
||||
uint64_t nodesEffort =
|
||||
rootMoves[0].effort * 100000 / std::max(size_t(1), size_t(nodes));
|
||||
|
||||
double fallingEval =
|
||||
(11.396 + 2.035 * (mainThread->bestPreviousAverageScore - bestValue)
|
||||
@@ -929,10 +930,7 @@ Value Search::Worker::search(
|
||||
{
|
||||
assert(move.is_ok());
|
||||
|
||||
if (move == excludedMove)
|
||||
continue;
|
||||
|
||||
if (!pos.legal(move))
|
||||
if (move == excludedMove || !pos.legal(move))
|
||||
continue;
|
||||
|
||||
assert(pos.capture_stage(move));
|
||||
@@ -1572,12 +1570,13 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta)
|
||||
return ttData.value;
|
||||
|
||||
// Step 4. Static evaluation of the position
|
||||
Value unadjustedStaticEval = VALUE_NONE;
|
||||
const auto correctionValue = correction_value(*thisThread, pos, ss);
|
||||
Value unadjustedStaticEval = VALUE_NONE;
|
||||
if (ss->inCheck)
|
||||
bestValue = futilityBase = -VALUE_INFINITE;
|
||||
else
|
||||
{
|
||||
const auto correctionValue = correction_value(*thisThread, pos, ss);
|
||||
|
||||
if (ss->ttHit)
|
||||
{
|
||||
// Never assume anything about values stored in TT
|
||||
@@ -1930,8 +1929,8 @@ Move Skill::pick_best(const RootMoves& rootMoves, size_t multiPV) {
|
||||
for (size_t i = 0; i < multiPV; ++i)
|
||||
{
|
||||
// This is our magic formula
|
||||
int push = (weakness * int(topScore - rootMoves[i].score)
|
||||
+ delta * (rng.rand<unsigned>() % int(weakness)))
|
||||
int push = int(weakness * int(topScore - rootMoves[i].score)
|
||||
+ delta * (rng.rand<unsigned>() % int(weakness)))
|
||||
/ 128;
|
||||
|
||||
if (rootMoves[i].score + push >= maxScore)
|
||||
|
||||
14
src/types.h
14
src/types.h
@@ -290,8 +290,8 @@ struct DirtyPiece {
|
||||
};
|
||||
|
||||
#define ENABLE_INCR_OPERATORS_ON(T) \
|
||||
inline T& operator++(T& d) { return d = T(int(d) + 1); } \
|
||||
inline T& operator--(T& d) { return d = T(int(d) - 1); }
|
||||
constexpr T& operator++(T& d) { return d = T(int(d) + 1); } \
|
||||
constexpr T& operator--(T& d) { return d = T(int(d) - 1); }
|
||||
|
||||
ENABLE_INCR_OPERATORS_ON(PieceType)
|
||||
ENABLE_INCR_OPERATORS_ON(Square)
|
||||
@@ -304,10 +304,10 @@ constexpr Direction operator+(Direction d1, Direction d2) { return Direction(int
|
||||
constexpr Direction operator*(int i, Direction d) { return Direction(i * int(d)); }
|
||||
|
||||
// Additional operators to add a Direction to a Square
|
||||
constexpr Square operator+(Square s, Direction d) { return Square(int(s) + int(d)); }
|
||||
constexpr Square operator-(Square s, Direction d) { return Square(int(s) - int(d)); }
|
||||
inline Square& operator+=(Square& s, Direction d) { return s = s + d; }
|
||||
inline Square& operator-=(Square& s, Direction d) { return s = s - d; }
|
||||
constexpr Square operator+(Square s, Direction d) { return Square(int(s) + int(d)); }
|
||||
constexpr Square operator-(Square s, Direction d) { return Square(int(s) - int(d)); }
|
||||
constexpr Square& operator+=(Square& s, Direction d) { return s = s + d; }
|
||||
constexpr Square& operator-=(Square& s, Direction d) { return s = s - d; }
|
||||
|
||||
// Toggle color
|
||||
constexpr Color operator~(Color c) { return Color(c ^ BLACK); }
|
||||
@@ -335,7 +335,7 @@ constexpr Piece make_piece(Color c, PieceType pt) { return Piece((c << 3) + pt);
|
||||
|
||||
constexpr PieceType type_of(Piece pc) { return PieceType(pc & 7); }
|
||||
|
||||
inline Color color_of(Piece pc) {
|
||||
constexpr Color color_of(Piece pc) {
|
||||
assert(pc != NO_PIECE);
|
||||
return Color(pc >> 3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user