From f520897d612f324be77e90c075f0aa50f5ae6b54 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Mon, 19 Oct 2009 17:57:14 -0700 Subject: [PATCH] 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.) --- backend.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-) 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; -- 1.7.0.4