Make index of Tori Shogi symbolic
authorH.G.Muller <hgm@hgm-xboard.(none)>
Sun, 18 Feb 2018 10:57:31 +0000 (11:57 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Sun, 18 Feb 2018 10:57:31 +0000 (11:57 +0100)
The variant number is used in several places to decide the result of
repetitions, and Tori Shogi is special in that respect. To make it
easier to add variants, these tests now use a symbolic constant TORI_NR
rather than a hard-coded '6'.

dropper.c

index 742f8ec..aade58a 100644 (file)
--- a/dropper.c
+++ b/dropper.c
@@ -389,6 +389,8 @@ VariantDesc variants[] = {
   {  7,  7,  6, 2, "torishogi\n",   toriIDs,  toriFEN,   toriDirs,  toriProms,  toriCodes,  toriValues  },
 };
 
+#define TORI_NR 6 /* must correspond to index of torishogi (which must be last) in table above! */
+
 // info per piece type. sometimes indexed by negated holdings count instead of piece
 #define pieceKey   (rawKey+1)
 #define PST        (rawPST+1)
@@ -456,10 +458,9 @@ GameInit (char *name)
 
     // determine variant parameters
     if(sscanf(name, "%dx%d+%d_%c", &f, &r, &i, &c) == 4) {
-       for(v=6; --v>0; ) if(variants[v].files == f && variants[v].ranks == r && variants[v].hand == i) break;
+       for(v=TORI_NR; --v>0; ) if(variants[v].files == f && variants[v].ranks == r && variants[v].hand == i) break;
     } else
-    for(v=6; --v>0;) if(!strcmp(name, variants[v].name)) break;
-printf("# variant %d: %s\n", v, variants[v].name);
+    for(v=TORI_NR; --v>0;) if(!strcmp(name, variants[v].name)) break;
     nrFiles = variants[v].files;
     nrRanks = variants[v].ranks;
     zone    = variants[v].zone;
@@ -628,7 +629,7 @@ printf("# variant %d: %s\n", v, variants[v].name);
     for(f=0,p=pstType[v]; *p; p++,f++) if(*p == ' ') f = 15; else  PST[BLACK+f] = (PST[WHITE+f] = pstData + 22*11*(*p - '0')) + 11*(*p > '2'); 
 
     InitCaptureCodes(variants[v].codes);
-    pinCodes = (v == 6 ? 0xFF2C : 0xFF1F); // rays along which pinning is possible
+    pinCodes = (v == TORI_NR ? 0xFF2C : 0xFF1F); // rays along which pinning is possible
 }
 
 void
@@ -915,7 +916,7 @@ EvasionDrops (int stm, StackFrame *f, int mask)
        i = zoneTab[x] & Z_LAST; // Pawn not on first & last rank (OK for zh)
        if(perpLoses) { // but it is Shogi!
            if(!(zoneTab[x] & stm)) i = 0; // outside zone, so dropping is always allowed
-           else if(perpLoses < 6) {       // Shogi variant with Lance
+           else if(perpLoses < TORI_NR) { // Shogi variant with Lance
                i *= 2;                    // no Pawn, then also no Lance!
                last += 1 - (zoneTab[x] & (Z_2ND & ~COLOR)) + (perpLoses & 4) >> 3; // on last 2 ranks trim off Knight (not in Wa)
            }
@@ -1346,7 +1347,7 @@ Search (int stm, int alpha, int beta, StackFrame *ff, int depth, int reduction,
                                for(i=moveNr+ply-2; i>=d; i-=2) if(checkHist[i+1] == CK_NONE) break;
                                if(i < d) score = INF-1; // we are suffering a perpetual, so lose
                                else if(perpLoses == 1) score = (stm == WHITE ? -INF : INF-1); // mini-Shogi, sente loses
-                               else if(perpLoses == 6) score = -INF; // Tori Shogi, repeating loses
+                               else if(perpLoses == TORI_NR) score = -INF; // Tori Shogi, repeating loses
                            }
                           
                        }