version 1.4.61b
[polyglot.git] / xboard2uci.c
index 2097de9..80e0a62 100644 (file)
@@ -75,6 +75,8 @@ typedef struct {
     \r
     double my_time;\r
     double opp_time;\r
+\r
+    int node_rate;\r
 } xb_t;\r
 \r
 typedef enum { WAIT, THINK, PONDER, ANALYSE } dummy_state_t;\r
@@ -165,6 +167,8 @@ void xboard2uci_init() {
 \r
    XB->my_time = 300.0;\r
    XB->opp_time = 300.0;\r
+\r
+   XB->node_rate = -1;\r
 }\r
 \r
 // xboard2uci_gui_step()\r
@@ -301,7 +305,7 @@ void xboard2uci_gui_step(char string[]) {
 \r
                } else if (match(string,"new")) {\r
 \r
-            uci_send_isready(Uci);\r
+                   uci_send_isready_sync(Uci);\r
                        my_log("POLYGLOT NEW GAME\n");\r
 \r
                        option_set(Option,"Chess960","false");\r
@@ -320,6 +324,7 @@ void xboard2uci_gui_step(char string[]) {
                        XB->result = FALSE;\r
 \r
                        XB->depth_limit = FALSE;\r
+            XB->node_rate=-1;\r
 \r
                        XB->computer = FALSE;\r
                        my_string_set(&XB->name,"<empty>");\r
@@ -351,12 +356,15 @@ void xboard2uci_gui_step(char string[]) {
                        if (DelayPong) {\r
                                if (XB->ping >= 0) gui_send(GUI,"pong %d",XB->ping); // HACK: get rid of old ping\r
                                XB->ping = atoi(Star[0]);\r
-                               uci_send_isready(Uci);\r
+                               uci_send_isready_sync(Uci);\r
                        } else {\r
                                ASSERT(XB->ping==-1);\r
                                gui_send(GUI,"pong %s",Star[0]);\r
                        }\r
-\r
+        } else if (match(string,"nps *")) {\r
+            \r
+                // fake WB play-by-nodes mode\r
+            XB->node_rate = atoi(Star[0]);\r
                } else if (match(string,"playother")) {\r
 \r
                        State->computer[game_turn(Game)] = FALSE;\r
@@ -744,18 +752,18 @@ void xboard2uci_engine_step(char string[]) {
                        }\r
                }\r
                if(((event & EVENT_ILLEGAL_MOVE)!=0) && (State->state == THINK)){\r
-            game_get_board(Game,board);\r
-            if(board->turn==White){\r
-                gui_send(GUI,"0-1 {polyglot: resign"\r
-                            " (illegal engine move white)}");\r
-            }else{\r
-                gui_send(GUI,"1-0 {polyglot: resign"\r
-                         " (illegal engine move black)}");\r
-            }\r
-            board_disp(board);\r
-            XB->result = TRUE;\r
-            mess();\r
-        }\r
+                   game_get_board(Game,board);\r
+                   if(board->turn==White){\r
+                       gui_send(GUI,"0-1 {polyglot: resign"\r
+                                " (illegal engine move by white: %s)}",Uci->bestmove);\r
+                   }else{\r
+                       gui_send(GUI,"1-0 {polyglot: resign"\r
+                                " (illegal engine move by black: %s)}",Uci->bestmove);\r
+                   }\r
+                   board_disp(board);\r
+                   XB->result = TRUE;\r
+                   mess();\r
+               }\r
 }\r
 \r
 // format_xboard_option_line\r
