mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 09:13:08 +00:00
Assorted trivial cleanups 5/2019
No functional change. bench: 4178282
This commit is contained in:
parent
2ead74d1e2
commit
d39bc2efa1
12 changed files with 73 additions and 82 deletions
|
@ -1,7 +1,7 @@
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
[](https://travis-ci.org/official-stockfish/Stockfish)
|
[](https://travis-ci.org/official-stockfish/Stockfish)
|
||||||
[](https://ci.appveyor.com/project/mcostalba/stockfish)
|
[](https://ci.appveyor.com/project/mcostalba/stockfish/branch/master)
|
||||||
|
|
||||||
[Stockfish](https://stockfishchess.org) is a free, powerful UCI chess engine
|
[Stockfish](https://stockfishchess.org) is a free, powerful UCI chess engine
|
||||||
derived from Glaurung 2.1. It is not a complete chess program and requires a
|
derived from Glaurung 2.1. It is not a complete chess program and requires a
|
||||||
|
|
|
@ -88,27 +88,28 @@ namespace Endgames {
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
|
||||||
add<KPK>("KPK");
|
add<KPK>("KPK");
|
||||||
add<KNNK>("KNNK");
|
add<KNNK>("KNNK");
|
||||||
add<KBNK>("KBNK");
|
add<KBNK>("KBNK");
|
||||||
add<KRKP>("KRKP");
|
add<KRKP>("KRKP");
|
||||||
add<KRKB>("KRKB");
|
add<KRKB>("KRKB");
|
||||||
add<KRKN>("KRKN");
|
add<KRKN>("KRKN");
|
||||||
add<KQKP>("KQKP");
|
add<KQKP>("KQKP");
|
||||||
add<KQKR>("KQKR");
|
add<KQKR>("KQKR");
|
||||||
add<KNNKP>("KNNKP");
|
add<KNNKP>("KNNKP");
|
||||||
|
|
||||||
add<KNPK>("KNPK");
|
add<KNPK>("KNPK");
|
||||||
add<KNPKB>("KNPKB");
|
add<KNPKB>("KNPKB");
|
||||||
add<KRPKR>("KRPKR");
|
add<KRPKR>("KRPKR");
|
||||||
add<KRPKB>("KRPKB");
|
add<KRPKB>("KRPKB");
|
||||||
add<KBPKB>("KBPKB");
|
add<KBPKB>("KBPKB");
|
||||||
add<KBPKN>("KBPKN");
|
add<KBPKN>("KBPKN");
|
||||||
add<KBPPKB>("KBPPKB");
|
add<KBPPKB>("KBPPKB");
|
||||||
add<KRPPKRP>("KRPPKRP");
|
add<KRPPKRP>("KRPPKRP");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Mate with KX vs K. This function is used to evaluate positions with
|
/// Mate with KX vs K. This function is used to evaluate positions with
|
||||||
/// king and plenty of material vs a lone king. It simply gives the
|
/// king and plenty of material vs a lone king. It simply gives the
|
||||||
/// attacking side a bonus for driving the defending king towards the edge
|
/// attacking side a bonus for driving the defending king towards the edge
|
||||||
|
|
|
@ -91,7 +91,7 @@ struct Endgame : public EndgameBase<T> {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// The Endgames class stores the pointers to endgame evaluation and scaling
|
/// The Endgames namespace handles the pointers to endgame evaluation and scaling
|
||||||
/// base objects in two std::map. We use polymorphism to invoke the actual
|
/// base objects in two std::map. We use polymorphism to invoke the actual
|
||||||
/// endgame function by calling its virtual operator().
|
/// endgame function by calling its virtual operator().
|
||||||
|
|
||||||
|
@ -102,6 +102,8 @@ namespace Endgames {
|
||||||
|
|
||||||
extern std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
extern std::pair<Map<Value>, Map<ScaleFactor>> maps;
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Map<T>& map() {
|
Map<T>& map() {
|
||||||
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
|
return std::get<std::is_same<T, ScaleFactor>::value>(maps);
|
||||||
|
@ -119,8 +121,6 @@ namespace Endgames {
|
||||||
const EndgameBase<T>* probe(Key key) {
|
const EndgameBase<T>* probe(Key key) {
|
||||||
return map<T>().count(key) ? map<T>()[key].get() : nullptr;
|
return map<T>().count(key) ? map<T>()[key].get() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // #ifndef ENDGAME_H_INCLUDED
|
#endif // #ifndef ENDGAME_H_INCLUDED
|
||||||
|
|
|
@ -190,10 +190,8 @@ namespace {
|
||||||
// color, including x-rays. But diagonal x-rays through pawns are not computed.
|
// color, including x-rays. But diagonal x-rays through pawns are not computed.
|
||||||
Bitboard attackedBy2[COLOR_NB];
|
Bitboard attackedBy2[COLOR_NB];
|
||||||
|
|
||||||
// kingRing[color] are the squares adjacent to the king, plus (only for a
|
// kingRing[color] are the squares adjacent to the king plus some other
|
||||||
// king on its first rank) the squares two ranks in front. For instance,
|
// very near squares, depending on king position.
|
||||||
// if black's king is on g8, kingRing[BLACK] is f8, h8, f7, g7, h7, f6, g6
|
|
||||||
// and h6.
|
|
||||||
Bitboard kingRing[COLOR_NB];
|
Bitboard kingRing[COLOR_NB];
|
||||||
|
|
||||||
// kingAttackersCount[color] is the number of pieces of the given color
|
// kingAttackersCount[color] is the number of pieces of the given color
|
||||||
|
@ -802,7 +800,7 @@ namespace {
|
||||||
|
|
||||||
// Early exit if score is high
|
// Early exit if score is high
|
||||||
Value v = (mg_value(score) + eg_value(score)) / 2;
|
Value v = (mg_value(score) + eg_value(score)) / 2;
|
||||||
if (abs(v) > (LazyThreshold + pos.non_pawn_material() / 64))
|
if (abs(v) > LazyThreshold + pos.non_pawn_material() / 64)
|
||||||
return pos.side_to_move() == WHITE ? v : -v;
|
return pos.side_to_move() == WHITE ? v : -v;
|
||||||
|
|
||||||
// Main evaluation begins here
|
// Main evaluation begins here
|
||||||
|
|
|
@ -42,8 +42,8 @@ int main(int argc, char* argv[]) {
|
||||||
Bitboards::init();
|
Bitboards::init();
|
||||||
Position::init();
|
Position::init();
|
||||||
Bitbases::init();
|
Bitbases::init();
|
||||||
Search::init();
|
|
||||||
Endgames::init();
|
Endgames::init();
|
||||||
|
Search::init();
|
||||||
Threads.set(Options["Threads"]);
|
Threads.set(Options["Threads"]);
|
||||||
Search::clear(); // After threads are up
|
Search::clear(); // After threads are up
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,6 @@ struct Entry {
|
||||||
Square kingSquares[COLOR_NB];
|
Square kingSquares[COLOR_NB];
|
||||||
Score kingSafety[COLOR_NB];
|
Score kingSafety[COLOR_NB];
|
||||||
int castlingRights[COLOR_NB];
|
int castlingRights[COLOR_NB];
|
||||||
int pawnsOnSquares[COLOR_NB][COLOR_NB]; // [color][light/dark squares]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef HashTable<Entry, 16384> Table;
|
typedef HashTable<Entry, 16384> Table;
|
||||||
|
|
|
@ -387,7 +387,7 @@ void Position::set_state(StateInfo* si) const {
|
||||||
if (type_of(pc) == PAWN)
|
if (type_of(pc) == PAWN)
|
||||||
si->pawnKey ^= Zobrist::psq[pc][s];
|
si->pawnKey ^= Zobrist::psq[pc][s];
|
||||||
|
|
||||||
else if (type_of(pc) != PAWN && type_of(pc) != KING)
|
else if (type_of(pc) != KING)
|
||||||
si->nonPawnMaterial[color_of(pc)] += PieceValue[MG][pc];
|
si->nonPawnMaterial[color_of(pc)] += PieceValue[MG][pc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,7 +491,7 @@ Bitboard Position::slider_blockers(Bitboard sliders, Square s, Bitboard& pinners
|
||||||
// Snipers are sliders that attack 's' when a piece and other snipers are removed
|
// Snipers are sliders that attack 's' when a piece and other snipers are removed
|
||||||
Bitboard snipers = ( (PseudoAttacks[ ROOK][s] & pieces(QUEEN, ROOK))
|
Bitboard snipers = ( (PseudoAttacks[ ROOK][s] & pieces(QUEEN, ROOK))
|
||||||
| (PseudoAttacks[BISHOP][s] & pieces(QUEEN, BISHOP))) & sliders;
|
| (PseudoAttacks[BISHOP][s] & pieces(QUEEN, BISHOP))) & sliders;
|
||||||
Bitboard occupancy = pieces() & ~snipers;
|
Bitboard occupancy = pieces() ^ snipers;
|
||||||
|
|
||||||
while (snipers)
|
while (snipers)
|
||||||
{
|
{
|
||||||
|
@ -1192,10 +1192,10 @@ bool Position::has_game_cycle(int ply) const {
|
||||||
if (ply > i)
|
if (ply > i)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// For nodes before or at the root, check that the move is a repetition one
|
// For nodes before or at the root, check that the move is a
|
||||||
// rather than a move to the current position.
|
// repetition rather than a move to the current position.
|
||||||
// In the cuckoo table, both moves Rc1c5 and Rc5c1 are stored in the same
|
// In the cuckoo table, both moves Rc1c5 and Rc5c1 are stored in
|
||||||
// location, so we have to select which square to check.
|
// the same location, so we have to select which square to check.
|
||||||
if (color_of(piece_on(empty(s1) ? s2 : s1)) != side_to_move())
|
if (color_of(piece_on(empty(s1) ? s2 : s1)) != side_to_move())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -149,7 +149,7 @@ namespace {
|
||||||
void Search::init() {
|
void Search::init() {
|
||||||
|
|
||||||
for (int i = 1; i < MAX_MOVES; ++i)
|
for (int i = 1; i < MAX_MOVES; ++i)
|
||||||
Reductions[i] = int(22.9 * std::log(i));
|
Reductions[i] = int(22.9 * std::log(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -240,17 +240,13 @@ void MainThread::search() {
|
||||||
minScore = std::min(minScore, th->rootMoves[0].score);
|
minScore = std::min(minScore, th->rootMoves[0].score);
|
||||||
|
|
||||||
// Vote according to score and depth, and select the best thread
|
// Vote according to score and depth, and select the best thread
|
||||||
int64_t bestVote = 0;
|
|
||||||
for (Thread* th : Threads)
|
for (Thread* th : Threads)
|
||||||
{
|
{
|
||||||
votes[th->rootMoves[0].pv[0]] +=
|
votes[th->rootMoves[0].pv[0]] +=
|
||||||
(th->rootMoves[0].score - minScore + 14) * int(th->completedDepth);
|
(th->rootMoves[0].score - minScore + 14) * int(th->completedDepth);
|
||||||
|
|
||||||
if (votes[th->rootMoves[0].pv[0]] > bestVote)
|
if (votes[th->rootMoves[0].pv[0]] > votes[bestThread->rootMoves[0].pv[0]])
|
||||||
{
|
|
||||||
bestVote = votes[th->rootMoves[0].pv[0]];
|
|
||||||
bestThread = th;
|
bestThread = th;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -538,13 +534,13 @@ namespace {
|
||||||
bool ttHit, ttPv, inCheck, givesCheck, improving;
|
bool ttHit, ttPv, inCheck, givesCheck, improving;
|
||||||
bool captureOrPromotion, doFullDepthSearch, moveCountPruning, ttCapture;
|
bool captureOrPromotion, doFullDepthSearch, moveCountPruning, ttCapture;
|
||||||
Piece movedPiece;
|
Piece movedPiece;
|
||||||
int moveCount, captureCount, quietCount;
|
int moveCount, captureCount, quietCount, singularLMR;
|
||||||
|
|
||||||
// Step 1. Initialize node
|
// Step 1. Initialize node
|
||||||
Thread* thisThread = pos.this_thread();
|
Thread* thisThread = pos.this_thread();
|
||||||
inCheck = pos.checkers();
|
inCheck = pos.checkers();
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
moveCount = captureCount = quietCount = ss->moveCount = 0;
|
moveCount = captureCount = quietCount = singularLMR = ss->moveCount = 0;
|
||||||
bestValue = -VALUE_INFINITE;
|
bestValue = -VALUE_INFINITE;
|
||||||
maxValue = VALUE_INFINITE;
|
maxValue = VALUE_INFINITE;
|
||||||
|
|
||||||
|
@ -589,10 +585,10 @@ namespace {
|
||||||
// starts with statScore = 0. Later grandchildren start with the last calculated
|
// starts with statScore = 0. Later grandchildren start with the last calculated
|
||||||
// statScore of the previous grandchild. This influences the reduction rules in
|
// statScore of the previous grandchild. This influences the reduction rules in
|
||||||
// LMR which are based on the statScore of parent position.
|
// LMR which are based on the statScore of parent position.
|
||||||
if (rootNode)
|
if (rootNode)
|
||||||
(ss + 4)->statScore = 0;
|
(ss + 4)->statScore = 0;
|
||||||
else
|
else
|
||||||
(ss + 2)->statScore = 0;
|
(ss + 2)->statScore = 0;
|
||||||
|
|
||||||
// Step 4. Transposition table lookup. We don't want the score of a partial
|
// Step 4. Transposition table lookup. We don't want the score of a partial
|
||||||
// search to overwrite a previous full search TT value, so we use a different
|
// search to overwrite a previous full search TT value, so we use a different
|
||||||
|
@ -850,7 +846,6 @@ moves_loop: // When in check, search starts from here
|
||||||
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
|
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
|
||||||
moveCountPruning = false;
|
moveCountPruning = false;
|
||||||
ttCapture = ttMove && pos.capture_or_promotion(ttMove);
|
ttCapture = ttMove && pos.capture_or_promotion(ttMove);
|
||||||
int singularExtensionLMRmultiplier = 0;
|
|
||||||
|
|
||||||
// Step 12. Loop through all pseudo-legal moves until no moves remain
|
// Step 12. Loop through all pseudo-legal moves until no moves remain
|
||||||
// or a beta cutoff occurs.
|
// or a beta cutoff occurs.
|
||||||
|
@ -907,12 +902,13 @@ moves_loop: // When in check, search starts from here
|
||||||
ss->excludedMove = MOVE_NONE;
|
ss->excludedMove = MOVE_NONE;
|
||||||
|
|
||||||
if (value < singularBeta)
|
if (value < singularBeta)
|
||||||
{
|
{
|
||||||
extension = ONE_PLY;
|
extension = ONE_PLY;
|
||||||
singularExtensionLMRmultiplier++;
|
singularLMR++;
|
||||||
|
|
||||||
if (value < singularBeta - std::min(3 * depth / ONE_PLY, 39))
|
if (value < singularBeta - std::min(3 * depth / ONE_PLY, 39))
|
||||||
singularExtensionLMRmultiplier++;
|
singularLMR++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multi-cut pruning
|
// Multi-cut pruning
|
||||||
// Our ttMove is assumed to fail high, and now we failed high also on a reduced
|
// Our ttMove is assumed to fail high, and now we failed high also on a reduced
|
||||||
|
@ -1023,8 +1019,9 @@ moves_loop: // When in check, search starts from here
|
||||||
// Decrease reduction if opponent's move count is high (~10 Elo)
|
// Decrease reduction if opponent's move count is high (~10 Elo)
|
||||||
if ((ss-1)->moveCount > 15)
|
if ((ss-1)->moveCount > 15)
|
||||||
r -= ONE_PLY;
|
r -= ONE_PLY;
|
||||||
|
|
||||||
// Decrease reduction if move has been singularly extended
|
// Decrease reduction if move has been singularly extended
|
||||||
r -= singularExtensionLMRmultiplier * ONE_PLY;
|
r -= singularLMR * ONE_PLY;
|
||||||
|
|
||||||
if (!captureOrPromotion)
|
if (!captureOrPromotion)
|
||||||
{
|
{
|
||||||
|
@ -1060,7 +1057,7 @@ moves_loop: // When in check, search starts from here
|
||||||
r -= ss->statScore / 20000 * ONE_PLY;
|
r -= ss->statScore / 20000 * ONE_PLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
Depth d = std::max(newDepth - std::max(r, DEPTH_ZERO), ONE_PLY);
|
Depth d = clamp(newDepth - r, ONE_PLY, newDepth);
|
||||||
|
|
||||||
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
|
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
|
||||||
|
|
||||||
|
@ -1476,7 +1473,7 @@ moves_loop: // When in check, search starts from here
|
||||||
void update_capture_stats(const Position& pos, Move move,
|
void update_capture_stats(const Position& pos, Move move,
|
||||||
Move* captures, int captureCount, int bonus) {
|
Move* captures, int captureCount, int bonus) {
|
||||||
|
|
||||||
CapturePieceToHistory& captureHistory = pos.this_thread()->captureHistory;
|
CapturePieceToHistory& captureHistory = pos.this_thread()->captureHistory;
|
||||||
Piece moved_piece = pos.moved_piece(move);
|
Piece moved_piece = pos.moved_piece(move);
|
||||||
PieceType captured = type_of(pos.piece_on(to_sq(move)));
|
PieceType captured = type_of(pos.piece_on(to_sq(move)));
|
||||||
|
|
||||||
|
@ -1715,10 +1712,4 @@ void Tablebases::rank_root_moves(Position& pos, Search::RootMoves& rootMoves) {
|
||||||
if (dtz_available || rootMoves[0].tbScore <= VALUE_DRAW)
|
if (dtz_available || rootMoves[0].tbScore <= VALUE_DRAW)
|
||||||
Cardinality = 0;
|
Cardinality = 0;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Assign the same rank to all moves
|
|
||||||
for (auto& m : rootMoves)
|
|
||||||
m.tbRank = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ struct RootMove {
|
||||||
Value score = -VALUE_INFINITE;
|
Value score = -VALUE_INFINITE;
|
||||||
Value previousScore = -VALUE_INFINITE;
|
Value previousScore = -VALUE_INFINITE;
|
||||||
int selDepth = 0;
|
int selDepth = 0;
|
||||||
int tbRank;
|
int tbRank = 0;
|
||||||
Value tbScore;
|
Value tbScore;
|
||||||
std::vector<Move> pv;
|
std::vector<Move> pv;
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,15 +43,16 @@ void TTEntry::save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev)
|
||||||
|
|
||||||
// Overwrite less valuable entries
|
// Overwrite less valuable entries
|
||||||
if ( (k >> 48) != key16
|
if ( (k >> 48) != key16
|
||||||
|| d / ONE_PLY + 10 > depth8
|
||(d - DEPTH_OFFSET) / ONE_PLY > depth8 - 4
|
||||||
|| b == BOUND_EXACT)
|
|| b == BOUND_EXACT)
|
||||||
{
|
{
|
||||||
|
assert((d - DEPTH_OFFSET) / ONE_PLY >= 0);
|
||||||
|
|
||||||
key16 = (uint16_t)(k >> 48);
|
key16 = (uint16_t)(k >> 48);
|
||||||
value16 = (int16_t)v;
|
value16 = (int16_t)v;
|
||||||
eval16 = (int16_t)ev;
|
eval16 = (int16_t)ev;
|
||||||
genBound8 = (uint8_t)(TT.generation8 | uint8_t(pv) << 2 | b);
|
genBound8 = (uint8_t)(TT.generation8 | uint8_t(pv) << 2 | b);
|
||||||
assert((d - DEPTH_NONE) / ONE_PLY >= 0);
|
depth8 = (uint8_t)((d - DEPTH_OFFSET) / ONE_PLY);
|
||||||
depth8 = (uint8_t)((d - DEPTH_NONE) / ONE_PLY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
src/tt.h
2
src/tt.h
|
@ -40,7 +40,7 @@ struct TTEntry {
|
||||||
Move move() const { return (Move )move16; }
|
Move move() const { return (Move )move16; }
|
||||||
Value value() const { return (Value)value16; }
|
Value value() const { return (Value)value16; }
|
||||||
Value eval() const { return (Value)eval16; }
|
Value eval() const { return (Value)eval16; }
|
||||||
Depth depth() const { return (Depth)(depth8 * int(ONE_PLY)) + DEPTH_NONE; }
|
Depth depth() const { return (Depth)(depth8 * int(ONE_PLY)) + DEPTH_OFFSET; }
|
||||||
bool is_pv() const { return (bool)(genBound8 & 0x4); }
|
bool is_pv() const { return (bool)(genBound8 & 0x4); }
|
||||||
Bound bound() const { return (Bound)(genBound8 & 0x3); }
|
Bound bound() const { return (Bound)(genBound8 & 0x3); }
|
||||||
void save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev);
|
void save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev);
|
||||||
|
|
|
@ -213,8 +213,9 @@ enum Depth : int {
|
||||||
DEPTH_QS_NO_CHECKS = -1 * ONE_PLY,
|
DEPTH_QS_NO_CHECKS = -1 * ONE_PLY,
|
||||||
DEPTH_QS_RECAPTURES = -5 * ONE_PLY,
|
DEPTH_QS_RECAPTURES = -5 * ONE_PLY,
|
||||||
|
|
||||||
DEPTH_NONE = -6 * ONE_PLY,
|
DEPTH_NONE = -6 * ONE_PLY,
|
||||||
DEPTH_MAX = MAX_PLY * ONE_PLY
|
DEPTH_OFFSET = DEPTH_NONE,
|
||||||
|
DEPTH_MAX = MAX_PLY * ONE_PLY
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(!(ONE_PLY & (ONE_PLY - 1)), "ONE_PLY is not a power of 2");
|
static_assert(!(ONE_PLY & (ONE_PLY - 1)), "ONE_PLY is not a power of 2");
|
||||||
|
|
Loading…
Add table
Reference in a new issue