extern signed char initialRights[BOARD_FILES]; /* [HGM] all rights enabled, set in InitPosition */
int quickFlag;
char *pieceDesc[EmptySquare];
+char *defaultDesc[EmptySquare] = {
+ "fmWfceFifmnD", "N", "B", "R", "Q",
+ "F", "A", "BN", "RN", "W", "K",
+ "mRcpR", "N0", "BW", "RF", "gQ",
+ "", "", "QN", "", "N", "",
+ "", "", "", "", "",
+ "", "", "", "", "", "",
+ "", "", "", "", "",
+ "", "", "", "", "", "K"
+};
int
WhitePiece (ChessSquare piece)
int i=0;
ChessSquare start = (int)p >= (int)BlackPawn ? BlackPawn : WhitePawn;
- while(start++ != p) if(pieceToChar[(int)start-1] != '.') i++;
+ while(start++ != p) if(pieceToChar[start-1] != '.' && pieceToChar[start-1] != '+') i++;
return i;
}
return TRUE;
}
+char defaultName[] = "PNBRQ......................................K" // white
+ "pnbrq......................................k"; // black
+char shogiName[] = "PNBRLS...G.++++++..........................K" // white
+ "pnbrls...g.++++++..........................k"; // black
+char xqName[] = "PH.R.AE..K.C................................" // white
+ "ph.r.ae..k.c................................"; // black
+
+char *
+CollectPieceDescriptors ()
+{ // make a line of piece descriptions for use in the PGN Piece tag:
+ // dump all engine defined pieces, and pieces with non-standard names,
+ // but suppress black pieces that are the same as their white counterpart
+ ChessSquare p;
+ static char buf[MSG_SIZ];
+ char *m, c, d, *pieceName = defaultName;
+ int len;
+ *buf = NULLCHAR;
+ if(!pieceDefs) return "";
+ if(gameInfo.variant == VariantChu) return ""; // for now don't do this for Chu Shogi
+ if(gameInfo.variant == VariantShogi) pieceName = shogiName;
+ if(gameInfo.variant == VariantXiangqi) pieceName = xqName;
+ for(p=WhitePawn; p<EmptySquare; p++) {
+ if((c = pieceToChar[p]) == '.' || c == '~') continue; // does not participate
+ m = pieceDesc[p]; d = (c == '+' ? pieceToChar[DEMOTED p] : c);
+ if(p >= BlackPawn && pieceToChar[BLACK_TO_WHITE p] == toupper(c)
+ && (c != '+' || pieceToChar[DEMOTED BLACK_TO_WHITE p] == d)) { // black member of normal pair
+ char *wm = pieceDesc[BLACK_TO_WHITE p];
+ if(!m && !wm || m && wm && !strcmp(wm, m)) continue; // moves as a white piece
+ } else // white or unpaired black
+ if((p < BlackPawn || CharToPiece(toupper(d)) != EmptySquare) && // white or lone black
+ !pieceDesc[p] /*&& pieceName[p] == c*/) continue; // orthodox piece known by its usual name
+// TODO: listing pieces because of unusual name can only be done if we have accurate Betza of all defaults
+ if(!m) m = defaultDesc[p];
+ len = strlen(buf);
+ snprintf(buf+len, MSG_SIZ-len, "%s%s%c:%s", len ? ";" : "", c == '+' ? "+" : "", d, m);
+ }
+ return buf;
+}
+
// [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";
while(islower(*desc) && (i = dirType[*desc-'a']) != '0') {
int b = dirs2[*desc-'a']; // when alone, use narrow version
if(desc[1] == 'h') b = dirs1[*desc-'a'], desc += 2; // dirs1 is wide version
- else if(islower(desc[1]) && i < '4'
- && ((i | dirType[desc[1]-'a']) & 3) == 3) { // combinable (perpendicular dim)
+ else if(*desc == desc[1] || islower(desc[1]) && i < '4'
+ && ((i | dirType[desc[1]-'a']) & 3) == 3) { // combinable (perpendicular dim or same)
b = dirs1[*desc-'a'] & dirs2[desc[1]-'a']; // intersect wide & perp narrow
desc += 2;
} else desc++;
if(*desc == 'c') mode |= his, desc++;
if(*desc == 'd') mode |= mine, desc++;
if(*desc == 'e') mode |= 8, desc++;
+ if(!mode) mode = his + 4;// no mode spec, use default = mc
+ if(*desc == 'p') mode |= 32, desc++;
+ if(*desc == 'g') mode |= 64, desc++;
+ if(*desc == 'o') mode |= 128, desc++;
if(*desc == 'n') jump = 0, desc++;
while(*desc == 'j') jump++, desc++;
- if(!mode) mode = his + 4;// no mode spec, use default = mc
dx = xStep[*p-'A'] - '0'; // step vector of atom
dy = yStep[*p-'A'] - '0';
if(isdigit(*++p)) expo = atoi(p++); // read exponent
if(expo > 9) p++; // allow double-digit
desc = p; // this is start of next move
- if(initial && board[r][f] != initialPosition[r][f]) continue;
+ if(initial && (board[r][f] != initialPosition[r][f] ||
+ r == 0 && board[TOUCHED_W] & 1<<f ||
+ r == BOARD_HEIGHT-1 && board[TOUCHED_B] & 1<<f ) ) continue;
if(expo > 1 && dx == 0 && dy == 0) { // castling indicated by O + number
mode |= 16; dy = 1;
}
do {
for(dir=0, bit=1; dir<8; dir++, bit += bit) { // loop over directions
- int i = expo, vx, vy;
+ int i = expo, hop = mode, vx, vy;
if(!(bit & dirSet)) continue; // does not move in this direction
vx = dx*rot[dir][0] + dy*rot[dir][1]; // rotate step vector
vy = dx*rot[dir][2] + dy*rot[dir][3];
x = f; y = r; // start square
do {
x += vx; y += vy; // step to next square
- if(y < 0 || y >= BOARD_HEIGHT || x < BOARD_LEFT || x >= BOARD_RGHT) break;
+ if(y < 0 || y >= BOARD_HEIGHT) break; // vertically off-board: always done
+ if(x < BOARD_LEFT) { if(mode & 128) x += BOARD_RGHT - BOARD_LEFT; else break; }
+ if(x >= BOARD_RGHT) { if(mode & 128) x -= BOARD_RGHT - BOARD_LEFT; else break; }
if(!jump && board[y - vy + vy/2][x - vx + vx/2] != EmptySquare) break; // blocked
if(jump > 1 && board[y - vy + vy/2][x - vx + vx/2] == EmptySquare) break; // no hop
if(board[y][x] < BlackPawn) occup = 1; else
if(board[y][x] < EmptySquare) occup = 2; else
occup = 4;
+ if(hop & 32+64) { if(occup != 4) { if(hop & 64 && i != 1) i = 2; hop &= 31; } continue; } // hopper
if(mode & 8 && y == board[EP_RANK] && occup == 4 && board[EP_FILE] == x) { // to e.p. square
cb(board, flags, mine == 1 ? WhiteCapturesEnPassant : BlackCapturesEnPassant, r, f, y, x, cl);
}
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 );
(cl->rtIn == -1 || cl->rtIn == rt || wildCard) &&
(cl->ftIn == -1 || cl->ftIn == ft || wildCard)) {
+ if(cl->count && rf == cl->rf && ff == cl->ff) return; // duplicate move
+
cl->count++;
if(cl->count == 1 || board[rt][ft] != EmptySquare) {
// [HGM] oneclick: if multiple moves, be sure we remember capture
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?)