Translate S-Chess gating moves
[uci2wb.git] / UCI2WB.c
index 3d26fcc..26010a2 100644 (file)
--- a/UCI2WB.c
+++ b/UCI2WB.c
@@ -30,7 +30,7 @@
 #define NONE  2\r
 #define ANALYZE 3\r
 \r
-char move[2000][10], checkOptions[8192], iniPos[256], hashOpt[20], pause, pondering, ponder, post, hasHash, c, sc='c', *suffix;\r
+char move[2000][10], checkOptions[8192], iniPos[256], hashOpt[20], pause, pondering, ponder, post, hasHash, c, sc='c', *suffix, *variants;\r
 int mps, tc, inc, sTime, depth, myTime, hisTime, stm, computer = NONE, memory, oldMem=0, cores, moveNr, lastDepth, lastScore, startTime, debug;\r
 int statDepth, statScore, statNodes, statTime, currNr, size; char currMove[20]; // for analyze mode\r
 \r
@@ -171,6 +171,8 @@ Engine2GUI()
                     line[13] = '=', line[14] = 0;\r
              }\r
            }\r
+           if(line[9] == 'e' && (line[14] == 'a' || line[14] == 'h')) // seirawan castling + gating at Rook\r
+               line[9] = line[14], line[11] = 'e'; // convert to RxK notation\r
            printf("move %s\n", line+9); // send move to GUI\r
            if(lastScore == 100001 && iniPos[0] != 'f') { printf("%s {mate}\n", stm == WHITE ? "1-0" : "0-1"); computer = NONE; }\r
            stm = WHITE+BLACK - stm;\r
@@ -282,6 +284,11 @@ GUI2Engine()
              else if(line[13] != '\n') line[13] = '+'; // cater to WB 4.4 bug :-(\r
            }\r
            sscanf(line, "usermove %s", command); // strips off linefeed\r
+           if(command[4] && (command[1] == '1' || command[1] == '8')) { // seirawan gating\r
+               command[5] = command[0], command[6] = command[1], command[7] = '\0';\r
+               if(command[2] == 'e' && (command[0] == 'a' || command[0] == 'h'))\r
+                   command[2] = (command[0]+command[2]+1)>>1, command[0] = 'e'; // gating at Rook\r
+           }\r
            stm = WHITE+BLACK - stm;\r
            // when pondering we either continue the ponder search as normal search, or abort it\r
            if(pondering || computer == ANALYZE) {\r
@@ -292,7 +299,8 @@ GUI2Engine()
                }\r
                StopPonder(1);\r
            }\r
-           sscanf(line, "usermove %s", move[moveNr++]); // possibly overwrites ponder move\r
+//         sscanf(line, "usermove %s", move[moveNr++]); // possibly overwrites ponder move\r
+           strcpy(move[moveNr++], command);\r
        }\r
        else if(!strcmp(command, "level")) {\r
            int sec = 0;\r
@@ -310,7 +318,8 @@ GUI2Engine()
            } else { fprintf(toE, "setoption name %s\n", line+7); DPRINT("# setoption name %s\n", line+7); }\r
        }\r
        else if(!strcmp(command, "protover")) {\r
-           printf("feature variants=\"%s\" setboard=1 usermove=1 debug=1 ping=1 reuse=0 done=0\n", sc=='s' ? "shogi,5x5+5_shogi" : VARIANTS);\r
+           if(!variants) variants = sc=='s' ? "shogi,5x5+5_shogi" : VARIANTS;\r
+           printf("feature variants=\"%s\" setboard=1 usermove=1 debug=1 ping=1 reuse=0 done=0\n", variants);\r
            printf("feature option=\"UCI2WB debug output -check %d\"\n", debug);\r
            fprintf(toE, "u%ci\n", sc); // this prompts UCI engine for options\r
        }\r
@@ -446,6 +455,7 @@ main(int argc, char **argv)
 \r
        if(argc == 2 && !strcmp(argv[1], "-v")) { printf("UCI2WB " VERSION " by H.G.Muller\n"); exit(0); }\r
        if(argc > 1 && !strcmp(argv[1], "debug")) { debug = 1; argc--; argv++; }\r
+       if(argc > 1 && !strcmp(argv[1], "-var")) { variants = argv[2]; argc-=2; argv+=2; }\r
        if(argc > 1 && argv[1][0] == '-') { sc = argv[1][1]; argc--; argv++; }\r
        if(argc < 2) { printf("usage is: U%cI2WB [debug] [-s] <engine.exe> [<engine directory>]\n", sc-32); exit(-1); }\r
        if(argc > 2) dir = argv[2];\r