X-Git-Url: http://hgm.nubati.net/cgi-bin/gitweb.cgi?p=uci2wb.git;a=blobdiff_plain;f=UCI2WB.c;h=7251f5df0aeba7130e4a87d73ce00a02d84c7a9e;hp=1dd839ed1ef1e9feeae2d0f07811cdf410bcab50;hb=HEAD;hpb=690cdbd5613b58bec306255fe5704040326da38a diff --git a/UCI2WB.c b/UCI2WB.c index 1dd839e..7251f5d 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -52,7 +52,7 @@ char move[2000][10], iniPos[256], hashOpt[20], suspended, ponder, post, hasHash, c, sc=' ', sc2, suffix[81], varOpt, searching, *binary; int mps, tc, inc, sTime, depth, myTime, hisTime, stm, computer = NONE, memory, oldMem=0, cores, moveNr, lastDepth, lastScore, startTime, debug, flob; -int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500], frc, byo = -1, namOpt, comp; +int statDepth, statScore, statNodes, statTime, currNr, hsize=9, size=9, collect, nr, sm, inex, on[500], frc, byo = -1, namOpt, comp; char currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20], threadOpt[20], varList[8000], anaOpt[20], checkOptions[8192] = "Ponder"; char pvs[99][999], 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 @@ -213,7 +213,7 @@ char *Convert(char *pv) if(sc != 's') return pv; p = pv; q = buf; while(c = *p++) { - if(c >= '0' && c <= '9' || c >= 'a' && c <= 'z') *q++ = 'a'+'0'+size - c; else *q++ = c; + if(c >= '0' && c <= '9' || c >= 'a' && c <= 'z') *q++ = 'a'+'0' + (c >= 'a' ? size : hsize) - c; else *q++ = c; } *q++ = 0; return buf; @@ -224,12 +224,12 @@ Move4GUI(char *m) { if(sc == 's') { // convert USI move to WB format - m[2] = 'a'+'0'+size - m[2]; + m[2] = 'a'+'0'+hsize - m[2]; m[3] = 'a'+'0'+size - m[3]; if(m[1] == '*') { // drop m[1] = '@'; } else { - m[0] = 'a'+'0'+size - m[0]; + m[0] = 'a'+'0'+hsize - m[0]; m[1] = 'a'+'0'+size - m[1]; if((stm == WHITE ? (m[1]>'0'+size-size/3 || m[3]>'0'+size-size/3) : (m[1] <= '0'+size/3 || m[3] <= '0'+size/3)) && m[4] != '+') @@ -348,7 +348,7 @@ HandleEngineOutput() 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")) { - memory = oldMem = atoi(val); hasHash = 1; + memory = oldMem = atoi(val); hasHash = max; strcpy(hashOpt, name); continue; } @@ -398,7 +398,7 @@ HandleEngineOutput() if(!*varList) strcpy(varList, sc=='s' ? ",shogi,5x5+5_shogi" : VARIANTS); // without clue guess liberally printf("feature variants=\"%s\"\n", varList+1); // from UCI_Variant combo and/or UCI_Chess960 check options if(*egts) printf("feature egt=\"%s\"\n", egts+1); - printf("feature smp=1 memory=%d done=1\n", hasHash); + printf("feature smp=1 memory=%d done=1\n", hasHash > 0); if(unit == 2) { unit = 1; EPRINT((f, "# setoption usemillisec true\n")) } fflush(stdout); return; // done with options } @@ -413,10 +413,10 @@ Move4Engine(char *m) if(m[1] == '@') { // drop m[1] = '*'; } else { - m[0] = 'a'+'0'+size - m[0]; + m[0] = 'a'+'0'+hsize - m[0]; m[1] = 'a'+'0'+size - m[1]; } - m[2] = 'a'+'0'+size - m[2]; + m[2] = 'a'+'0'+hsize - m[2]; m[3] = 'a'+'0'+size - m[3]; if(m[4] == '=') m[4] = 0; // no '=' in USI format! else if(m[4]) m[4] = '+'; // cater to WB 4.4 bug :-( @@ -541,12 +541,17 @@ GUI2Engine() } } - +void +IsReady () +{ + EPRINT((f, "# isready\n")) fflush(toE); + HandleEngineOutput(); // wait for readyok +} void DoCommand () { - char line[1024], command[256], *p, *q, *r, type[99]; + char line[1024], command[256], *p, *q, *r, type[99], c; int i; p=line; while(qStart < qEnd && (*p++ = *qStart++) != '\n') {} *p = 0; @@ -560,10 +565,9 @@ DoCommand () oldMem = memory; // we can set other options here if(varOpt && strstr(varList, ",normal")) EPRINT((f, "# setoption name UCI_Variant value chess\n")) - EPRINT((f, "# isready\n")) fflush(toE); - HandleEngineOutput(); // wait for readyok + IsReady(); if(sc == 'x') { if(newGame) EPRINT((f, "# setoption newgame\n")) } else // optional in UCCI - EPRINT((f, "# u%cinewgame\n", sc)) fflush(toE); + { EPRINT((f, "# u%cinewgame\n", sc)) fflush(toE); if(sc != 's') IsReady(); } // avoid isready in USI } else if(!strcmp(command, "e")) { strcpy(move[moveNr++], type); stm ^= WHITE|BLACK; return; } else if(!strcmp(command, "option")) { @@ -605,8 +609,8 @@ DoCommand () EPRINT((f, "# setoption name UCI_Variant value %sucinewgame\nisready\n", line+8)) fflush(toE); HandleEngineOutput(); // wait for readyok } - 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"); + c = 0; if(sscanf(line+8, "%dx%d+%d_shogi%c", &hsize, &size, &i, &c) && c == '\n') strcpy(iniPos, "position startpos"); + if(!strcmp(line+8, "shogi\n")) hsize = size = 9, strcpy(iniPos, "position startpos"); if(!strcmp(line+8, "xiangqi\n")) sprintf(iniPos, "%s %c", XQPOS+9*(sc2 == 'c'), sc2 == 'c' ? 'r' : 'w'); // with -c use Cyclone dialect if(!strcmp(line+8, "fischerandom\n")) { frc |= 1; if(frc > 0) EPRINT((f, "# setoption name UCI_Chess960 value true\n")) } } @@ -623,7 +627,7 @@ DoCommand () else if(!strcmp(command, "force")) computer = NONE; else if(!strcmp(command, "go")) computer = stm; else if(!strcmp(command, "ping")) { /* static int done; if(!done) pause = 1, fprintf(toE, "isready\n"), fflush(toE), printf("# send isready\n"), fflush(stdout), Sync(PAUSE); done = 1;*/ printf("po%s", line+2); } - else if(!strcmp(command, "memory")) sscanf(line, "memory %d", &memory); + else if(!strcmp(command, "memory")) { sscanf(line, "memory %d", &memory); if(memory > hasHash) memory = hasHash; } else if(!strcmp(command, "cores")&& !!*threadOpt) { sscanf(line, "cores %d", &cores); EPRINT((f, "# setoption %s%s %s%d\n", nameWord, threadOpt, valueWord, cores)) } else if(!strcmp(command, "egtpath")){ sscanf(line+8, "%s %[^\n]", type, command);