1 /* 2 * moves.h - Move generation and checking 3 * 4 * Copyright 1991 by Digital Equipment Corporation, Maynard, 5 * Massachusetts. 6 * 7 * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, 8 * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free 9 * Software Foundation, Inc. 10 * 11 * Enhancements Copyright 2005 Alessandro Scotti 12 * 13 * The following terms apply to Digital Equipment Corporation's copyright 14 * interest in XBoard: 15 * ------------------------------------------------------------------------ 16 * All Rights Reserved 17 * 18 * Permission to use, copy, modify, and distribute this software and its 19 * documentation for any purpose and without fee is hereby granted, 20 * provided that the above copyright notice appear in all copies and that 21 * both that copyright notice and this permission notice appear in 22 * supporting documentation, and that the name of Digital not be 23 * used in advertising or publicity pertaining to distribution of the 24 * software without specific, written prior permission. 25 * 26 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 27 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 28 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 29 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 30 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 31 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 32 * SOFTWARE. 33 * ------------------------------------------------------------------------ 34 * 35 * The following terms apply to the enhanced version of XBoard 36 * distributed by the Free Software Foundation: 37 * ------------------------------------------------------------------------ 38 * 39 * GNU XBoard is free software: you can redistribute it and/or modify 40 * it under the terms of the GNU General Public License as published by 41 * the Free Software Foundation, either version 3 of the License, or (at 42 * your option) any later version. 43 * 44 * GNU XBoard is distributed in the hope that it will be useful, but 45 * WITHOUT ANY WARRANTY; without even the implied warranty of 46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 47 * General Public License for more details. 48 * 49 * You should have received a copy of the GNU General Public License 50 * along with this program. If not, see http://www.gnu.org/licenses/. * 51 * 52 *------------------------------------------------------------------------ 53 ** See the file ChangeLog for a revision history. */ 54 55 #define SUFFIXES "'!" 56 57 extern ChessSquare PromoPiece P((ChessMove moveType)); 58 extern ChessMove PromoCharToMoveType P((int whiteOnMove, int promoChar)); 59 extern char PieceSuffix P((ChessSquare p)); 60 extern ChessSquare CharToPiece P((int c)); 61 extern int PieceToNumber P((ChessSquare p)); 62 63 extern void CopyBoard P((Board to, Board from)); 64 extern int CompareBoards P((Board board1, Board board2)); 65 extern unsigned char pieceToChar[(int)EmptySquare+1]; 66 extern unsigned char pieceNickName[(int)EmptySquare]; 67 extern int promoPartner[(int)EmptySquare]; 68 extern char *pieceDesc[(int)EmptySquare]; 69 extern Board initialPosition; 70 extern Boolean pieceDefs; 71 72 typedef void (*MoveCallback) P((Board board, int flags, ChessMove kind, 73 int rf, int ff, int rt, int ft, 74 VOIDSTAR closure)); 75 76 /* Values for flags arguments */ 77 #define F_WHITE_ON_MOVE 1 78 #define F_WHITE_KCASTLE_OK 2 79 #define F_WHITE_QCASTLE_OK 4 80 #define F_BLACK_KCASTLE_OK 8 81 #define F_BLACK_QCASTLE_OK 16 82 #define F_ALL_CASTLE_OK (F_WHITE_KCASTLE_OK | F_WHITE_QCASTLE_OK | \ 83 F_BLACK_KCASTLE_OK | F_BLACK_QCASTLE_OK) 84 #define F_IGNORE_CHECK 32 85 #define F_KRIEGSPIEL_CAPTURE 64 /* pawns can try to capture invisible pieces */ 86 #define F_ATOMIC_CAPTURE 128 /* capturing piece explodes, destroying itself 87 and all non-pawns on adjacent squares; 88 destroying your own king is illegal */ 89 #define F_FRC_TYPE_CASTLING 256 /* generate castlings as captures of own Rook */ 90 #define F_MANDATORY_CAPTURE 0x200 91 #define F_NULL_MOVE 0x400 92 93 /* Special epfile values. [HGM] positive values are non-reversible moves! */ 94 #define EP_NONE (-6) /* [HGM] Tricky! order matters: */ 95 #define EP_UNKNOWN (-1) /* >= EP_UNKNOWN spoils rep-draw */ 96 #define EP_CAPTURE (-2) /* <= EP_NONE is reversible move */ 97 #define EP_PAWN_MOVE (-3) 98 #define EP_IRON_LION (-4) 99 #define EP_ROYAL_LION (-5) 100 #define EP_REP_DRAW (-15) 101 #define EP_RULE_DRAW (-14) 102 #define EP_INSUF_DRAW (-13) 103 #define EP_DRAWS (-10) 104 #define EP_WINS (-9) 105 #define EP_BEROLIN_A 16 /* [HGM] berolina: add to file if pawn to be taken of a-side of e.p.file */ 106 #define EP_CHECKMATE 100 /* [HGM] verify: record mates in epStatus for easy claim verification */ 107 #define EP_STALEMATE -16 108 109 /* Call callback once for each pseudo-legal move in the given 110 position, except castling moves. A move is pseudo-legal if it is 111 legal, or if it would be legal except that it leaves the king in 112 check. In the arguments, epfile is EP_NONE if the previous move 113 was not a double pawn push, or the file 0..7 if it was, or 114 EP_UNKNOWN if we don't know and want to allow all e.p. captures. 115 Promotion moves generated are to Queen only. 116 */ 117 extern void GenPseudoLegal P((Board board, int flags, 118 MoveCallback callback, VOIDSTAR closure, ChessSquare filter)); 119 120 /* Like GenPseudoLegal, but include castling moves and (unless 121 F_IGNORE_CHECK is set in the flags) omit moves that would leave the 122 king in check. The CASTLE_OK flags are true if castling is not yet 123 ruled out by a move of the king or rook. Return TRUE if the player 124 on move is currently in check and F_IGNORE_CHECK is not set. 125 */ 126 extern int GenLegal P((Board board, int flags, 127 MoveCallback callback, VOIDSTAR closure, ChessSquare filter)); 128 129 /* If the player on move were to move from (rf, ff) to (rt, ft), would 130 he leave himself in check? Or if rf == -1, is the player on move 131 in check now? enPassant must be TRUE if the indicated move is an 132 e.p. capture. The possibility of castling out of a check along the 133 back rank is not accounted for (i.e., we still return nonzero), as 134 this is illegal anyway. Return value is the number of times the 135 king is in check. */ 136 extern int CheckTest P((Board board, int flags, 137 int rf, int ff, int rt, int ft, int enPassant)); 138 139 /* Is a move from (rf, ff) to (rt, ft) legal for the player whom the 140 flags say is on move? Other arguments as in GenPseudoLegal. 141 Returns the type of move made, taking promoChar into account. */ 142 extern ChessMove LegalityTest P((Board board, int flags, 143 int rf, int ff, int rt, int ft, 144 int promoChar)); 145 146 #define MT_NONE 0 147 #define MT_CHECK 1 148 #define MT_CHECKMATE 2 149 #define MT_STALEMATE 3 150 #define MT_STAINMATE 4 /* [HGM] xq: for games where being stalemated counts as a loss */ 151 #define MT_STEALMATE 5 /* [HGM] losers: for games where being stalemated counts as a win */ 152 #define MT_TRICKMATE 6 /* [HGM] losers: for games where being checkmated counts as a win */ 153 #define MT_BARE 7 /* [HGM] shatranj: for games where having bare king loses */ 154 #define MT_DRAW 8 /* [HGM] shatranj: other draws */ 155 #define MT_NOKING 9 /* [HGM] atomic: for games lost through king capture */ 156 157 /* Return MT_NONE, MT_CHECK, MT_CHECKMATE, or MT_STALEMATE */ 158 extern int MateTest P((Board board, int flags)); 159 160 typedef struct { 161 /* Input data */ 162 ChessSquare pieceIn; /* EmptySquare if unknown */ 163 int rfIn, ffIn, rtIn, ftIn; /* -1 if unknown */ 164 int promoCharIn; /* NULLCHAR if unknown */ 165 /* Output data for matched move */ 166 ChessMove kind; 167 ChessSquare piece; 168 int rf, ff, rt, ft; 169 int promoChar; /* 'q' if a promotion and promoCharIn was NULLCHAR */ 170 int count; /* Number of possibilities found */ 171 int captures; /* [HGM] oneclick: number of matching captures */ 172 } DisambiguateClosure; 173 174 /* Disambiguate a partially-known move */ 175 void Disambiguate P((Board board, int flags, DisambiguateClosure *closure)); 176 177 178 /* Convert coordinates to normal algebraic notation. 179 promoChar must be NULLCHAR or '.' if not a promotion. 180 */ 181 ChessMove CoordsToAlgebraic P((Board board, int flags, 182 int rf, int ff, int rt, int ft, 183 int promoChar, char out[MOVE_LEN])); 184 185 extern int quickFlag, killX, killY, kill2X, kill2Y, legNr; 186