From 8a892f02b87c910603094e2830ed0693dc192569 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Mon, 4 Apr 2016 13:32:06 +0200 Subject: [PATCH] Support Chess960 AIf an engine annunces an option UCI_Chess960 UCI2WB will report to the GUI it supports variant fischerandom. In addition it will request the GUI to encode castling moves as KxR through feature oocastle=0. A flag argument -f will make UCI2WB support FRC even when the engine does not have the option. In that case the GUI is set to deliver castling moves as O-O[-O] (feature oocastle=1), and any castling field in a received FEN will be overwritten with KQkq. (This is the obsolete 'Arena standard' for FRC.) --- UCI2WB.c | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-) diff --git a/UCI2WB.c b/UCI2WB.c index 9f1ad06..c69971f 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -41,7 +41,7 @@ char move[2000][10], checkOptions[8192], iniPos[256], hashOpt[20], pause, pondering, suspended, ponder, post, hasHash, c, sc='c', *suffix, *variants; int mps, tc, inc, sTime, depth, myTime, hisTime, stm, computer = NONE, memory, oldMem=0, cores, moveNr, lastDepth, lastScore, startTime, debug; -int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500]; +int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500], frc; char currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20], threadOpt[20]; char board[100]; // XQ board for UCCI char *nameWord = "name ", *valueWord = "value ", *wTime = "w", *bTime = "b", *wInc = "winc", *bInc = "binc", newGame; // keywords that differ in UCCI @@ -307,6 +307,7 @@ Engine2GUI() if(p = strstr(line+6, " max ")) sscanf(p+1, "max %d", &max), *p = '\n'; if(p = strstr(line+6, " default ")) sscanf(p+1, "default %[^\n]*", val), *p = '\n'; if(!(p = strstr(line+6, " name "))) p = line+1; sscanf(p+6, "%[^\n]", name); // 'name' is omitted in UCCI + if(!strcasecmp(name, "UCI_Chess960")) { frc=2; continue; } if(!strcasecmp(name, "Threads")) { strcpy(threadOpt, name); continue; } if(!strcasecmp(name, "Ponder") || !strcasecmp(name, "USI_Ponder")) { strcpy(canPonder, name); continue; } if(!strcasecmp(name, "Hash") || !strcasecmp(name, "USI_Hash") || !strcasecmp(name, "hashsize")) { @@ -342,6 +343,7 @@ Engine2GUI() } else if(!strcmp(command, "readyok")) { pause = 0; Sync(WAKEUP); } // resume processing of GUI commands else if(sc == 'x'&& !strcmp(command, "ucciok") || sscanf(command, "u%ciok", &c)==1 && c==sc) { + if(frc) printf("feature variants=\"normal,fischerandom\" oocastle=%d\n", frc<0); // unannounced FRC uses O-O castling printf("feature smp=1 memory=%d done=1\n", hasHash); if(unit == 2) unit = 1, fprintf(toE, "setoption usemillisec true\n"); Sync(WAKEUP); // done with options @@ -397,7 +399,7 @@ GUI2Engine() sscanf(line, "%s", command); if(!strcmp(command, "new")) { computer = BLACK; moveNr = 0; depth = -1; move[0][0] = 0; - stm = WHITE; strcpy(iniPos, "position startpos"); + stm = WHITE; strcpy(iniPos, "position startpos"); frc &= ~1; if(memory != oldMem && hasHash) fprintf(toE, "setoption name %s %s%d\n", hashOpt, valueWord, memory); oldMem = memory; // we can set other options here @@ -415,9 +417,9 @@ GUI2Engine() if(pondering || computer == ANALYZE) { if(pondering && !strcmp(command, move[moveNr])) { // ponder hit char *draw = drawOffer ? " draw" : ""; drawOffer = 0; - pondering = 0; moveNr++; startTime = GetTickCount(); // clock starts running now - fprintf(toE, "ponderhit%s\n", draw); DPRINT("# ponderhit%s\n", draw); - fflush(toE); fflush(stdout); pause = 2; Sync(PAUSE); // block input during thinking + pondering = 0; pause = 2; moveNr++; startTime = GetTickCount(); // clock starts running now + fprintf(toE, "ponderhit%s\n", draw); DPRINT("# ponderhit%s\n", draw); fflush(toE); fflush(stdout); + Sync(PAUSE); // block input during thinking goto nomove; } StopPonder(1); @@ -454,6 +456,7 @@ GUI2Engine() else r = strchr(strchr(q+4, ' ') + 1, ' '); // skip to second space (after e.p. square) *r = 0; sprintf(command, "%s%s %s %s", line+9, q+1, p, r+1); } else strcpy(command, line+9); + if(frc == -1 && (p = strchr(command, ' '))) strncpy(p+3, "KQkq", 4); // unannounced FRC sprintf(iniPos, "%s%sfen %s", iniPos[0]=='p' ? "position " : "", sc=='s' ? "s" : "", command); iniPos[strlen(iniPos)-1] = sm = 0; collect = (computer == ANALYZE); } @@ -461,6 +464,7 @@ GUI2Engine() if(!strcmp(line+8, "shogi\n")) size = 9, strcpy(iniPos, "position startpos"); if(!strcmp(line+8, "5x5+5_shogi\n")) size = 5, strcpy(iniPos, "position startpos"); if(!strcmp(line+8, "xiangqi\n")) strcpy(iniPos, "fen rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR r"); + if(!strcmp(line+8, "fischerandom\n")) { frc |= 1; if(frc > 0) fprintf(toE, "setoption name UCI_Chess960 value true\n"); } } else if(!strcmp(command, "undo") && (i=1) || !strcmp(command, "remove") && (i=2)) { if(pondering || computer == ANALYZE) StopPonder(1); @@ -605,6 +609,8 @@ main(int argc, char **argv) if(argc > 3) suffix = argv[3]; if(sc == 'x') nameWord = valueWord = bTime = "", wTime = "opp", bInc = "increment", wInc = "oppincrement", unit = 1000; // switch to UCCI keywords + else if(sc == 'f' ) frc = -1, sc = 'c'; // UCI for unannounced Chess960 + else if(sc == 'n') sc = 'c'; // UCI for normal Chess // spawn engine proc if(StartEngine(argv[1], dir) != NO_ERROR) { perror(argv[1]), exit(-1); } -- 1.7.0.4