X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=moves.c;h=a66c2e0a0868fe288bc4422aa89dbcfeb4f4de00;hb=0bf664e507241790adc9f419b24be4d1d5963b28;hp=5c265a690332ada9d2199df18b96a14904346b5d;hpb=f667c02d582c1a09d2a2f5e0b048fdb13c072777;p=xboard.git diff --git a/moves.c b/moves.c index 5c265a6..a66c2e0 100644 --- a/moves.c +++ b/moves.c @@ -114,19 +114,32 @@ SameColor (ChessSquare piece1, ChessSquare piece2) #define SameColor(piece1, piece2) (piece1 < EmptySquare && piece2 < EmptySquare && (piece1 < BlackPawn) == (piece2 < BlackPawn) || piece1 == DarkSquare || piece2 == DarkSquare) #endif -char pieceToChar[] = { +unsigned char pieceToChar[EmptySquare+1] = { 'P', 'N', 'B', 'R', 'Q', 'F', 'E', 'A', 'C', 'W', 'M', 'O', 'H', 'I', 'J', 'G', 'D', 'V', 'L', 'S', 'U', 'K', 'p', 'n', 'b', 'r', 'q', 'f', 'e', 'a', 'c', 'w', 'm', 'o', 'h', 'i', 'j', 'g', 'd', 'v', 'l', 's', 'u', 'k', 'x' }; -char pieceNickName[EmptySquare]; +unsigned char pieceNickName[EmptySquare]; char PieceToChar (ChessSquare p) { + int c; if((int)p < 0 || (int)p >= (int)EmptySquare) return('x'); /* [HGM] for safety */ - return pieceToChar[(int) p]; + c = pieceToChar[(int) p]; + if(c & 128) c = c & 63 | 64; + return c; +} + +char +PieceSuffix (ChessSquare p) +{ + int c; + if((int)p < 0 || (int)p >= (int)EmptySquare) return 0; /* [HGM] for safety */ + c = pieceToChar[(int) p]; + if(c < 128) return 0; + return SUFFIXES[c - 128 >> 6]; } int @@ -1973,6 +1986,7 @@ DisambiguateCallback (Board board, int flags, ChessMove kind, int rf, int ff, in { register DisambiguateClosure *cl = (DisambiguateClosure *) closure; int wildCard = FALSE; ChessSquare piece = board[rf][ff]; + extern int kifu; // in parser.c // [HGM] wild: for wild-card pieces rt and rf are dummies if(piece == WhiteFalcon || piece == BlackFalcon || @@ -1990,6 +2004,18 @@ DisambiguateCallback (Board board, int flags, ChessMove kind, int rf, int ff, in if(cl->count && rf == cl->rf && ff == cl->ff) return; // duplicate move + if(cl->count == 1 && kifu & 0x7E && cl->rfIn == -1 && cl->ffIn == -1) { // traditional Shogi disambiguation required + int this = 1, other = 1; + if(kifu & 2) this &= (flags & 1 ? rt > rf : rt < rf), other &= (flags & 1 ? cl->rt > cl->rf : cl->rt < cl->rf); + if(kifu & 4) this &= (flags & 1 ? rt < rf : rt > rf), other &= (flags & 1 ? cl->rt < cl->rf : cl->rt > cl->rf); + if(kifu & 8) this &= (rf == rt), other &= (cl->rt == cl->rf); + if(kifu & 0x10) this &= (flags & 1 ? ft <= ff : ft >= ff), other &= (flags & 1 ? cl->ft <= cl->ff : cl->ft >= cl->ff); + if(kifu & 0x20) this &= (flags & 1 ? ft >= ff : ft <= ff), other &= (flags & 1 ? cl->ft >= cl->ff : cl->ft <= cl->ff); + if(kifu & 0x40) this &= (ft == ff), other &= (cl->ft == cl->ff); // should never be used + if(!other) cl->count--; // the old move did not satisfy the requested relative position, erase it + if(!this) return; // the current move does not satisfy the requested relative position, ignore it + } + cl->count++; if(cl->count == 1 || board[rt][ft] != EmptySquare) { // [HGM] oneclick: if multiple moves, be sure we remember capture @@ -2326,6 +2352,7 @@ CoordsToAlgebraic (Board board, int flags, int rf, int ff, int rt, int ft, int p } if(c=='+') *outp++ = c; *outp++ = ToUpper(PieceToChar(piece)); + if(*outp = PieceSuffix(piece)) outp++; if (cl.file || (cl.either && !cl.rank)) { *outp++ = ff + AAA;