mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
small cleanups
closes https://github.com/official-stockfish/Stockfish/pull/2653 No functional change
This commit is contained in:
parent
d940e59dad
commit
383b12e1a5
14 changed files with 64 additions and 50 deletions
|
@ -69,7 +69,7 @@ const std::string Bitboards::pretty(Bitboard b) {
|
|||
void Bitboards::init() {
|
||||
|
||||
for (unsigned i = 0; i < (1 << 16); ++i)
|
||||
PopCnt16[i] = std::bitset<16>(i).count();
|
||||
PopCnt16[i] = uint8_t(std::bitset<16>(i).count());
|
||||
|
||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||
SquareBB[s] = (1ULL << s);
|
||||
|
|
|
@ -311,7 +311,7 @@ namespace {
|
|||
|
||||
if (Pt == BISHOP)
|
||||
{
|
||||
// Penalty according to number of pawns on the same color square as the
|
||||
// Penalty according to the number of our pawns on the same color square as the
|
||||
// bishop, bigger when the center files are blocked with pawns and smaller
|
||||
// when the bishop is outside the pawn chain.
|
||||
Bitboard blocked = pos.pieces(Us, PAWN) & shift<Down>(pos.pieces());
|
||||
|
|
|
@ -44,7 +44,7 @@ int main(int argc, char* argv[]) {
|
|||
Position::init();
|
||||
Bitbases::init();
|
||||
Endgames::init();
|
||||
Threads.set(Options["Threads"]);
|
||||
Threads.set(size_t(Options["Threads"]));
|
||||
Search::clear(); // After threads are up
|
||||
|
||||
UCI::loop(argc, argv);
|
||||
|
|
|
@ -213,8 +213,31 @@ namespace {
|
|||
|
||||
|
||||
template<Color Us, GenType Type>
|
||||
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||
ExtMove* generate_all(const Position& pos, ExtMove* moveList) {
|
||||
constexpr bool Checks = Type == QUIET_CHECKS; // Reduce template instantations
|
||||
Bitboard target;
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
case CAPTURES:
|
||||
target = pos.pieces(~Us);
|
||||
break;
|
||||
case QUIETS:
|
||||
case QUIET_CHECKS:
|
||||
target = ~pos.pieces();
|
||||
break;
|
||||
case EVASIONS:
|
||||
{
|
||||
Square checksq = lsb(pos.checkers());
|
||||
target = between_bb(pos.square<KING>(Us), checksq) | checksq;
|
||||
break;
|
||||
}
|
||||
case NON_EVASIONS:
|
||||
target = ~pos.pieces(Us);
|
||||
break;
|
||||
default:
|
||||
static_assert(true, "Unsupported type in generate_all()");
|
||||
}
|
||||
|
||||
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
|
||||
moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target);
|
||||
|
@ -255,12 +278,8 @@ ExtMove* generate(const Position& pos, ExtMove* moveList) {
|
|||
|
||||
Color us = pos.side_to_move();
|
||||
|
||||
Bitboard target = Type == CAPTURES ? pos.pieces(~us)
|
||||
: Type == QUIETS ? ~pos.pieces()
|
||||
: Type == NON_EVASIONS ? ~pos.pieces(us) : 0;
|
||||
|
||||
return us == WHITE ? generate_all<WHITE, Type>(pos, moveList, target)
|
||||
: generate_all<BLACK, Type>(pos, moveList, target);
|
||||
return us == WHITE ? generate_all<WHITE, Type>(pos, moveList)
|
||||
: generate_all<BLACK, Type>(pos, moveList);
|
||||
}
|
||||
|
||||
// Explicit template instantiations
|
||||
|
@ -293,8 +312,8 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
|
|||
*moveList++ = make_move(from, pop_lsb(&b));
|
||||
}
|
||||
|
||||
return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList, ~pos.pieces())
|
||||
: generate_all<BLACK, QUIET_CHECKS>(pos, moveList, ~pos.pieces());
|
||||
return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList)
|
||||
: generate_all<BLACK, QUIET_CHECKS>(pos, moveList);
|
||||
}
|
||||
|
||||
|
||||
|
@ -325,11 +344,8 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
|
|||
return moveList; // Double check, only a king move can save the day
|
||||
|
||||
// Generate blocking evasions or captures of the checking piece
|
||||
Square checksq = lsb(pos.checkers());
|
||||
Bitboard target = between_bb(checksq, ksq) | checksq;
|
||||
|
||||
return us == WHITE ? generate_all<WHITE, EVASIONS>(pos, moveList, target)
|
||||
: generate_all<BLACK, EVASIONS>(pos, moveList, target);
|
||||
return us == WHITE ? generate_all<WHITE, EVASIONS>(pos, moveList)
|
||||
: generate_all<BLACK, EVASIONS>(pos, moveList);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ namespace {
|
|||
e->passedPawns[Us] = 0;
|
||||
e->kingSquares[Us] = SQ_NONE;
|
||||
e->pawnAttacks[Us] = e->pawnAttacksSpan[Us] = pawn_attacks_bb<Us>(ourPawns);
|
||||
e->blockedCount += popcount(shift<Up>(ourPawns) & (theirPawns | doubleAttackThem));
|
||||
|
||||
// Loop through all pawns of the current color and score each pawn
|
||||
while ((s = *pl++) != SQ_NONE)
|
||||
|
@ -106,8 +107,6 @@ namespace {
|
|||
phalanx = neighbours & rank_bb(s);
|
||||
support = neighbours & rank_bb(s - Up);
|
||||
|
||||
e->blockedCount += blocked || more_than_one(leverPush);
|
||||
|
||||
// A pawn is backward when it is behind all pawns of the same color on
|
||||
// the adjacent files and cannot safely advance.
|
||||
backward = !(neighbours & forward_ranks_bb(Them, s + Up))
|
||||
|
@ -216,7 +215,7 @@ Score Entry::evaluate_shelter(const Position& pos, Square ksq) {
|
|||
b = theirPawns & file_bb(f);
|
||||
int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
|
||||
|
||||
File d = File(edge_distance(f));
|
||||
int d = edge_distance(f);
|
||||
bonus += make_score(ShelterStrength[d][ourRank], 0);
|
||||
|
||||
if (ourRank && (ourRank == theirRank - 1))
|
||||
|
|
|
@ -591,7 +591,7 @@ bool Position::pseudo_legal(const Move m) const {
|
|||
if ( !(attacks_from<PAWN>(from, us) & pieces(~us) & to) // Not a capture
|
||||
&& !((from + pawn_push(us) == to) && empty(to)) // Not a single push
|
||||
&& !( (from + 2 * pawn_push(us) == to) // Not a double push
|
||||
&& (rank_of(from) == relative_rank(us, RANK_2))
|
||||
&& (relative_rank(us, from) == RANK_2)
|
||||
&& empty(to)
|
||||
&& empty(to - pawn_push(us))))
|
||||
return false;
|
||||
|
|
|
@ -98,7 +98,7 @@ public:
|
|||
bool is_on_semiopen_file(Color c, Square s) const;
|
||||
|
||||
// Castling
|
||||
int castling_rights(Color c) const;
|
||||
CastlingRights castling_rights(Color c) const;
|
||||
bool can_castle(CastlingRights cr) const;
|
||||
bool castling_impeded(CastlingRights cr) const;
|
||||
Square castling_rook_square(CastlingRights cr) const;
|
||||
|
@ -268,7 +268,7 @@ inline bool Position::can_castle(CastlingRights cr) const {
|
|||
return st->castlingRights & cr;
|
||||
}
|
||||
|
||||
inline int Position::castling_rights(Color c) const {
|
||||
inline CastlingRights Position::castling_rights(Color c) const {
|
||||
return c & CastlingRights(st->castlingRights);
|
||||
}
|
||||
|
||||
|
@ -399,8 +399,7 @@ inline Thread* Position::this_thread() const {
|
|||
inline void Position::put_piece(Piece pc, Square s) {
|
||||
|
||||
board[s] = pc;
|
||||
byTypeBB[ALL_PIECES] |= s;
|
||||
byTypeBB[type_of(pc)] |= s;
|
||||
byTypeBB[ALL_PIECES] |= byTypeBB[type_of(pc)] |= s;
|
||||
byColorBB[color_of(pc)] |= s;
|
||||
index[s] = pieceCount[pc]++;
|
||||
pieceList[pc][index[s]] = s;
|
||||
|
|
|
@ -272,9 +272,9 @@ void MainThread::search() {
|
|||
Thread* bestThread = this;
|
||||
|
||||
// Check if there are threads with a better score than main thread
|
||||
if ( Options["MultiPV"] == 1
|
||||
if ( int(Options["MultiPV"]) == 1
|
||||
&& !Limits.depth
|
||||
&& !(Skill(Options["Skill Level"]).enabled() || Options["UCI_LimitStrength"])
|
||||
&& !(Skill(Options["Skill Level"]).enabled() || int(Options["UCI_LimitStrength"]))
|
||||
&& rootMoves[0].pv[0] != MOVE_NONE)
|
||||
{
|
||||
std::map<Move, int64_t> votes;
|
||||
|
@ -350,17 +350,17 @@ void Thread::search() {
|
|||
if (mainThread)
|
||||
{
|
||||
if (mainThread->bestPreviousScore == VALUE_INFINITE)
|
||||
for (int i=0; i<4; ++i)
|
||||
for (int i = 0; i < 4; ++i)
|
||||
mainThread->iterValue[i] = VALUE_ZERO;
|
||||
else
|
||||
for (int i=0; i<4; ++i)
|
||||
for (int i = 0; i < 4; ++i)
|
||||
mainThread->iterValue[i] = mainThread->bestPreviousScore;
|
||||
}
|
||||
|
||||
std::copy(&lowPlyHistory[2][0], &lowPlyHistory.back().back() + 1, &lowPlyHistory[0][0]);
|
||||
std::fill(&lowPlyHistory[MAX_LPH - 2][0], &lowPlyHistory.back().back() + 1, 0);
|
||||
|
||||
size_t multiPV = Options["MultiPV"];
|
||||
size_t multiPV = size_t(Options["MultiPV"]);
|
||||
|
||||
// Pick integer skill levels, but non-deterministically round up or down
|
||||
// such that the average integer skill corresponds to the input floating point one.
|
||||
|
@ -540,8 +540,8 @@ void Thread::search() {
|
|||
&& !Threads.stop
|
||||
&& !mainThread->stopOnPonderhit)
|
||||
{
|
||||
double fallingEval = (332 + 6 * (mainThread->bestPreviousScore - bestValue)
|
||||
+ 6 * (mainThread->iterValue[iterIdx] - bestValue)) / 704.0;
|
||||
double fallingEval = (332 + 6 * (mainThread->bestPreviousScore - bestValue)
|
||||
+ 6 * (mainThread->iterValue[iterIdx] - bestValue)) / 704.0;
|
||||
fallingEval = Utility::clamp(fallingEval, 0.5, 1.5);
|
||||
|
||||
// If the bestMove is stable over several iterations, reduce time accordingly
|
||||
|
|
|
@ -530,7 +530,7 @@ int decompress_pairs(PairsData* d, uint64_t idx) {
|
|||
// I(k) = k * d->span + d->span / 2 (1)
|
||||
|
||||
// First step is to get the 'k' of the I(k) nearest to our idx, using definition (1)
|
||||
uint32_t k = idx / d->span;
|
||||
uint32_t k = uint32_t(idx / d->span);
|
||||
|
||||
// Then we read the corresponding SparseIndex[] entry
|
||||
uint32_t block = number<uint32_t, LittleEndian>(&d->sparseIndex[k].block);
|
||||
|
@ -576,7 +576,7 @@ int decompress_pairs(PairsData* d, uint64_t idx) {
|
|||
// All the symbols of a given length are consecutive integers (numerical
|
||||
// sequence property), so we can compute the offset of our symbol of
|
||||
// length len, stored at the beginning of buf64.
|
||||
sym = (buf64 - d->base64[len]) >> (64 - len - d->minSymLen);
|
||||
sym = Sym((buf64 - d->base64[len]) >> (64 - len - d->minSymLen));
|
||||
|
||||
// Now add the value of the lowest symbol of length len to get our symbol
|
||||
sym += number<Sym, LittleEndian>(&d->lowestSym[len]);
|
||||
|
@ -984,7 +984,7 @@ uint8_t* set_sizes(PairsData* d, uint8_t* data) {
|
|||
|
||||
d->sizeofBlock = 1ULL << *data++;
|
||||
d->span = 1ULL << *data++;
|
||||
d->sparseIndexSize = (tbSize + d->span - 1) / d->span; // Round up
|
||||
d->sparseIndexSize = size_t((tbSize + d->span - 1) / d->span); // Round up
|
||||
auto padding = number<uint8_t, LittleEndian>(data++);
|
||||
d->blocksNum = number<uint32_t, LittleEndian>(data); data += sizeof(uint32_t);
|
||||
d->blockLengthSize = d->blocksNum + padding; // Padded to ensure SparseIndex[]
|
||||
|
|
|
@ -151,7 +151,7 @@ void ThreadPool::set(size_t requested) {
|
|||
clear();
|
||||
|
||||
// Reallocate the hash with the new threadpool size
|
||||
TT.resize(Options["Hash"]);
|
||||
TT.resize(size_t(Options["Hash"]));
|
||||
|
||||
// Init thread number dependent search params.
|
||||
Search::init();
|
||||
|
|
|
@ -35,10 +35,10 @@ TimeManagement Time; // Our global time management object
|
|||
|
||||
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
||||
|
||||
TimePoint minThinkingTime = Options["Minimum Thinking Time"];
|
||||
TimePoint moveOverhead = Options["Move Overhead"];
|
||||
TimePoint slowMover = Options["Slow Mover"];
|
||||
TimePoint npmsec = Options["nodestime"];
|
||||
TimePoint minThinkingTime = TimePoint(Options["Minimum Thinking Time"]);
|
||||
TimePoint moveOverhead = TimePoint(Options["Move Overhead"]);
|
||||
TimePoint slowMover = TimePoint(Options["Slow Mover"]);
|
||||
TimePoint npmsec = TimePoint(Options["nodestime"]);
|
||||
|
||||
// opt_scale is a percentage of available time to use for the current move.
|
||||
// max_scale is a multiplier applied to optimumTime.
|
||||
|
@ -91,8 +91,8 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
|||
}
|
||||
|
||||
// Never use more than 80% of the available time for this move
|
||||
optimumTime = std::max<int>(minThinkingTime, opt_scale * timeLeft);
|
||||
maximumTime = std::min(0.8 * limits.time[us] - moveOverhead, max_scale * optimumTime);
|
||||
optimumTime = std::max(minThinkingTime, TimePoint(opt_scale * timeLeft));
|
||||
maximumTime = TimePoint(std::min(0.8 * limits.time[us] - moveOverhead, max_scale * optimumTime));
|
||||
|
||||
if (Options["Ponder"])
|
||||
optimumTime += optimumTime / 4;
|
||||
|
|
|
@ -94,8 +94,8 @@ void TranspositionTable::clear() {
|
|||
WinProcGroup::bindThisThread(idx);
|
||||
|
||||
// Each thread will zero its part of the hash table
|
||||
const size_t stride = clusterCount / Options["Threads"],
|
||||
start = stride * idx,
|
||||
const size_t stride = size_t(clusterCount / Options["Threads"]),
|
||||
start = size_t(stride * idx),
|
||||
len = idx != Options["Threads"] - 1 ?
|
||||
stride : clusterCount - start;
|
||||
|
||||
|
@ -103,7 +103,7 @@ void TranspositionTable::clear() {
|
|||
});
|
||||
}
|
||||
|
||||
for (std::thread& th: threads)
|
||||
for (std::thread& th : threads)
|
||||
th.join();
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ template<> void Tune::Entry<int>::init_option() { make_option(name, value, range
|
|||
|
||||
template<> void Tune::Entry<int>::read_option() {
|
||||
if (Options.count(name))
|
||||
value = Options[name];
|
||||
value = int(Options[name]);
|
||||
}
|
||||
|
||||
template<> void Tune::Entry<Value>::init_option() { make_option(name, value, range); }
|
||||
|
@ -100,10 +100,10 @@ template<> void Tune::Entry<Score>::init_option() {
|
|||
|
||||
template<> void Tune::Entry<Score>::read_option() {
|
||||
if (Options.count("m" + name))
|
||||
value = make_score(Options["m" + name], eg_value(value));
|
||||
value = make_score(int(Options["m" + name]), eg_value(value));
|
||||
|
||||
if (Options.count("e" + name))
|
||||
value = make_score(mg_value(value), Options["e" + name]);
|
||||
value = make_score(mg_value(value), int(Options["e" + name]));
|
||||
}
|
||||
|
||||
// Instead of a variable here we have a PostUpdate function: just call it
|
||||
|
|
|
@ -38,9 +38,9 @@ namespace UCI {
|
|||
|
||||
/// 'On change' actions, triggered by an option's value change
|
||||
void on_clear_hash(const Option&) { Search::clear(); }
|
||||
void on_hash_size(const Option& o) { TT.resize(o); }
|
||||
void on_hash_size(const Option& o) { TT.resize(size_t(o)); }
|
||||
void on_logger(const Option& o) { start_logger(o); }
|
||||
void on_threads(const Option& o) { Threads.set(o); }
|
||||
void on_threads(const Option& o) { Threads.set(size_t(o)); }
|
||||
void on_tb_path(const Option& o) { Tablebases::init(o); }
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue