X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=fairymax.c;h=931099a579ca46d54f77227b4e7828a93961712d;hb=5b64a22e62beb2c9d21d5567993eb0f74b1fa074;hp=dfa3ea61bbb0e5861a7efcef4f5cf76d4a8fd4fa;hpb=c62ef367da4863f395624f3eb02cc9f215b42ada;p=fairymax.git diff --git a/fairymax.c b/fairymax.c index dfa3ea6..931099a 100644 --- a/fairymax.c +++ b/fairymax.c @@ -32,13 +32,24 @@ #ifdef WIN32 # include +# define CPUtime 1000.*clock #else # include +# include +# include int GetTickCount() // with thanks to Tord { struct timeval t; gettimeofday(&t, NULL); return t.tv_sec*1000 + t.tv_usec/1000; } + double CPUtime() + { // get CPU time used by process, converted to 'MILLICLOCKS' + struct tms cpuTimes; + static int cps = 0; + if(!cps) cps = sysconf(_SC_CLK_TCK); + times(&cpuTimes); + return ((double)(cpuTimes.tms_utime + cpuTimes.tms_stime) * CLOCKS_PER_SEC * 1000)/cps; + } #endif int StartKey; @@ -522,7 +533,8 @@ int main(int argc, char **argv) { int Computer, MaxTime, MaxMoves, TimeInc, sec, i, j; char line[256], command[256], c, cc; - int m, nr; + int m, nr, hh; + double cpuT; FILE *f; if(argc>1 && sscanf(argv[1], "%d", &m)==1) @@ -555,6 +567,7 @@ int main(int argc, char **argv) /* the game have to be done in this time. */ /* If MaxMoves=1 any leftover time is lost*/ Ticks = GetTickCount(); + cpuT = CPUtime(); printf("# times @ %u\n", Ticks); m = MovesLeft<=0 ? 40 : MovesLeft; tlim = (0.6-0.06*(BW-8))*(TimeLeft+(m-1)*TimeInc)/(m+7); if(tlim>TimeLeft/15) tlim = TimeLeft/15; @@ -568,12 +581,14 @@ int main(int argc, char **argv) Computer = EMPTY; continue; } else UnderProm = -1; + m = GetTickCount() - Ticks; + printf("# times @ %u: real=%d cpu=%1.0f\n", m + Ticks, m, + (CPUtime() - cpuT)/CLOCKS_PER_SEC); printf("move "); printf("%c%c%c%c",'a'+(K&15),'0'+BH-(K>>4), 'a'+(L&15),'0'+BH-(L>>4)); if(prom)printf("%c",piecename[prom&15]+'a'-1); printf("\n"); - m = GetTickCount() - Ticks; /* time-control accounting */ TimeLeft -= m; @@ -876,7 +891,7 @@ int main(int argc, char **argv) if(b[L] && (b[L]&16) == Side && w[b[L]&15] < 0) // capture own King: castling { i=K; K = L; L = i>L ? i-1 : i+2; } if(w[GT&15] < -1) pl[GT&31]++, J+=89729; // promotion to royal piece - if(b[K]&32) GT = 0; // non-virgin mover => true promotion rather than gating + if((b[K]&15) < 3) GT = 0; // Pawn => true promotion rather than gating if(D(Side,-I,I,Q,O,LL|S,3)!=I) { /* did have move syntax, but illegal move */ printf("Illegal move:%s\n", line);