char pieceToChar[] = {
'P', 'N', 'B', 'R', 'Q', 'F', 'E', 'A', 'C', 'W', 'M',
- 'O', 'H', 'I', 'J', 'G', 'D', 'V', 'L', 's', 'U', 'K',
+ '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' };
if (board[rt][ft] != EmptySquare) break;
}
if(m==1) goto mounted;
- if(m==2) goto finishGold;
+ if(m==2) goto finishSilver;
break;
case WhiteQueen:
}
}
- return cl.check;
+ return cl.fking < BOARD_RGHT ? cl.check : 1000; // [HGM] atomic: return 1000 if we have no king
}
char castlingRights[];
{
MateTestClosure cl;
- int inCheck;
+ int inCheck, r, f, myPieces=0, hisPieces=0, nrKing=0;
+ ChessSquare king = flags & F_WHITE_ON_MOVE ? WhiteKing : BlackKing;
+ for(r=0; r<BOARD_HEIGHT; r++) for(f=BOARD_LEFT; f<BOARD_RGHT; f++) {
+ // [HGM] losers: Count pieces and kings, to detect other unorthodox winning conditions
+ nrKing += (board[r][f] == king); // stm has king
+ if( board[r][f] != EmptySquare ) {
+ if((int)board[r][f] <= (int)king && (int)board[r][f] >= (int)king - (int)WhiteKing + (int)WhitePawn)
+ myPieces++;
+ else hisPieces++;
+ }
+ }
+ if(appData.debugMode) fprintf(debugFP, "MateTest: K=%d, my=%d, his=%d\n", nrKing, myPieces, hisPieces);
+ switch(gameInfo.variant) { // [HGM] losers: extinction wins
+ case VariantShatranj:
+ if(hisPieces == 1) return myPieces > 1 ? MT_BARE : MT_DRAW;
+ default:
+ break;
+ case VariantAtomic:
+ if(nrKing == 0) return MT_NOKING;
+ break;
+ case VariantLosers:
+ if(myPieces == 1) return MT_BARE;
+ }
cl.count = 0;
inCheck = GenLegal(board, flags, epfile, castlingRights, MateTestCallback, (VOIDSTAR) &cl);
+ // [HGM] 3check: yet to do!
if (cl.count > 0) {
return inCheck ? MT_CHECK : MT_NONE;
} else {
+ if(gameInfo.variant == VariantSuicide) // [HGM] losers: always stalemate, since no check, but result varies
+ return myPieces == hisPieces ? MT_STALEMATE :
+ myPieces > hisPieces ? MT_STAINMATE : MT_STEALMATE;
+ else if(gameInfo.variant == VariantLosers) return inCheck ? MT_TRICKMATE : MT_STEALMATE;
+ else if(gameInfo.variant == VariantGiveaway) return MT_STEALMATE; // no check exists, stalemated = win
+
return inCheck ? MT_CHECKMATE
: (gameInfo.variant == VariantXiangqi || gameInfo.variant == VariantShatranj) ?
MT_STAINMATE : MT_STALEMATE;
#define MT_CHECK 1
#define MT_CHECKMATE 2
#define MT_STALEMATE 3
-#define MT_STAINMATE 4 /* [HGM] xq: for games where being stalemate counts as a loss */
+#define MT_STAINMATE 4 /* [HGM] xq: for games where being stalemated counts as a loss */
+#define MT_STEALMATE 5 /* [HGM] losers: for games where being stalemated counts as a win */
+#define MT_TRICKMATE 6 /* [HGM] losers: for games where being checkmated counts as a win */
+#define MT_BARE 7 /* [HGM] shatranj: for games where having bare king loses */
+#define MT_DRAW 8 /* [HGM] shatranj: other draws */
+#define MT_NOKING 9 /* [HGM] atomic: for games lost through king capture */
/* Return MT_NONE, MT_CHECK, MT_CHECKMATE, or MT_STALEMATE */
extern int MateTest P((Board board, int flags, int epfile,