Fix diagonal moves Janggi in opponent Palace
authorH.G.Muller <hgm@hgm-xboard.(none)>
Thu, 8 Oct 2020 14:17:38 +0000 (16:17 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Thu, 8 Oct 2020 14:22:53 +0000 (16:22 +0200)
The test for being in Palace should not refer to the Palace of your
own color, but to the Palace on your current board half. Also, Cannons
should not be able to jump over or capture each other inside the Palace.

moves.c

diff --git a/moves.c b/moves.c
index f60ec7a..0adace5 100644 (file)
--- a/moves.c
+++ b/moves.c
@@ -779,15 +779,18 @@ PalaceDiags (Board board, int flags, int rf, int ff, int isRook, MoveCallback ca
 {   // Janggi diagonal palace moves
     int piece = board[rf][ff];
     int middle = BOARD_WIDTH/2;
-    int palace = (piece < BlackPawn ? 1 : BOARD_HEIGHT-2);
+    int palace = (rf < 3 ? 1 : BOARD_HEIGHT-2);
     if(ff == middle) {
        if(rf == palace && isRook) Ferz(board, flags, rf, ff, callback, closure);
     } else if((ff == middle+1 || ff == middle-1) && (rf == palace+1 || rf == palace-1)) { // Palace corner
        int rt = 2*palace - rf, ft = 2*middle - ff; // reflect
-       if((board[palace][middle] == EmptySquare) == isRook && !SameColor(piece, board[rt][ft]))
-           callback(board, flags, NormalMove, rf, ff, rt, ft, closure);
-       if(isRook && !SameColor(piece, board[palace][middle]))
+       ChessSquare center = board[palace][middle];
+       if(isRook && !SameColor(piece, center))
            callback(board, flags, NormalMove, rf, ff, palace, middle, closure);
+       if(center == WhiteCannon || center == BlackCannon) return;
+       if((center == EmptySquare) == isRook && !SameColor(piece, board[rt][ft])
+          && piece + board[rt][ft] != WhiteCannon + BlackCannon)
+           callback(board, flags, NormalMove, rf, ff, rt, ft, closure);
     }
 }