mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Add syzygy support
bench: 8080602
This commit is contained in:
parent
3c07603dac
commit
f53aea45e3
8 changed files with 113 additions and 11 deletions
10
src/Makefile
10
src/Makefile
|
@ -36,7 +36,7 @@ PGOBENCH = ./$(EXE) bench 16 1 1000 default time
|
||||||
### Object files
|
### Object files
|
||||||
OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
||||||
material.o misc.o movegen.o movepick.o pawns.o position.o \
|
material.o misc.o movegen.o movepick.o pawns.o position.o \
|
||||||
search.o thread.o timeman.o tt.o uci.o ucioption.o
|
search.o thread.o timeman.o tt.o uci.o ucioption.o syzygy/tbprobe.o
|
||||||
|
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
### Section 2. High-level Configuration
|
### Section 2. High-level Configuration
|
||||||
|
@ -375,14 +375,14 @@ profile-build:
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_prepare)
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 1/4. Building executable for benchmark ..."
|
@echo "Step 1/4. Building executable for benchmark ..."
|
||||||
@touch *.cpp *.h
|
@touch *.cpp *.h syzygy/*.cpp syzygy/*.h
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make)
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 2/4. Running benchmark for pgo-build ..."
|
@echo "Step 2/4. Running benchmark for pgo-build ..."
|
||||||
@$(PGOBENCH) > /dev/null
|
@$(PGOBENCH) > /dev/null
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 3/4. Building final executable ..."
|
@echo "Step 3/4. Building final executable ..."
|
||||||
@touch *.cpp *.h
|
@touch *.cpp *.h syzygy/*.cpp syzygy/*.h
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use)
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Step 4/4. Deleting profile data ..."
|
@echo "Step 4/4. Deleting profile data ..."
|
||||||
|
@ -397,7 +397,7 @@ install:
|
||||||
-strip $(BINDIR)/$(EXE)
|
-strip $(BINDIR)/$(EXE)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda
|
$(RM) $(EXE) $(EXE).exe *.o .depend *~ core bench.txt *.gcda ./syzygy/*.o ./syzygy/*.gcda
|
||||||
|
|
||||||
default:
|
default:
|
||||||
help
|
help
|
||||||
|
@ -462,7 +462,7 @@ gcc-profile-use:
|
||||||
all
|
all
|
||||||
|
|
||||||
gcc-profile-clean:
|
gcc-profile-clean:
|
||||||
@rm -rf *.gcda *.gcno bench.txt
|
@rm -rf *.gcda *.gcno syzygy/*.gcda syzygy/*.gcno bench.txt
|
||||||
|
|
||||||
icc-profile-prepare:
|
icc-profile-prepare:
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) icc-profile-clean
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@ int main(int argc, char* argv[]) {
|
||||||
Eval::init();
|
Eval::init();
|
||||||
Pawns::init();
|
Pawns::init();
|
||||||
Threads.init();
|
Threads.init();
|
||||||
|
Tablebases::init(Options["SyzygyPath"]);
|
||||||
TT.resize(Options["Hash"]);
|
TT.resize(Options["Hash"]);
|
||||||
|
|
||||||
UCI::loop(argc, argv);
|
UCI::loop(argc, argv);
|
||||||
|
|
|
@ -170,6 +170,7 @@ public:
|
||||||
uint64_t nodes_searched() const;
|
uint64_t nodes_searched() const;
|
||||||
void set_nodes_searched(uint64_t n);
|
void set_nodes_searched(uint64_t n);
|
||||||
bool is_draw() const;
|
bool is_draw() const;
|
||||||
|
int rule50_count() const;
|
||||||
Score psq_score() const;
|
Score psq_score() const;
|
||||||
Value non_pawn_material(Color c) const;
|
Value non_pawn_material(Color c) const;
|
||||||
|
|
||||||
|
@ -347,6 +348,10 @@ inline int Position::game_ply() const {
|
||||||
return gamePly;
|
return gamePly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int Position::rule50_count() const {
|
||||||
|
return st->rule50;
|
||||||
|
}
|
||||||
|
|
||||||
inline uint64_t Position::nodes_searched() const {
|
inline uint64_t Position::nodes_searched() const {
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
namespace Search {
|
namespace Search {
|
||||||
|
|
||||||
|
@ -44,6 +45,18 @@ namespace Search {
|
||||||
StateStackPtr SetupStates;
|
StateStackPtr SetupStates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Tablebases {
|
||||||
|
|
||||||
|
int Cardinality;
|
||||||
|
uint64_t Hits;
|
||||||
|
bool RootInTB;
|
||||||
|
bool UseRule50;
|
||||||
|
Depth ProbeDepth;
|
||||||
|
Value Score;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace TB = Tablebases;
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using Eval::evaluate;
|
using Eval::evaluate;
|
||||||
using namespace Search;
|
using namespace Search;
|
||||||
|
@ -186,6 +199,19 @@ void Search::think() {
|
||||||
DrawValue[ RootPos.side_to_move()] = VALUE_DRAW - Value(contempt);
|
DrawValue[ RootPos.side_to_move()] = VALUE_DRAW - Value(contempt);
|
||||||
DrawValue[~RootPos.side_to_move()] = VALUE_DRAW + Value(contempt);
|
DrawValue[~RootPos.side_to_move()] = VALUE_DRAW + Value(contempt);
|
||||||
|
|
||||||
|
TB::Hits = 0;
|
||||||
|
TB::RootInTB = false;
|
||||||
|
TB::UseRule50 = Options["Syzygy50MoveRule"];
|
||||||
|
TB::ProbeDepth = Options["SyzygyProbeDepth"] * ONE_PLY;
|
||||||
|
TB::Cardinality = Options["SyzygyProbeLimit"];
|
||||||
|
|
||||||
|
// Skip TB probing when no TB found: !TBLargest -> !TB::Cardinality
|
||||||
|
if (TB::Cardinality > TB::MaxCardinality)
|
||||||
|
{
|
||||||
|
TB::Cardinality = TB::MaxCardinality;
|
||||||
|
TB::ProbeDepth = DEPTH_ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
if (RootMoves.empty())
|
if (RootMoves.empty())
|
||||||
{
|
{
|
||||||
RootMoves.push_back(MOVE_NONE);
|
RootMoves.push_back(MOVE_NONE);
|
||||||
|
@ -195,6 +221,37 @@ void Search::think() {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (TB::Cardinality >= RootPos.count<ALL_PIECES>(WHITE)
|
||||||
|
+ RootPos.count<ALL_PIECES>(BLACK))
|
||||||
|
{
|
||||||
|
// If the current root position is in the tablebases then RootMoves
|
||||||
|
// contains only moves that preserve the draw or win.
|
||||||
|
TB::RootInTB = Tablebases::root_probe(RootPos, RootMoves, TB::Score);
|
||||||
|
|
||||||
|
if (TB::RootInTB)
|
||||||
|
TB::Cardinality = 0; // Do not probe tablebases during the search
|
||||||
|
|
||||||
|
else // If DTZ tables are missing, use WDL tables as a fallback
|
||||||
|
{
|
||||||
|
// Filter out moves that do not preserve a draw or win
|
||||||
|
TB::RootInTB = Tablebases::root_probe_wdl(RootPos, RootMoves, TB::Score);
|
||||||
|
|
||||||
|
// Only probe during search if winning
|
||||||
|
if (TB::Score <= VALUE_DRAW)
|
||||||
|
TB::Cardinality = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TB::RootInTB)
|
||||||
|
{
|
||||||
|
TB::Hits = RootMoves.size();
|
||||||
|
|
||||||
|
if (!TB::UseRule50)
|
||||||
|
TB::Score = TB::Score > VALUE_DRAW ? VALUE_MATE - MAX_PLY - 1
|
||||||
|
: TB::Score < VALUE_DRAW ? -VALUE_MATE + MAX_PLY + 1
|
||||||
|
: VALUE_DRAW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (Thread* th : Threads)
|
for (Thread* th : Threads)
|
||||||
th->maxPly = 0;
|
th->maxPly = 0;
|
||||||
|
|
||||||
|
@ -487,6 +544,36 @@ namespace {
|
||||||
return ttValue;
|
return ttValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Step 4a. Tablebase probe
|
||||||
|
if (!RootNode && TB::Cardinality)
|
||||||
|
{
|
||||||
|
int piecesCnt = pos.count<ALL_PIECES>(WHITE) + pos.count<ALL_PIECES>(BLACK);
|
||||||
|
|
||||||
|
if ( piecesCnt <= TB::Cardinality
|
||||||
|
&& (piecesCnt < TB::Cardinality || depth >= TB::ProbeDepth)
|
||||||
|
&& pos.rule50_count() == 0)
|
||||||
|
{
|
||||||
|
int found, v = Tablebases::probe_wdl(pos, &found);
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
TB::Hits++;
|
||||||
|
|
||||||
|
int drawScore = TB::UseRule50 ? 1 : 0;
|
||||||
|
|
||||||
|
value = v < -drawScore ? -VALUE_MATE + MAX_PLY + ss->ply
|
||||||
|
: v > drawScore ? VALUE_MATE - MAX_PLY - ss->ply
|
||||||
|
: VALUE_DRAW + 2 * v * drawScore;
|
||||||
|
|
||||||
|
tte->save(posKey, value_to_tt(value, ss->ply), BOUND_EXACT,
|
||||||
|
std::min(DEPTH_MAX - ONE_PLY, depth + 6 * ONE_PLY),
|
||||||
|
MOVE_NONE, VALUE_NONE, TT.generation());
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
|
@ -1347,6 +1434,9 @@ moves_loop: // When in check and at SpNode search starts from here
|
||||||
Depth d = updated ? depth : depth - ONE_PLY;
|
Depth d = updated ? depth : depth - ONE_PLY;
|
||||||
Value v = updated ? RootMoves[i].score : RootMoves[i].previousScore;
|
Value v = updated ? RootMoves[i].score : RootMoves[i].previousScore;
|
||||||
|
|
||||||
|
bool tb = TB::RootInTB && abs(v) < VALUE_MATE - MAX_PLY;
|
||||||
|
v = tb ? TB::Score : v;
|
||||||
|
|
||||||
if (ss.rdbuf()->in_avail()) // Not at first line
|
if (ss.rdbuf()->in_avail()) // Not at first line
|
||||||
ss << "\n";
|
ss << "\n";
|
||||||
|
|
||||||
|
@ -1355,11 +1445,12 @@ moves_loop: // When in check and at SpNode search starts from here
|
||||||
<< " multipv " << i + 1
|
<< " multipv " << i + 1
|
||||||
<< " score " << UCI::value(v);
|
<< " score " << UCI::value(v);
|
||||||
|
|
||||||
if (i == PVIdx)
|
if (!tb && i == PVIdx)
|
||||||
ss << (v >= beta ? " lowerbound" : v <= alpha ? " upperbound" : "");
|
ss << (v >= beta ? " lowerbound" : v <= alpha ? " upperbound" : "");
|
||||||
|
|
||||||
ss << " nodes " << pos.nodes_searched()
|
ss << " nodes " << pos.nodes_searched()
|
||||||
<< " nps " << pos.nodes_searched() * 1000 / elapsed
|
<< " nps " << pos.nodes_searched() * 1000 / elapsed
|
||||||
|
<< " tbhits " << TB::Hits
|
||||||
<< " time " << elapsed
|
<< " time " << elapsed
|
||||||
<< " pv";
|
<< " pv";
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,6 @@ struct Thread;
|
||||||
const int MAX_THREADS = 128;
|
const int MAX_THREADS = 128;
|
||||||
const int MAX_SPLITPOINTS_PER_THREAD = 8;
|
const int MAX_SPLITPOINTS_PER_THREAD = 8;
|
||||||
|
|
||||||
struct Thread;
|
|
||||||
|
|
||||||
/// SplitPoint struct stores information shared by the threads searching in
|
/// SplitPoint struct stores information shared by the threads searching in
|
||||||
/// parallel below the same split point. It is populated at splitting time.
|
/// parallel below the same split point. It is populated at splitting time.
|
||||||
|
|
||||||
|
|
|
@ -184,8 +184,8 @@ enum Value : int {
|
||||||
VALUE_INFINITE = 32001,
|
VALUE_INFINITE = 32001,
|
||||||
VALUE_NONE = 32002,
|
VALUE_NONE = 32002,
|
||||||
|
|
||||||
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - MAX_PLY,
|
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - 2 * MAX_PLY,
|
||||||
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + MAX_PLY,
|
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
|
||||||
|
|
||||||
PawnValueMg = 198, PawnValueEg = 258,
|
PawnValueMg = 198, PawnValueEg = 258,
|
||||||
KnightValueMg = 817, KnightValueEg = 846,
|
KnightValueMg = 817, KnightValueEg = 846,
|
||||||
|
|
|
@ -220,7 +220,7 @@ string UCI::value(Value v) {
|
||||||
|
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
|
|
||||||
if (abs(v) < VALUE_MATE_IN_MAX_PLY)
|
if (abs(v) < VALUE_MATE - MAX_PLY)
|
||||||
ss << "cp " << v * 100 / PawnValueEg;
|
ss << "cp " << v * 100 / PawnValueEg;
|
||||||
else
|
else
|
||||||
ss << "mate " << (v > 0 ? VALUE_MATE - v + 1 : -VALUE_MATE - v) / 2;
|
ss << "mate " << (v > 0 ? VALUE_MATE - v + 1 : -VALUE_MATE - v) / 2;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ void on_clear_hash(const Option&) { TT.clear(); }
|
||||||
void on_hash_size(const Option& o) { TT.resize(o); }
|
void on_hash_size(const Option& o) { TT.resize(o); }
|
||||||
void on_logger(const Option& o) { start_logger(o); }
|
void on_logger(const Option& o) { start_logger(o); }
|
||||||
void on_threads(const Option&) { Threads.read_uci_options(); }
|
void on_threads(const Option&) { Threads.read_uci_options(); }
|
||||||
|
void on_tb_path(const Option& o) { Tablebases::init(o); }
|
||||||
|
|
||||||
|
|
||||||
/// Our case insensitive less() function as required by UCI protocol
|
/// Our case insensitive less() function as required by UCI protocol
|
||||||
|
@ -66,6 +68,10 @@ void init(OptionsMap& o) {
|
||||||
o["Minimum Thinking Time"] << Option(20, 0, 5000);
|
o["Minimum Thinking Time"] << Option(20, 0, 5000);
|
||||||
o["Slow Mover"] << Option(80, 10, 1000);
|
o["Slow Mover"] << Option(80, 10, 1000);
|
||||||
o["UCI_Chess960"] << Option(false);
|
o["UCI_Chess960"] << Option(false);
|
||||||
|
o["SyzygyPath"] << Option("<empty>", on_tb_path);
|
||||||
|
o["SyzygyProbeDepth"] << Option(1, 1, 100);
|
||||||
|
o["Syzygy50MoveRule"] << Option(true);
|
||||||
|
o["SyzygyProbeLimit"] << Option(6, 0, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue