Make debug output less verbose
[hachu.git] / hachu.c
diff --git a/hachu.c b/hachu.c
index 28f58f1..b00538a 100644 (file)
--- a/hachu.c
+++ b/hachu.c
@@ -97,6 +97,8 @@ int stm, xstm, hashKeyH, hashKeyL, framePtr, msp, nonCapts, rootEval, retMSP, re
 int nodes, startTime, tlim1, tlim2, repCnt, comp;\r
 Move retMove, moveStack[10000], path[100], repStack[300], pv[1000], repeatMove[300];\r
 \r
+      int maxDepth;                            // used by search\r
+\r
 #define X 36 /* slider              */\r
 #define R 37 /* jump capture        */\r
 #define N -1 /* Knight              */\r
@@ -689,6 +691,7 @@ SetUp(char *array, int var)
        if(name[1]) name[1] += 'A' - 'a';\r
       } else color = WHITE;\r
       p1 = LookUp(name, var);\r
+      if(!p1) printf("tellusererror Unknown piece '%s' in setup\n", name), exit(-1);\r
       if(pflag && p1->promoted) p1 = LookUp(p1->promoted, var); // use promoted piece instead\r
       n = AddPiece(color, p1);\r
       p[n].pos = j;\r
@@ -1814,14 +1817,12 @@ pmoves(int start, int end)
     #define INVALID 0\r
 \r
     // some parameter of your engine\r
-    #define MAXMOVES 500  /* maximum game length  */\r
-    #define MAXPLY   60   /* maximum search depth */\r
+    #define MAXMOVES 2000 /* maximum game length  */\r
+    #define MAXPLY   20   /* maximum search depth */\r
 \r
     #define OFF 0\r
     #define ON  1\r
 \r
-#define DEFAULT_FEN ""\r
-\r
 typedef Move MOVE;\r
 \r
     int moveNr;              // part of game state; incremented by MakeMove\r
@@ -1889,7 +1890,8 @@ Convert (char *fen)
     if(isalpha(*fen)) {\r
       char *table = fenNames;\r
       n = *fen > 'Z' ? 'a' - 'A' : 0;\r
-      if(table[2* (*fen - 'A' - n)] == '.') *p++ = *fen; else {\r
+      if(currentVariant == V_CHESS && *fen - 'A' - n == 'N' // In Chess N is Knight, not Lion\r
+           || table[2* (*fen - 'A' - n)] == '.') *p++ = *fen; else {\r
         *p++ = ':';\r
         *p++ = table[2* (*fen - 'A' - n)] + n;\r
         *p++ = table[2* (*fen - 'A' - n)+1] + n;\r
@@ -2085,7 +2087,7 @@ SearchBestMove (int stm, int timeLeft, int mps, int timeControl, int inc, int ti
   nodes = 0;\r
 MapFromScratch(attacks);\r
   retMove = INVALID; repCnt = 0;\r
-  score = Search(-INF-1, INF+1, rootEval, 20, sup1, sup2);\r
+  score = Search(-INF-1, INF+1, rootEval, maxDepth, sup1, sup2);\r
   *move = retMove;\r
   *ponderMove = INVALID;\r
   return score;\r
@@ -2099,7 +2101,7 @@ PonderUntilInput (int stm)
     int TakeBack(int n)\r
     { // reset the game and then replay it to the desired point\r
       int last, stm;\r
-      stm = Setup2(NULL);\r
+      Init(currentVariant); stm = Setup2(NULL);\r
 printf("# setup done");fflush(stdout);\r
       last = moveNr - n; if(last < 0) last = 0;\r
       for(moveNr=0; moveNr<last; moveNr++) stm = MakeMove2(stm, gameMove[moveNr]),printf("make %2d: %x\n", moveNr, gameMove[moveNr]);\r
@@ -2120,7 +2122,6 @@ printf("# setup done");fflush(stdout);
       int engineSide=NONE;                     // side played by engine\r
       int timeLeft;                            // timeleft on engine's clock\r
       int mps, timeControl, inc, timePerMove;  // time-control parameters, to be used by Search\r
-      int maxDepth;                            // used by search\r
       MOVE move, ponderMove;\r
       int i, score;\r
       char inBuf[8000], command[80];\r
@@ -2133,6 +2134,7 @@ printf("# setup done");fflush(stdout);
 \r
         if(stm == engineSide) {         // if it is the engine's turn to move, set it thinking, and let it move\r
      \r
+pboard(board);\r
           score = SearchBestMove(stm, timeLeft, mps, timeControl, inc, timePerMove, &move, &ponderMove);\r
 \r
           if(move == INVALID) {         // game apparently ended\r
@@ -2179,8 +2181,6 @@ printf("# setup done");fflush(stdout);
         // wait for input, and read it until we have collected a complete line\r
         for(i = 0; (inBuf[i] = getchar()) != '\n'; i++);\r
         inBuf[i+1] = 0;\r
-pboard(board);\r
-pmoves(retFirst, retMSP);\r
 \r
         // extract the first word\r
         sscanf(inBuf, "%s", command);\r
@@ -2218,7 +2218,6 @@ printf("in: %s\n", command);
           for(i=0; i<5; i++) {\r
             sscanf(inBuf+8, "%s", command);\r
             if(!strcmp(variants[i].name, command)) {\r
-printf("var %d\n",i);\r
               Init(i); stm = Setup2(NULL); break;\r
             }\r
          }\r
@@ -2230,10 +2229,10 @@ printf("var %d\n",i);
         if(!strcmp(command, "ping"))    { printf("pong%s", inBuf+4); continue; }\r
     //  if(!strcmp(command, ""))        { sscanf(inBuf, " %d", &); continue; }\r
         if(!strcmp(command, "new"))     {\r
-          engineSide = BLACK; Init(V_CHESS); stm = Setup2(DEFAULT_FEN); maxDepth = MAXPLY; randomize = OFF; comp = 0;\r
+          engineSide = BLACK; Init(V_CHESS); stm = Setup2(NULL); maxDepth = MAXPLY; randomize = OFF; comp = 0;\r
           continue;\r
         }\r
-        if(!strcmp(command, "setboard")){ engineSide = NONE;  stm = Setup2(inBuf+9); continue; }\r
+        if(!strcmp(command, "setboard")){ engineSide = NONE;  Init(currentVariant); stm = Setup2(inBuf+9); continue; }\r
         if(!strcmp(command, "easy"))    { ponder = OFF; continue; }\r
         if(!strcmp(command, "hard"))    { ponder = ON;  continue; }\r
         if(!strcmp(command, "undo"))    { stm = TakeBack(1); continue; }\r
@@ -2264,6 +2263,7 @@ printf("var %d\n",i);
         if(!strcmp(command, ""))  {  continue; }\r
         if(!strcmp(command, "usermove")){\r
           int move = ParseMove(inBuf+9);\r
+pboard(board);\r
           if(move == INVALID) {\r
             if(reason) printf("Illegal move {%s}\n", reason); else printf("%s\n", reason="Illegal move");\r
             if(comp) PrintResult(stm, -INF); // against computer: claim\r