\r
#ifdef WIN32 \r
# include <windows.h>\r
+# define CPUtime 1000.*clock\r
#else\r
# include <sys/time.h>\r
+# include <sys/times.h>\r
+# include <unistd.h>\r
int GetTickCount() // with thanks to Tord\r
{ struct timeval t;\r
gettimeofday(&t, NULL);\r
return t.tv_sec*1000 + t.tv_usec/1000;\r
}\r
+ double CPUtime()\r
+ { // get CPU time used by process, converted to 'MILLICLOCKS'\r
+ struct tms cpuTimes;\r
+ static int cps = 0;\r
+ if(!cps) cps = sysconf(_SC_CLK_TCK);\r
+ times(&cpuTimes);\r
+ return ((double)(cpuTimes.tms_utime + cpuTimes.tms_stime) * CLOCKS_PER_SEC * 1000)/cps;\r
+ }\r
#endif\r
\r
int StartKey;\r
#endif\r
\r
/* make unique integer from engine move representation */\r
-#define PACK_MOVE 256*K + L + (PromPiece << 16);\r
+#define PACK_MOVE 256*K + L + (PromPiece << 16) + (GT<<24);\r
\r
/* convert intger argument back to engine move representation */\r
-#define UNPACK_MOVE(A) K = (A)>>8 & 255; L = (A) & 255; PromPiece = (A)>>16 & 255;\r
+#define UNPACK_MOVE(A) K = (A)>>8 & 255; L = (A) & 255; PromPiece = (A)>>16 & 255; GT = (A)>>24 & 255;\r
\r
/* Global variables visible to engine. Normally they */\r
/* would be replaced by the names under which these */\r
{\r
int Computer, MaxTime, MaxMoves, TimeInc, sec, i, j;\r
char line[256], command[256], c, cc;\r
- int m, nr;\r
+ int m, nr, hh;\r
+ double cpuT;\r
FILE *f;\r
\r
if(argc>1 && sscanf(argv[1], "%d", &m)==1)\r
/* the game have to be done in this time. */\r
/* If MaxMoves=1 any leftover time is lost*/\r
Ticks = GetTickCount();\r
+ cpuT = CPUtime(); printf("# times @ %u\n", Ticks);\r
m = MovesLeft<=0 ? 40 : MovesLeft;\r
tlim = (0.6-0.06*(BW-8))*(TimeLeft+(m-1)*TimeInc)/(m+7);\r
if(tlim>TimeLeft/15) tlim = TimeLeft/15;\r
Computer = EMPTY;\r
continue;\r
} else UnderProm = -1;\r
+ m = GetTickCount() - Ticks;\r
+ printf("# times @ %u: real=%d cpu=%1.0f\n", m + Ticks, m,\r
+ (CPUtime() - cpuT)/CLOCKS_PER_SEC);\r
printf("move ");\r
printf("%c%c%c%c",'a'+(K&15),'0'+BH-(K>>4),\r
'a'+(L&15),'0'+BH-(L>>4));\r
if(prom)printf("%c",piecename[prom&15]+'a'-1);\r
printf("\n");\r
- m = GetTickCount() - Ticks;\r
\r
/* time-control accounting */\r
TimeLeft -= m;\r
if (!strcmp(command, "protover")) {\r
printf("feature myname=\"" NAME " " VERSION "\"\n");\r
printf("feature memory=1\n");\r
- printf("feature setboard=0 ping=1 done=0\n");\r
+ printf("feature setboard=0 xedit=1 ping=1 done=0\n");\r
printf("feature variants=\"");\r
PrintVariants(0);\r
printf("\"\n");\r
Q = -Q;\r
continue;\r
}\r
- if( m >= 'A' && m <= 'Z' && piecetype[m&31]\r
- && line[1] >= 'a' && line[1] <= 'a'+BW-1\r
+ if( m >= 'A' && m <= 'Z' && piecetype[m&31]) {\r
+ p = (color == WHITE ? piecetype : blacktype)[line[0]&31];\r
+ if(line[1] == '@') { // stuff holdings\r
+ pl[color+p+5] = m = line[2] - '0';\r
+ pl[BLACK+WHITE-color]+=m;pl[p+color]+=m;\r
+ Q+=m*w[p]; R+=m*(w[p]/FAC);\r
+ continue;\r
+ } else\r
+ if(line[1] >= 'a' && line[1] <= 'a'+BW-1\r
&& line[2] >= '1' && line[2] <= '0'+BH) {\r
m = line[1]-16*line[2]+799;\r
- switch(p = (color == WHITE ? piecetype : blacktype)[line[0]&31])\r
+ switch(p)\r
{\r
case 1:\r
case 2:\r
pl[BLACK+WHITE-color]++;pl[p+color]++;\r
if(w[p+color] == -1)pl[p+color]=1; // fake we have one if value = -1, to thwart extinction condition\r
continue;\r
+ }\r
}\r
}\r
if(Side != color) Q = -Q;\r
if(b[L] && (b[L]&16) == Side && w[b[L]&15] < 0) // capture own King: castling\r
{ i=K; K = L; L = i>L ? i-1 : i+2; }\r
if(w[GT&15] < -1) pl[GT&31]++, J+=89729; // promotion to royal piece\r
- if(b[K]&32) GT = 0; // non-virgin mover => true promotion rather than gating\r
+ if((b[K]&15) < 3) GT = 0; // Pawn => true promotion rather than gating\r
if(D(Side,-I,I,Q,O,LL|S,3)!=I) {\r
/* did have move syntax, but illegal move */\r
printf("Illegal move:%s\n", line);\r