31int main(
int argc,
char *argv[])
43 std::srand(
static_cast<unsigned int> (std::time(
nullptr)));
47#if defined(BELOFTE_UCIMODE)
65 for (
int i = 1; i < argc; i++) {
66 std::string arg = argv[i];
67 if (arg ==
"--help") {
71 }
else if (arg ==
"--version") {
75 }
else if (arg ==
"-xboard") {
78 }
else if ((arg ==
"bench") || (arg ==
"--bench")) {
81 }
else if (arg.substr(0, 1) ==
"@") {
82 if (arg.length() > 1) {
87 App().
bout <<
"Use filename with @" << std::endl;
93 }
else if (arg.substr(0, 2) ==
"--") {
99 }
catch (
const std::logic_error& e) {
100 std::cout <<
"Logic Error: " << e.what() << std::endl;
102 std::cout <<
"Error: Uncatched exception" << std::endl;
112 if (!
App().m_reader.isFileAttached()) {
120 }
catch (
const std::logic_error& e) {
121 std::cout <<
"Logic Error: " << e.what() << std::endl;
123 std::cout <<
"Error: Uncatched exception" << std::endl;
152 }
else if (params !=
"") {
153 sendError(
"unknown command", command +
" " + params);
160void engineInterface::initCommand(std::vector<engineUserCommand *> cmds)
162 for (
size_t i = 0; i < cmds.size(); i++) {
172 bool const published)
176 for (
size_t i = 0; i < sCommands.size(); i++) {
177 m_allowedCommands[sCommands[i]] = published;
185#pragma GCC diagnostic push
186#pragma GCC diagnostic ignored "-Weffc++"
195#pragma GCC diagnostic pop
216 }
catch (...) {
throw;
221std::string commandReader::readLine()
225 while (line.empty()) {
229 if (!std::getline(m_inputfile, line)) {
238 || (line[0] ==
';')) line =
"";
247 std::string line = readLine();
249 if (line ==
"__END__") {
256 std::stringstream ss(line);
258 std::getline(ss, cmd.
m_args);
273 m_inputfile.open(m_filename.c_str(), std::ios_base::in);
279 if (m_filename ==
"")
return false;
280 if (!m_inputfile)
return false;
281 if (m_inputfile.eof())
detach();
282 return m_inputfile.is_open();
316 , m_allowedCommands{}
345 m_allowedCommands.clear();
360 attachCommand({
"about",
"xboard",
"uci",
"help",
"bench",
"perft"});
371 attachCommand({
"uci",
"setoption",
"isready",
"position",
"go",
372 "stop",
"ucinewgame",
"ponderhit"});
382 attachCommand({
"accepted",
"belofte",
"black",
"option",
"otim",
"ping",
383 "time",
"rejected",
"white"},
false);
384 attachCommand({
"bd",
"undo",
"new",
"setboard",
"usermove",
"game",
385 "remove",
"force",
"level",
"post",
"nopost",
"random",
386 "easy",
"hard",
"go",
"?",
"result",
"sd",
"st",
"protover"});
402 , m_game{new
bGame()}
404 , m_stringsettings{{}}
405 , m_engineInterfaces{{}}
406 , m_interfaceName{
""}
409 m_engineInterfaces[
"xboard"] =
new XboardMode();
410 m_engineInterfaces[
"uci"] =
new UCIMode();
417 engineInterfaces_t::iterator itr = m_engineInterfaces.begin();
418 while (itr != m_engineInterfaces.end()) {
420 itr = m_engineInterfaces.erase(itr);
422 m_engineInterfaces.clear();
427 std::string sOldName = m_interfaceName;
428 m_interfaceName = iName;
429 m_ui = m_engineInterfaces[m_interfaceName];
440 if (m_settings.find(s) != m_settings.end())
return m_settings[s];
446 m_stringsettings[s] = v;
451 if (m_stringsettings.find(s) != m_stringsettings.end())
return m_stringsettings[s];
461 std::string sExename;
463 std::string sFile(sName);
464 sExename = sFile.substr(sFile.find_last_of(
"/\\") + 1);
467 if (sExename.find(
".exe") != std::string::npos)
468 sExename.erase(sExename.find(
".exe"));
500#if defined(BELOFTE_NOSIGNALS)
502 signal(SIGTERM, SIG_IGN);
503 signal(SIGINT, SIG_IGN);
int main(int argc, char *argv[])
Main entry point.
static void platform_ctor()
The main program.
static void platform_dtor()
engineInterface * AppEI()
This is the main include file, needs to be included before any other include.
engineInterface * AppEI()
std::map< std::string, engineUserCommand * > engineCommands_t
implementation of specific implementation
UCIMode(std::string const &n="uci")
XboardMode(std::string const &n="xboard")
Singleton implementation of application.
void setName(char *sName)
set name of executable based on argv[0] Remove leading / and \ characters Remove trailing ....
bel_hash m_hashEngine
read input
void setConfig(std::string const &s, int64_t v)
int64_t getConfig(std::string const &s, int64_t v)
std::string getName() const
std::string const setMode(std::string const &iName)
commandReader m_reader
searching output
game representation, singleton
void setDepthCommand(depth_t const d)
implementation of single command
bool isBatchMode()
no interactive input, mainly during start and '@' execute
bool attach(std::string const &ifile)
implementation of user interface
virtual ~engineInterface()
engineInterface(std::string const &n, std::string const &h="")
Common commands to all modes.
void attachCommand(belofte::stringList const &sCommands, bool const published=true)
virtual void sendDebug(int const l, std::string const &info)
static engineCommands_t m_engineCommands
void execute(std::string const &command, std::string const ¶ms)
virtual void sendError(std::string const &error, std::string const &description)
virtual void sendPrompt()
basic format for single command
virtual void execute(std::string const &args)
constexpr depth_t DEFAULT_DEPTH