mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Refactor syzygy code in search
Move to SF coding style. Also skip calculating piece count in search() when TB are not found (!TBCardinality) No functional change.
This commit is contained in:
parent
35c1ccef39
commit
c30eb4c9c9
1 changed files with 47 additions and 56 deletions
|
@ -188,13 +188,24 @@ template uint64_t Search::perft<true>(Position& pos, Depth depth);
|
||||||
void Search::think() {
|
void Search::think() {
|
||||||
|
|
||||||
TimeMgr.init(Limits, RootPos.game_ply(), RootPos.side_to_move());
|
TimeMgr.init(Limits, RootPos.game_ply(), RootPos.side_to_move());
|
||||||
TBHits = TBCardinality = 0;
|
|
||||||
RootInTB = false;
|
|
||||||
|
|
||||||
int cf = Options["Contempt"] * PawnValueEg / 100; // From centipawns
|
int cf = Options["Contempt"] * PawnValueEg / 100; // From centipawns
|
||||||
DrawValue[ RootPos.side_to_move()] = VALUE_DRAW - Value(cf);
|
DrawValue[ RootPos.side_to_move()] = VALUE_DRAW - Value(cf);
|
||||||
DrawValue[~RootPos.side_to_move()] = VALUE_DRAW + Value(cf);
|
DrawValue[~RootPos.side_to_move()] = VALUE_DRAW + Value(cf);
|
||||||
|
|
||||||
|
TBHits = 0;
|
||||||
|
RootInTB = false;
|
||||||
|
TBProbeDepth = Options["SyzygyProbeDepth"] * ONE_PLY;
|
||||||
|
TB50MoveRule = Options["Syzygy50MoveRule"];
|
||||||
|
TBCardinality = Options["SyzygyProbeLimit"];
|
||||||
|
|
||||||
|
// Skip TB probing when no TB found: !TBLargest -> !TBCardinality
|
||||||
|
if (TBCardinality > Tablebases::TBLargest)
|
||||||
|
{
|
||||||
|
TBCardinality = Tablebases::TBLargest;
|
||||||
|
TBProbeDepth = DEPTH_ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
if (RootMoves.empty())
|
if (RootMoves.empty())
|
||||||
{
|
{
|
||||||
RootMoves.push_back(MOVE_NONE);
|
RootMoves.push_back(MOVE_NONE);
|
||||||
|
@ -204,36 +215,16 @@ void Search::think() {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Check Tablebases at root
|
if (TBCardinality >= RootPos.count<ALL_PIECES>(WHITE)
|
||||||
int piecesCnt = RootPos.count<ALL_PIECES>(WHITE) + RootPos.count<ALL_PIECES>(BLACK);
|
+ RootPos.count<ALL_PIECES>(BLACK))
|
||||||
TBCardinality = Options["SyzygyProbeLimit"];
|
|
||||||
TBProbeDepth = Options["SyzygyProbeDepth"] * ONE_PLY;
|
|
||||||
if (TBCardinality > Tablebases::TBLargest)
|
|
||||||
{
|
{
|
||||||
TBCardinality = Tablebases::TBLargest;
|
|
||||||
TBProbeDepth = 0 * ONE_PLY;
|
|
||||||
}
|
|
||||||
TB50MoveRule = Options["Syzygy50MoveRule"];
|
|
||||||
|
|
||||||
if (piecesCnt <= TBCardinality)
|
|
||||||
{
|
|
||||||
TBHits = RootMoves.size();
|
|
||||||
|
|
||||||
// If the current root position is in the tablebases then RootMoves
|
// If the current root position is in the tablebases then RootMoves
|
||||||
// contains only moves that preserve the draw or win.
|
// contains only moves that preserve the draw or win.
|
||||||
RootInTB = Tablebases::root_probe(RootPos, TBScore);
|
RootInTB = Tablebases::root_probe(RootPos, TBScore);
|
||||||
|
|
||||||
if (RootInTB)
|
if (RootInTB)
|
||||||
{
|
|
||||||
TBCardinality = 0; // Do not probe tablebases during the search
|
TBCardinality = 0; // Do not probe tablebases during the search
|
||||||
|
|
||||||
// It might be a good idea to mangle the hash key (xor it
|
|
||||||
// with a fixed value) in order to "clear" the hash table of
|
|
||||||
// the results of previous probes. However, that would have to
|
|
||||||
// be done from within the Position class, so we skip it for now.
|
|
||||||
|
|
||||||
// Optional: decrease target time.
|
|
||||||
}
|
|
||||||
else // If DTZ tables are missing, use WDL tables as a fallback
|
else // If DTZ tables are missing, use WDL tables as a fallback
|
||||||
{
|
{
|
||||||
// Filter out moves that do not preserve a draw or win
|
// Filter out moves that do not preserve a draw or win
|
||||||
|
@ -244,15 +235,14 @@ void Search::think() {
|
||||||
TBCardinality = 0;
|
TBCardinality = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!RootInTB)
|
if (RootInTB)
|
||||||
{
|
|
||||||
TBHits = 0;
|
|
||||||
}
|
|
||||||
else if (!TB50MoveRule)
|
|
||||||
{
|
{
|
||||||
|
TBHits = RootMoves.size();
|
||||||
|
|
||||||
|
if (!TB50MoveRule)
|
||||||
TBScore = TBScore > VALUE_DRAW ? VALUE_MATE - MAX_PLY - 1
|
TBScore = TBScore > VALUE_DRAW ? VALUE_MATE - MAX_PLY - 1
|
||||||
: TBScore < VALUE_DRAW ? -VALUE_MATE + MAX_PLY + 1
|
: TBScore < VALUE_DRAW ? -VALUE_MATE + MAX_PLY + 1
|
||||||
: TBScore;
|
: VALUE_DRAW;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +460,6 @@ namespace {
|
||||||
bool inCheck, givesCheck, singularExtensionNode, improving;
|
bool inCheck, givesCheck, singularExtensionNode, improving;
|
||||||
bool captureOrPromotion, dangerous, doFullDepthSearch;
|
bool captureOrPromotion, dangerous, doFullDepthSearch;
|
||||||
int moveCount, quietCount;
|
int moveCount, quietCount;
|
||||||
int piecesCnt;
|
|
||||||
|
|
||||||
// Step 1. Initialize node
|
// Step 1. Initialize node
|
||||||
Thread* thisThread = pos.this_thread();
|
Thread* thisThread = pos.this_thread();
|
||||||
|
@ -549,10 +538,11 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 4a. Tablebase probe
|
// Step 4a. Tablebase probe
|
||||||
piecesCnt = pos.count<ALL_PIECES>(WHITE) + pos.count<ALL_PIECES>(BLACK);
|
if (!RootNode && TBCardinality)
|
||||||
|
{
|
||||||
|
int piecesCnt = pos.count<ALL_PIECES>(WHITE) + pos.count<ALL_PIECES>(BLACK);
|
||||||
|
|
||||||
if ( !RootNode
|
if ( piecesCnt <= TBCardinality
|
||||||
&& piecesCnt <= TBCardinality
|
|
||||||
&& (piecesCnt < TBCardinality || depth >= TBProbeDepth)
|
&& (piecesCnt < TBCardinality || depth >= TBProbeDepth)
|
||||||
&& pos.rule50_count() == 0)
|
&& pos.rule50_count() == 0)
|
||||||
{
|
{
|
||||||
|
@ -580,6 +570,7 @@ namespace {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Step 5. Evaluate the position statically and update parent's gain statistics
|
// Step 5. Evaluate the position statically and update parent's gain statistics
|
||||||
if (inCheck)
|
if (inCheck)
|
||||||
|
|
Loading…
Add table
Reference in a new issue