From 6cab23ba23301b578d4995f3c889e574ea4b9e99 Mon Sep 17 00:00:00 2001
From: H.G. Muller <h.g.muller@hccnet.nl>
Date: Sat, 1 Aug 2009 13:09:49 -0700
Subject: [PATCH] temporary fix for pre-select

As a temporary kludge I replaced looking into the holdings for the piece type by figuring out which piece would belong on the clicked holdings square. This is a non-trivial process, as it depends on which pieces participate in a certain variant.
---
 backend.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/backend.c b/backend.c
index ff989cd..d782fb0 100644
--- a/backend.c
+++ b/backend.c
@@ -5206,7 +5206,13 @@ if(appData.debugMode) fprintf(debugFP, "moveType 1 = %d, promochar = %x\n", move
     /* [HGM] convert drag-and-drop piece drops to standard form */
     if( fromX == BOARD_LEFT-2 || fromX == BOARD_RGHT+1) {
          moveType = WhiteOnMove(currentMove) ? WhiteDrop : BlackDrop;
-         fromX = boards[currentMove][fromY][fromX];
+	   if(appData.debugMode) fprintf(debugFP, "Drop move %d, curr=%d, x=%d,y=%d, p=%d\n", 
+		moveType, currentMove, fromX, fromY, boards[currentMove][fromY][fromX]);
+//         fromX = boards[currentMove][fromY][fromX];
+	   // 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++; 
          fromY = DROP_RANK;
     }
 
-- 
1.7.0.4