X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=moves.c;h=843593d30c370810aa6d3fb97d73449610636047;hb=f6e0ba4110818a2785aa480eaa05836b742e9992;hp=1849fced49e40730b616d6c2a70bde996557cca1;hpb=0deaf903dc63c9837413a352d92108b93e74d5e3;p=xboard.git diff --git a/moves.c b/moves.c index 1849fce..843593d 100644 --- a/moves.c +++ b/moves.c @@ -5,7 +5,8 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc. + * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free + * Software Foundation, Inc. * * Enhancements Copyright 2005 Alessandro Scotti * @@ -126,7 +127,7 @@ char PieceToChar (ChessSquare p) { int c; - if((int)p < 0 || (int)p >= (int)EmptySquare) return('x'); /* [HGM] for safety */ + if((int)p < 0 || (int)p >= (int)EmptySquare) return('?'); /* [HGM] for safety */ c = pieceToChar[(int) p]; if(c & 128) c = c & 63 | 64; return c; @@ -205,8 +206,8 @@ CollectPieceDescriptors () // but suppress black pieces that are the same as their white counterpart ChessSquare p; static char buf[MSG_SIZ], s[2]; - char *m, c, d, *pieceName = defaultName; - int len; + char *m, *pieceName = defaultName; + int len, c, d; *buf = NULLCHAR; if(!pieceDefs) return ""; if(gameInfo.variant == VariantChu) return ""; // for now don't do this for Chu Shogi @@ -232,6 +233,38 @@ CollectPieceDescriptors () return buf; } +int +LoadPieceDesc (char *s) +{ + ChessSquare piece; + static char suf[] = SUFFIXES; + char *r, *p, *q = s; + int ok = TRUE, promoted, c; + while(q && *s) { + p = s; + q = strchr(s, ';'); + if(q) *q = 0, s = q+1; + if(*p == '+') promoted = 1, p++; else promoted = 0; + c = *p++; + if(!c) { ok = FALSE; continue; } // bad syntax + if(*p && (r = strchr(suf, *p))) c += 64*(r - suf + 1), p++; + if(*p++ != ':') { ok = FALSE; continue; } // bad syntax + if(!strcmp(p, "(null)")) continue; // handle bug in writing of XBoard 4.8.0 + piece = CharToPiece(c); + if(piece >= EmptySquare) { ok = FALSE; continue; } // non-existent piece + if(promoted) { + piece = promoPartner[piece]; + if(pieceToChar[piece] != '+') { ok = FALSE; continue; } // promoted form does not exist + } + ASSIGN(pieceDesc[piece], p); + if(piece < BlackPawn && (pieceToChar[WHITE_TO_BLACK piece] == pieceToChar[piece] + 32 || promoted)) { + ASSIGN(pieceDesc[WHITE_TO_BLACK piece], p); + } + pieceDefs = TRUE; + } + return ok; +} + // [HGM] gen: configurable move generation from Betza notation sent by engine. // Some notes about two-leg moves: GenPseudoLegal() works in two modes, depending on whether a 'kill- // square has been set: without one is generates all moves, and a global int legNr flags in bits 0 and 1 @@ -427,11 +460,14 @@ MovesFromString (Board board, int flags, int f, int r, int tx, int ty, int angle if(!(bit & all)) *atom = rotate[*atom - 'A']; // orth-diag interconversion to make direction valid if(occup & mode & 0x104) // no side effects, merge legs to one move MovesFromString(board, flags, f, r, x, y, dir, cont, cb, cl); - if(occup & mode & 3 && (killX < 0 || killX == x && killY == y)) { // destructive first leg + if(occup & mode & 3 && (killX < 0 || kill2X < 0 && (legNr > 1 || killX == x && killY == y) || + (legNr == 1 ? kill2X == x && kill2Y == y : killX == x && killY == y))) { // destructive first leg int cnt = 0; + legNr <<= 1; MovesFromString(board, flags, f, r, x, y, dir, cont, &OK, &cnt); // count possible continuations + legNr >>= 1; if(cnt) { // and if there are - if(killX < 0) cb(board, flags, FirstLeg, r, f, y, x, cl); // then generate their first leg + if(legNr & 1 ? killX < 0 : kill2X < 0) cb(board, flags, FirstLeg, r, f, y, x, cl); // then generate their first leg legNr <<= 1; MovesFromString(board, flags, f, r, x, y, dir, cont, cb, cl); legNr >>= 1; @@ -1644,7 +1680,7 @@ CheckTest (Board board, int flags, int rf, int ff, int rt, int ft, int enPassant { CheckTestClosure cl; ChessSquare king = flags & F_WHITE_ON_MOVE ? WhiteKing : BlackKing; - ChessSquare captured = EmptySquare, ep=0, trampled=0; + ChessSquare captured = EmptySquare, ep=0, trampled=0, trampled2 = 0; int saveKill = killX; /* Suppress warnings on uninitialized variables */ @@ -1669,7 +1705,10 @@ CheckTest (Board board, int flags, int rf, int ff, int rt, int ft, int enPassant board[rf][ft] = EmptySquare; } else { captured = board[rt][ft]; - if(killX >= 0) { trampled = board[killY][killX]; board[killY][killX] = EmptySquare; killX = -1; } + if(killX >= 0) { + trampled = board[killY][killX]; board[killY][killX] = EmptySquare; killX = -1; saveKill += (kill2X << 16) + (1 << 30); + if(kill2X >= 0) { trampled2 = board[kill2Y][kill2X]; board[kill2Y][kill2X] = EmptySquare; kill2X = -1; } + } } if(rf == DROP_RANK) board[rt][ft] = ff; else { // [HGM] drop board[rt][ft] = board[rf][ff]; @@ -1718,7 +1757,10 @@ CheckTest (Board board, int flags, int rf, int ff, int rt, int ft, int enPassant board[rf][ft] = captured; board[rt][ft] = EmptySquare; } else { - if(saveKill >= 0) board[killY][killX = saveKill] = trampled; + if(saveKill >= 0) { + if(saveKill & 1<<30) board[kill2Y][kill2X = saveKill >> 16 & 0xFFF] = trampled2; + board[killY][killX = saveKill & 0xFFF] = trampled; + } board[rt][ft] = captured; } board[EP_STATUS] = ep;