Make sure King-capture move is printed
[hachu.git] / hachu.c
diff --git a/hachu.c b/hachu.c
index 68c0a6c..38ae201 100644 (file)
--- a/hachu.c
+++ b/hachu.c
@@ -1460,7 +1460,7 @@ GenCapts(int sqr, int victimValue)
     for(i=0; i<8; i++) {    // scan all knight jumps to locate source\r
       int x = sqr - nStep[i], attacker = board[x];\r
       if(attacker == EMPTY || (attacker & TYPE) != stm) continue;\r
-      if(p[attacker].range[i] <= N && p[attacker].range[i] >= S) { // has Knight jump in our direction\r
+      if(p[attacker].range[i] <= N && p[attacker].range[i] >= S && p[attacker].range[i] != J) { // has Knight jump in our direction\r
        NewCapture(x, sqr + victimValue, p[attacker].promoFlag);   // plain jump (as in N)\r
        if(p[attacker].range[i] < N) { // Lion power; generate double captures over two possible intermediates\r
          int v = kStep[i]; // leftish path\r
@@ -2007,6 +2007,7 @@ SearchBestMove (int stm, int timeLeft, int mps, int timeControl, int inc, int ti
   tlim2 = 1.9*targetTime;\r
   nodes = 0;\r
 MapFromScratch(attacks);\r
+  retMove = INVALID;\r
   score = Search(-INF-1, INF+1, rootEval, 20, sup1, sup2);\r
   *move = retMove;\r
   *ponderMove = INVALID;\r
@@ -2056,6 +2057,19 @@ printf("# setup done");fflush(stdout);
           score = SearchBestMove(stm, timeLeft, mps, timeControl, inc, timePerMove, &move, &ponderMove);\r
 \r
           if(move == INVALID) {         // game apparently ended\r
+            int kcapt = 0, xstm = stm ^ WHITE, king, k = p[king=royal[xstm]].pos;\r
+            if( k != ABSENT) { // test if King capture possible\r
+              if(attacks[2*k + stm]) {\r
+                if( p[king + 2].pos == ABSENT ) kcapt = 1; // we have an attack on his only King\r
+              }\r
+            } else { // he has no king! Test for attacks on Crown Prince\r
+              k = p[king + 2].pos;\r
+              if(attacks[2*k + stm]) kcapt = 1; // we have attack on Crown Prince\r
+            }\r
+            if(kcapt) { // print King capture before claiming\r
+              GenCapts(k, 0);\r
+              printf("move %s\n", MoveToText(moveStack[msp-1], 1));\r
+            }\r
             engineSide = NONE;          // so stop playing\r
             PrintResult(stm, score);\r
           } else {\r