Change code for testing acceptable evasion drops
authorH.G.Muller <hgm@hgm-xboard.(none)>
Sun, 18 Feb 2018 22:18:38 +0000 (23:18 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Sun, 18 Feb 2018 22:18:38 +0000 (23:18 +0100)
The code deciding whether a piece could be dropped to block a distant check
was dependant on the exact numbering of the variants, making it difficult
to add new variants. It is replaced by code that only requires that variants
without dropping restriction in the last two ranks come behind all others.
The number of the first such variant is given by the constant KNIGHTLESS
(which must be adapted if variants with Knights are added!).

dropper.c

index 41c4ac8..f45319d 100644 (file)
--- a/dropper.c
+++ b/dropper.c
@@ -65,7 +65,7 @@ int moveNr;              // part of game state; incremented by MakeMove
 #define promoGain (rawGain + 1)
 
 int pvStack[MAXPLY*MAXPLY/2];
-int nrRanks, nrFiles, specials, pinCodes, maxDrop, moveSP, pawn, queen, lanceMask, *pvPtr = pvStack, boardEnd, perpLoses, searchNr;
+int nrRanks, nrFiles, specials, pinCodes, maxDrop, moveSP, pawn, queen, lanceMask, knightLim, *pvPtr = pvStack, boardEnd, perpLoses, searchNr;
 int  frontier, killZone, impasse, frontierPenalty, killPenalty;
 int rawInts[21*22], pieceValues[96], pieceCode[96];
 signed char   rawChar[32*22], steps[512];
@@ -390,6 +390,7 @@ VariantDesc variants[] = {
 };
 
 #define TORI_NR 6 /* must correspond to index of torishogi (which must be last) in table above! */
+#define KNIGHTLESS 4 /* first variant without a Knight (except mini-, which has no 2-rank zone) */
 
 // info per piece type. sometimes indexed by negated holdings count instead of piece
 #define pieceKey   (rawKey+1)
@@ -470,6 +471,7 @@ GameInit (char *name)
     startPos= variants[v].fen;
     codes   = variants[v].proms;
     lanceMask = lances[v];
+    knightLim = (v >= KNIGHTLESS) * 6; // 6 for variants where last piece can be dropped on last two ranks
     perpLoses = v; // this works for now, as only zh allows perpetuals
 
     if((p = betza[v])) { // configure GUI for this variant
@@ -919,7 +921,7 @@ EvasionDrops (int stm, StackFrame *f, int mask)
            if(!(zoneTab[x] & stm)) i = 0; // outside zone, so dropping is always allowed
            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)
+               last -= (zoneTab[x] & (Z_2ND & ~COLOR)) > knightLim; // on last 2 ranks trim off Knight (not in Wa)
            }
            if(pawnCount[sqr2file[x]] & maxBulk[stm]) i += !i; // no Pawn in pawn-crowded file
        }