From 734ccf35681fc778bd4cee4cd94df4e909b5a497 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Thu, 18 Sep 2014 23:08:36 +0200 Subject: [PATCH] Test legality even when off if engine defined pieces After reception of a piece command XBoard will mark target squares even when legality testing is off, and now also will require the lifted piece to land on a marked square (like when the engine highlighted them through a highlight command). A problem is that this does not work for drops, as drops do not mark target squares. So drops are always accepted. Which of course is bad for Pawn drops. But there really is no way yet for an engine to specify how pieces can be dropped, similar to the 'piece' command. --- backend.c | 23 ++++++++++++++++------- 1 files changed, 16 insertions(+), 7 deletions(-) diff --git a/backend.c b/backend.c index 88848ef..8278e5b 100644 --- a/backend.c +++ b/backend.c @@ -7261,8 +7261,8 @@ Mark (Board board, int flags, ChessMove kind, int rf, int ff, int rt, int ft, VO if(rf == fromY && ff == fromX && (killX < 0 && !(rt == rf && ft == ff) || abs(ft-killX) < 2 && abs(rt-killY) < 2)) (*m)[rt][ft] = 1 + (board[rt][ft] != EmptySquare || kind == WhiteCapturesEnPassant - || kind == BlackCapturesEnPassant) + 3*(kind == FirstLeg && killX < 0); - else if(flags & F_MANDATORY_CAPTURE && board[rt][ft] != EmptySquare) (*m)[rt][ft] = 3; + || kind == BlackCapturesEnPassant) + 3*(kind == FirstLeg && killX < 0), legal[rt][ft] = 1; + else if(flags & F_MANDATORY_CAPTURE && board[rt][ft] != EmptySquare) (*m)[rt][ft] = 3, legal[rt][ft] = 1; } static int hoverSavedValid; @@ -7354,7 +7354,7 @@ void ReportClick(char *action, int x, int y) char buf[MSG_SIZ]; // Inform engine of what user does int r, f; if(action[0] == 'l') // mark any target square of a lifted piece as legal to-square, clear markers - for(r=0; r= BOARD_LEFT && fromX < BOARD_RGHT && (x != killX || y != killY) && !sweepSelecting) { if(dragging) DragPieceEnd(xPix, yPix), dragging = 0; DisplayMessage(_("only marked squares are legal"),""); DrawPosition(TRUE, NULL); @@ -8887,9 +8888,17 @@ printf("score=%d count=%d\n",score,count); startedFromSetupPosition = TRUE; return; } - if(sscanf(message, "piece %c %s", &promoChar, buf1) == 2) { - ChessSquare piece = CharToPiece(promoChar); - if(piece < EmptySquare && !appData.testLegality) { ASSIGN(pieceDesc[piece], buf1); pieceDefs = TRUE; } + if(sscanf(message, "piece %s %s", buf2, buf1) == 2) { + ChessSquare piece = WhitePawn; + char *p=buf2; + if(cps != &first || appData.testLegality) return; + if(*p == '+') piece = CHUPROMOTED WhitePawn, p++; + piece += CharToPiece(*p) - WhitePawn; + if(piece < EmptySquare) { + pieceDefs = TRUE; + ASSIGN(pieceDesc[piece], buf1); + if(isupper(*p) && p[1] == '&') { ASSIGN(pieceDesc[WHITE_TO_BLACK piece], buf1); } + } return; } /* [HGM] Allow engine to set up a position. Don't ask me why one would -- 1.7.0.4