Recognize drop moves as illegal move
[fairymax.git] / fairymax.c
index 83002e5..91fe48d 100644 (file)
 \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
@@ -68,10 +79,10 @@ int StartKey;
 #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
@@ -522,7 +533,8 @@ int main(int argc, char **argv)
 {\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
@@ -555,6 +567,7 @@ int main(int argc, char **argv)
                         /* 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
@@ -568,12 +581,14 @@ int main(int argc, char **argv)
                                  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
@@ -869,14 +884,14 @@ int main(int argc, char **argv)
                 GT = (Side == WHITE ? piecetype : blacktype)[line[4]&31];\r
                 if(GT) PromPiece = (Side == WHITE ? 7 : 7+pm) - GT, GT |= 32 + Side;\r
                 {char *c=line; K=c[0]-16*c[1]+799;L=c[2]-16*c[3]+799; }\r
-                if (m)\r
+                if (m & line[1] != '@')\r
                         /* doesn't have move syntax */\r
                        printf("Error (unknown command): %s\n", command);\r
                 else { int i=-1;\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