closes https://github.com/official-stockfish/Stockfish/pull/2653
No functional change
14 files changed:
void Bitboards::init() {
for (unsigned i = 0; i < (1 << 16); ++i)
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);
for (Square s = SQ_A1; s <= SQ_H8; ++s)
SquareBB[s] = (1ULL << s);
- // 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());
// 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());
Position::init();
Bitbases::init();
Endgames::init();
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);
Search::clear(); // After threads are up
UCI::loop(argc, argv);
template<Color Us, GenType Type>
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
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);
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target);
Color us = pos.side_to_move();
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
}
// Explicit template instantiations
*moveList++ = make_move(from, pop_lsb(&b));
}
*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);
return moveList; // Double check, only a king move can save the day
// Generate blocking evasions or captures of the checking piece
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);
e->passedPawns[Us] = 0;
e->kingSquares[Us] = SQ_NONE;
e->pawnAttacks[Us] = e->pawnAttacksSpan[Us] = pawn_attacks_bb<Us>(ourPawns);
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)
// Loop through all pawns of the current color and score each pawn
while ((s = *pl++) != SQ_NONE)
phalanx = neighbours & rank_bb(s);
support = neighbours & rank_bb(s - Up);
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))
// 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))
b = theirPawns & file_bb(f);
int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
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))
bonus += make_score(ShelterStrength[d][ourRank], 0);
if (ourRank && (ourRank == theirRank - 1))
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
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;
&& empty(to)
&& empty(to - pawn_push(us))))
return false;
bool is_on_semiopen_file(Color c, Square s) const;
// Castling
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;
bool can_castle(CastlingRights cr) const;
bool castling_impeded(CastlingRights cr) const;
Square castling_rook_square(CastlingRights cr) const;
return st->castlingRights & cr;
}
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);
}
return c & CastlingRights(st->castlingRights);
}
inline void Position::put_piece(Piece pc, Square s) {
board[s] = pc;
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;
byColorBB[color_of(pc)] |= s;
index[s] = pieceCount[pc]++;
pieceList[pc][index[s]] = s;
Thread* bestThread = this;
// Check if there are threads with a better score than main thread
Thread* bestThread = this;
// Check if there are threads with a better score than main thread
- if ( Options["MultiPV"] == 1
+ if ( int(Options["MultiPV"]) == 1
- && !(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;
&& rootMoves[0].pv[0] != MOVE_NONE)
{
std::map<Move, int64_t> votes;
if (mainThread)
{
if (mainThread->bestPreviousScore == VALUE_INFINITE)
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
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);
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.
// Pick integer skill levels, but non-deterministically round up or down
// such that the average integer skill corresponds to the input floating point one.
&& !Threads.stop
&& !mainThread->stopOnPonderhit)
{
&& !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
fallingEval = Utility::clamp(fallingEval, 0.5, 1.5);
// If the bestMove is stable over several iterations, reduce time accordingly
// 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)
// 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);
// Then we read the corresponding SparseIndex[] entry
uint32_t block = number<uint32_t, LittleEndian>(&d->sparseIndex[k].block);
// 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.
// 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]);
// Now add the value of the lowest symbol of length len to get our symbol
sym += number<Sym, LittleEndian>(&d->lowestSym[len]);
d->sizeofBlock = 1ULL << *data++;
d->span = 1ULL << *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[]
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[]
clear();
// Reallocate the hash with the new threadpool size
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();
// Init thread number dependent search params.
Search::init();
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
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.
// opt_scale is a percentage of available time to use for the current move.
// max_scale is a multiplier applied to optimumTime.
}
// Never use more than 80% of the available time for this move
}
// 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;
if (Options["Ponder"])
optimumTime += optimumTime / 4;
WinProcGroup::bindThisThread(idx);
// Each thread will zero its part of the hash table
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;
len = idx != Options["Threads"] - 1 ?
stride : clusterCount - start;
- for (std::thread& th: threads)
+ for (std::thread& th : threads)
template<> void Tune::Entry<int>::read_option() {
if (Options.count(name))
template<> void Tune::Entry<int>::read_option() {
if (Options.count(name))
+ value = int(Options[name]);
}
template<> void Tune::Entry<Value>::init_option() { make_option(name, value, range); }
}
template<> void Tune::Entry<Value>::init_option() { make_option(name, value, range); }
template<> void Tune::Entry<Score>::read_option() {
if (Options.count("m" + name))
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))
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
}
// Instead of a variable here we have a PostUpdate function: just call it
/// 'On change' actions, triggered by an option's value change
void on_clear_hash(const Option&) { Search::clear(); }
/// '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_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); }
void on_tb_path(const Option& o) { Tablebases::init(o); }