#ifdef WIN32
# include <windows.h>
# define CPUtime 1000.*clock
+ int Input()
+ { // checks for waiting input in pipe
+ static int init; static HANDLE inp; DWORD cnt;
+ if(!init) inp = GetStdHandle(STD_INPUT_HANDLE);
+ if(!PeekNamedPipe(inp, NULL, 0, NULL, &cnt, NULL) &&
+ !GetNumberOfConsoleInputEvents(inp, &cnt)) return 1;
+ return cnt;
+ }
#else
# include <sys/time.h>
# include <sys/times.h>
+# include <sys/ioctl.h>
# include <unistd.h>
int GetTickCount() // with thanks to Tord
{ struct timeval t;
gettimeofday(&t, NULL);
return t.tv_sec*1000 + t.tv_usec/1000;
}
+ int Input()
+ {
+ int cnt;
+ if(ioctl(0, FIONREAD, &cnt)) return 1;
+ return cnt;
+ }
#endif
#define DEBUG 0
int gameMove[MAXMOVES]; // holds the game history
int stm = WHITE;
+int engineSide=NONE; // side played by engine
// Some routines your engine should have to do the various essential things
void PonderUntilInput(int stm); // Search current position for stm, deepening forever until there is input.
int
TimeIsUp (int mode)
{ // determine if we should stop, depending on time already used, TC mode, time left on clock and from where it is called ('mode')
- int t = ReadClock(0), targetTime, panicTime;
+ int t, targetTime, panicTime;
+ if(Input() && DoCommand(1)) return 1; // abort if command waiting that cannot be handled during search
+ if(engineSide == ANALYZE) return 0; // no timing on analyze or ponder
+ t = ReadClock(0);
if(timePerMove >= 0) { // fixed time per move
targetTime = panicTime = 10*timeLeft - 30;
} else if(mps) { // classical TC
else printf("0-1\n");
}
-int engineSide=NONE; // side played by engine
int ponderMove;
char inBuf[800];
}
if(searching) {
- if(!strcmp(command, "usermove")) { return 1; } // TODO during search we just test for ponder hit
+// if(!strcmp(command, "usermove")) { return 1; } // TODO during search we just test for ponder hit
*inBuf = *command; // backlog command (by repairing inBuf)
return 1; // and request search abort
}
}
fflush(stdout); // make sure everything is printed before we do something that might take time
-#if 0
+
// now it is not our turn (anymore)
if(engineSide == ANALYZE) { // in analysis, we always ponder the position
- PonderUntilInput(stm);
- } else
+ nodeCount = forceMove = undoInfo.move = abortFlag = 0; ReadClock(1);
+ Search(stm^COLOR, -INF, INF, &undoInfo, maxDepth, 0, maxDepth);
+ }
+#if 0
+ else
if(engineSide != NONE && ponder == ON && moveNr != 0) { // ponder while waiting for input
if(ponderMove == INVALID) { // if we have no move to ponder on, ponder the position
PonderUntilInput(stm);