From: H.G. Muller Date: Tue, 20 Oct 2009 00:57:14 +0000 (-0700) Subject: fix for bug #27751: negative holding counts displayed X-Git-Tag: v4.4.1.20091019~5 X-Git-Url: http://winboard.nl/cgi-bin?p=xboard.git;a=commitdiff_plain;h=f520897d612f324be77e90c075f0aa50f5ae6b54 fix for bug #27751: negative holding counts displayed I put code in the back-end to prevent holdings counts from becoming negative when a drop move is made from empty holdings. (This can happen when re-loading ICS bughouse games, as the smoves command fails to fill the holdings.) --- diff --git a/backend.c b/backend.c index 5b8dcfa..bf1a32c 100755 --- a/backend.c +++ b/backend.c @@ -7514,14 +7514,20 @@ ApplyMove(fromX, fromY, toX, toY, promoChar, board, castling, ep) p = (int) fromX; if(p < (int) BlackPawn) { /* white drop */ p -= (int)WhitePawn; + p = PieceToNumber((ChessSquare)p); if(p >= gameInfo.holdingsSize) p = 0; - if(--board[p][BOARD_WIDTH-2] == 0) + if(--board[p][BOARD_WIDTH-2] <= 0) board[p][BOARD_WIDTH-1] = EmptySquare; + if((int)board[p][BOARD_WIDTH-2] < 0) + board[p][BOARD_WIDTH-2] = 0; } else { /* black drop */ p -= (int)BlackPawn; + p = PieceToNumber((ChessSquare)p); if(p >= gameInfo.holdingsSize) p = 0; - if(--board[BOARD_HEIGHT-1-p][1] == 0) + if(--board[BOARD_HEIGHT-1-p][1] <= 0) board[BOARD_HEIGHT-1-p][0] = EmptySquare; + if((int)board[BOARD_HEIGHT-1-p][1] < 0) + board[BOARD_HEIGHT-1-p][1] = 0; } } if (captured != EmptySquare && gameInfo.holdingsSize > 0 @@ -7555,7 +7561,6 @@ ApplyMove(fromX, fromY, toX, toY, promoChar, board, castling, ep) board[BOARD_HEIGHT-1-p][0] = WHITE_TO_BLACK captured; } } - } else if (gameInfo.variant == VariantAtomic) { if (captured != EmptySquare) { int y, x;