These macros were expanding to offsets added to what followed them.
Now the thing that followed them is passed to them as an argument.
This will allow them to expand the prmomotion or demotion to a table
lookup, rather than just an addition. Where PROMOTED appeared in a case
label, though, it was just a readability enhancement for the fixed
assignment, and a new macro PROMO equal to the old PROMOTED is introduced
for that.
if(fromY == DROP_RANK && k==toY && j==toX) continue; // dropped pieces always stand for themselves
old = (k==toY && j==toX) ? boards[moveNum-1][fromY][fromX] : boards[moveNum-1][k][j]; // trace back mover
if(old == new) continue;
- if(old == PROMOTED new) boards[moveNum][k][j] = old; // prevent promoted pieces to revert to primordial ones
+ if(old == PROMOTED(new)) boards[moveNum][k][j] = old;// prevent promoted pieces to revert to primordial ones
else if(new == WhiteWazir || new == BlackWazir) {
if(old < WhiteCannon || old >= BlackPawn && old < BlackCannon)
- boards[moveNum][k][j] = PROMOTED old; // choose correct type of Gold in promotion
+ boards[moveNum][k][j] = PROMOTED(old); // choose correct type of Gold in promotion
else boards[moveNum][k][j] = old; // preserve type of Gold
} else if((old == WhitePawn || old == BlackPawn) && new != EmptySquare) // Pawn promotions (but not e.p.capture!)
- boards[moveNum][k][j] = PROMOTED new; // use non-primordial representation of chosen piece
+ boards[moveNum][k][j] = PROMOTED(new); // use non-primordial representation of chosen piece
}
} else {
/* Move from ICS was illegal!? Punt. */
else snprintf(message, MSG_SIZ, "%c%c%d\n", PieceToChar(*bp), AAA + j, ONE + i - '0');
if(message[0] == '+' || message[0] == '~') {
snprintf(message, MSG_SIZ,"%c%c%d+\n",
- PieceToChar((ChessSquare)(DEMOTED *bp)),
+ PieceToChar((ChessSquare)(DEMOTED(*bp))),
AAA + j, ONE + i - '0');
}
if(cps->alphaRank) { /* [HGM] shogi: translate coords */
AAA + j, ONE + i - '0');
if(message[0] == '+' || message[0] == '~') {
snprintf(message, MSG_SIZ,"%c%c%d+\n",
- PieceToChar((ChessSquare)(DEMOTED *bp)),
+ PieceToChar((ChessSquare)(DEMOTED(*bp))),
AAA + j, ONE + i - '0');
}
if(cps->alphaRank) { /* [HGM] shogi: translate coords */
if(!appData.pieceMenu && toX == fromX && toY == fromY && boards[0][rf][ff] != EmptySquare) {
ChessSquare q, p = boards[0][rf][ff];
if(p >= BlackPawn) p = BLACK_TO_WHITE p;
- if(CHUPROMOTED p < BlackPawn) p = q = CHUPROMOTED boards[0][rf][ff];
+ if(CHUPROMOTED(p) < BlackPawn) p = q = CHUPROMOTED(boards[0][rf][ff]);
else p = CHUDEMOTED (q = boards[0][rf][ff]);
if(PieceToChar(q) == '+') gatingPiece = p;
}
if(legal[y][x] == 2 || HasPromotionChoice(fromX, fromY, toX, toY, &promoChoice, FALSE)) {
if(appData.sweepSelect) {
promoSweep = defaultPromoChoice;
- if(gameInfo.variant != VariantChuChess && PieceToChar(CHUPROMOTED piece) == '+') promoSweep = CHUPROMOTED piece;
+ if(gameInfo.variant != VariantChuChess && PieceToChar(CHUPROMOTED(piece)) == '+') promoSweep = CHUPROMOTED(piece);
selectFlag = 0; lastX = xPix; lastY = yPix;
ReportClick("put", x, y); // extra put to prompt engine for 'choice' command
Sweep(0); // Pawn that is going to promote: preview promotion piece
if(sscanf(message, "piece %s %s", buf2, buf1) == 2) {
ChessSquare piece = WhitePawn;
char *p=message+6, *q, *s = SUFFIXES, ID = *p;
- if(*p == '+') piece = CHUPROMOTED WhitePawn, ID = *++p;
+ if(*p == '+') piece = CHUPROMOTED(WhitePawn), ID = *++p;
if(q = strchr(s, p[1])) ID += 64*(q - s + 1), p++;
piece += CharToPiece(ID & 255) - WhitePawn;
if(cps != &first || appData.testLegality && *engineVariant == NULLCHAR
) {
/* white pawn promotion */
board[toY][toX] = CharToPiece(ToUpper(promoChar));
- if(board[toY][toX] < WhiteCannon && PieceToChar(PROMOTED board[toY][toX]) == '~') /* [HGM] use shadow piece (if available) */
- board[toY][toX] = (ChessSquare) (PROMOTED board[toY][toX]);
+ if(board[toY][toX] < WhiteCannon && PieceToChar(PROMOTED(board[toY][toX])) == '~') /* [HGM] use shadow piece (if available) */
+ board[toY][toX] = (ChessSquare) (PROMOTED(board[toY][toX]));
board[fromY][fromX] = EmptySquare;
} else if ((fromY >= BOARD_HEIGHT>>1)
&& (oldEP == toX || oldEP == EP_UNKNOWN || appData.testLegality || abs(toX - fromX) > 4)
) {
/* black pawn promotion */
board[toY][toX] = CharToPiece(ToLower(promoChar));
- if(board[toY][toX] < BlackCannon && PieceToChar(PROMOTED board[toY][toX]) == '~') /* [HGM] use shadow piece (if available) */
- board[toY][toX] = (ChessSquare) (PROMOTED board[toY][toX]);
+ if(board[toY][toX] < BlackCannon && PieceToChar(PROMOTED(board[toY][toX])) == '~') /* [HGM] use shadow piece (if available) */
+ board[toY][toX] = (ChessSquare) (PROMOTED(board[toY][toX]));
board[fromY][fromX] = EmptySquare;
} else if ((fromY < BOARD_HEIGHT>>1)
&& (oldEP == toX || oldEP == EP_UNKNOWN || appData.testLegality || abs(toX - fromX) > 4)
p = (int) captured;
if (p >= (int) BlackPawn) {
p -= (int)BlackPawn;
- if(DEMOTED p >= 0 && PieceToChar(p) == '+') {
+ if(DEMOTED(p) >= 0 && PieceToChar(p) == '+') {
/* Restore shogi-promoted piece to its original first */
- captured = (ChessSquare) (DEMOTED captured);
- p = DEMOTED p;
+ captured = (ChessSquare) (DEMOTED(captured));
+ p = DEMOTED(p);
}
p = PieceToNumber((ChessSquare)p);
if(p >= gameInfo.holdingsSize) { p = 0; captured = BlackPawn; }
board[p][BOARD_WIDTH-1] = BLACK_TO_WHITE captured;
} else {
p -= (int)WhitePawn;
- if(DEMOTED p >= 0 && PieceToChar(p) == '+') {
- captured = (ChessSquare) (DEMOTED captured);
- p = DEMOTED p;
+ if(DEMOTED(p) >= 0 && PieceToChar(p) == '+') {
+ captured = (ChessSquare) (DEMOTED(captured));
+ p = DEMOTED(p);
}
p = PieceToNumber((ChessSquare)p);
if(p >= gameInfo.holdingsSize) { p = 0; captured = WhitePawn; }
} else
if(promoChar == '+') {
/* [HGM] Shogi-style promotions, to piece implied by original (Might overwrite ordinary Pawn promotion) */
- board[toY][toX] = (ChessSquare) (CHUPROMOTED piece);
+ board[toY][toX] = (ChessSquare) (CHUPROMOTED(piece));
if(gameInfo.variant == VariantChuChess && (piece == WhiteKnight || piece == BlackKnight))
board[toY][toX] = piece + WhiteLion - WhiteKnight; // adjust Knight promotions to Lion
} else if(!appData.testLegality && promoChar != NULLCHAR && promoChar != '=') { // without legality testing, unconditionally believe promoChar
ChessSquare newPiece = CharToPiece(piece < BlackPawn ? ToUpper(promoChar) : ToLower(promoChar));
- if((newPiece <= WhiteMan || newPiece >= BlackPawn && newPiece <= BlackMan) // unpromoted piece specified
- && pieceToChar[PROMOTED newPiece] == '~') newPiece = PROMOTED newPiece; // but promoted version available
+ if((newPiece <= WhiteMan || newPiece >= BlackPawn && newPiece <= BlackMan) // unpromoted piece specified
+ && pieceToChar[PROMOTED(newPiece)] == '~') newPiece = PROMOTED(newPiece);// but promoted version available
board[toY][toX] = newPiece;
}
if((gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat || gameInfo.variant == VariantGrand)
case PromotePiece:
if(piece >= (int)WhitePawn && piece < (int)WhiteMan ||
piece >= (int)BlackPawn && piece < (int)BlackMan ) {
- selection = (ChessSquare) (PROMOTED piece);
+ selection = (ChessSquare) (PROMOTED(piece));
} else if(piece == EmptySquare) selection = WhiteSilver;
else selection = (ChessSquare)((int)piece - 1);
goto defaultlabel;
case DemotePiece:
if(piece > (int)WhiteMan && piece <= (int)WhiteKing ||
piece > (int)BlackMan && piece <= (int)BlackKing ) {
- selection = (ChessSquare) (DEMOTED piece);
+ selection = (ChessSquare) (DEMOTED(piece));
} else if(piece == EmptySquare) selection = BlackSilver;
else selection = (ChessSquare)((int)piece + 1);
goto defaultlabel;
if(PieceToChar(piece) == '+') {
/* [HGM] write promoted pieces as '+<unpromoted>' (Shogi) */
*p++ = '+';
- piece = (ChessSquare)(CHUDEMOTED piece);
+ piece = (ChessSquare)(CHUDEMOTED(piece));
}
*p++ = (piece == DarkSquare ? '*' : PieceToChar(piece));
if(*p = PieceSuffix(piece)) p++;
if(p[-1] == '~') {
/* [HGM] flag promoted pieces as '<promoted>~' (Crazyhouse) */
- p[-1] = PieceToChar((ChessSquare)(CHUDEMOTED piece));
+ p[-1] = PieceToChar((ChessSquare)(CHUDEMOTED(piece)));
*p++ = '~';
}
}
if(q = strchr(s, p[1])) p++;
piece = CharToPiece(c + (q ? 64*(q - s + 1) : 0));
if(piece == EmptySquare) return FALSE; /* unknown piece */
- piece = (ChessSquare) (CHUPROMOTED piece ); p++;
+ piece = (ChessSquare) (CHUPROMOTED(piece)); p++;
if(PieceToChar(piece) != '+') return FALSE; /* unpromotable piece */
} else {
char c = *p++;
if(piece==EmptySquare) return FALSE; /* unknown piece */
if(*p == '~') { /* [HGM] make it a promoted piece for Crazyhouse */
- piece = (ChessSquare) (PROMOTED piece);
+ piece = (ChessSquare) (PROMOTED(piece));
if(PieceToChar(piece) != '~') return FALSE; /* cannot be a promoted piece */
p++;
}
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);
+ 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
+ && (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 ((flags & F_WHITE_ON_MOVE) != (board[rf][ff] < BlackPawn)) continue; // [HGM] speed: wrong color
m = 0; piece = board[rf][ff];
if(PieceToChar(piece) == '~')
- piece = (ChessSquare) ( DEMOTED piece );
+ piece = (ChessSquare) ( DEMOTED(piece) );
if(filter != EmptySquare && piece != filter) continue;
if(pieceDefs && pieceDesc[piece]) { // [HGM] gen: use engine-defined moves
MovesFromString(board, flags, ff, rf, -1, -1, 0, pieceDesc[piece], callback, closure);
/* Gold General (and all its promoted versions) . First do the */
/* diagonal forward steps, then proceed as normal Wazir */
- case SHOGI (PROMOTED WhitePawn):
+ case SHOGI (PROMO WhitePawn):
if(gameInfo.variant == VariantShogi) goto WhiteGold;
- case SHOGI (PROMOTED BlackPawn):
+ case SHOGI (PROMO BlackPawn):
if(gameInfo.variant == VariantShogi) goto BlackGold;
SlideVertical(board, flags, rf, ff, callback, closure);
break;
- case SHOGI (PROMOTED WhiteKnight):
+ case SHOGI (PROMO WhiteKnight):
if(gameInfo.variant == VariantShogi) goto WhiteGold;
case SHOGI BlackDrunk:
case SHOGI BlackAlfil:
StepBackward(board, flags, rf, ff, callback, closure);
break;
- case SHOGI (PROMOTED BlackKnight):
+ case SHOGI (PROMO BlackKnight):
if(gameInfo.variant == VariantShogi) goto BlackGold;
case SHOGI WhiteDrunk:
case SHOGI WhiteAlfil:
StepSideways(board, flags, rf, ff, callback, closure);
break;
- case SHOGI (PROMOTED WhiteQueen):
+ case SHOGI (PROMO WhiteQueen):
case SHOGI WhiteTokin:
case SHOGI WhiteWazir:
WhiteGold:
Wazir(board, flags, rf, ff, callback, closure);
break;
- case SHOGI (PROMOTED BlackQueen):
+ case SHOGI (PROMO BlackQueen):
case SHOGI BlackTokin:
case SHOGI BlackWazir:
BlackGold:
StepVertical(board, flags, rf, ff, callback, closure);
break;
- case SHOGI (PROMOTED WhiteFerz):
+ case SHOGI (PROMO WhiteFerz):
if(gameInfo.variant == VariantShogi) goto WhiteGold;
- case SHOGI (PROMOTED BlackFerz):
+ case SHOGI (PROMO BlackFerz):
if(gameInfo.variant == VariantShogi) goto BlackGold;
case SHOGI WhitePSword:
case SHOGI BlackPSword:
if(quickFlag) flags = flags & ~1 | quickFlag & 1; // [HGM] speed: in quick mode quickFlag specifies side-to-move.
if(rf == DROP_RANK) return LegalDrop(board, flags, ff, rt, ft);
piece = filterPiece = board[rf][ff];
- if(PieceToChar(piece) == '~') filterPiece = DEMOTED piece;
+ if(PieceToChar(piece) == '~') filterPiece = DEMOTED(piece);
/* [HGM] Cobra and Falcon are wildcard pieces; consider all their moves legal */
/* (perhaps we should disallow moves that obviously leave us in check?) */
if(cl.kind != NormalMove || promoChar == NULLCHAR || promoChar == '=') return cl.kind;
if(promoChar != '+')
return CharToPiece(promoChar) == EmptySquare ? ImpossibleMove : IllegalMove;
- if(PieceToChar(CHUPROMOTED board[rf][ff]) != '+') {
+ if(PieceToChar(CHUPROMOTED(board[rf][ff])) != '+') {
if(PieceToChar(CHUPROMOTED (board[rf][ff] < BlackPawn ? WhitePawn : BlackPawn)) != '.')
return ImpossibleMove;
}
// should test if in zone, really
if(gameInfo.variant == VariantChuChess && (piece == WhiteKnight || piece == BlackKnight) && HasLion(board, flags))
return IllegalMove;
- if(PieceToChar(PROMOTED piece) == '+') return flags & F_WHITE_ON_MOVE ? WhitePromotion : BlackPromotion;
+ if(PieceToChar(PROMOTED(piece)) == '+') return flags & F_WHITE_ON_MOVE ? WhitePromotion : BlackPromotion;
} else
if(promoChar == '=') cl.kind = IllegalMove; else // [HGM] shogi: no deferred promotion outside Shogi
if (cl.kind == WhitePromotion || cl.kind == BlackPromotion) {
if ((cl->pieceIn == EmptySquare || cl->pieceIn == board[rf][ff]
|| PieceToChar(board[rf][ff]) == '~'
- && cl->pieceIn == (ChessSquare)(DEMOTED board[rf][ff])
+ && cl->pieceIn == (ChessSquare)(DEMOTED(board[rf][ff]))
) &&
(cl->rfIn == -1 || cl->rfIn == rf) &&
(cl->ffIn == -1 || cl->ffIn == ff) &&
else if(c == 'l' && gameInfo.variant == VariantChuChess && HasLion(board, flags)) closure->kind = IllegalMove;
} else if (c == '+') { // '+' outside shogi, check if pieceToCharTable enabled it
ChessSquare p = closure->piece;
- if(p > WhiteMan && p < BlackPawn || p > BlackMan || PieceToChar(PROMOTED p) != '+')
+ if(p > WhiteMan && p < BlackPawn || p > BlackMan || PieceToChar(PROMOTED(p)) != '+')
closure->kind = ImpossibleMove; // used on non-promotable piece
else if(gameInfo.variant == VariantChuChess && HasLion(board, flags)) closure->kind = IllegalMove;
} else if (c != NULLCHAR) closure->kind = IllegalMove;
if ((rt == cl->rt && ft == cl->ft || rt == rf && ft == ff) && // [HGM] null move matches any toSquare
(board[rf][ff] == cl->piece
|| PieceToChar(board[rf][ff]) == '~' &&
- (ChessSquare) (DEMOTED board[rf][ff]) == cl->piece)
+ (ChessSquare) (DEMOTED(board[rf][ff])) == cl->piece)
) {
if (rf == cl->rf) {
if (ff == cl->ff) {
if (promoChar == 'x') promoChar = NULLCHAR;
piece = board[rf][ff];
- if(PieceToChar(piece)=='~') piece = (ChessSquare)(DEMOTED piece);
+ if(PieceToChar(piece)=='~') piece = (ChessSquare)(DEMOTED(piece));
switch (piece) {
case WhitePawn:
cl.kind = IllegalMove;
cl.rank = cl.file = cl.either = 0;
c = PieceToChar(piece) ;
- GenLegal(board, flags, CoordsToAlgebraicCallback, (VOIDSTAR) &cl, c!='~' ? piece : (DEMOTED piece)); // [HGM] speed
+ GenLegal(board, flags, CoordsToAlgebraicCallback, (VOIDSTAR) &cl, c!='~' ? piece : (DEMOTED(piece))); // [HGM] speed
if (cl.kind == IllegalMove && !(flags&F_IGNORE_CHECK)) {
/* Generate pretty moves for moving into check, but
still return IllegalMove.
*/
- GenLegal(board, flags|F_IGNORE_CHECK, CoordsToAlgebraicCallback, (VOIDSTAR) &cl, c!='~' ? piece : (DEMOTED piece));
+ GenLegal(board, flags|F_IGNORE_CHECK, CoordsToAlgebraicCallback, (VOIDSTAR) &cl, c!='~' ? piece : (DEMOTED(piece)));
if (cl.kind == IllegalMove) break;
cl.kind = IllegalMove;
}
*/
if( c == '~' || c == '+') {
/* [HGM] print nonexistent piece as its demoted version */
- piece = (ChessSquare) (DEMOTED piece - 11*(gameInfo.variant == VariantChu));
+ piece = (ChessSquare) (CHUDEMOTED(piece));
}
if(c=='+') *outp++ = c;
*outp++ = ToUpper(PieceToChar(piece));
if(piece) {
cl.pieceIn = CharToPiece(wom ? piece : piece + 'a' - 'A');
if(cl.pieceIn == EmptySquare) return ImpossibleMove; // non-existent piece
- if(promoted) cl.pieceIn = (ChessSquare) (CHUPROMOTED cl.pieceIn);
+ if(promoted) cl.pieceIn = (ChessSquare) (CHUPROMOTED(cl.pieceIn));
} else cl.pieceIn = EmptySquare;
if(separator == '@' || separator == '*') { // drop move. We only get here without from-square or promoted piece
fromY = DROP_RANK; fromX = cl.pieceIn;
ChessSquare realPiece = boards[yyboardindex][fromY][fromX];
// Note that Disambiguate does not work for illegal moves, but flags them as impossible
if(piece) { // check if correct piece indicated
- if(PieceToChar(realPiece) == '~') realPiece = (ChessSquare) (DEMOTED realPiece);
+ if(PieceToChar(realPiece) == '~') realPiece = (ChessSquare) (DEMOTED(realPiece));
if(!(appData.icsActive && PieceToChar(realPiece) == '+') && // trust ICS if it moves promoted pieces
piece && realPiece != cl.pieceIn) return ImpossibleMove;
} else if(!separator && **p == '+') { // could be a protocol move, where bare '+' suffix means shogi-style promotion
- if(realPiece < (wom ? WhiteCannon : BlackCannon) && PieceToChar(PROMOTED realPiece) == '+') // seems to be that
+ if(realPiece < (wom ? WhiteCannon : BlackCannon) && PieceToChar(PROMOTED(realPiece)) == '+') // seems to be that
currentMoveString[4] = cl.promoCharIn = *(*p)++; // append promochar after all
}
result = LegalityTest(boards[yyboardindex], PosFlags(yyboardindex), fromY, fromX, toY, toX, cl.promoCharIn);