X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=UCI2WB.c;h=acb34d9bc12f64f605d2e7c07b5b782e99f2d820;hb=31a0e8b25fb5a579176c4d460dd417253fe8dd35;hp=53b2f19bd738af77078a72ab6ffc82d1b4dbf264;hpb=b7c746a0f37859a73d49a9cdb03cf3b32ce1391e;p=uci2wb.git diff --git a/UCI2WB.c b/UCI2WB.c index 53b2f19..acb34d9 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -1,6 +1,6 @@ /************************* UCI2WB by H.G.Muller ****************************/ -#define VERSION "1.6" +#define VERSION "1.8" #include #include @@ -30,7 +30,7 @@ #define NONE 2 #define ANALYZE 3 -char move[2000][10], checkOptions[8192], iniPos[256], hashOpt[20], pause, pondering, ponder, post, hasHash, c, sc='c', *suffix; +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 @@ -122,6 +122,27 @@ 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; + } + } + if(m[0] == 'e' && (m[5] == 'a' || m[5] == 'h')) // seirawan castling + gating at Rook + m[0] = m[5], m[2] = 'e'; // convert to RxK notation +} + void * Engine2GUI() { @@ -157,20 +178,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; - } - } + 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; @@ -178,6 +186,7 @@ Engine2GUI() else if(!strcmp(command, "info")) { 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(!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; @@ -230,14 +239,37 @@ 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] != '\n') m[4] = '+'; // cater to WB 4.4 bug :-( + } + if(m[4] && (m[1] == '1' || m[1] == '8')) { // seirawan gating + m[5] = m[0], m[6] = m[1], m[7] = '\0'; // copy from-square behind it, as gating square + if(m[2] == 'e' && (m[0] == 'a' || m[0] == 'h')) + m[2] = (m[0]+m[2]+1)>>1, m[0] = 'e'; // gating at Rook } } void GUI2Engine() { - char line[256], command[256], *p, *q; + char line[256], command[256], *p, *q, *r; while(1) { int i, x; @@ -267,20 +299,8 @@ GUI2Engine() Sync(PAUSE); // wait for readyok } else if(!strcmp(command, "usermove")) { - if(sc == 's') { - // convert input move to USI format - if(line[10] == '@') { // drop - line[10] = '*'; - } else { - line[9] = 'a'+'0'+size - line[9]; - line[10] = 'a'+'0'+size - line[10]; - } - line[11] = 'a'+'0'+size - line[11]; - line[12] = 'a'+'0'+size - line[12]; - if(line[13] == '=') line[13] = 0; // no '=' in USI format! - else if(line[13] != '\n') line[13] = '+'; // cater to WB 4.4 bug :-( - } sscanf(line, "usermove %s", command); // strips off linefeed + Move4Engine(command); stm = WHITE+BLACK - stm; // when pondering we either continue the ponder search as normal search, or abort it if(pondering || computer == ANALYZE) { @@ -291,7 +311,7 @@ GUI2Engine() } StopPonder(1); } - sscanf(line, "usermove %s", move[moveNr++]); // possibly overwrites ponder move + strcpy(move[moveNr++], command); // possibly overwrites ponder move } else if(!strcmp(command, "level")) { int sec = 0; @@ -309,16 +329,21 @@ GUI2Engine() } else { fprintf(toE, "setoption name %s\n", line+7); DPRINT("# setoption name %s\n", line+7); } } else if(!strcmp(command, "protover")) { - printf("feature variants=\"%s\" setboard=1 usermove=1 debug=1 ping=1 reuse=0 done=0\n", sc=='s' ? "shogi,5x5+5_shogi" : VARIANTS); + 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 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); + 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] = 0; } else if(!strcmp(command, "variant")) { @@ -349,7 +374,7 @@ GUI2Engine() else if(!strcmp(command, "memory")) sscanf(line, "memory %d", &memory); else if(!strcmp(command, "cores")) sscanf(line, "cores %d", &cores); else if(!strcmp(command, "sd")) sscanf(line, "sd %d", &depth); - else if(!strcmp(command, "st")) sscanf(line, "st %d", &sTime), sTime *= 1000, inc = 0; + else if(!strcmp(command, "st")) sscanf(line, "st %d", &sTime), sTime = 1000*sTime - 30, inc = 0; else if(!strcmp(command, "quit")) fprintf(toE, "quit\n"), fflush(toE), exit(0); } } @@ -445,6 +470,7 @@ main(int argc, char **argv) if(argc == 2 && !strcmp(argv[1], "-v")) { printf("UCI2WB " VERSION " by H.G.Muller\n"); exit(0); } if(argc > 1 && !strcmp(argv[1], "debug")) { debug = 1; argc--; argv++; } + if(argc > 1 && !strcmp(argv[1], "-var")) { variants = argv[2]; argc-=2; argv+=2; } if(argc > 1 && argv[1][0] == '-') { sc = argv[1][1]; argc--; argv++; } if(argc < 2) { printf("usage is: U%cI2WB [debug] [-s] []\n", sc-32); exit(-1); } if(argc > 2) dir = argv[2];