UCI protocol: letting the engine know the game result

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

flok

UCI protocol: letting the engine know the game result

Post by flok »

Hi,

Currently the UCI protocol does not specify a way of the gui telling the engine the end-result of a game. It only sends a "ucinewgame" and that's it.
For engines that would like to "learn" from a game, it would be useful if they were informed what the result was, like the xboard protocol does. This may be deducible but that can be tricky (e.g. when the program was asked for a hint).

To get around this problem I would like to propose a new UCI command "gameover" with as parameters win, draw or lose.

To stay compatible with UCI engines that do not support this feature I think it is best that the engine announces support of it via an option-line:

Code: Select all

option name GameOver_command type check default true
and then the gui announcing that it will use it.

So what happens is as follows:

Code: Select all

gui eng> uci
eng gui> option name GameOver_command type check default true
gui eng> setoption name GameOver_command value true   # this tells the engine that it can expect the gameover command
gui eng> ucinewgame
gui eng> position [...]
[...]
gui eng> gameover 1-0 white
[...]
Please let me know what you think.

p.s. a somewhat tested patch for polyglot could be:

(start polyglot with -pg GameOver_command=true - with this patch the setoption thing is not implemented)

Code: Select all

diff -uNrBbd polyglot-2.0.4.org/option.c polyglot-gameover/option.c
--- polyglot-2.0.4.org/option.c 2016-11-15 10:44:53.000000000 +0100
+++ polyglot-gameover/option.c  2017-01-19 13:53:21.188280741 +0100
@@ -40,6 +40,7 @@
     { "LogFile",          "file","0","0",       "polyglot.log", NULL,0,NNB,  PG|XBOARD|XBSEL|UCI},

     { "UCI",              "check","0","0",      "false"     , NULL,0,NNB,  PG},
+    { "GameOver_command", "check","0","0",      "false"     , NULL,0,NNB,  PG|UCI},

     { "UseNice",          "check","0","0",      "false"     , NULL,0,NNB,  PG|XBOARD|UCI},
     { "NiceValue",        "spin", "0","20",     "5"         , NULL,0,NNB,  PG|XBOARD|UCI},
diff -uNrBbd polyglot-2.0.4.org/uci.c polyglot-gameover/uci.c
--- polyglot-2.0.4.org/uci.c    2016-11-15 10:44:53.000000000 +0100
+++ polyglot-gameover/uci.c     2016-12-16 10:19:57.248771338 +0100
@@ -280,6 +280,20 @@
    }
 }

+// uci_send_gameover()
+
+void uci_send_gameover(uci_t * uci, const int result) {
+
+   ASSERT(uci!=NULL);
+
+   if (result > 0)
+      engine_send(uci->engine,"gameover win");
+   else if &#40;result < 0&#41;
+      engine_send&#40;uci->engine,"gameover lose");
+   else
+      engine_send&#40;uci->engine,"gameover draw");
+&#125;
+
 // uci_send_option&#40;)

 bool uci_send_option&#40;uci_t * uci, const char option&#91;&#93;, const char format&#91;&#93;, ...) &#123;
diff -uNrBbd polyglot-2.0.4.org/uci.h polyglot-gameover/uci.h
--- polyglot-2.0.4.org/uci.h    2016-11-15 10&#58;44&#58;53.000000000 +0100
+++ polyglot-gameover/uci.h     2016-12-16 10&#58;19&#58;32.848771404 +0100
@@ -98,6 +98,7 @@
 extern void uci_send_stop         &#40;uci_t * uci&#41;;
 extern void uci_send_stop_sync    &#40;uci_t * uci&#41;;
 extern void uci_send_ucinewgame   &#40;uci_t * uci&#41;;
+extern void uci_send_gameover     &#40;uci_t * uci, const int result&#41;;
 extern void uci_set_threads       &#40;uci_t * uci, int n&#41;;
 extern const char * uci_thread_option&#40;uci_t * uci&#41;;
 extern bool uci_send_option       &#40;uci_t * uci, const char option&#91;&#93;, const char format&#91;&#93;, ...);
diff -uNrBbd polyglot-2.0.4.org/xboard2uci.c polyglot-gameover/xboard2uci.c
--- polyglot-2.0.4.org/xboard2uci.c     2016-11-15 10&#58;44&#58;53.000000000 +0100
+++ polyglot-gameover/xboard2uci.c      2017-01-19 13&#58;52&#58;14.852280615 +0100
@@ -499,6 +499,7 @@
                        || match&#40;string,"result * &#123;* &#125;")
                        || match&#40;string,"result * &#123; *&#125;")
                        || match&#40;string,"result * &#123; * &#125;")) &#123;
+                               int xb_result = 0;

                                my_log&#40;"POLYGLOT GAME END\n");

@@ -506,17 +507,35 @@

                                mess&#40;);

+                               if &#40;FALSE&#41; &#123;
+                               &#125; else if &#40;my_string_equal&#40;Star&#91;0&#93;,"1-0")) &#123;
+                                       xb_result = 1;
+                               &#125; else if &#40;my_string_equal&#40;Star&#91;0&#93;,"0-1")) &#123;
+                                       xb_result = -1;
+                               &#125; else if &#40;my_string_equal&#40;Star&#91;0&#93;,"1/2-1/2")) &#123;
+                                       xb_result = 0;
+                               &#125;
+
+                               if &#40;option_get_bool&#40;Option,"GameOver_command")) &#123;
+                                       if &#40;xb_result == 0&#41;
+                                               uci_send_gameover&#40;Uci, 0&#41;;
+                                       else if &#40;State->computer&#91;White&#93; == TRUE&#41;
+                                               uci_send_gameover&#40;Uci, xb_result&#41;;
+                                       else
+                                               uci_send_gameover&#40;Uci, xb_result * -1&#41;;
+                               &#125;
+
                                // book learning

                                if &#40;option_get_bool&#40;Option,"Book") &&
                     option_get_bool&#40;Option,"BookLearn")) &#123;

                                        if &#40;FALSE&#41; &#123;
-                                       &#125; else if &#40;my_string_equal&#40;Star&#91;0&#93;,"1-0")) &#123;
+                                       &#125; else if &#40;xb_result == 1&#41; &#123;
                                                learn&#40;+1&#41;;
-                                       &#125; else if &#40;my_string_equal&#40;Star&#91;0&#93;,"0-1")) &#123;
+                                       &#125; else if &#40;xb_result == -1&#41; &#123;
                                                learn&#40;-1&#41;;
-                                       &#125; else if &#40;my_string_equal&#40;Star&#91;0&#93;,"1/2-1/2")) &#123;
+                                       &#125; else if &#40;xb_result == 0&#41; &#123;
                                                learn&#40;0&#41;;
                                        &#125;
                                &#125;
jdart
Posts: 4367
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: UCI protocol: letting the engine know the game result

Post by jdart »

Yes, this is one of the bigger holes in the protocol IMO.

Another is that it is reasonably hard to keep track of the game state from the engine's perspective, given that the GUI can move forward and back through the game. Having a ply counter would help.

--Jon