Change the piece order again
authorH.G.Muller <hgm@hgm-xboard.(none)>
Thu, 4 Feb 2016 18:43:14 +0000 (19:43 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 5 Feb 2016 08:14:17 +0000 (09:14 +0100)
The internal piece encoding is now altered such that the uninteresting
ones (promoted Shogi pieces and symmetry partners) are all at the end,
just before King. These now start with the PromoBishop. A slash in the
pieceToChar string skips to this new 'promoted series', so that strings
can be made 'future proof' (for when new pieces are added before it).
The promoted Chu pieces all get new book keys by this, but as it is
unlikely that they occurin opening lines, this was considered acceptable.
The +L, +T in Chu are now represented by Pegasus and Gnu rather than
Knight and Chancellor, but the latter two are defined as fall-backs to
remain compatible with old Chu themes.
The +N, +L, +S replacements in Shogi are now also taken from amongst the
regular pieces, rather than extra images stored beyond King.

backend.c
book.c
common.h
draw.c
moves.c

index 99f752e..ffd9c44 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -6003,19 +6003,10 @@ ptclen (const char *s, char *escapes)
 {
     int n = 0;
     if(!*escapes) return strlen(s);
-    while(*s) n += (*s != '-' && *s != '^' && *s != '*' && !strchr(escapes, *s)), s++;
+    while(*s) n += (*s != '/' && *s != '-' && *s != '^' && *s != '*' && !strchr(escapes, *s)), s++;
     return n;
 }
 
-static int pieceOrder[] = {
-  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, // P N B R Q F E A C W M
- 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, // O H I J G D V L S U Lion
- 45, 23, 24, 25, 26, 27, 28, 29, 46, 31, 32, // Sword Zebra Camel Tower Wolf Dragon Duck Axe Leopard Gnu Cub
- 44, 51, 56, 57, 58, 59, 60, 61, 62, 63, 34, // Whale Pegasus Wizard Copper Iron Viking Flag Amazon Wheel Shield Claw
- 33, 55, 53, 42, 37, 48, 39, 40, 41, 22, 30, // +P +N =B =R +L +S +E +Ph +Kn Butterfly Hat
- 38, 43, 35, 36, 49, 47, 52, 50, 54, 64, 65 // +V +M =H =D Princess HSword +GB HCrown Wheer Shierd King
-};
-
 int
 SetCharTableEsc (unsigned char *table, const char * map, char * escapes)
 /* [HGM] moved here from winboard.c because of its general usefulness */
@@ -6026,25 +6017,26 @@ SetCharTableEsc (unsigned char *table, const char * map, char * escapes)
 
     if( map != NULL && (NrPieces=ptclen(map, escapes)) <= (int) EmptySquare
                     && NrPieces >= 12 && !(NrPieces&1)) {
-        int i, ii, j = 0; /* [HGM] Accept even length from 12 to 88 */
+        int i, ii, offs, j = 0; /* [HGM] Accept even length from 12 to 88 */
 
         for( i=0; i<(int) EmptySquare; i++ ) table[i] = '.';
-        for( ii=0; ii<NrPieces/2-1; ii++ ) {
+        for( i=offs=0; i<NrPieces/2-1; i++ ) {
             char *p, c=0;
-            i = pieceOrder[ii];
+            if(map[j] == '/') offs = WhitePBishop - i, j++;
             if(*escapes && (map[j] == '*' || map[j] == '-' || map[j] == '^')) c = map[j++];
-            table[i] = map[j++];
-            if(p = strchr(escapes, map[j])) j++, table[i] += 64*(p - escapes + 1);
-            if(c) partner[i] = table[i], table[i] = c;
+            table[i+offs] = map[j++];
+            if(p = strchr(escapes, map[j])) j++, table[i+offs] += 64*(p - escapes + 1);
+            if(c) partner[i+offs] = table[i+offs], table[i+offs] = c;
         }
         table[(int) WhiteKing]  = map[j++];
-        for( ii=0; ii<NrPieces/2-1; ii++ ) {
+        for( ii=offs=0; ii<NrPieces/2-1; ii++ ) {
             char *p, c=0;
-            i = WHITE_TO_BLACK pieceOrder[ii];
+            if(map[j] == '/') offs = WhitePBishop - ii, j++;
+            i = WHITE_TO_BLACK ii;
             if(*escapes && (map[j] == '*' || map[j] == '-' || map[j] == '^')) c = map[j++];
-            table[i] = map[j++];
-            if(p = strchr(escapes, map[j])) j++, table[i] += 64*(p - escapes + 1);
-            if(c) partner[i] = table[i], table[i] = c;
+            table[i+offs] = map[j++];
+            if(p = strchr(escapes, map[j])) j++, table[i+offs] += 64*(p - escapes + 1);
+            if(c) partner[i+offs] = table[i+offs], table[i+offs] = c;
         }
         table[(int) BlackKing]  = map[j++];
 
@@ -6251,8 +6243,8 @@ InitPosition (int redraw)
       gameInfo.boardWidth  = 12;
       gameInfo.boardHeight = 12;
       nrCastlingRights = 0;
-      SetCharTableEsc(pieceToChar, "P.BRQSEXOGCATHD.VMLIFN^T.......^H..^A^L.........^P.^F^G..^E^X^O..^S^C^B^R^V^D^I^MK"
-                                   "p.brqsexogcathd.vmlifn^t.......^h..^a^l.........^p.^f^g..^e^x^o..^s^c^b^r^v^d^i^mk", SUFFIXES);
+      SetCharTableEsc(pieceToChar, "P.BRQSEXOGCATHD.VMLIFN.........^T..^L......^A^H/^F^G^M.^E^X^O^I.^P.^B^R..^D^S^C^VK"
+                                   "p.brqsexogcathd.vmlifn.........^t..^l......^a^h/^f^g^m.^e^x^o^i.^p.^b^r..^d^s^c^vk", SUFFIXES);
       break;
     case VariantCourier:
       pieces = CourierArray;
diff --git a/book.c b/book.c
index 6a257d8..cfc25c8 100644 (file)
--- a/book.c
+++ b/book.c
@@ -315,7 +315,7 @@ hash (int moveNr)
             if(p != EmptySquare){
                    int j = (int)p, promoted = 0;
                    j -= (j >= (int)BlackPawn) ? (int)BlackPawn :(int)WhitePawn;
-                   if(j >= WhiteTokin && j != WhiteKing) promoted++, j -= WhiteTokin;
+                   if(j >= WhitePBishop && j != WhiteKing) promoted++, j -= WhiteTokin;
                    if(j > (int)WhiteQueen) j++;  // make space for King
                    if(j > (int) WhiteKing) j = (int)WhiteQueen + 1;
                    p_enc = 2*j + ((int)p < (int)BlackPawn);
index 81f2553..61d0c5e 100644 (file)
--- a/common.h
+++ b/common.h
@@ -294,28 +294,26 @@ typedef enum {
     WhiteFerz, WhiteAlfil, WhiteAngel, WhiteMarshall, WhiteWazir, WhiteMan,
     WhiteCannon, WhiteNightrider, WhiteCardinal, WhiteDragon, WhiteGrasshopper,
     WhiteSilver, WhiteFalcon, WhiteLance, WhiteCobra, WhiteUnicorn, WhiteLion,
-    WhiteButterfly, WhiteZebra, WhiteCamel, WhiteTower, WhiteWolf,
-    WhiteFlying, WhiteDuck, WhiteAxe, WhiteHat, WhiteGnu, WhiteCub,
-    WhiteTokin, WhiteClaw, WhitePCardinal, WhitePDragon, WhiteCat,
-    WhitePSword, WhiteMonarch, WhiteMother, WhiteNothing, WhitePRook, WhitePDagger,
-    WhiteDolphin, WhiteStag, WhiteHorned, WhiteEagle, WhiteSword,
-    WhiteCrown, WhiteHCrown, WhiteHorse, WhiteDrunk, WhitePBishop,
-    WhiteWheel, WhitePKnight, WhiteWizard, WhiteCopper, WhiteIron, WhiteViking,
-    WhiteFlag, WhiteAmazon, WhiteWheer, WhiteShield, WhiteShierd,
-    WhiteKing,
+    WhiteSword, WhiteZebra, WhiteCamel, WhiteTower, WhiteWolf,
+    WhiteHat, WhiteDuck, WhiteAmazon, WhiteFlying, WhiteGnu, WhiteCub,
+    WhiteShield, WhiteHorse, WhiteWizard, WhiteCopper, WhiteIron,
+    WhiteViking, WhiteFlag, WhiteAxe, WhiteDolphin, WhiteCat, WhiteClaw,
+    WhiteWheel, WhiteButterfly, WhitePBishop, WhitePRook, WhiteHCrown,
+    WhiteShierd, WhiteMonarch, WhiteMother, WhiteNothing, WhiteDrunk, WhiteWheer,
+    WhiteTokin, WhitePKnight, WhitePCardinal, WhitePDragon, WhitePLance,
+    WhitePSilver, WhiteDagger, WhitePSword, WhitePDagger, WhiteCrown, WhiteKing,
     BlackPawn, BlackKnight, BlackBishop, BlackRook, BlackQueen,
     BlackFerz, BlackAlfil, BlackAngel, BlackMarshall, BlackWazir, BlackMan,
     BlackCannon, BlackNightrider, BlackCardinal, BlackDragon, BlackGrasshopper,
     BlackSilver, BlackFalcon, BlackLance, BlackCobra, BlackUnicorn, BlackLion,
-    BlackButterfly, BlackZebra, BlackCamel, BlackTower, BlackWolf,
-    BlackFlying, BlackDuck, BlackAxe, BlackHat, BlackGnu, BlackCub,
-    BlackTokin, BlackClaw, BlackPCardinal, BlackPDragon, BlackCat,
-    BlackPSword, BlackMonarch, BlackMother, BlackNothing, BlackPRook, BlackPDagger,
-    BlackDolphin, BlackStag, BlackHorned, BlackEagle, BlackSword,
-    BlackCrown, BlackHCrown, BlackHorse, BlackDrunk, BlackPBishop,
-    BlackWheel, BlackPKnight, BlackWizard, BlackCopper, BlackIron, BlackViking,
-    BlackFlag, BlackAmazon, BlackWheer, BlackShield, BlackShierd,
-    BlackKing,
+    BlackSword, BlackZebra, BlackCamel, BlackTower, BlackWolf,
+    BlackHat, BlackDuck, BlackAmazon, BlackFlying, BlackGnu, BlackCub,
+    BlackShield, BlackHorse, BlackWizard, BlackCopper, BlackIron,
+    BlackViking, BlackFlag, BlackAxe, BlackDolphin, BlackCat, BlackClaw,
+    BlackWheel, BlackButterfly, BlackPBishop, BlackPRook, BlackHCrown,
+    BlackShierd, BlackMonarch, BlackMother, BlackNothing, BlackDrunk, BlackWheer,
+    BlackTokin, BlackPKnight, BlackPCardinal, BlackPDragon, BlackPLance,
+    BlackPSilver, BlackDagger, BlackPSword, BlackPDagger, BlackCrown, BlackKing,
     EmptySquare, DarkSquare,
     NoRights, // [HGM] gamestate: for castling rights hidden in board[CASTLING]
     ClearBoard, WhitePlay, BlackPlay, PromotePiece, DemotePiece /*for use on EditPosition menus*/
diff --git a/draw.c b/draw.c
index 2df683f..afb6393 100644 (file)
--- a/draw.c
+++ b/draw.c
@@ -106,9 +106,9 @@ extern char *getenv();
 Boolean cairoAnimate;
 Option *currBoard;
 cairo_surface_t *csBoardWindow;
-static cairo_surface_t *pngPieceImages[2][(int)BlackPawn+4];   // png 256 x 256 images
-static cairo_surface_t *pngPieceBitmaps[2][(int)BlackPawn];    // scaled pieces as used
-static cairo_surface_t *pngPieceBitmaps2[2][(int)BlackPawn+4]; // scaled pieces in store
+static cairo_surface_t *pngPieceImages[2][(int)BlackPawn];   // png 256 x 256 images
+static cairo_surface_t *pngPieceBitmaps[2][(int)BlackPawn];  // scaled pieces as used
+static cairo_surface_t *pngPieceBitmaps2[2][(int)BlackPawn]; // scaled pieces in store
 static RsvgHandle *svgPieces[2][(int)BlackPawn+4]; // vector pieces in store
 static cairo_surface_t *pngBoardBitmap[2], *pngOriginalBoardBitmap[2];
 int useTexture, textureW[2], textureH[2];
@@ -144,9 +144,9 @@ SelectPieces(VariantClass v)
           pngPieceBitmaps[i][p] = pngPieceBitmaps2[i][p]; // defaults
        if(v == VariantShogi && BOARD_HEIGHT != 7) { // no exceptions in Tori Shogi
           pngPieceBitmaps[i][(int)WhiteCannon] = pngPieceBitmaps2[i][(int)WhiteTokin];
-          pngPieceBitmaps[i][(int)WhiteNightrider] = pngPieceBitmaps2[i][(int)WhiteKing+2];
-          pngPieceBitmaps[i][(int)WhiteGrasshopper] = pngPieceBitmaps2[i][(int)WhiteKing+3];
-          pngPieceBitmaps[i][(int)WhiteSilver] = pngPieceBitmaps2[i][(int)WhiteKing+4];
+          pngPieceBitmaps[i][(int)WhiteNightrider] = pngPieceBitmaps2[i][(int)WhitePKnight];
+          pngPieceBitmaps[i][(int)WhiteGrasshopper] = pngPieceBitmaps2[i][(int)WhitePLance];
+          pngPieceBitmaps[i][(int)WhiteSilver] = pngPieceBitmaps2[i][(int)WhitePSilver];
           pngPieceBitmaps[i][(int)WhiteQueen] = pngPieceBitmaps2[i][(int)WhiteLance];
           pngPieceBitmaps[i][(int)WhiteFalcon] = pngPieceBitmaps2[i][(int)WhiteMonarch]; // for Sho Shogi
        }
@@ -165,12 +165,12 @@ SelectPieces(VariantClass v)
        if(v == VariantChu) {
           pngPieceBitmaps[i][(int)WhiteNightrider] = pngPieceBitmaps2[i][(int)WhiteClaw];
           pngPieceBitmaps[i][(int)WhiteClaw]    = pngPieceBitmaps2[i][(int)WhiteNightrider];
-          pngPieceBitmaps[i][(int)WhiteUnicorn] = pngPieceBitmaps2[i][(int)WhiteHorned];
-          pngPieceBitmaps[i][(int)WhiteSilver]  = pngPieceBitmaps2[i][(int)WhiteStag];
-          pngPieceBitmaps[i][(int)WhiteFalcon]  = pngPieceBitmaps2[i][(int)WhiteEagle];
-          pngPieceBitmaps[i][(int)WhiteHorned]  = pngPieceBitmaps2[i][(int)WhiteUnicorn];
-          pngPieceBitmaps[i][(int)WhiteStag]    = pngPieceBitmaps2[i][(int)WhiteSilver];
-          pngPieceBitmaps[i][(int)WhiteEagle]   = pngPieceBitmaps2[i][(int)WhiteFalcon];
+          pngPieceBitmaps[i][(int)WhiteUnicorn] = pngPieceBitmaps2[i][(int)WhiteCat];
+          pngPieceBitmaps[i][(int)WhiteSilver]  = pngPieceBitmaps2[i][(int)WhiteSword];
+          pngPieceBitmaps[i][(int)WhiteFalcon]  = pngPieceBitmaps2[i][(int)WhiteDagger];
+          pngPieceBitmaps[i][(int)WhiteCat]     = pngPieceBitmaps2[i][(int)WhiteUnicorn];
+          pngPieceBitmaps[i][(int)WhiteSword]   = pngPieceBitmaps2[i][(int)WhiteSilver];
+          pngPieceBitmaps[i][(int)WhiteDagger]  = pngPieceBitmaps2[i][(int)WhiteFalcon];
           pngPieceBitmaps[i][(int)WhiteMan]     = pngPieceBitmaps2[i][(int)WhiteCopper];
           pngPieceBitmaps[i][(int)WhiteCopper]  = pngPieceBitmaps2[i][(int)WhiteMan];
           pngPieceBitmaps[i][(int)WhiteAxe]     = pngPieceBitmaps2[i][(int)WhiteCannon];
@@ -292,16 +292,19 @@ CreatePNGBoard (char *s, int kind)
 char *pngPieceNames[] = // must be in same order as internal piece encoding
 { "Pawn", "Knight", "Bishop", "Rook", "Queen", "Advisor", "Elephant", "Archbishop", "Marshall", "Gold", "Commoner",
   "Canon", "Nightrider", "CrownedBishop", "CrownedRook", "Crown", "Chancellor", "Hawk", "Lance", "Cobra", "Unicorn", "Lion",
-  "Butterfly", "Zebra", "Camel", "Tower", "Wolf", "Dragon", "Duck", "Axe", "Hat", "Gnu", "Cub",
-  "GoldPawn", "Claw", "PromoHorse", "PromoDragon", "GoldLance", "PromoSword", "Prince", "Phoenix", "Kylin", "PromoRook", "PromoHSword",
-  "Dolphin", "Sword", "Leopard", "HSword", "GoldSilver", "Princess", "HCrown", "Pegasus", "Elephant", "PromoBishop",
-  "Left", "GoldKnight", "Wizard", "Copper", "Iron", "Viking", "Flag", "Lance", "Right", "LShield", "RShield", "King",
-  "Claw", "GoldKnight", "GoldLance", "GoldSilver", NULL
+  "Sword", "Zebra", "Camel", "Tower", "Wolf", "Hat", "Duck", "Lance", "Dragon", "Gnu", "Cub",
+  "LShield", "Pegasus", "Wizard", "Copper", "Iron", "Viking", "Flag", "Axe", "Dolphin", "Leopard", "Claw",
+  "Left", "Butterfly", "PromoBishop", "PromoRook", "HCrown", "RShield", "Prince", "Phoenix", "Kylin", "Drunk", "Right",
+  "GoldPawn", "GoldKnight", "PromoHorse", "PromoDragon", "GoldLance", "GoldSilver", "HSword", "PromoSword", "PromoHSword", "Princess", "King",
+  NULL
 };
 
-char *backupPiece[] = { "Princess", NULL, NULL, NULL, NULL, NULL, NULL,
-                        NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-                       NULL, NULL, NULL, NULL, NULL, NULL, "King", "Queen", "Lion" }; // pieces that map on other when not kanji
+char *backupPiece[] = { // pieces that map on other in default theme ("Crown" - "Drunk")
+  "Princess", NULL, NULL, NULL, NULL, NULL, NULL,
+  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "Chancellor", NULL,
+  NULL, "Knight", NULL, "Commoner", NULL, NULL, NULL, "Canon", NULL, NULL, NULL,
+  NULL, NULL, NULL, NULL, NULL, NULL, "King", "Queen", "Lion", "Elephant"
+};
 
 RsvgHandle *
 LoadSVG (char *dir, int color, int piece, int retry)
@@ -341,7 +344,7 @@ LoadSVG (char *dir, int color, int piece, int retry)
 
       return svg;
     }
-    if(!retry && piece >= WhiteGrasshopper && piece <= WhiteNothing) // pieces that are only different in kanji sets
+    if(!retry && piece >= WhiteGrasshopper && piece <= WhiteDrunk) // pieces that are only different in kanji sets
         return LoadSVG(dir, color, piece, 1);
     if(svgerror)
        g_error_free(svgerror);
diff --git a/moves.c b/moves.c
index 67a23ac..bef359e 100644 (file)
--- a/moves.c
+++ b/moves.c
@@ -912,8 +912,8 @@ GenPseudoLegal (Board board, int flags, MoveCallback callback, VOIDSTAR closure,
                break;
 
 
-            case SHOGI WhiteStag:
-            case SHOGI BlackStag:
+            case SHOGI WhiteGnu:
+            case SHOGI BlackGnu:
                if(gameInfo.variant == VariantShogi) goto BlackGold;
                SlideVertical(board, flags, rf, ff, callback, closure);
                Ferz(board, flags, rf, ff, callback, closure);
@@ -1277,7 +1277,7 @@ GenPseudoLegal (Board board, int flags, MoveCallback callback, VOIDSTAR closure,
                SlideVertical(board, flags, rf, ff, callback, closure);
                break;
 
-            case SHOGI WhiteHorned:
+            case SHOGI WhiteCat:
                Sting(board, flags, rf, ff, 1, 0, callback, closure);
                callback(board, flags, NormalMove, rf, ff, rf, ff, closure);
                if(killX >= 0) break;
@@ -1286,7 +1286,7 @@ GenPseudoLegal (Board board, int flags, MoveCallback callback, VOIDSTAR closure,
                SlideBackward(board, flags, rf, ff, callback, closure);
                break;
 
-            case SHOGI BlackHorned:
+            case SHOGI BlackCat:
                Sting(board, flags, rf, ff, -1, 0, callback, closure);
                callback(board, flags, NormalMove, rf, ff, rf, ff, closure);
                if(killX >= 0) break;
@@ -1295,7 +1295,7 @@ GenPseudoLegal (Board board, int flags, MoveCallback callback, VOIDSTAR closure,
                SlideForward(board, flags, rf, ff, callback, closure);
                break;
 
-            case SHOGI WhiteEagle:
+            case SHOGI WhiteDagger:
                Sting(board, flags, rf, ff, 1,  1, callback, closure);
                Sting(board, flags, rf, ff, 1, -1, callback, closure);
                callback(board, flags, NormalMove, rf, ff, rf, ff, closure);
@@ -1304,7 +1304,7 @@ GenPseudoLegal (Board board, int flags, MoveCallback callback, VOIDSTAR closure,
                SlideDiagBackward(board, flags, rf, ff, callback, closure);
                break;
 
-            case SHOGI BlackEagle:
+            case SHOGI BlackDagger:
                Sting(board, flags, rf, ff, -1,  1, callback, closure);
                Sting(board, flags, rf, ff, -1, -1, callback, closure);
                callback(board, flags, NormalMove, rf, ff, rf, ff, closure);