@@ -774,7 +782,7 @@ void format_xboard_option_line(char * option_line, option_t *opt){
     strcat(option_line,option_string);\r
     sprintf(option_string," -%s",opt->type);\r
     strcat(option_line,option_string);\r
-    if(!IS_BUTTON(opt) && strcmp(opt->type,"combo")){\r
+    if(!IS_BUTTON(opt->type) && strcmp(opt->type,"combo")){\r
         if(strcmp(opt->type,"check")){\r
             sprintf(option_string," %s",opt->value);\r
         }else{\r
@@ -785,11 +793,11 @@ void format_xboard_option_line(char * option_line, option_t *opt){
         }\r
         strcat(option_line,option_string);\r
     }\r
-    if(IS_SPIN(opt)){\r
+    if(IS_SPIN(opt->type)){\r
         sprintf(option_string," %s",opt->min);\r
             strcat(option_line,option_string);\r
     }\r
-    if(IS_SPIN(opt)){\r
+    if(IS_SPIN(opt->type)){\r
         sprintf(option_string," %s",opt->max);\r
         strcat(option_line,option_string);\r
     }\r
@@ -830,6 +838,7 @@ static void send_xboard_options(){
     gui_send(GUI,"feature pause=0");\r
     gui_send(GUI,"feature ping=1");\r
     gui_send(GUI,"feature playother=1");\r
+    gui_send(GUI,"feature sigint=1");\r
     gui_send(GUI,"feature reuse=1");\r
     gui_send(GUI,"feature san=0");\r
     gui_send(GUI,"feature setboard=1");\r
@@ -837,6 +846,7 @@ static void send_xboard_options(){
     gui_send(GUI,"feature sigterm=0");\r
     gui_send(GUI,"feature time=1");\r
     gui_send(GUI,"feature usermove=1");\r
+    gui_send(GUI,"feature nps=1");\r
     if (XB->has_feature_memory){\r
         gui_send(GUI,"feature memory=1");\r
     }else{\r
@@ -1281,30 +1291,63 @@ static void search_update() {
          if (XB->time_limit) {\r
 \r
             // fixed time per move\r
-\r
-            engine_send_queue(Engine," movetime %.0f",XB->time_max*1000.0);\r
+             \r
+             if(XB->node_rate > 0){\r
+                 engine_send_queue(Engine,\r
+                                   " nodes %.0f",\r
+                                   XB->time_max*((double)XB->node_rate));\r
+             }else{\r
+                 engine_send_queue(Engine,\r
+                                   " movetime %.0f",\r
+                                   XB->time_max*1000.0);\r
+             }\r
 \r
          } else {\r
 \r
             // time controls\r
 \r
-            if (colour_is_white(Uci->board->turn)) {\r
-               engine_send_queue(Engine," wtime %.0f btime %.0f",XB->my_time*1000.0,XB->opp_time*1000.0);\r
-            } else {\r
-               engine_send_queue(Engine," wtime %.0f btime %.0f",XB->opp_time*1000.0,XB->my_time*1000.0);\r
-            }\r
-\r
-            if (XB->inc != 0.0) engine_send_queue(Engine," winc %.0f binc %.0f",XB->inc*1000.0,XB->inc*1000.0);\r
-\r
-            if (XB->mps != 0) {\r
-\r
-               move_nb = XB->mps - (Uci->board->move_nb % XB->mps);\r
-               ASSERT(move_nb>=1&&move_nb<=XB->mps);\r
-\r
-               engine_send_queue(Engine," movestogo %d",move_nb);\r
-            }\r
+                 if(XB->node_rate > 0) {\r
+                     double time;\r
+                     move_nb = 40;\r
+                     if (XB->mps != 0){\r
+                         move_nb = XB->mps - (Uci->board->move_nb % XB->mps);\r
+                     }\r
+                     time = XB->my_time / move_nb;\r
+                     if(XB->inc != 0){\r
+                         time += XB->inc;\r
+                     }\r
+                     if(time > XB->my_time){\r
+                         time = XB->my_time;\r
+                     }\r
+                     engine_send_queue(Engine,\r
+                                       " nodes %.0f",\r
+                                       time*XB->node_rate);\r
+                 } else {\r
+                     \r
+                     if (colour_is_white(Uci->board->turn)) {\r
+                         engine_send_queue(Engine,\r
+                                           " wtime %.0f btime %.0f",\r
+                                           XB->my_time*1000.0,XB->opp_time*1000.0);\r
+                     } else {\r
+                         engine_send_queue(Engine,\r
+                                           " wtime %.0f btime %.0f",\r
+                                           XB->opp_time*1000.0,XB->my_time*1000.0);\r
+                     }\r
+                     \r
+                     if (XB->inc != 0.0){\r
+                         engine_send_queue(Engine,\r
+                                           " winc %.0f binc %.0f",\r
+                                           XB->inc*1000.0,XB->inc*1000.0);\r
+                     }\r
+                     if (XB->mps != 0) {\r
+\r
+                         move_nb = XB->mps - (Uci->board->move_nb % XB->mps);\r
+                         ASSERT(move_nb>=1&&move_nb<=XB->mps);\r
+                         \r
+                         engine_send_queue(Engine," movestogo %d",move_nb);\r
+                     }\r
+                 }\r
          }\r
-\r
          if (XB->depth_limit) engine_send_queue(Engine," depth %d",XB->depth_max);\r
 \r
          if (State->state == PONDER) engine_send_queue(Engine," ponder");\r