Add Chess pieces
[hachu.git] / hachu.c
diff --git a/hachu.c b/hachu.c
index 5b6f69c..bfb25f2 100644 (file)
--- a/hachu.c
+++ b/hachu.c
@@ -262,6 +262,16 @@ PieceDesc taikyokuPieces[] = {
   { NULL }  // sentinel\r
 };\r
 \r
+PieceDesc chessPieces[] = {\r
+  {"Q", "",  95, { X,X,X,X,X,X,X,X } },\r
+  {"R", "",  50, { X,0,X,0,X,0,X,0 } },\r
+  {"B", "",  33, { 0,X,0,X,0,X,0,X } },\r
+  {"N", "",  30, { N,N,N,N,N,N,N,N } },\r
+  {"K", "",  28, { 1,1,1,1,1,1,1,1 } },\r
+  {"P", "Q",  8, { 0,1,0,0,0,0,0,1 } },\r
+  { NULL }  // sentinel\r
+};\r
+\r
 char chuArray[] = "L:FLCSGK:DEGSC:FLL/:RV.B.:BT:KN:PH:BT.B.:RV/:SM:VMR:DH:DK:LN:FK:DK:DHR:VM:SM/PPPPPPPPPPPP/...:GB....:GB..."\r
                  "/............/............/"\r
                  "...:gb....:gb.../pppppppppppp/:sm:vmr:dh:dk:fk:ln:dk:dhr:vm:sm/:rv.b.:bt:ph:kn:bt.b.:rv/l:flcsg:dekgsc:fll";\r
@@ -825,7 +835,7 @@ MapFromScratch (int *map)
 void\r
 Connect (int sqr, int piece, int dir)\r
 { // scan to both sides along ray to elongate attacks from there, and remove our own attacks on there, if needed\r
-  int x, step = kStep[dir], r1 = p[piece].range[dir], r2 = p[piece].range[dir+4], piece1, piece2;\r
+  int x, step = kStep[dir], r1 = p[piece].range[dir], r2 = p[piece].range[dir+4], r3, r4, piece1, piece2;\r
   int d1, d2, r, y, c;\r
 \r
   if((attacks[2*sqr] + attacks[2*sqr+1]) & attackMask[dir]) {         // there are incoming attack(s) from 'behind'\r
@@ -840,16 +850,27 @@ Connect (int sqr, int piece, int dir)
       d2 = dist[y-sqr]; piece2 = board[y];\r
       attacks[2*y+stm] -= -(d2 <= r1) & one[dir];                     // remove our attack on it if in-range\r
       // we have two pieces now shooting at each other. See how far they get.\r
-      if(d1 + d2 <= (r1 = p[piece1].range[dir])) {                    // 1 hits 2\r
+      if(d1 + d2 <= (r3 = p[piece1].range[dir])) {                    // 1 hits 2\r
        attacks[2*y + (piece1 & WHITE)] += one[dir];                  // count attack\r
        UPDATE_MOBILITY(piece1, d2);\r
-      } else UPDATE_MOBILITY(piece1, r1 - d1);                        // does not connect, but could still gain mobility\r
-      if(d1 + d2 <= (r2 = p[piece2].range[dir+4])) {                  // 2 hits 1\r
+      } else UPDATE_MOBILITY(piece1, r3 - d1);                        // does not connect, but could still gain mobility\r
+      if(d1 + d2 <= (r4 = p[piece2].range[dir+4])) {                  // 2 hits 1\r
        attacks[2*x + (piece2 & WHITE)] += one[dir+4];                // count attack\r
        UPDATE_MOBILITY(piece2, d1);\r
-      } else UPDATE_MOBILITY(piece2, r2 - d2);                        // does not connect, but could still gain mobility\r
+      } else UPDATE_MOBILITY(piece2, r4 - d2);                        // does not connect, but could still gain mobility\r
       // if r1 or r2<0, moves typically jump, and thus cannot be unblocked. Exceptions are FF and BS distant moves.\r
       // test for d1+d2 > 2 && rN == F && d== 3 or rN == S\r
+      if(d1 <= 2) { // could be jump interactions\r
+       if(d1 == 2) {\r
+         if(r2 <= J) attacks[2*x + stm] -= one[dir+4];\r
+         if(r1 <= J) attacks[2*y + stm] -= one[dir];\r
+       } else { // d1 == 1\r
+         if(r2 < J) attacks[2*x + stm] -= one[dir+4];\r
+         if(r1 < J) attacks[2*y + stm] -= one[dir];\r
+         if(board[x-step] != EMPTY && board[x-step] != EDGE)\r
+           attacks[2*(x-step) + stm] -= one[dir+4];\r
+       }\r
+      }\r
 \r
     } else { // we were only attacked from behind\r
 \r