X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=UCI2WB.c;h=bb6527d4e040e5ef8e46263764350ffc52151733;hb=fb39d7ec4a7ab6f693cb2e1b18c4b421356a2129;hp=764f9217d85d3db4e59d8885c0c84c51b0a8be53;hpb=35ffc8b7ee8e505a23a9ce60a5734a72560d93a5;p=uci2wb.git diff --git a/UCI2WB.c b/UCI2WB.c index 764f921..bb6527d 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -20,27 +20,38 @@ #include #include -#ifdef _MSC_VER -#define SLEEP() Sleep(1) -#else -#define SLEEP() usleep(10) -#endif - // Set VARIANTS for in WinBoard variant feature. (With -s option this will always be reset to use "shogi".) # define VARIANTS "normal,xiangqi" +#define DPRINT if(debug) printf + #define WHITE 0 #define BLACK 1 #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; -int mps, tc, inc, sTime, depth, myTime, hisTime, stm, computer = NONE, memory, oldMem=0, cores, moveNr, lastDepth, lastScore, startTime; +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 FILE *toE, *fromE; int pid; +#ifdef WIN32 +WinPipe(HANDLE *hRd, HANDLE *hWr) +{ + SECURITY_ATTRIBUTES saAttr; + + /* Set the bInheritHandle flag so pipe handles are inherited. */ + saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); + saAttr.bInheritHandle = TRUE; + saAttr.lpSecurityDescriptor = NULL; + + /* Create a pipe */ + return CreatePipe(hRd, hWr, &saAttr, 0); +} +#endif + #define INIT 0 #define WAKEUP 1 #define PAUSE 2 @@ -49,7 +60,12 @@ void Sync (int action) { #ifdef WIN32 - if(action == PAUSE) while(pause) SLEEP(); // in Windows we still rely on polling. :-( + static HANDLE hWr, hRd; DWORD d; char c; + switch(action) { + case INIT: WinPipe(&hRd, &hWr); break; + case WAKEUP: WriteFile(hWr, "\n", 1, &d, NULL); break; + case PAUSE: ReadFile(hRd, &c, 1, &d, NULL); + } #else static int syncPipe[2]; char c; switch(action) { @@ -65,7 +81,7 @@ StartSearch(char *ponder) { // send the 'go' command to engine. Suffix by ponder. int nr = moveNr + (ponder[0] != 0); // we ponder for one move ahead! fprintf(toE, "\ngo btime %d wtime %d", stm == BLACK ^ sc=='s' ? myTime : hisTime, stm == WHITE ^ sc=='s' ? myTime : hisTime); - printf( "\n# go btime %d wtime %d", stm == BLACK ^ sc=='s' ? myTime : hisTime, stm == WHITE ^ sc=='s' ? myTime : hisTime); + DPRINT( "\n# go btime %d wtime %d", stm == BLACK ^ sc=='s' ? myTime : hisTime, stm == WHITE ^ sc=='s' ? myTime : hisTime); if(sTime > 0) fprintf(toE, " movetime %d", sTime),printf(" movetime %d", sTime); else if(mps) fprintf(toE, " movestogo %d", mps*(nr/(2*mps)+1)-nr/2),printf(" movestogo %d", mps*(nr/(2*mps)+1)-nr/2); if(inc && !suffix) fprintf(toE, " winc %d binc %d", inc, inc),printf(" winc %d binc %d", inc, inc); @@ -80,7 +96,7 @@ StopPonder(int pondering) { if(!pondering) return; pause = 1; - fprintf(toE, "stop\n"); fflush(toE); printf("# stop\n"); // note: 'pondering' remains set until engine acknowledges 'stop' with 'bestmove' + fprintf(toE, "stop\n"); fflush(toE); DPRINT("# stop\n"); // note: 'pondering' remains set until engine acknowledges 'stop' with 'bestmove' Sync(PAUSE); // wait for engine to acknowledge 'stop' with 'bestmove'. } @@ -89,7 +105,7 @@ LoadPos(int moveNr) { int j; fprintf(toE, "%s moves", iniPos); - printf( "# %s moves", iniPos); + DPRINT( "# %s moves", iniPos); for(j=0; j 1 && !strcmp(argv[1], "debug")) { debug = 1; argc--; argv++; } if(argc > 1 && argv[1][0] == '-') { sc = argv[1][1]; argc--; argv++; } - if(argc < 2) { printf("usage is: U%cI2WB [-s] []\n", sc-32); exit(-1); } + if(argc < 2) { printf("usage is: U%cI2WB [debug] [-s] []\n", sc-32); exit(-1); } if(argc > 2) dir = argv[2]; if(argc > 3) suffix = argv[3];