* Massachusetts.
*
* Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
- * 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+ * 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
*
* Enhancements Copyright 2005 Alessandro Scotti
*
{
register GenLegalClosure *cl = (GenLegalClosure *) closure;
- if (!(flags & F_IGNORE_CHECK) &&
- CheckTest(board, flags, rf, ff, rt, ft,
+ if (!(flags & F_IGNORE_CHECK) ) {
+ int check, promo = (gameInfo.variant == VariantSpartan && kind == BlackPromotion);
+ if(promo) board[rf][ff] = BlackKing; // [HGM] spartan: promote to King before check-test
+ check = CheckTest(board, flags, rf, ff, rt, ft,
kind == WhiteCapturesEnPassant ||
- kind == BlackCapturesEnPassant)) return;
+ kind == BlackCapturesEnPassant);
+ if(promo) board[rf][ff] = BlackLance;
+ if(check) return;
+ }
if (flags & F_ATOMIC_CAPTURE) {
if (board[rt][ft] != EmptySquare ||
kind == WhiteCapturesEnPassant || kind == BlackCapturesEnPassant) {
if (promoChar != NULLCHAR) {
if(promoChar == '=') cl.kind = IllegalMove; else // [HGM] shogi: no deferred promotion outside Shogi
if (cl.kind == WhitePromotion || cl.kind == BlackPromotion) {
- if(CharToPiece(flags & F_WHITE_ON_MOVE ? ToUpper(promoChar) : ToLower(promoChar)) == EmptySquare)
+ ChessSquare piece = CharToPiece(flags & F_WHITE_ON_MOVE ? ToUpper(promoChar) : ToLower(promoChar));
+ if(piece == EmptySquare)
cl.kind = ImpossibleMove; // non-existing piece
+ if(gameInfo.variant == VariantSpartan && cl.kind == BlackPromotion ) {
+ if(promoChar != PieceToChar(BlackKing)) {
+ if(CheckTest(board, flags, rf, ff, rt, ft, FALSE)) cl.kind = IllegalMove; // [HGM] spartan: only promotion to King was possible
+ if(piece == BlackLance) cl.kind = ImpossibleMove;
+ } else { // promotion to King allowed only if we do not haave two yet
+ int r, f, kings = 0;
+ for(r=0; r<BOARD_HEIGHT; r++) for(f=BOARD_LEFT; f<BOARD_RGHT; f++) kings += (board[r][f] == BlackKing);
+ if(kings == 2) cl.kind = IllegalMove;
+ }
+ } else if(piece == WhitePawn || piece == BlackPawn) cl.kind = ImpossibleMove; // cannot stay Pawn in any variant
+ else if((piece == WhiteUnicorn || piece == BlackUnicorn) && gameInfo.variant == VariantKnightmate)
+ cl.kind = IllegalMove; // promotion to Royal Knight not allowed
+ else if((piece == WhiteKing || piece == BlackKing) && gameInfo.variant != VariantSuicide && gameInfo.variant != VariantGiveaway)
+ cl.kind = IllegalMove; // promotion to King usually not allowed
} else {
cl.kind = IllegalMove;
}