From 2827780f4ce2a51ac7f5ea1a85040682597de2a2 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Thu, 25 Sep 2014 11:48:00 +0200 Subject: [PATCH] Reparse ambiguous move under built-in rules When a move parses as ambiguous under engine-defined piece locomotion, we re-parse it with XBoard's native idea of the pieces, just in case it is a move from a game that was saved without the engine having redefined the pieces. This keeps games created before the introduction of the 'piece' command loadable. --- backend.c | 1 - moves.c | 13 ++++++++++++- moves.h | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/backend.c b/backend.c index 605940e..e37d1eb 100644 --- a/backend.c +++ b/backend.c @@ -295,7 +295,6 @@ ChessSquare promoSweep = EmptySquare, defaultPromoChoice; int promoDefaultAltered; int keepInfo = 0; /* [HGM] to protect PGN tags in auto-step game analysis */ static int initPing = -1; -static Boolean pieceDefs; /* States for ics_getting_history */ #define H_FALSE 0 diff --git a/moves.c b/moves.c index 29638b8..32cabf7 100644 --- a/moves.c +++ b/moves.c @@ -170,6 +170,8 @@ CompareBoards (Board board1, Board board2) // [HGM] gen: configurable move generation from Betza notation sent by engine. +Boolean pieceDefs; + // alphabet "abcdefghijklmnopqrstuvwxyz" char symmetry[] = "FBNW.FFW.NKN.NW.QR....W..N"; char xStep[] = "2110.130.102.10.00....0..2"; @@ -532,7 +534,10 @@ GenPseudoLegal (Board board, int flags, MoveCallback callback, VOIDSTAR closure, if(PieceToChar(piece) == '~') piece = (ChessSquare) ( DEMOTED piece ); if(filter != EmptySquare && piece != filter) continue; - if(pieceDesc[piece]) { MovesFromString(board, flags, ff, rf, pieceDesc[piece], callback, closure); continue; } // [HGM] gen + if(pieceDefs && pieceDesc[piece]) { // [HGM] gen: use engine-defined moves + MovesFromString(board, flags, ff, rf, pieceDesc[piece], callback, closure); + continue; + } if(IS_SHOGI(gameInfo.variant)) piece = (ChessSquare) ( SHOGI piece ); @@ -1876,6 +1881,12 @@ Disambiguate (Board board, int flags, DisambiguateClosure *closure) return; } } + } else if(pieceDefs && closure->count > 1) { // [HGM] gen: move is ambiguous under engine-defined rules + DisambiguateClosure spare = *closure; + pieceDefs = FALSE; spare.count = 0; // See if the (erroneous) built-in rules would resolve that + GenLegal(board, flags, DisambiguateCallback, (VOIDSTAR) &spare, closure->pieceIn); + if(spare.count == 1) *closure = spare; // It does, so use those in stead (game from file saved before gen patch?) + pieceDefs = TRUE; } if (c == 'x') c = NULLCHAR; // get rid of any 'x' (which should never happen?) diff --git a/moves.h b/moves.h index db6df14..c08544e 100644 --- a/moves.h +++ b/moves.h @@ -63,6 +63,7 @@ extern char pieceToChar[(int)EmptySquare+1]; extern char pieceNickName[(int)EmptySquare]; extern char *pieceDesc[(int)EmptySquare]; extern Board initialPosition; +extern Boolean pieceDefs; typedef void (*MoveCallback) P((Board board, int flags, ChessMove kind, int rf, int ff, int rt, int ft, -- 1.7.0.4