From 2737a903d524d4aaaca2d16fb518f70a3e9b83d1 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Tue, 1 Oct 2013 22:27:54 +0200 Subject: [PATCH] Fix reading of SAN Lion double moves Notations like Lxb2xc3 and Lxb2-c2 are now understood by the parser, albeit in a frail way. (No error recovery...) --- backend.c | 9 ++++++++- parser.c | 12 +++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/backend.c b/backend.c index 48a32a4..4c2afbc 100644 --- a/backend.c +++ b/backend.c @@ -5402,6 +5402,7 @@ ParseOneMove (char *move, int moveNum, ChessMove *moveType, int *fromX, int *fro case WhiteNonPromotion: case BlackNonPromotion: case NormalMove: + case FirstLeg: case WhiteCapturesEnPassant: case BlackCapturesEnPassant: case WhiteKingSideCastle: @@ -9497,6 +9498,7 @@ ParseGameHistory (char *game) case WhiteNonPromotion: case BlackNonPromotion: case NormalMove: + case FirstLeg: case WhiteCapturesEnPassant: case BlackCapturesEnPassant: case WhiteKingSideCastle: @@ -10897,7 +10899,7 @@ GameEnds (ChessMove result, char *resultDetails, int whosays) result, resultDetails ? resultDetails : "(null)", whosays); } - fromX = fromY = -1; // [HGM] abort any move the user is entering. + fromX = fromY = killX = killY = -1; // [HGM] abort any move the user is entering. // [HGM] lion if(pausing) PauseEvent(); // can happen when we abort a paused game (New Game or Quit) @@ -11393,6 +11395,7 @@ Reset (int redraw, int init) ClearPremoveHighlights(); gotPremove = FALSE; alarmSounded = FALSE; + killX = killY = -1; // [HGM] lion GameEnds(EndOfFile, NULL, GE_PLAYER); if(appData.serverMovesName != NULL) { @@ -11573,6 +11576,7 @@ LoadGameOneMove (ChessMove readAhead) case WhiteNonPromotion: case BlackNonPromotion: case NormalMove: + case FirstLeg: case WhiteKingSideCastle: case WhiteQueenSideCastle: case BlackKingSideCastle: @@ -12257,6 +12261,7 @@ GameContainsPosition (FILE *f, ListGame *lg) case WhiteNonPromotion: case BlackNonPromotion: case NormalMove: + case FirstLeg: case WhiteKingSideCastle: case WhiteQueenSideCastle: case BlackKingSideCastle: @@ -12321,6 +12326,7 @@ LoadGame (FILE *f, int gameNumber, char *title, int useList) if (gameMode != BeginningOfGame) { Reset(FALSE, TRUE); } + killX = killY = -1; // [HGM] lion: in case we did not Reset gameFileFP = f; if (lastLoadGameFP != NULL && lastLoadGameFP != f) { @@ -12474,6 +12480,7 @@ LoadGame (FILE *f, int gameNumber, char *title, int useList) break; case NormalMove: + case FirstLeg: /* Only a NormalMove can be at the start of a game * without a position diagram. */ if (lastLoadGameStart == EndOfFile ) { diff --git a/parser.c b/parser.c index ada3509..c6172fc 100644 --- a/parser.c +++ b/parser.c @@ -154,7 +154,7 @@ PromoSuffix (char **p) if(**p == '+' && IS_SHOGI(gameInfo.variant)) { (*p)++; return '+'; } if(**p == '=' || (gameInfo.variant == VariantSChess) && **p == '/') (*p)++; // optional = (or / for Seirawan gating) if(**p == '(' && (*p)[2] == ')' && isalpha( (*p)[1] )) { (*p) += 3; return ToLower((*p)[-2]); } - if(isalpha(**p)) return ToLower(*(*p)++); + if(isalpha(**p) && **p != 'x') return ToLower(*(*p)++); // reserve 'x' for multi-leg captures? if(*p != start) return '='; // must be the optional = return NULLCHAR; // no suffix detected } @@ -275,6 +275,15 @@ NextUnit (char **p) fromY = (currentMoveString[1] = coord[1] + '0') - ONE; currentMoveString[4] = cl.promoCharIn = PromoSuffix(p); currentMoveString[5] = NULLCHAR; + if(!cl.promoCharIn && (**p == '-' || **p == 'x')) { // Lion-type multi-leg move + currentMoveString[5] = (killX = toX) + AAA; // what we thought was to-square is in fact kill-square + currentMoveString[6] = (killY = toY) + ONE; // append it as suffix behind long algebraic move + currentMoveString[4] = ';'; + currentMoveString[7] = NULLCHAR; + // read new to-square (VERY non-robust! Assumes correct (non-alpha-rank) syntax, and messes up on errors) + toX = cl.ftIn = (currentMoveString[2] = *++*p) - AAA; ++*p; + toY = cl.rtIn = (currentMoveString[3] = Number(p) + '0') - ONE; + } if(type[0] != NOTHING && type[1] != NOTHING && type[3] != NOTHING) { // fully specified. // Note that Disambiguate does not work for illegal moves, but flags them as impossible if(piece) { // check if correct piece indicated @@ -317,6 +326,7 @@ NextUnit (char **p) currentMoveString[0] = cl.ff + AAA; currentMoveString[1] = cl.rf + ONE; currentMoveString[3] = cl.rt + ONE; + if(killX < 0) // [HGM] lion: do not overwrite kill-square suffix currentMoveString[4] = cl.promoChar; if((cl.kind == WhiteCapturesEnPassant || cl.kind == BlackCapturesEnPassant) && (Match("ep", p) || Match("e.p.", p))); -- 1.7.0.4