48 m_allowedCommands.clear();
68 sendError(
"unknown command, not executing",
69 command + (params.size() ?
" <" + params +
">" :
""));
74void engineInterface::initCommand(std::vector<engineUserCommand *> cmds)
76 for (
size_t i = 0; i < cmds.size(); ++i) {
89 for (
size_t i = 0; i < sCommands.size(); ++i) {
90 m_allowedCommands[sCommands[i]] = published;
104 bool bUnsupported = std::any_of(sParams.begin(), sParams.end(),
105 [](std::string
const& s)
106 { return s ==
"unsupported"; });
107 bool bUnpublished = std::any_of(sParams.begin(), sParams.end(),
108 [](std::string
const& s)
109 { return s ==
"hidden"; });
110 if (bUnsupported || bUnpublished || args ==
"") {
112 sParams.emplace_back(
"all");
114 if (std::any_of(sParams.begin(), sParams.end(),
115 [](std::string
const& s)
116 { return ((s ==
"all") || (s ==
"--all")); })) {
117 App().
bout <<
"Help for " MYNAME " - mode: " << m_name <<
"\n";
120 bool bAllowed = m_allowedCommands.find(v->
m_name) != m_allowedCommands.end();
123 <<
" - " << v->
m_hint <<
" (u)\n";
126 <<
" - " << v->
m_hint << (bAllowed ?
"\n" :
" (h)\n");
129 if (bUnsupported)
App().
bout <<
"\nu: Unsupported.";
130 if (bUnpublished)
App().
bout <<
"\nh: Hidden";
136 <<
" - " << v->
m_hint <<
"\n";
138 App().
bout <<
"\n** Unsupported **";
140 App().
bout <<
"Unknown command [" << args <<
"]";
161 App().
bout(-2) <<
"ERROR: " << error;
162 if (!description.empty())
App().
bout <<
" (" << description <<
")";
197 }
else if (score < 0) {
221 return "Draw by insufficient material";
223 return "Draw by repetition";
225 return "50 move rule";
229 return "White mates";
231 return "Black mates";
244 attachCommand({
"about",
"xboard",
"uci",
"help",
"bench",
"perft"});
258 attachCommand({
"uci",
"setoption",
"isready",
"position",
"go",
259 "stop",
"ucinewgame",
"ponderhit"});
264 std::stringstream sOut;
291 App().
bout(l) <<
"info string ";
298 if (depth <=
App().sout.getLevel()) {
299 std::stringstream sOut;
314 bScore const sc, int64_t
const timems,
315 int64_t
const nodes)
const
317 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
318 std::stringstream sOut;
320 if (nMaxDepth > nLogDepth)
333 if ((nLogDepth == 0) && nVariationDepth) {
336 for (std::string
const& m : b.
getVariation()) sOut <<
" " << m;
343 if (nVariationDepth) {
346 for (std::string
const& m : b.
getVariation()) sOut <<
" " << m;
358 depth_t const nMaxDepth, std::string
const& comment,
359 bScore const sc, int64_t
const timems,
360 int64_t
const nodes)
const
362 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
363 std::stringstream sOut;
367 if (nMaxDepth > nLogDepth)
369 }
else if (nVariationDepth) {
372 if (nMaxDepth > nVariationDepth)
380 if (nodes && (timems > 10))
388 if ((nLogDepth == 0) && nVariationDepth) {
391 for (std::string
const& m : b.
getVariation()) sOut <<
" " << m;
398 if (nVariationDepth) {
401 for (std::string
const& m : b.
getVariation()) sOut <<
" " << m;
404 if (comment !=
"") sOut <<
" string " << comment;
411 bMove const& mv,
movenum_t const moveid, int64_t
const nodes)
const
413 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
414 std::stringstream sOut;
416 if (nVariationDepth > nCurDepth)
420 sOut <<
" currmove ";
439 return " score lowerbound";
441 return " score upperbound";
455 attachCommand({
"accepted",
"belofte",
"black",
"option",
"otim",
"ping",
456 "time",
"rejected",
"white"},
false);
457 attachCommand({
"bd",
"undo",
"new",
"setboard",
"usermove",
"game",
458 "remove",
"force",
"level",
"post",
"nopost",
"random",
459 "easy",
"hard",
"go",
"?",
"result",
"sd",
"st",
"protover"});
478 App().
bout(-2) <<
"Illegal move: " << mv;
479 if (reason !=
"")
App().
bout <<
" (" << reason <<
")";
484#pragma GCC diagnostic push
485#pragma GCC diagnostic ignored "-Wunused-parameter"
490 bScore const sc, int64_t
const t, int64_t
const nodes)
const
492 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
494 std::stringstream sNew;
496 for (std::string
const& m : b.
getVariation()) sNew <<
" " << m;
497 if (sNew.str().size()) {
498 static std::string& sOld = *
new std::string();
499 if (sNew.str() != sOld) {
502 App().
sout <<
" " << std::setw(3) << nVariationDepth
503 << (nVariationDepth == nMaxDepth ?
" " :
"&");
505 App().
sout <<
" " << std::setw(6) << (t / 10);
506 App().
sout <<
" " << std::setw(8) << nodes;
515#pragma GCC diagnostic pop
535 int localscore = score;
538 localscore = (-localscore +
SCORE_MATE) + 100000;
539 }
else if (localscore <= -SCORE_WINNING && localscore >= -
SCORE_MATE) {
540 localscore = (-localscore -
SCORE_MATE) - 100000;
548 if (sResult !=
"")
return " {" + sResult +
"}";
engineInterface * AppEI()
This is the main include file, needs to be included before any other include.
void sendPrompt() override
void sendDebug(int const l, std::string const &info) override
void sendResult(bBoard const &b, gameResult_t const gr) const override
void sendInfoCurrMove(bBoard const &b, depth_t const nCurDepth, bMove const &m, movenum_t const moveid, int64_t const nodes) const override
void sendInfoDepth(int depth, int seldepth, int64_t nodes, int nps) override
void sendMove(bBoard &b, bMove const &m) override
void sendInfoSearching(bBoard const &b, int const nLogDepth, depth_t const nMaxDepth, bScore const sc, int64_t const t, int64_t const nodes) const override
std::string scoreString(bScore const score) const override
UCIMode(std::string const &s="uci")
void sendInfo(std::string const &info) override
std::string engineGameResultString(gameResult_t const gr) const override
void sendDebug(int const l, std::string const &info) override
void sendInvalidMove(std::string const &info, std::string const &reason) override
void sendResult(bBoard const &b, gameResult_t const gr) const override
void sendInfoSearching(bBoard const &b, int const nLogDepth, depth_t const nMaxDepth, bScore const sc, int64_t const t, int64_t const nodes) const override
std::string scoreString(bScore const score) const override
void sendInfo(std::string const &info) override
XboardMode(std::string const &s="xboard")
outputWriter sout
normal output
constexpr bmove_t getBMoveT() const
movesequence_t const & getPreviousMoves() const
movesequence_t const & getVariation() const
simple coordmove, with 4 characters, or 5 characters in case of promotion mostly used for interface
std::string getResult(gameResult_t gr) const
PgnMove is for user-interface only.
static gameResult_t gameEndedResult(bBoard const &b)
Class static function See if board is in finite state, meaning game is ended.
static bool isDrawResult(gameResult_t const gr)
static constexpr bool isDrawScore(bScore const score)
static constexpr bool isUndefinedScore(bScore const score)
implementation of single command
virtual void sendResult(bBoard const &b, gameResult_t const gr) const
virtual ~engineInterface()
void attachCommand(belofte::stringList const &sCommands, bool const published=true)
virtual void sendResponse(std::string const &response)
engineInterface(std::string const &s, std::string const &h="")
Common commands to all modes this ctor is called for each iface.
static engineCommands_t & getEngineCommands()
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.
virtual std::string engineGameResultString(gameResult_t const gr) const
void execute(std::string const &command, std::string const ¶ms)
virtual void sendInfo(std::string const &info)
virtual void sendInfoSearchStart(std::string const &info)
virtual void sendError(std::string const &error, std::string const &description)
static std::string scoreAsString(bScore const score)
basic format for single command
virtual void execute(std::string const &args)
constexpr bScore SCORE_ALMOST_NORMAL
constexpr bScore SCORE_MATE
enum gameResult gameResult_t
constexpr bScore SCORE_PRACTICAL_DRAW
constexpr bScore SCORE_CONVERGE_BYDEPTH
constexpr bScore SCORE_WINNING
constexpr bScore SCORE_THEORETIC_DRAW
constexpr bScore SCORE_INFINITE
std::string to_string(int16_t value)
std::to_string not compatible on Mac OS (Apple LLVM version 5.0) provide generic utility function
stringList const stringSplit(std::string src, std::string const &delim)
Split delimited long string into a vector.
std::vector< std::string > stringList