26 m_name +
" <" + args +
">");
102 belofte::stringList sParams = belofte::stringSplit(args,
" ");
103 bool bUnsupported = std::any_of(sParams.begin(), sParams.end(),
104 [](std::string
const& s)
105 { return s ==
"unsupported"; });
106 bool bUnpublished = std::any_of(sParams.begin(), sParams.end(),
107 [](std::string
const& s)
108 { return s ==
"hidden"; });
109 if (bUnsupported || bUnpublished || args ==
"") {
111 sParams.emplace_back(
"all");
113 if (std::any_of(sParams.begin(), sParams.end(),
114 [](std::string
const& s)
115 { return ((s ==
"all") || (s ==
"--all")); })) {
116 App().
bout <<
"Help for " MYNAME " - mode: " << m_name <<
"\n";
119 bool bAllowed = m_allowedCommands.find(v->
m_name) != m_allowedCommands.end();
128 << (bAllowed ?
"" :
" (h)")
132 if (bUnsupported)
App().
bout <<
"\nu: Unsupported.";
133 if (bUnpublished)
App().
bout <<
"\nh: Hidden";
140 <<
" - " << v->
m_hint <<
"\n";
142 App().
bout <<
"\n** Unsupported **";
144 App().
bout <<
"Unknown command [" << args <<
"]";
158 App().
bout(-2) <<
"ERROR: " << error;
159 if (!description.empty())
App().
bout <<
" (" << description <<
")";
181 std::stringstream sOut;
198 App().
bout(l) <<
"info string ";
205 if (depth <=
App().sout.getLevel()) {
206 std::stringstream sOut;
207 sOut <<
"info depth " << depth
209 <<
" seldepth " << seldepth
211 <<
" nodes " << nodes
221 if (0 <=
App().sout.getLevel()) {
222 std::stringstream sOut;
231 sOut <<
" score mate " << mateinx;
233 sOut <<
" score lowerbound";
235 sOut <<
" score upperbound";
239 sOut <<
" score cp " << belofte::scoreAsStr(sc);
243 sOut <<
" time " << belofte::prettyTime(timems);
249 for (std::string
const& m : b.
getVariation()) sOut <<
" " << m;
259 int64_t
const nodes)
const
261 if (nLogDepth <=
App().sout.getLevel()) {
262 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
263 std::stringstream sOut;
265 if (nVariationDepth) sOut <<
" depth " << nVariationDepth;
267 if (nVariationDepth != nMaxDepth) sOut <<
" seldepth " <<
static_cast<int>(nMaxDepth);
268 sOut <<
" time " << belofte::to_string(timems);
270 sOut <<
" nodes " << belofte::to_string(nodes)
271 <<
" nps " << belofte::to_string((nodes * 1000)/ timems);
274 sOut <<
" nodes " << belofte::to_string(nodes);
280 sOut <<
" score upperbound";
283 sOut <<
" score lowerbound";
285 sOut <<
" score cp " << belofte::scoreAsStr(sc);
287 if ((nLogDepth == 0) && nVariationDepth) {
290 for (std::string
const& m : b.
getVariation()) sOut <<
" " << m;
297 if (nVariationDepth) {
300 for (std::string
const& m : b.
getVariation()) sOut <<
" " << m;
303 if (comment !=
"") sOut <<
" string " << comment;
311 bMove const& mv,
movenum_t const moveid, int64_t
const nodes)
const
313 if (nLogDepth <=
App().sout.getLevel()) {
314 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
315 std::stringstream sOut;
317 if (nVariationDepth) sOut <<
" depth " << nVariationDepth;
319 if (nVariationDepth != nMaxDepth) sOut <<
" seldepth " << nMaxDepth;
321 sOut <<
" nodes " << belofte::to_string(nodes);
322 sOut <<
" currmovenumber " << moveid;
323 sOut <<
" currmove ";
326 if (nVariationDepth) {
331 if (comment !=
"") sOut <<
" string " << comment;
362 App().
sout <<
" {Draw by insufficient material}";
364 App().
sout <<
" {Draw by repetition}";
366 App().
sout <<
" {50 move rule}";
371 App().
sout <<
" {White mates}";
373 App().
sout <<
" {Black mates}";
381 App().
bout(-2) <<
"Illegal move: " << mv;
382 if (reason !=
"")
App().
bout <<
" (" << reason <<
")";
387 depth_t const nMaxDepth, std::string
const& comment UNUSED,
388 bScore const sc, int64_t
const t, int64_t
const nodes)
const
390 if (nLogDepth <=
App().sout.getLevel()) {
391 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
393 && (nVariationDepth)) {
394 std::stringstream sNew;
396 for (std::string
const& m : b.
getVariation()) sNew <<
" " << m;
397 if (sNew.str().size()) {
398 static std::string& sOld = *
new std::string();
399 if (sNew.str() != sOld) {
402 App().
sout <<
" " << std::setw(3) << nVariationDepth
403 << (nVariationDepth == nMaxDepth ?
" " :
"&");
404 App().
sout <<
" " << std::setw(8) << belofte::to_string(sc);
405 App().
sout <<
" " << std::setw(6) << (t / 10);
406 App().
sout <<
" " << std::setw(8) << nodes;
438 App().
bout <<
"Usage: " << args <<
" [options] [[@]script] \n"
439 <<
"\t--help\t\tThis help message\n"
440 <<
"\t--version\tShow version information\n"
441 <<
"\t--uci\t\tUse UCI interface\n"
442 <<
"\t--xboard\tUse Xboard/Winboard interface\n"
443 <<
"\t[script]\tcontaining commands to execute.";
454 "var Random var StaticEval var BruteForce "
455 "var SearchIterativeBF var AB var ABFS var ABFH");
457 "var PiecesOnly var StaticBoard var PositionalBoard");
461 +
App().getConfig(
"about",
""));
488 if (args.substr(0,1) ==
"@") {
539 belofte::stringList sOptions = belofte::stringSplit(args,
" ");
540 if (sOptions.size() && sOptions[0] ==
"name") {
542 sOptions.erase(sOptions.begin());
544 if (sOptions.size() >= 2) {
546 std::string
const opt[] = {
"alg",
"evaltype",
"UCI_Opponent",
547 "UCI_EngineAbout",
"UCI_Variant"};
548 if (std::find(std::begin(opt), std::end(opt), sOptions[0])
551 if (sOptions.size() == 2) {
554 std::string sParams = std::accumulate(sOptions.begin() + 2, sOptions.end(), std::string(),
555 [](std::string result, std::string sElem) {
556 return std::move(result) + std::move(sElem) +
" ";
574 std::string startorfen = args.substr(0, args.find(
' '));
575 std::size_t iMoves = args.find(
"moves ");
576 if (startorfen ==
"startpos" || startorfen ==
"") {
578 if (iMoves != std::string::npos) {
579 if (!
Game()->playGameMoveSeries(args.substr(
static_cast<unsigned long>(iMoves) + 6)))
582 }
else if (startorfen ==
"fen") {
583 if (iMoves != std::string::npos) {
584 Game()->
setFEN(args.substr(4,
static_cast<unsigned long>(iMoves) - 4));
585 if (!
Game()->playGameMoveSeries(args.substr(
static_cast<unsigned long>(iMoves) + 6)))
600 belofte::stringList goOptions = belofte::stringSplit(args,
" ");
601 if (atoi(goOptions[0].c_str()) > 0) nDepth =
static_cast<depth_t>(atoi(goOptions[0].c_str()));
614 belofte::stringList
const goOptions = belofte::stringSplit(args,
" ");
616 if (!goOptions.empty()) perftdepth = atoi(goOptions[0].c_str());
619 int64_t nNodes =
Game()->
DoPerft(search, perftdepth);
622 std::string sNodes = belofte::to_string(nNodes);
623 std::string sTotalNodes = belofte::to_string(nNodes + nNonLeafNodes);
624 std::string sNPS =
"0";
625 if ((nNodes + nNonLeafNodes) > 0LL) {
626 sNPS = belofte::to_string(
static_cast<int64_t
>(
630 if (
Game()->isExpecting(sNodes)) {
631 std::stringstream ss;
632 ss <<
"perft " << args <<
" -> " << sNodes
633 <<
" (Total: " << sTotalNodes
634 <<
") <- Execution time = " << search.
getDuration()
640 "perft " + args +
" -> " + sNodes +
" instead of <- "
641 +
Game()->getExpecting());
653 belofte::stringList sParams = belofte::stringSplit(args,
" ");
657 if (std::any_of(sParams.begin(), sParams.end(),
658 [](std::string
const& s)
659 { return s ==
"-perf"; })) {
660 sParams.erase(sParams.begin() + 1);
662 }
else if (std::any_of(sParams.begin(), sParams.end(),
663 [](std::string
const& s)
664 { return s ==
"-sts"; })) {
665 sParams.erase(sParams.begin() + 1);
669 if (sParams.empty()) {
671 }
else if (sParams[0] ==
"pos") {
672 sParams.erase(sParams.begin());
673 bEpdPos epd(sParams, typeOfTest);
675 }
else if (sParams[0] ==
"file") {
676 sParams.erase(sParams.begin());
697 belofte::stringList
const goOptions = belofte::stringSplit(args,
" ");
699 int nDepth, nInf, nTime, nInc, nMoves, nMoveTime, nMate, nPonder;
702 nDepth = belofte::positionParamValue(goOptions,
"depth", 1);
703 nInf = belofte::positionParamIndex(goOptions,
"infinite");
705 if (
Game()->getCurrentPosition().whiteToMove()) {
706 nTime = belofte::positionParamValue(goOptions,
"wtime", 1);
707 nInc = belofte::positionParamValue(goOptions,
"winc", 1);
709 nTime = belofte::positionParamValue(goOptions,
"btime", 1);
710 nInc = belofte::positionParamValue(goOptions,
"binc", 1);
713 nMoves = belofte::positionParamValue(goOptions,
"movestogo", 1);
714 nMoveTime = belofte::positionParamValue(goOptions,
"movetime", 1);
716 nNodes = belofte::positionParamValue(goOptions,
"nodes", 1);
717 nMate = belofte::positionParamValue(goOptions,
"mate", 1);
718 nPonder = belofte::positionParamIndex(goOptions,
"ponder");
720 if (belofte::positionParamIndex(goOptions,
"searchmoves") != -1) {
726 }
else if (nInf != -1) {
728 }
else if (nMoveTime != -1) {
730 }
else if (nTime != -1) {
732 if (nMoves != -1) level.
setMoveTime(nTime, nMoves, nInc);
735 if (nMoves != -1) level.
setMoveTime(nTime, nMoves);
738 }
else if (nMate != -1) {
742 if (nNodes != -1) level.
setNodes(nNodes);
758 if (!
Game()->playGameMoveSeries(args)) {
765 if (
App().getMode() ==
"xboard") {
767 if (
AppEI()->isRunning()) {
790 App().
bout <<
Game()->operator std::string() <<
"\n";
795 App().
bout <<
Game()->operator std::string() <<
"\n";
801 App().
bout << b.operator std::string() <<
"\n";
822 std::string curdir =
".";
823 if (args.length()) curdir = args +
".";
825 hDir = opendir(curdir.c_str());
827 struct dirent *hFile;
828 while ((hFile = readdir(hDir)) !=
nullptr) {
829 std::string sFile(hFile->d_name);
830 if (sFile[0] ==
'.')
continue;
832#if !defined(NODIRENT)
833 << (hFile->d_type == DT_DIR ?
"/" :
"")
877 if (
App().getMode() !=
"xboard") {
885#if defined(BELOFTE_NOSIGNALS)
893 AppEI()->
sendResponse(
"feature option=\"alg -combo AB /// Random /// StaticEval /// "
894 "BruteForce /// SearchIterativeBF /// ABFS /// ABFH\"");
896 "PositionalBoard /// PiecesOnly /// StaticBoard\"");
938 belofte::stringList
const options = belofte::stringSplit(args,
"=");
939 if (options.size() == 2) {
941 std::string
const opt[] = {
"alg",
"evaltype"};
942 if (std::find(std::begin(opt), std::end(opt), options[0])
961 std::stringstream ss;
964 ss <<
"# Eval: (" << (b.
minimizing() == 1 ?
"maximizing) white" :
"minimizing) black")
965 <<
" to move - " <<
Game()->
getEval()->operator std::string();
966 #if !defined(BELOFTE_NORANDOM)
967 if (
App().getConfig(
"random", 0)) ss <<
" +-Rnd";
976 ss <<
"\ninfo cp " << belofte::scoreAsStr(sc);
978 if (!
App().getConfig(
"random", 0)) {
982 ss <<
" (inbalanced eval: "
983 << belofte::scoreAsStr(isc)
1008 belofte::stringList
const levelOptions = belofte::stringSplit(args,
" ");
1009 int nMovesPerPeriod = 0;
1010 int nTimePerPeriod = 0;
1013 if (levelOptions.size() == 3) {
1014 nMovesPerPeriod = atoi(levelOptions[0].c_str());
1015 nIncrement = atoi(levelOptions[2].c_str());
1016 belofte::stringList sPeriods = belofte::stringSplit(levelOptions[1],
":");
1017 if (sPeriods.size() == 2) {
1018 nTimePerPeriod = atoi(sPeriods[0].c_str()) * 60
1019 + atoi(sPeriods[1].c_str());
1021 nTimePerPeriod = atoi(levelOptions[1].c_str()) * 60;
1026 if (nMovesPerPeriod == 0) {
1027 if (nIncrement == 0) {
1034 if (nIncrement == 0) {
1039 nMovesPerPeriod, nIncrement * 1000);
engineInterface * AppEI()
This is the main include file, needs to be included before any other include.
engineInterface * AppEI()
void sendPrompt() override
std::string getDuration() const
long long getDurationMicroSec() const
void sendDebug(int const l, std::string const &info) override
void sendInfoScore(long long timems, bBoard const &b, bScore const cp) override
void sendInfoDepth(int depth, int seldepth, int64_t nodes, int nps) override
void sendMove(bBoard &b, bMove const &m) override
void sendInfoCurrMove(bBoard const &b, depth_t const nLogDepth, depth_t const nMaxDepth, std::string const &comment, bMove const &m, movenum_t const moveid, int64_t const nodes) const override
void sendInfoSearching(bBoard const &b, int const nLogDepth, depth_t const nMaxDepth, std::string const &comment, bScore const sc, int64_t const t, int64_t const nodes) const override
void sendInfo(std::string const &info) override
Sub-class to react uniformly on UCI interface specific stuff.
UCIengineCommand(std::string const &s, std::string const &h)
~UCIengineCommand() override
~UCIengineOption() override
UCIengineOption(std::string const &s, std::string const &h)
~Xboard1engineCommand() override
Xboard1engineCommand(std::string const &s, std::string const &h)
~Xboard2engineCommand() override
Xboard2engineCommand(std::string const &s, std::string const &h)
void sendDebug(int const l, std::string const &info) override
void sendInfoSearching(bBoard const &b, int const nLogDepth, depth_t const nMaxDepth, std::string const &comment, bScore const sc, int64_t const t, int64_t const nodes) const override
void sendInvalidMove(std::string const &info, std::string const &reason) override
void sendInfo(std::string const &info) override
outputWriter sout
normal output
bel_debug m_debuginterface
void setConfig(std::string const &s, int64_t v)
int64_t getConfig(std::string const &s, int64_t v)
std::string const setMode(std::string const &iName)
commandReader m_reader
searching output
bGameStage getStage() const
void invertColours()
invert colours update kingpos, update colour to move, castle rights, ...
movesequence_t const & getPreviousMoves() const
movesequence_t const & getVariation() const
bScore minimizing() const
void setAlgorithm(std::string const &alg)
void setEval(std::string const &e)
bPositionEvaluation * getEval() const
simple coordmove, with 4 characters, or 5 characters in case of promotion mostly used for interface
virtual bEpdResult parse() final
Main epd parser for multiple lines of epd file Will calculate a total score and some statistics.
virtual bEpdResult parse()
bScore EvalForPlayer(bBoard const &b)
void revertGameMove()
required for Winboard protocol, not supported in UCI (except debug)
void setPlayerName(std::string const &n)
std::string getResult(gameResult_t rs) const
void setExpecting(std::string const &s)
Following command should return value as expected.
void DoSearch()
Start search thread and exit in case of batch mode, will wait until end of search.
gameResult_t EvalFinalScore(bBoard const &b)
void setFEN(std::string const &fenstr)
int64_t DoPerft(bSearchAlgorithm &sa, int const d)
do perft search at depth
bBoard & getCurrentPosition()
void setLevel(bLevel const &l)
void setGameTime(int const msPerGame)
new level or new game
void setRemainingTime(int const msPerGame)
xboard issues time command to update available time
void setMoveTime(int const msPerMove)
void setMateSearch(depth_t const d)
void setDepthCommand(depth_t const d)
PgnMove is for user-interface only.
int64_t getNonLeafNodes() const
static void run_bench(bSearchAlgorithm &search, depth_t const nDepth)
void execute(std::string const &args)
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
Parse epd position or epd file e.g.
void execute(std::string const &args) override
Parse epd position e.g.
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
execute command file with exec command
void execute(std::string const &args) override
execute command file with @ command
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
check if engine still alive, doing delayed constructors
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
check if engine still alive, doing delayed constructors
void execute(std::string const &args) override
void execute(std::string const &args) override
set start position, alternatives args = [fen 'fenstring' | startpos ] moves 'move1' ....
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
Read setoption command.
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
void execute(std::string const &args) override
bool attach(std::string const &ifile)
~dummyEngineCommand() override
dummyEngineCommand(std::string const &s, std::string const &h)
virtual void sendResponse(std::string const &response)
virtual void sendResult(bBoard const &b, gameResult_t rs) const
virtual void sendInvalidMove(std::string const &info, std::string const &reason)
static engineCommands_t m_engineCommands
virtual void setRunning(bool const r)
virtual void sendMove(bBoard &b, bMove const &m)
virtual void sendHelp(std::string const &args)
Send help on command or all commands.
void execute(std::string const &command, std::string const ¶ms)
virtual void sendError(std::string const &error, std::string const &description)
basic format for single command
virtual ~engineUserCommand()
virtual void execute(std::string const &args)
engineUserCommand(std::string const &s, std::string const &h)
void setLevel(int const l)
enum tEpdTestType epdTest_t
constexpr bScore SCORE_ALMOST_NORMAL
constexpr bScore SCORE_MATE
enum gameResult gameResult_t
constexpr bScore SCORE_PUNDEFINED
constexpr bScore SCORE_WINNING
constexpr bScore SCORE_POSITIVE
constexpr bScore SCORE_INFINITE