Update JAWS patch for version 4.9
authorH.G.Muller <hgm@hgm-xboard.(none)>
Tue, 5 Jul 2022 18:32:35 +0000 (20:32 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Tue, 5 Jul 2022 18:32:35 +0000 (20:32 +0200)
The JAWS patch was still at the stage of 4.5. So many piece names
had to be added to expand from 22 to 66 types. To prevent having
too many versions of the same name, the routine PieceToName() is
now adding the color prefixes, rather than taking them from the name table.
Calls to GenLegal() and HAsPromotionChoice() need an extra argument
in 4.9.

winboard/jaws.c

index aa843ad..4c7416a 100644 (file)
@@ -86,40 +86,27 @@ extern long whiteTimeRemaining, blackTimeRemaining, timeControl, timeIncrement;
 \r
 // from moves.c, added WinBoard_F piece types and ranks / files\r
 \r
-char *squareToChar[] = { "ay", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" };\r
-\r
-char *squareToNum[] = {"naught", "1", "2", "3", "4", "5", "6", "7", "8", "9" };\r
-\r
-char *ordinals[] = {"zeroth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "nineth"};\r
-\r
-char *pieceToName[] = {\r
-               "White Pawn", "White Knight", "White Bishop", "White Rook", "White Queen",\r
-               "White Guard", "White Elephant", "White Arch Bishop", "White Chancellor",\r
-               "White General", "White Man", "White Cannon", "White Night Rider",\r
-               "White Crowned Bishop", "White Crowned Rook", "White Grass Hopper", "White Veteran",\r
-               "White Falcon", "White Amazon", "White Snake", "White Unicorn",\r
-               "White King",\r
-               "Black Pawn", "Black Knight", "Black Bishop", "Black Rook", "Black Queen",\r
-               "Black Guard", "Black Elephant", "Black Arch Bishop", "Black Chancellor",\r
-               "Black General", "Black Man", "Black Cannon", "Black Night Rider",\r
-               "Black Crowned Bishop", "Black Crowned Rook", "Black Grass Hopper", "Black Veteran",\r
-               "Black Falcon", "Black Amazon", "Black Snake", "Black Unicorn",\r
-               "Black King",\r
-               "Empty"\r
-       };\r
+char *squareToChar[] = { "ay", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t" };\r
+\r
+char *squareToNum[] = {"naught", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" };\r
+\r
+char *ordinals[] = {"zeroth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "nineth", "tenth", "eleventh", "twelfth", "thriteenth", "fourteenth", "fifteenth", "sixteenth" };\r
 \r
 char *pieceTypeName[] = {\r
                "Pawn", "Knight", "Bishop", "Rook", "Queen",\r
                "Guard", "Elephant", "Arch Bishop", "Chancellor",\r
                "General", "Man", "Cannon", "Night Rider",\r
                "Crowned Bishop", "Crowned Rook", "Grass Hopper", "Veteran",\r
-               "Falcon", "Amazon", "Snake", "Unicorn",\r
-               "King",\r
-               "Pawn", "Knight", "Bishop", "Rook", "Queen",\r
-               "Guard", "Elephant", "Arch Bishop", "Chancellor",\r
-               "General", "Man", "Cannon", "Night Rider",\r
-               "Crowned Bishop", "Crowned Rook", "Grass Hopper", "Veteran",\r
-               "Falcon", "Amazon", "Snake", "Unicorn",\r
+               "Falcon", "Lance", "Snake", "Unicorn", "Lion",\r
+               "Sword", "Zebra", "Camel", "Tower", "Wolf",\r
+               "Hat", "Duck", "Amazon", "Dragon", "Wildebeest", "Lion",\r
+               "Shield", "Pegasus", "Wizard", "Champion", "Helmet",\r
+               "Viking", "Flag", "Axe", "Dolphin", "Leopard", "Tiger",\r
+               "Wheel", "Butterfly", "Promo Bishop", "Promo Rook",\r
+               "Sleeping Beauty", "Reverse Shield", "Prince", "Promo Queen",\r
+               "Promo Lion", "Drunk Elephant", "Reverse Wheel", \r
+               "Tokin", "Promo Knight", "Promo Horse", "Promo Dragon", "Promo Lance",\r
+               "Promo Silver", "Dagger", "Promo Sword", "Promo Dagger", "Princess",\r
                "King",\r
                "Empty"\r
        };\r
@@ -136,8 +123,12 @@ char* PieceToName(p, i)
        ChessSquare p;\r
        int i;\r
 {\r
-       if(i) return pieceToName[(int) p];\r
-               return pieceTypeName[(int) p];\r
+       static char buf[MSG_SIZ];\r
+        int black = (p >= BlackPawn);\r
+        if(black) p -= BlackPawn;\r
+        sprintf(buf, i ? black ? "Black " : "White " : "");\r
+        snprintf(buf + strlen(buf), " %s", pieceTypeName[(int) p]);\r
+               return buf;\r
 }\r
 \r
 char* SquareToChar(x)\r
@@ -149,7 +140,7 @@ char* SquareToChar(x)
 char* SquareToNum(y)\r
                        int y;\r
 {\r
-               return squareToNum[y + (gameInfo.boardHeight < 10)];\r
+               return squareToNum[y + (gameInfo.boardHeight != 10)];\r
 }\r
 \r
 \r
@@ -167,7 +158,7 @@ VOID SayString(char *mess, BOOL flag)
         int l = strlen(buf);\r
        if(appData.debugMode) fprintf(debugFP, "SAY '%s'\n", mess);\r
         if(l) buf[l++] = ' '; // separate by space from previous\r
-       safeStrCpy(buf+l, _(mess), 8000-1-l); // buffer\r
+       safeStrCpy(buf+l, T_(mess), 8000-1-l); // buffer\r
         if(!flag) return; // wait for flush\r
        if(p = StrCaseStr(buf, "Xboard adjudication:")) {\r
                int i;\r
@@ -337,7 +328,7 @@ KeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                if(currentPiece != EmptySquare) {\r
                        char buf[MSG_SIZ];\r
                        n = boards[currentMove][fromY][1];\r
-                       snprintf(buf, MSG_SIZ, "%d %s%s", n, PieceToName(currentPiece,0), n == 1 ? "" : "s");\r
+                       snprintf(buf, MSG_SIZ, "%d %s%s", n, T_(PieceToName(currentPiece,0)), n == 1 ? "" : "s");\r
                        SayString(buf, FALSE);\r
                }\r
                SayString(" ", TRUE);\r
@@ -347,7 +338,7 @@ KeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                if(currentPiece != EmptySquare) {\r
                        char buf[MSG_SIZ];\r
                        n = boards[currentMove][fromY][BOARD_WIDTH-2];\r
-                       snprintf(buf, MSG_SIZ,"%d %s%s", n, PieceToName(currentPiece,0), n == 1 ? "" : "s");\r
+                       snprintf(buf, MSG_SIZ,"%d %s%s", n, T_(PieceToName(currentPiece,0)), n == 1 ? "" : "s");\r
                        SayString(buf, FALSE);\r
                }\r
                SayString(" ", TRUE);\r
@@ -357,8 +348,8 @@ KeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                xchar = SquareToChar(fromX);\r
                ynum = SquareToNum(fromY);\r
                if(currentPiece != EmptySquare) {\r
-                 snprintf(buf, MSG_SIZ, "%s %s %s", xchar, ynum, piece);\r
-               } else snprintf(buf, MSG_SIZ, "%s %s", xchar, ynum);\r
+                 snprintf(buf, MSG_SIZ, "%s %s %s", T_(xchar), T_(ynum), T_(piece));\r
+               } else snprintf(buf, MSG_SIZ, "%s %s", T_(xchar), T_(ynum));\r
                SayString(buf, FALSE);\r
                SayString(" ", TRUE);\r
        }\r
@@ -443,7 +434,7 @@ PossibleAttackMove()
        swapColor = piece <  (int)BlackPawn && !WhiteOnMove(currentMove) ||\r
                    piece >= (int)BlackPawn &&  WhiteOnMove(currentMove);\r
        cl.count = 0; cl.rf = fromY; cl.ff = fromX; cl.rt = cl.ft = -1;\r
-       GenLegal(boards[currentMove], PosFlags(currentMove + swapColor), ReadCallback, (VOIDSTAR) &cl);\r
+       GenLegal(boards[currentMove], PosFlags(currentMove + swapColor), ReadCallback, (VOIDSTAR) &cl, EmptySquare);\r
        if(cl.count == 0) SayString("None", FALSE);\r
        SayString("", TRUE); // flush\r
        boards[currentMove][fromY][fromX] = victim; // repair\r
@@ -471,14 +462,14 @@ PossibleAttacked()
        victim = boards[currentMove][fromY][fromX]; // put dummy piece on target square, to activate Pawn captures\r
        boards[currentMove][fromY][fromX] = WhiteOnMove(currentMove) ? WhiteQueen : BlackQueen;\r
        cl.count = 0; cl.rt = fromY; cl.ft = fromX; cl.rf = cl.ff = -1;\r
-       GenLegal(boards[currentMove], PosFlags(currentMove+1), ReadCallback, (VOIDSTAR) &cl);\r
+       GenLegal(boards[currentMove], PosFlags(currentMove+1), ReadCallback, (VOIDSTAR) &cl, EmptySquare);\r
        if(cl.count == 0) SayString("None", FALSE);\r
 \r
        SayString("You are defended by", FALSE);\r
 \r
        boards[currentMove][fromY][fromX] = WhiteOnMove(currentMove) ? BlackQueen : WhiteQueen;\r
        cl.count = 0; cl.rt = fromY; cl.ft = fromX; cl.rf = cl.ff = -1;\r
-       GenLegal(boards[currentMove], PosFlags(currentMove), ReadCallback, (VOIDSTAR) &cl);\r
+       GenLegal(boards[currentMove], PosFlags(currentMove), ReadCallback, (VOIDSTAR) &cl, EmptySquare);\r
        if(cl.count == 0) SayString("None", FALSE);\r
        SayString("", TRUE); // flush\r
        boards[currentMove][fromY][fromX] = victim; // put back original occupant\r
@@ -1151,7 +1142,7 @@ KeyboardMove(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                        click-click move is possible */\r
                        char promoChoice = NULLCHAR;\r
 \r
-                       if (HasPromotionChoice(oldFromX, oldFromY, fromX, fromY, &promoChoice)) {\r
+                       if (HasPromotionChoice(oldFromX, oldFromY, fromX, fromY, &promoChoice, FALSE)) {\r
                                if (appData.alwaysPromoteToQueen) {\r
                                        UserMoveEvent(oldFromX, oldFromY, fromX, fromY, 'q');\r
                                }\r