// includes\r
\r
#include <cerrno>\r
-#include <csignal>\r
#include <cstdio>\r
#include <cstdlib>\r
#include <cstring>\r
\r
-#ifdef _WIN32\r
- #include <windows.h>\r
-#else\r
- #include <unistd.h>\r
-#endif\r
-\r
-#include "adapter.h"\r
#include "attack.h"\r
#include "board.h"\r
#include "book.h"\r
#include "hash.h"\r
#include "list.h"\r
#include "main.h"\r
+#include "mainloop.h"\r
#include "move.h"\r
#include "move_gen.h"\r
#include "option.h"\r
#include "square.h"\r
#include "uci.h"\r
#include "util.h"\r
+#include "xboard2uci.h"\r
+#include "uci2uci.h"\r
+\r
// constants\r
\r
\r
-static const char * const Version = "1.4W10UCIb16";\r
+static const char * const Version = "1.4b27";\r
static const char * const HelpMessage = "\\r
SYNTAX\n\\r
-polyglot [configfile]\n\\r
-polyglot make-book [-pgn inputfile] [-bin outputfile] [-max-ply ply] [-min-game games] [-min-score score] [-only-white] [-only-black] [-uniform]\n\\r
-polyglot merge-book -in1 inputfile1 -in2 inputfile2 [-out outputfile]\n\\r
-polyglot [configfile] epd-test [-epd inputfile] [-min-depth depth] [-max-depth depth] [-max-time time] [-depth-delta delta]\n\\r
-polyglot perft [-fen fen] [-max-depth depth]\\r
+* polyglot [configfile]\n\\r
+* polyglot -ec enginecommand\n\\r
+* polyglot make-book [-pgn inputfile] [-bin outputfile] [-max-ply ply] [-min-game games] [-min-score score] [-only-white] [-only-black] [-uniform]\n\\r
+* polyglot merge-book -in1 inputfile1 -in2 inputfile2 [-out outputfile]\n\\r
+* polyglot info-book [-bin inputfile] [-exact]\n\\r
+* polyglot dumb-book [-bin inputfile] -color color [-out outputfile]\n\\r
+* polyglot [configfile] epd-test [-epd inputfile] [-min-depth depth] [-max-depth depth] [-min-time time] [-max-time time] [-depth-delta delta]\n\\r
+* polyglot perft [-fen fen] [-max-depth depth]\\r
";\r
\r
-\r
-\r
static const int SearchDepth = 63;\r
static const double SearchTime = 3600.0;\r
static const int StringSize = 4096;\r
+\r
// variables\r
+\r
static bool Init;\r
+\r
// prototypes\r
\r
static void parse_option ();\r
static void init_book ();\r
static bool parse_line (char line[], char * * name_ptr, char * * value_ptr);\r
static void stop_search ();\r
-static void sig_quit(int);\r
\r
// functions\r
\r
}\r
// init\r
\r
- Init = false;\r
-\r
- signal(SIGINT,sig_quit);\r
-\r
-#ifdef _WIN32\r
- signal(SIGTERM,SIG_IGN);\r
-#ifdef SIGPIPE\r
- signal(SIGPIPE,SIG_IGN);\r
-#endif\r
-#endif\r
-\r
- util_init();\r
- printf("PolyGlot %s by Fabien Letouzey\n",Version);\r
-\r
- option_init();\r
-\r
- square_init();\r
- piece_init();\r
- attack_init();\r
-\r
- hash_init();\r
-\r
- my_random_init();\r
-\r
- // build book\r
+ Init = false;\r
+\r
+ util_init();\r
+ printf("PolyGlot %s by Fabien Letouzey\n",Version);\r
+ \r
+ option_init();\r
+ \r
+ square_init();\r
+ piece_init();\r
+ attack_init();\r
+ \r
+ hash_init();\r
+ \r
+ my_random_init();\r
+\r
+ // build book\r
+ \r
+ if (argc >= 2 && my_string_equal(argv[1],"make-book")) {\r
+ book_make(argc,argv);\r
+ return EXIT_SUCCESS;\r
+ }\r
+ \r
+ if (argc >= 2 && my_string_equal(argv[1],"merge-book")) {\r
+ book_merge(argc,argv);\r
+ return EXIT_SUCCESS;\r
+ }\r
\r
- if (argc >= 2 && my_string_equal(argv[1],"make-book")) {\r
- book_make(argc,argv);\r
+ if (argc >= 2 && my_string_equal(argv[1],"merge-book")) {\r
+ book_merge(argc,argv);\r
return EXIT_SUCCESS;\r
}\r
\r
- if (argc >= 2 && my_string_equal(argv[1],"merge-book")) {\r
- book_merge(argc,argv);\r
+ if (argc >= 2 && my_string_equal(argv[1],"dump-book")) {\r
+ book_dump(argc,argv);\r
return EXIT_SUCCESS;\r
}\r
\r
- if (argc >= 2 && my_string_equal(argv[1],"perft")) {\r
- do_perft(argc,argv);\r
+ if (argc >= 2 && my_string_equal(argv[1],"info-book")) {\r
+ book_info(argc,argv);\r
return EXIT_SUCCESS;\r
}\r
-\r
- if (argc >= 3 && my_string_equal(argv[1],"-ec")) {\r
- option_set("EngineCommand",argv[2]);\r
- Init=true;\r
- engine_open(Engine);\r
- gui_init(GUI);\r
- uci_open(Uci,Engine);\r
- if (my_string_equal(option_get_string("EngineName"),"<empty>")) {\r
+ \r
+ if (argc >= 2 && my_string_equal(argv[1],"perft")) {\r
+ do_perft(argc,argv);\r
+ return EXIT_SUCCESS;\r
+ }\r
+ \r
+ if (argc >= 3 && my_string_equal(argv[1],"-ec")) {\r
+ option_set("EngineCommand",argv[2]);\r
+ engine_open(Engine);\r
+ if(!engine_active(Engine)){\r
+ my_fatal("Could not start \"%s\"\n",option_get("EngineCommand"));\r
+ }\r
+ Init=true;\r
+ gui_init(GUI);\r
+ uci_open(Uci,Engine);\r
+ if (my_string_equal(option_get_string("EngineName"),"<empty>")) {\r
option_set("EngineName",Uci->name);\r
- }\r
- adapter_loop();\r
- return EXIT_SUCCESS; // we don't get here\r
- }\r
-\r
- // read options\r
-\r
- if (argc == 2) option_set("OptionFile",argv[1]); // HACK for compatibility\r
-\r
- parse_option(); // HACK: also launches the engine\r
+ }\r
+ mainloop();\r
+ return EXIT_SUCCESS; \r
+ }\r
+ \r
+ // read options\r
+ \r
+ if (argc == 2) option_set("OptionFile",argv[1]); // HACK for compatibility\r
+\r
+ parse_option(); // HACK: also launches the engine\r
+ \r
+ // EPD test\r
+ \r
+ if (argc >= 2 && my_string_equal(argv[1],"epd-test")){\r
+ epd_test(argc,argv);\r
+ return EXIT_SUCCESS;\r
+ }else if(argc >= 3 && my_string_equal(argv[2],"epd-test")){\r
+ epd_test(argc-1,argv+1);\r
+ return EXIT_SUCCESS;\r
+ }\r
+ \r
+ if (argc >= 3) my_fatal("Too many arguments\n");\r
\r
- // EPD test\r
\r
- if (argc >= 2 && my_string_equal(argv[1],"epd-test")){\r
- epd_test(argc,argv);\r
- return EXIT_SUCCESS;\r
- }else if(argc >= 3 && my_string_equal(argv[2],"epd-test")){\r
- epd_test(argc-1,argv+1);\r
- return EXIT_SUCCESS;\r
- }\r
- \r
- init_book();\r
- // adapter\r
- \r
- gui_init(GUI);\r
- adapter_loop();\r
- return EXIT_SUCCESS; // we never get here....\r
+ init_book();\r
+ gui_init(GUI);\r
+ mainloop();\r
+ return EXIT_SUCCESS; \r
}\r
\r
// polyglot_set_option\r
// init_book()\r
\r
static void init_book(){\r
- const char *empty_var[]={};\r
book_clear();\r
if (option_get_bool("Book")){\r
my_log("POLYGLOT *** SETTING BOOK ***\n");\r
\r
static void parse_option() {\r
\r
- const char * file_name;\r
- FILE * file;\r
- char line[256];\r
- char * name, * value;\r
+ const char * file_name;\r
+ FILE * file;\r
+ char line[256];\r
+ char * name, * value;\r
file_name = option_get_string("OptionFile");\r
-\r
- file = fopen(file_name,"r");\r
- if (file == NULL) {\r
- my_fatal("Can't open file \"%s\": %s\n",file_name,strerror(errno));\r
- }\r
-\r
- // PolyGlot options (assumed first)\r
-\r
+ \r
+ file = fopen(file_name,"r");\r
+ if (file == NULL) {\r
+ my_fatal("Can't open file \"%s\": %s\n",file_name,strerror(errno));\r
+ }\r
+ \r
+ // PolyGlot options (assumed first)\r
+ \r
while (true) {\r
-\r
- if (!my_file_read_line(file,line,256)) {\r
- my_fatal("parse_option(): missing [Engine] section\n");\r
- }\r
-\r
- if(line[0]=='#') continue;\r
-\r
- if (my_string_case_equal(line,"[engine]")) break;\r
-\r
- if (parse_line(line,&name,&value)) {\r
- option_set(name,value);\r
- option_set_default(name,value);\r
- }\r
+ \r
+ if (!my_file_read_line(file,line,256)) {\r
+ my_fatal("parse_option(): missing [Engine] section\n");\r
+ }\r
+ \r
+ if (my_string_case_equal(line,"[engine]")) break;\r
+ \r
+ if (parse_line(line,&name,&value)) {\r
+ option_set(name,value);\r
+ option_set_default(name,value);\r
+ }\r
}\r
-\r
+ \r
if (option_get_bool("Log")) {\r
- my_log_open(option_get_string("LogFile"));\r
+ my_log_open(option_get_string("LogFile"));\r
}\r
-\r
+ \r
my_log("POLYGLOT *** START ***\n");\r
my_log("POLYGLOT INI file \"%s\"\n",file_name);\r
engine_open(Engine);\r
+ if(!engine_active(Engine)){\r
+ my_fatal("Could not start \"%s\"\n",option_get("EngineCommand"));\r
+ }\r
+\r
if (option_get_bool("UCI")) {\r
my_log("POLYGLOT *** Switching to UCI mode ***\n");\r
}\r
-\r
- \r
- Init = true;\r
uci_open(Uci,Engine);\r
+ Init = true;\r
while (my_file_read_line(file,line,256)) {\r
if (line[0] == '[') my_fatal("parse_option(): unknown section %s\n",line);\r
- if (line[0]=='#') continue;\r
- \r
if (parse_line(line,&name,&value)) {\r
uci_send_option(Uci,name,"%s",value);\r
//to get a decent display in winboard_x we need to now if an engine really is doing multipv analysis\r
}\r
}\r
if (my_string_equal(option_get_string("EngineName"),"<empty>")) {\r
- option_set("EngineName",Uci->name);\r
+ option_set("EngineName",Uci->name);\r
}\r
-\r
+ \r
fclose(file);\r
}\r
\r
// parse_line()\r
\r
static bool parse_line(char line[], char * * name_ptr, char * * value_ptr) {\r
-\r
- char * ptr;\r
- char * name, * value;\r
-\r
- ASSERT(line!=NULL);\r
- ASSERT(name_ptr!=NULL);\r
- ASSERT(value_ptr!=NULL);\r
-\r
- // remove comments\r
-\r
- ptr = strchr(line,';');\r
- if (ptr != NULL) *ptr = '\0';\r
-\r
- ptr = strchr(line,'#');\r
- if (ptr != NULL) *ptr = '\0';\r
-\r
- // split at '='\r
-\r
- ptr = strchr(line,'=');\r
- if (ptr == NULL) return false;\r
-\r
- name = line;\r
- value = ptr+1;\r
-\r
- // cleanup name\r
-\r
- while (*name == ' ') name++; // remove leading spaces\r
-\r
- while (ptr > name && ptr[-1] == ' ') ptr--; // remove trailing spaces\r
- *ptr = '\0';\r
-\r
- if (*name == '\0') return false;\r
-\r
- // cleanup value\r
-\r
- ptr = &value[strlen(value)]; // pointer to string terminator\r
-\r
- while (*value == ' ') value++; // remove leading spaces\r
-\r
- while (ptr > value && ptr[-1] == ' ') ptr--; // remove trailing spaces\r
- *ptr = '\0';\r
-\r
- if (*value == '\0') return false;\r
-\r
- // end\r
-\r
- *name_ptr = name;\r
- *value_ptr = value;\r
-\r
- return true;\r
-}\r
-\r
-static void sig_quit(int dummy){\r
- my_log("POLYGLOT *** SIGINT Received ***\n");\r
- quit();\r
+ \r
+ char * ptr;\r
+ char * name, * value;\r
+ \r
+ ASSERT(line!=NULL);\r
+ ASSERT(name_ptr!=NULL);\r
+ ASSERT(value_ptr!=NULL);\r
+ \r
+ // remove comments\r
+ \r
+ ptr = strchr(line,';');\r
+ if (ptr != NULL) *ptr = '\0';\r
+ \r
+ ptr = strchr(line,'#');\r
+ if (ptr != NULL) *ptr = '\0';\r
+ \r
+ // split at '='\r
+ \r
+ ptr = strchr(line,'=');\r
+ if (ptr == NULL) return false;\r
+ \r
+ name = line;\r
+ value = ptr+1;\r
+ \r
+ // cleanup name\r
+ \r
+ while (*name == ' ') name++; // remove leading spaces\r
+ \r
+ while (ptr > name && ptr[-1] == ' ') ptr--; // remove trailing spaces\r
+ *ptr = '\0';\r
+ \r
+ if (*name == '\0') return false;\r
+ \r
+ // cleanup value\r
+ \r
+ ptr = &value[strlen(value)]; // pointer to string terminator\r
+ \r
+ while (*value == ' ') value++; // remove leading spaces\r
+ \r
+ while (ptr > value && ptr[-1] == ' ') ptr--; // remove trailing spaces\r
+ *ptr = '\0';\r
+ \r
+ if (*value == '\0') return false;\r
+ \r
+ // end\r
+ \r
+ *name_ptr = name;\r
+ *value_ptr = value;\r
+ \r
+ return true;\r
}\r
\r
-\r
// quit()\r
\r
void quit() {\r
\r
- char string[StringSize];\r
-\r
- my_log("POLYGLOT *** QUIT ***\n");\r
-\r
- if (Init) {\r
-\r
- stop_search();\r
- engine_send(Engine,"quit");\r
-\r
- // wait for the engine to quit\r
- while (true) {\r
- engine_get(Engine,string,StringSize); // HACK: calls exit() on receiving EOF\r
- }\r
- }\r
- exit(EXIT_SUCCESS);\r
+ my_log("POLYGLOT *** QUIT ***\n");\r
+ \r
+ if (Init) {\r
+ \r
+ stop_search();\r
+ engine_send(Engine,"quit");\r
+ my_log("POLYGLOT Closing engine\n");\r
+ engine_close(Engine);\r
+ \r
+ }\r
+ my_log("POLYGLOT Calling exit\n");\r
+ exit(EXIT_SUCCESS);\r
}\r
\r
// stop_search()\r
\r
static void stop_search() {\r
-\r
- if (Init && Uci->searching) {\r
-\r
- ASSERT(Uci->searching);\r
- ASSERT(Uci->pending_nb>=1);\r
-\r
- my_log("POLYGLOT STOP SEARCH\n");\r
-\r
-/*\r
- engine_send(Engine,"stop");\r
- Uci->searching = false;\r
-*/\r
-\r
- if (option_get_bool("SyncStop")) {\r
- uci_send_stop_sync(Uci);\r
- } else {\r
- uci_send_stop(Uci);\r
- }\r
- }\r
+ \r
+ if (Init && Uci->searching) {\r
+ \r
+ ASSERT(Uci->searching);\r
+ ASSERT(Uci->pending_nb>=1);\r
+ \r
+ my_log("POLYGLOT STOP SEARCH\n");\r
+ \r
+ if (option_get_bool("SyncStop")) {\r
+ uci_send_stop_sync(Uci);\r
+ } else {\r
+ uci_send_stop(Uci);\r
+ }\r
+ }\r
}\r
\r
+\r
// end of main.cpp\r
\r