26 m_name +
" <" + args +
">");
93 App().
bout <<
"Help for " MYNAME " - mode: " << m_name <<
'\n';
97 if (m_allowedCommands.find(v->
m_name) != m_allowedCommands.end()) {
100 <<
" - " << v->
m_hint <<
'\n';
103 }
else if (args ==
"--all") {
106 bool bAllowed = m_allowedCommands.find(v->
m_name) != m_allowedCommands.end();
110 << (bAllowed ?
"" :
" (+)")
113 App().
bout <<
"\n*: Unimplemented.\n+: Extra";
119 <<
" - " << v->
m_hint <<
'\n';
121 App().
bout <<
"\n** Unimplemented **";
123 App().
bout <<
"Unknown command [" << args <<
"]";
131 App().
bout << response << std::endl;
135 std::string
const& description)
137 App().
bout <<
"ERROR: " << error
138 << ((description !=
"") ?
" (" + description +
")" :
"")
144 if (
App().bout.getVerbosity() >= l)
145 App().
bout <<
"# " << info << std::endl;
160 if (
App().bout.getVerbosity() >= l)
161 App().
bout <<
"info string " << info << std::endl;
165 int64_t nodes,
int nps)
167 if (
App().sout.getVerbosity() >= nDepth) {
168 App().
sout <<
"info depth " <<
static_cast<int>(nDepth)
169 <<
" seldepth " <<
static_cast<int>(seldepth)
170 <<
" nodes " << nodes
171 <<
" nps " << nps <<
'\n';
178 if (
App().sout.getVerbosity() >= 0) {
193 bScore const sc, int64_t
const timems, int64_t
const nodes)
const
195 if (
App().sout.getVerbosity() >= nLogDepth) {
196 std::stringstream sOut;
198 " depth " <<
static_cast<int>(nLogDepth);
199 if (nLogDepth != nMaxDepth) sOut <<
" seldepth " <<
static_cast<int>(nMaxDepth);
206 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
207 if ((nLogDepth == 0) && nVariationDepth) {
211 if (
App().getConfig(
"UCI_ShowCurrLine", 0)
215 if (nVariationDepth) {
220 if ((comment !=
"") &&
App().getConfig(
"debug", 0))
221 sOut <<
" string " << comment;
222 App().
sout << sOut.str() <<
'\n';
228 bMove const& mv,
movenum_t const moveid, int64_t
const nodes)
const
230 if (
App().sout.getVerbosity() >= nLogDepth) {
231 std::stringstream sOut;
233 " depth " <<
static_cast<int>(nLogDepth);
234 if (nLogDepth != nMaxDepth) sOut <<
" seldepth " <<
static_cast<int>(nMaxDepth);
236 <<
" currmovenumber " <<
static_cast<int>(moveid)
237 <<
" currmove " << mv;
238 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
240 && nVariationDepth) {
244 if ((comment !=
"") &&
App().getConfig(
"debug", 0))
245 sOut <<
" string " << comment;
247 App().
sout << sOut.str() <<
'\n';
274 App().
sout <<
" {Draw by insufficient material}";
276 App().
sout <<
" {Draw by repetition}";
278 App().
sout <<
" {50 move rule}";
283 App().
sout <<
" {White mates}";
285 App().
sout <<
" {Black mates}";
292 std::string
const& reason)
294 App().
bout <<
"Illegal move: " << mv
295 << ((reason !=
"") ?
" (" + reason +
")" :
"")
300 depth_t const nMaxDepth, std::string
const& comment UNUSED,
301 bScore const sc, int64_t
const t, int64_t
const nodes)
const
303 if (
App().sout.getVerbosity() >= nLogDepth) {
304 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
305 std::stringstream sNew;
307 && (nVariationDepth)) {
310 if (sNew.str().size()) {
311 static std::string& sOld = *
new std::string();
312 if (sNew.str() != sOld) {
315 App().
sout <<
" " << std::setw(3) << nVariationDepth
316 << (nVariationDepth == nMaxDepth ?
" " :
"&")
318 <<
" " << std::setw(6) << (t / 10)
319 <<
" " << std::setw(8) << nodes
337 App().
bout <<
"Bye" << std::endl;
350 App().
bout <<
"Usage: " << args <<
" [options] [[@]script] \n"
351 <<
"\t--help\tThis help message\n"
352 <<
"\t--version\tShow version information and exit\n"
353 <<
"\t--uci\t\tUse UCI interface\n"
354 <<
"\t--xboard\tUse Xboard/Winboard interface\n"
355 <<
"\t--bench\t\tRun benchmark and exit\n"
356 <<
"\t[script]\tcontaining commands to execute."
368 "var Random var StaticEval var BruteForce "
369 "var SearchIterativeBF var AB var ABFS var ABFH");
371 "var PiecesOnly var StaticBoard var PositionalBoard");
374 +
App().getConfig(
"about",
""));
402 if (args.substr(0,1) ==
"@") {
454 if (sOptions.size() >= 3) {
456 std::string
const opt[] = {
"alg",
"evaltype",
"UCI_ShowCurrLine",
"UCI_Opponent",
"UCI_EngineAbout"};
457 if (std::find(std::begin(opt), std::end(opt), sOptions[1])
460 if (sOptions.size() == 3) {
463 std::string sParams = std::accumulate(sOptions.begin() + 3, sOptions.end(), std::string(),
464 [](std::string result, std::string sElem) {
465 return std::move(result) + std::move(sElem) +
" ";
483 std::string startorfen = args.substr(0, args.find(
' '));
484 std::size_t iMoves = args.find(
"moves ");
485 if (startorfen ==
"startpos" || startorfen ==
"") {
487 if (iMoves != std::string::npos) {
488 if (!
Game()->playGameMoveSeries(args.substr(
static_cast<unsigned long>(iMoves) + 6)))
491 }
else if (startorfen ==
"fen") {
492 if (iMoves != std::string::npos) {
493 Game()->
setFEN(args.substr(4,
static_cast<unsigned long>(iMoves) - 4));
494 if (!
Game()->playGameMoveSeries(args.substr(
static_cast<unsigned long>(iMoves) + 6)))
510 if (atoi(goOptions[0].c_str()) > 0) nDepth =
static_cast<depth_t>(atoi(goOptions[0].c_str()));
526 int64_t nNodes =
Game()->
DoPerft(
static_cast<depth_t>(atoi(perftOptions[0].c_str())), search);
531 std::string sNPS =
"0";
532 if ((nNodes + nNonLeafNodes) > 0LL) {
537 if (
App().bout.checkExpected(sNodes)) {
538 App().
bout <<
"perft " << args <<
" -> " << sNodes
539 <<
" (Total: " << sTotalNodes
540 <<
") <- Execution time = " << search.
getDuration()
545 "perft " + args +
" -> " + sNodes +
" instead of <- "
546 +
App().bout.getExpecting());
562 if (std::any_of(sParams.begin(), sParams.end(),
563 [](std::string
const& s)
564 { return s ==
"-perf"; })) {
565 sParams.erase(sParams.begin() + 1);
569 if (std::any_of(sParams.begin(), sParams.end(),
570 [](std::string
const& s)
571 { return s ==
"-sts"; })) {
572 sParams.erase(sParams.begin() + 1);
576 if (sParams[0] ==
"pos") {
577 sParams.erase(sParams.begin());
579 epd.parse(typeOfTest);
580 }
else if (sParams[0] ==
"file") {
581 sParams.erase(sParams.begin());
583 epd.parse(typeOfTest);
587 epd.parse(typeOfTest);
605 int nInf, nTime, nInc, nMoves, nMoveTime, nPonder;
611 if (
Game()->getCurrentPosition().whiteToMove()) {
632 }
else if (nMoveTime != -1) {
634 }
else if (nTime != -1) {
636 if (nMoves != -1) level.
setMoveTime(nTime, nMoves, nInc);
639 if (nMoves != -1) level.
setMoveTime(nTime, nMoves);
642 }
else if (nMate != -1) {
646 if (nDepth != -1) level.
setDepth(nDepth);
647 if (nNodes != -1) level.
setNodes(nNodes);
652 }
else if ((
App().getMode() !=
"xboard")
690 App().
bout <<
Game()->operator std::string() <<
'\n';
695 App().
bout <<
Game()->operator std::string() <<
'\n';
701 App().
bout << b.operator std::string() <<
'\n';
724 #if !defined(NODIRENT)
728 std::string curdir =
".";
730 if (args.length()) curdir = args +
".";
732 hDir = opendir(curdir.c_str());
734 struct dirent *hFile;
735 while ((hFile = readdir(hDir)) !=
nullptr) {
736 std::string sFile(hFile->d_name);
737 if (sFile[0] ==
'.')
continue;
738 App().
bout << sFile << std::endl;
771 if (
App().getMode() !=
"xboard") {
778 #if defined(BELOFTE_NOSIGNALS)
786 AppEI()->
sendResponse(
"feature option=\"alg -combo AB /// Random /// StaticEval /// "
787 "BruteForce /// SearchIterativeBF /// ABFS /// ABFH\"");
789 "PositionalBoard /// PiecesOnly /// StaticBoard \"");
815 App().
setConfig(
"UCI_ShowCurrLine", (args ==
"true") ? 1 : 0);
833 if (options.size() == 2) {
835 std::string
const opt[] = {
"alg",
"evaltype"};
836 if (std::find(std::begin(opt), std::end(opt), options[0])
860 std::stringstream ss;
863 ss <<
"# Eval: (" << (b.
minimizing() == 1 ?
"maximizing) white" :
"minimizing) black")
864 <<
" to move - " <<
Game()->
getEval()->operator std::string();
865 if (
Game()->getRandom()) ss <<
" +-Rnd";
875 if (!
Game()->getRandom()) {
879 ss <<
" (inbalanced eval: "
888 App().
bout << ss.str() << std::endl;
908 int nMovesPerPeriod = 0;
909 int nTimePerPeriod = 0;
912 if (levelOptions.size() == 3) {
913 nMovesPerPeriod = atoi(levelOptions[0].c_str());
914 nIncrement = atoi(levelOptions[2].c_str());
916 if (sPeriods.size() == 2) {
917 nTimePerPeriod = atoi(sPeriods[0].c_str()) * 60
918 + atoi(sPeriods[1].c_str());
920 nTimePerPeriod = atoi(levelOptions[1].c_str()) * 60;
925 if (nMovesPerPeriod == 0) {
926 if (nIncrement == 0) {
933 if (nIncrement == 0) {
938 nMovesPerPeriod, nIncrement * 1000);
956 #if !defined(BELOFTE_NORANDOM)
engineInterface * AppEI()
This is the main include file, needs to be included before any other include.
uint_fast16_t movenum_t
moveflags (high order word) & basicmove (low order word)
int_fast16_t bScore
used to return id of move in movelist
std::string getDuration() const
long long getDurationMicroSec() const
void sendDebug(int const l, std::string const &info) override
static std::string uciscorestring(bScore const sc)
convert score to uci score string to be returned to uci interface, if value in there,...
void sendInfoScore(long long timems, bBoard const &b, bScore const cp) override
void sendInfoSearching(bBoard const &b, depth_t const nLogDepth, depth_t const nMaxDepth, std::string const &comment, bScore const sc, int64_t const timems, int64_t const nodes) const override
void sendInfoDepth(depth_t depth, depth_t seldepth, int64_t nodes, int nps) override
void sendMove(bBoard const &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
UCIengineCommand(std::string const &s, std::string const &h)
~UCIengineCommand() override
~Xboard1engineCommand() override
Xboard1engineCommand(std::string const &s, std::string const &h)
~Xboard2engineCommand() override
Xboard2engineCommand(std::string const &s, std::string const &h)
void sendInfoSearching(bBoard const &b, depth_t const nLogDepth, depth_t const nMaxDepth, std::string const &comment, bScore const sc, int64_t const timems, int64_t const nodes) const override
void sendInvalidMove(std::string const &info, std::string const &reason) override
outputWriter sout
normal output
bel_debug m_debuginterface
std::string setMode(std::string const &iName)
void setConfig(std::string const &s, int64_t v)
int64_t getConfig(std::string const &s, int64_t v)
commandReader m_reader
searching output
bGameStage getStage() const
movesequence_t getVariation() const
movesequence_t getPreviousMoves() const
bScore minimizing() const
void invert()
invert board position update kingpos, update colour to move, castle rights, ...
std::string setAlgorithm(std::string const &alg="")
std::string setEval(std::string const &e="")
bPositionEvaluation * getEval()
simple coordmove, with 4 characters, or 5 characters in case of promotion mostly used for interface
bScore EvalForPlayer(bBoard &b)
void revertGameMove()
required for Winboard protocol, not supported in UCI (except debug)
bool playUIsuppliedMove(std::string const &coordmove)
void setPlayerName(std::string const &n)
gameResult_t EvalFinalScore(bBoard &b)
std::string getResult(gameResult_t rs) const
void setRandom(bool const r)
void DoSearch()
Start search thread and exit.
void setFEN(std::string const &fenstr)
bBoard & getCurrentPosition()
void setLevel(bLevel const &l)
int64_t DoPerft(depth_t const d, bSearchAlgorithm &sa)
do perft search at depth
void setDepth(depth_t const d)
void setGameTime(int const msPerGame)
new level or new game
void setRemainingTime(int const msPerGame)
xboard issues time command to update available time
void setNodes(int64_t const n)
void setMoveTime(int const msPerMove)
void setMateSearch(depth_t const d)
set level to search mate in n different from bruteforce search which is non optimised
void initDepths(depth_t const d)
static std::string getMoveSequenceStr(std::string const &sLabel, movesequence_t const &sq1)
static member function to convert movesequence to string
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
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
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
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
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 sendMove(bBoard const &b, bMove const &m)
virtual void sendPrompt()
virtual void sendResponse(std::string const &response)
virtual void sendInvalidMove(std::string const &info, std::string const &reason UNUSED)
virtual void sendDebug(int const l, std::string const &info)
static engineCommands_t m_engineCommands
virtual void setRunning(bool const r)
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 sendResult(bBoard &b, gameResult_t rs) const
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 setExpecting(std::string const &s)
void setVerbosity(int const l)
enum tEpdTestType epdTest_t
enum gameResult gameResult_t
constexpr bScore SCORE_PUNDEFINED
constexpr bScore SCORE_POSITIVE
constexpr auto INFINITE_DEPTH
std::string alltrim(std::string s, std::string const &delim=" ")
trim left and right spaces or delim from string
int positionParamIndex(stringList const ¶m, std::string const &findstr)
find position in which param has been found
std::vector< std::string > stringList
int positionParamValue(stringList const ¶m, std::string const &findstr, unsigned long const nOffSet=0)
std::string to_string(long value)
std::to_string not compatible on Mac OS (Apple LLVM version 5.0) provide generic utility function
stringList stringSplit(std::string src, std::string delim)
Split delimited long string into a vector.