From c172f0cc52bcf9d4433149de82290c2941136180 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Sun, 28 Sep 2014 10:09:17 +0200 Subject: [PATCH] Allow use of second-row pieces for non-promoted in drop games Second-row pieces were automatically demoted on capture, but this should really happen only when the piece-to-char table says it is a shogi-promoted piece (assigned a '+' there). Pieces assigned a letter should really stay themselves. PieceToNumber had to be adapted to skip '+' pieces in order to count correctly for second-row pieces, as did the code in UserMoveEvent() that mapped the from-square onto the piece type. (Why do we do that anyway? The piece type was displayed on the from-square!) --- backend.c | 8 ++++---- moves.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend.c b/backend.c index f988046..b248d03 100644 --- a/backend.c +++ b/backend.c @@ -6986,7 +6986,7 @@ UserMoveEvent(int fromX, int fromY, int toX, int toY, int promoChar) // holdings might not be sent yet in ICS play; we have to figure out which piece belongs here if(fromX == 0) fromY = BOARD_HEIGHT-1 - fromY; // black holdings upside-down fromX = fromX ? WhitePawn : BlackPawn; // first piece type in selected holdings - while(PieceToChar(fromX) == '.' || PieceToNumber(fromX) != fromY && fromX != (int) EmptySquare) fromX++; + while(PieceToChar(fromX) == '.' || PieceToChar(fromX) == '+' || PieceToNumber(fromX) != fromY && fromX != (int) EmptySquare) fromX++; fromY = DROP_RANK; } @@ -10149,8 +10149,8 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) p = (int) captured; if (p >= (int) BlackPawn) { p -= (int)BlackPawn; - if(gameInfo.variant == VariantShogi && DEMOTED p >= 0) { - /* in Shogi restore piece to its original first */ + if(DEMOTED p >= 0 && PieceToChar(p) == '+') { + /* Restore shogi-promoted piece to its original first */ captured = (ChessSquare) (DEMOTED captured); p = DEMOTED p; } @@ -10160,7 +10160,7 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) board[p][BOARD_WIDTH-1] = BLACK_TO_WHITE captured; } else { p -= (int)WhitePawn; - if(gameInfo.variant == VariantShogi && DEMOTED p >= 0) { + if(DEMOTED p >= 0 && PieceToChar(p) == '+') { captured = (ChessSquare) (DEMOTED captured); p = DEMOTED p; } diff --git a/moves.c b/moves.c index bcaef30..015f5f2 100644 --- a/moves.c +++ b/moves.c @@ -135,7 +135,7 @@ PieceToNumber (ChessSquare p) /* [HGM] holdings: count piece type, ignoring non int i=0; ChessSquare start = (int)p >= (int)BlackPawn ? BlackPawn : WhitePawn; - while(start++ != p) if(pieceToChar[(int)start-1] != '.') i++; + while(start++ != p) if(pieceToChar[start-1] != '.' && pieceToChar[start-1] != '+') i++; return i; } -- 1.7.0.4