Sweep (int step)
{
ChessSquare king = WhiteKing, pawn = WhitePawn, last = promoSweep;
+ static int toggleFlag;
if(gameInfo.variant == VariantKnightmate) king = WhiteUnicorn;
if(gameInfo.variant == VariantSuicide || gameInfo.variant == VariantGiveaway) king = EmptySquare;
if(promoSweep >= BlackPawn) king = WHITE_TO_BLACK king, pawn = WHITE_TO_BLACK pawn;
if(gameInfo.variant == VariantSpartan && pawn == BlackPawn) pawn = BlackLance, king = EmptySquare;
if(fromY != BOARD_HEIGHT-2 && fromY != 1) pawn = EmptySquare;
+ if(!step) toggleFlag = Partner(&last); // piece has shogi-promotion
do {
- if(step && !Partner(&promoSweep)) promoSweep -= step;
+ if(step && !(toggleFlag && Partner(&promoSweep))) promoSweep -= step;
if(promoSweep == EmptySquare) promoSweep = BlackPawn; // wrap
else if((int)promoSweep == -1) promoSweep = WhiteKing;
else if(promoSweep == BlackPawn && step < 0) promoSweep = WhitePawn;
/* [HGM] rewritten IsPromotion to only flag promotions that offer a choice */
/* [HGM] add Shogi promotions */
int promotionZoneSize=1, highestPromotingPiece = (int)WhitePawn;
- ChessSquare piece;
+ ChessSquare piece, partner;
ChessMove moveType;
Boolean premove;
}
// give caller the default choice even if we will not make it
*promoChoice = ToLower(PieceToChar(defaultPromoChoice));
- if(IS_SHOGI(gameInfo.variant)) *promoChoice = (defaultPromoChoice == piece ? '=' : '+');
- if(gameInfo.variant == VariantChuChess) *promoChoice = (piece == WhitePawn || piece == BlackPawn ? 'q' : '+');
+ partner = piece; // pieces can promote if the pieceToCharTable says so
+ if(IS_SHOGI(gameInfo.variant)) *promoChoice = (defaultPromoChoice == piece && sweepSelect ? '=' : '+'); // obsolete?
+ else if(Partner(&partner)) *promoChoice = (defaultPromoChoice == piece && sweepSelect ? NULLCHAR : '+');
if( sweepSelect && gameInfo.variant != VariantGreat
&& gameInfo.variant != VariantGrand
&& gameInfo.variant != VariantSuper) return FALSE;
int
CanPromote (ChessSquare piece, int y)
{
+ int zone = (gameInfo.variant == VariantChuChess ? 3 : 1);
if(gameMode == EditPosition) return FALSE; // no promotions when editing position
// some variants have fixed promotion piece, no promotion at all, or another selection mechanism
if(IS_SHOGI(gameInfo.variant) || gameInfo.variant == VariantXiangqi ||
gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat ||
gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier ||
gameInfo.variant == VariantMakruk || gameInfo.variant == VariantASEAN) return FALSE;
- return (piece == BlackPawn && y == 1 ||
- piece == WhitePawn && y == BOARD_HEIGHT-2 ||
+ return (piece == BlackPawn && y <= zone ||
+ piece == WhitePawn && y >= BOARD_HEIGHT-1-zone ||
piece == BlackLance && y == 1 ||
piece == WhiteLance && y == BOARD_HEIGHT-2 );
}
if(appData.sweepSelect) {
ChessSquare piece = boards[currentMove][fromY][fromX];
promoSweep = defaultPromoChoice;
+ if(gameInfo.variant == VariantChuChess && piece != WhitePawn && piece != BlackPawn) promoSweep = piece; else
if(PieceToChar(CHUPROMOTED piece) == '+') promoSweep = CHUPROMOTED piece;
selectFlag = 0; lastX = xPix; lastY = yPix;
Sweep(0); // Pawn that is going to promote: preview promotion piece
ClearHighlights();
}
} else if(sweepSelecting) { // this must be the up-click corresponding to the down-click that started the sweep
- sweepSelecting = 0;
+ sweepSelecting = 0; appData.animate = FALSE; // do not animate, a selected piece already on to-square
if (appData.animate || appData.highlightLastMove) {
SetHighlights(fromX, fromY, toX, toY);
} else {
DisplayMessage("Click in holdings to choose piece", "");
return;
}
- PromotionPopUp();
+ PromotionPopUp(promoChoice);
} else {
int oldMove = currentMove;
UserMoveEvent(fromX, fromY, toX, toY, promoChoice);
ClearHighlights();
return;
}
+ if(promoChar == '=' && !IS_SHOGI(gameInfo.variant)) promoChar = NULLCHAR;
UserMoveEvent(fromX, fromY, toX, toY, promoChar);
if (!appData.highlightLastMove || gotPremove) ClearHighlights();
}
void
-PromotionPopUp ()
+PromotionPopUp (char choice)
{ // choice depends on variant: prepare dialog acordingly
count = 8;
- SetPromo(_("Cancel"), --count, 0); // Beware: GenericPopUp cannot handle user buttons named "cancel" (lowe case)!
- if(!IS_SHOGI(gameInfo.variant)) {
+ SetPromo(_("Cancel"), --count, -1); // Beware: GenericPopUp cannot handle user buttons named "cancel" (lowe case)!
+ if(choice != '+') {
if (!appData.testLegality || gameInfo.variant == VariantSuicide ||
gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove) ||
gameInfo.variant == VariantGiveaway) {
void CancelDelayedEvent P((void));
// [HGM] mouse: next six used by mouse handler, which was moved to backend
extern int fromX, fromY, toX, toY;
-void PromotionPopUp P((void));
+void PromotionPopUp P((char choice));
void DragPieceBegin P((int x, int y, Boolean instantly));
void DragPieceEnd P((int x, int y));
void DragPieceMove P((int x, int y));
/* [HGM] in Shogi non-pawns can promote */
*outp++ = promoChar; // Don't bother to correct move type, return value is never used!
}
- else if (gameInfo.variant != VariantSuper && promoChar &&
+ else if (gameInfo.variant == VariantChuChess && promoChar ||
+ gameInfo.variant != VariantSuper && promoChar &&
(piece == WhiteLance || piece == BlackLance) ) { // Lance sometimes represents Pawn
*outp++ = '=';
*outp++ = ToUpper(promoChar);
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) && **p != 'x') return ToLower(*(*p)++); // reserve 'x' for multi-leg captures?
- if(*p != start) return '='; // must be the optional =
+ if(*p != start) return **p == '+' ? *(*p)++ : '='; // must be the optional = (or =+)
return NULLCHAR; // no suffix detected
}
toY = cl.rtIn = (currentMoveString[3] = Number(p) + '0') - ONE;
}
if(type[0] != NOTHING && type[1] != NOTHING && type[3] != NOTHING) { // fully specified.
+ 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
- ChessSquare realPiece = boards[yyboardindex][fromY][fromX];
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
+ currentMoveString[4] = cl.promoCharIn = *(*p)++; // append promochar after all
}
result = LegalityTest(boards[yyboardindex], PosFlags(yyboardindex), fromY, fromX, toY, toX, cl.promoCharIn);
if (currentMoveString[4] == NULLCHAR) { // suppy missing mandatory promotion character
return CallWindowProc(buttonDesc[i].wndproc, hwnd, message, wParam, lParam);\r
}\r
\r
+static int promoStyle;\r
+\r
/* Process messages for Promotion dialog box */\r
LRESULT CALLBACK\r
Promotion(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
PieceToChar(BlackMarshall) != '~') ) ?\r
SW_SHOW : SW_HIDE);\r
/* [HGM] Hide B & R button in Shogi, use Q as promote, N as defer */\r
- ShowWindow(GetDlgItem(hDlg, PB_Rook),\r
- gameInfo.variant != VariantShogi ?\r
- SW_SHOW : SW_HIDE);\r
- ShowWindow(GetDlgItem(hDlg, PB_Bishop), \r
- gameInfo.variant != VariantShogi ?\r
- SW_SHOW : SW_HIDE);\r
- if(gameInfo.variant == VariantShogi) {\r
+ ShowWindow(GetDlgItem(hDlg, PB_Rook), !style ? SW_SHOW : SW_HIDE);\r
+ ShowWindow(GetDlgItem(hDlg, PB_Bishop), !style ? SW_SHOW : SW_HIDE);\r
+ if(style) {\r
SetDlgItemText(hDlg, PB_Queen, "YES");\r
SetDlgItemText(hDlg, PB_Knight, "NO");\r
SetWindowText(hDlg, "Promote?");\r
promoChar = gameInfo.variant == VariantSuper ? PieceToChar(BlackSilver) : PieceToChar(BlackKing);\r
break;\r
case PB_Queen:\r
- promoChar = gameInfo.variant == VariantShogi ? '+' : ToLower(PieceToChar(WhiteOnMove(currentMove) ? WhiteQueen : BlackQueen));\r
+ promoChar = style ? '+' : ToLower(PieceToChar(WhiteOnMove(currentMove) ? WhiteQueen : BlackQueen));\r
break;\r
case PB_Rook:\r
promoChar = ToLower(PieceToChar(WhiteOnMove(currentMove) ? WhiteRook : BlackRook));\r
promoChar = ToLower(PieceToChar(WhiteOnMove(currentMove) ? WhiteAngel : BlackAngel));\r
break;\r
case PB_Knight:\r
- promoChar = gameInfo.variant == VariantShogi ? '=' : PieceToChar(WhiteOnMove(currentMove) ? WhiteKnight : BlackKnight);\r
+ promoChar = gameInfo.variant == VariantShogi ? '=' : style ? NULLCHAR : \r
+ ToLower(PieceToChar(WhiteOnMove(currentMove) ? WhiteKnight : BlackKnight));\r
break;\r
default:\r
return FALSE;\r
}\r
\r
void\r
-PromotionPopUp()\r
+PromotionPopUp(char choice)\r
{\r
+ promoStyle = (choice == '+');\r
DrawPosition(TRUE, NULL);\r
PromotionPopup(hwndMain);\r
}\r
static char *history[HISTORY_SIZE];\r
int histIn = 0, histP = 0;\r
\r
+\r
VOID\r
SaveInHistory(char *cmd)\r
{\r