X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=UCI2WB.c;h=78ab021dba1b243c2bb56779b87a22099ba8601b;hb=f3ac0c6de501ca2f972ae2047739619ba7010c2a;hp=26010a201e2b1b68af1af5d6455cae5060a1c6c1;hpb=1b936bccc1ce09ac1ea15a4186b3bbc51eacaaf8;p=uci2wb.git diff --git a/UCI2WB.c b/UCI2WB.c index 26010a2..78ab021 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -1,6 +1,6 @@ /************************* UCI2WB by H.G.Muller ****************************/ -#define VERSION "1.7" +#define VERSION "1.9" #include #include @@ -32,7 +32,7 @@ char move[2000][10], checkOptions[8192], iniPos[256], hashOpt[20], pause, pondering, 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; char currMove[20]; // for analyze mode +int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500]; char currMove[20], moveMap[500][10]; // for analyze mode FILE *toE, *fromE; int pid; @@ -122,6 +122,25 @@ char *Convert(char *pv) return buf; } +void +Move4GUI(char *m) +{ + if(sc == 's') { + // convert USI move to WB format + m[2] = 'a'+'0'+size - m[2]; + m[3] = 'a'+'0'+size - m[3]; + if(m[1] == '*') { // drop + m[1] = '@'; + } else { + m[0] = 'a'+'0'+size - 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] != '+') + m[4] = '=', m[5] = 0; + } + } +} + void * Engine2GUI() { @@ -157,22 +176,7 @@ Engine2GUI() } p[-1] = '\n'; *p = 0; // strip off ponder move } - if(sc == 's') { - // convert USI move to WB format - line[11] = 'a'+'0'+size - line[11]; - line[12] = 'a'+'0'+size - line[12]; - if(line[10] == '*') { // drop - line[10] = '@'; - } else { - line[9] = 'a'+'0'+size - line[9]; - line[10] = 'a'+'0'+size - line[10]; - if((stm == WHITE ? (line[10]>'0'+size-size/3 || line[12]>'0'+size-size/3) - : (line[10] <= '0'+size/3 || line[12] <= '0'+size/3)) && line[13] != '+') - line[13] = '=', line[14] = 0; - } - } - if(line[9] == 'e' && (line[14] == 'a' || line[14] == 'h')) // seirawan castling + gating at Rook - line[9] = line[14], line[11] = 'e'; // convert to RxK notation + Move4GUI(line+9); printf("move %s\n", line+9); // send move to GUI if(lastScore == 100001 && iniPos[0] != 'f') { printf("%s {mate}\n", stm == WHITE ? "1-0" : "0-1"); computer = NONE; } stm = WHITE+BLACK - stm; @@ -181,6 +185,17 @@ Engine2GUI() int d=0, s=0, t=0, n=0; char *pv; if(sscanf(line+5, "string times @ %c", &dummy) == 1) { printf("# %s", line+12); continue; } + if(collect && (pv = strstr(line+5, "currmove "))) { + if(p = strstr(line+5, "currmovenumber ")) { + n = atoi(p+15); + if(collect == 1 && n != 1) continue; // wait for move 1 + if(collect + (n == 1) > 2) { // done collecting + if(inex && collect == 2) printf("%d 0 0 0 OK to exclude\n", lastDepth); + collect = 3; continue; + } + collect = 2; on[nr=n] = 1; sscanf(pv+9, "%s", moveMap[n]); continue; // store move + } + } if(!post) continue; if(sscanf(line+5, "string %c", &dummy) == 1) printf("%d 0 0 0 %s", lastDepth, line+12); else { if(p = strstr(line+4, " depth ")) sscanf(p+7, "%d", &d), statDepth = d; @@ -233,14 +248,32 @@ Engine2GUI() if(sscanf(line, "id name %[^\n]", name) == 1) printf("feature myname=\"%s (U%cI2WB)\"\n", name, sc-32); } else if(!strcmp(command, "readyok")) { pause = 0; Sync(WAKEUP); } // resume processing of GUI commands - else if(sscanf(command, "u%ciok", &c)==1 && c==sc) printf("feature smp=1 memory=%d done=1\n", hasHash); // done with options + else if(sscanf(command, "u%ciok", &c)==1 && c==sc) printf("feature smp=1 memory=%d done=1\n", hasHash), Sync(WAKEUP); // done with options + } +} + +void +Move4Engine(char *m) +{ + if(sc == 's') { + // convert input move to USI format + if(m[1] == '@') { // drop + m[1] = '*'; + } else { + m[0] = 'a'+'0'+size - m[0]; + m[1] = 'a'+'0'+size - m[1]; + } + m[2] = 'a'+'0'+size - 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 :-( } } void GUI2Engine() { - char line[256], command[256], *p, *q; + char line[256], command[256], *p, *q, *r; while(1) { int i, x; @@ -250,8 +283,15 @@ GUI2Engine() LoadPos(moveNr); // load position // and set engine thinking (note USI swaps colors!) startTime = GetTickCount(); - if(computer == ANALYZE) fprintf(toE, "\ngo infinite\n"), printf("\ngo infinite\n"); - else StartSearch(""); + if(computer == ANALYZE) { + fprintf(toE, "\ngo infinite"); DPRINT("\n# go infinite"); + if(sm & 1) { // some moves are disabled + fprintf(toE, " searchmoves"); DPRINT(" searchmoves"); + for(i=1; i>1, command[0] = 'e'; // gating at Rook - } - stm = WHITE+BLACK - stm; + Move4Engine(command); + stm = WHITE+BLACK - stm; collect = (computer == ANALYZE); sm = 0; // when pondering we either continue the ponder search as normal search, or abort it if(pondering || computer == ANALYZE) { if(pondering && !strcmp(command, move[moveNr])) { // ponder hit @@ -299,8 +322,7 @@ GUI2Engine() } StopPonder(1); } -// sscanf(line, "usermove %s", move[moveNr++]); // possibly overwrites ponder move - strcpy(move[moveNr++], command); + strcpy(move[moveNr++], command); // possibly overwrites ponder move } else if(!strcmp(command, "level")) { int sec = 0; @@ -319,17 +341,21 @@ GUI2Engine() } else if(!strcmp(command, "protover")) { if(!variants) variants = sc=='s' ? "shogi,5x5+5_shogi" : VARIANTS; - printf("feature variants=\"%s\" setboard=1 usermove=1 debug=1 ping=1 reuse=0 done=0\n", variants); + printf("feature variants=\"%s\" setboard=1 usermove=1 debug=1 ping=1 reuse=0 exclude=1 done=0\n", variants); printf("feature option=\"UCI2WB debug output -check %d\"\n", debug); - fprintf(toE, "u%ci\n", sc); // this prompts UCI engine for options + fprintf(toE, "u%ci\n", sc); fflush(toE); // this prompts UCI engine for options + Sync(PAUSE); // wait for uciok } else if(!strcmp(command, "setboard")) { if(strstr(line+9, " b ")) stm = BLACK; - if(sc == 's' && (p = strchr(line+9, '['))) { char c; - *p++ = ' '; q = strchr(p, ']'); c = 'w' + 'b' - q[2]; strcpy(q+2, " 1\n"); while(*--q != ' ') q[2] = *q; *p = c; p[1] = ' '; - } - sprintf(iniPos, "%s%sfen %s", iniPos[0]=='p' ? "position " : "", sc=='s' ? "s" : "", line+9); - iniPos[strlen(iniPos)-1] = 0; + if(p = strchr(line+9, '[')) { char c; + *p++ = 0; q = strchr(p, ']'); *q = 0; r = q + 4; + if(sc == 's') q[2] = 'w' + 'b' - q[2], strcpy(r=q+3, " 1\n"); // Shogi: reverse color + 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); + sprintf(iniPos, "%s%sfen %s", iniPos[0]=='p' ? "position " : "", sc=='s' ? "s" : "", command); + iniPos[strlen(iniPos)-1] = sm = 0; collect = (computer == ANALYZE); } else if(!strcmp(command, "variant")) { if(!strcmp(line+8, "shogi\n")) size = 9, strcpy(iniPos, "position startpos"); @@ -338,14 +364,21 @@ GUI2Engine() } else if(!strcmp(command, "undo") && (i=1) || !strcmp(command, "remove") && (i=2)) { if(pondering || computer == ANALYZE) StopPonder(1); - moveNr = moveNr > i ? moveNr - i : 0; + moveNr = moveNr > i ? moveNr - i : 0; collect = (computer == ANALYZE); sm = 0; } else if(!strcmp(command, ".")) { printf("stat01: %d %d %d %d 100 %s\n", statTime, statNodes, statDepth, 100-currNr, currMove); goto nomove; } + else if(!strcmp(command+2, "clude") && collect > 2) { // include or exclude + int all = !strcmp(line+8, "all"), in = command[1] == 'n'; + inex = 1; line[strlen(line)-1] = sm = 0; // strip LF and clear sm flag + for(i=1; i