17 : m_name{std::move(n)}
18 , m_hint{std::move(h)}
25 m_allowedCommands.clear();
45 if (
App().getMode() !=
"xboard"
46 || !
Game()->playGameMoveSeries(command)) {
51 sendError(
"unknown command, not executing",
52 command + (params.size() ?
" <" + params +
">" :
""));
60 for (
size_t i = 0; i < cmds.size(); ++i) {
73 for (
size_t i = 0; i < sCommands.size(); ++i) {
74 m_allowedCommands[sCommands[i]] = published;
88 bool bUnsupported = std::any_of(sParams.begin(), sParams.end(),
89 [](std::string
const& s)
90 { return s ==
"unsupported"; });
91 bool bUnpublished = std::any_of(sParams.begin(), sParams.end(),
92 [](std::string
const& s)
93 { return s ==
"hidden"; });
94 if (bUnsupported || bUnpublished || args ==
"") {
96 sParams.emplace_back(
"all");
98 if (std::any_of(sParams.begin(), sParams.end(),
99 [](std::string
const& s)
100 { return ((s ==
"all") || (s ==
"--all")); })) {
101 App().
bout <<
"Help for " MYNAME " - mode: " << m_name <<
"\n";
104 bool bAllowed = m_allowedCommands.find(v->
m_name) != m_allowedCommands.end();
107 <<
" - " << v->
m_hint <<
" (u)\n";
110 <<
" - " << v->
m_hint << (bAllowed ?
"\n" :
" (h)\n");
113 if (bUnsupported)
App().
bout <<
"\nu: Unsupported.";
114 if (bUnpublished)
App().
bout <<
"\nh: Hidden";
120 <<
" - " << v->
m_hint <<
"\n";
122 App().
bout <<
"\n** Unsupported **";
124 App().
bout <<
"Unknown command [" << args <<
"]";
145 App().
bout(-2) <<
"ERROR: " << error;
146 if (!description.empty())
App().
bout <<
" (" << description <<
")";
181 }
else if (score < 0) {
205 return "Draw by insufficient material";
207 return "Draw by repetition";
209 return "50 move rule";
213 return "White mates";
215 return "Black mates";
248#if defined(BELOFTE_UCIMODE)
251#elif defined(BELOFTE_XBOARDMODE)
259 attachCommand({
"usage",
"version",
"exec",
"ls",
"export",
"save",
"load"},
false);
270 "UCI_Variant"},
false);
272 "stop",
"ucinewgame",
"ponderhit"});
281 attachCommand({
"accepted",
"black",
"option",
"otim",
"ping",
282 "time",
"rejected",
"white"},
false);
283 attachCommand({
"bd",
"undo",
"new",
"setboard",
"usermove",
"game",
284 "remove",
"force",
"level",
"post",
"nopost",
"random",
285 "easy",
"hard",
"go",
"?",
"result",
"sd",
"st",
"protover"});
317 if (
App().getConfig(
"UCIdebug", 0)) {
318 App().
sout <<
"info string " << info;
325 App().
bout(l) <<
"info string " << info;
331 if (depth <=
App().sout.getLevel()) {
335#if !defined(NO_NPS_LOG)
345 bScore const sc, int64_t
const timems,
346 int64_t
const nodes)
const
348 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
350 if (nMaxDepth > nLogDepth)
352#if !defined(NO_NPS_LOG)
357#if !defined(NO_NPS_LOG)
372 depth_t const nMaxDepth, std::string
const& comment,
373 bScore const sc, int64_t
const timems,
374 int64_t
const nodes)
const
376 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
380 if (nMaxDepth > nLogDepth)
382 }
else if (nVariationDepth) {
385 if (nMaxDepth > nVariationDepth)
391#if !defined(NO_NPS_LOG)
393 if (nodes && (timems > 10))
401 printPV(b, nLogDepth, nVariationDepth);
402 if (comment !=
"")
App().
sout <<
" string " << comment;
410void UCIMode::printPV(
bBoard const& b,
412 int const nVariationDepth)
414 if ((nLogDepth == 0) && nVariationDepth) {
424 if (nVariationDepth) {
434 bMove const& mv,
movenum_t const moveid, int64_t
const nodes)
const
436 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
438 if (nVariationDepth > nCurDepth)
442 <<
" currmove " << mv;
457 return " score lowerbound";
459 return " score upperbound";
482 App().
bout(-2) <<
"Illegal move: " << mv;
483 if (reason !=
"")
App().
bout <<
" (" << reason <<
")";
488#pragma GCC diagnostic push
489#pragma GCC diagnostic ignored "-Wunused-parameter"
494 bScore const sc, int64_t
const t, int64_t
const nodes)
const
496 int nVariationDepth =
static_cast<int>(b.
getVariation().size());
498 std::stringstream sNew;
500 for (std::string
const& m : b.
getVariation()) sNew <<
" " << m;
501 if (sNew.str().size()) {
502 static std::string& sOld = *
new std::string();
503 if (sNew.str() != sOld) {
506 App().
sout <<
" " << std::setw(3) << nVariationDepth
507 << (nVariationDepth == nMaxDepth ?
" " :
"&")
509 <<
" " << std::setw(6) << (t / 10)
510 <<
" " << std::setw(8) << nodes
519#pragma GCC diagnostic pop
539 int localscore = score;
544 localscore = (-localscore +
SCORE_MATE) + 100000;
546 localscore = (-localscore -
SCORE_MATE) - 100000;
554 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
UCIMode(std::string &&s="uci")
std::string scoreString(bScore const score) const override
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
XboardMode(std::string &&s="xboard")
void sendInvalidMove(std::string const &mv, 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
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
static std::string getResult(gameResult_t gr)
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)
constexpr bool isUndefinedScore() const
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)
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
static void initCommand(std::vector< engineUserCommand * > cmds)
void execute(std::string const &command, std::string const ¶ms)
virtual void sendInfo(std::string const &info)
virtual void sendInfoSearchStart(std::string const &info)
engineInterface(std::string &&n, std::string &&h="")
Common commands to all modes this ctor is called for each iface.
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_UNDEFINED
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