2 * moves.h - Move generation and checking
\r
3 * $Id: moves.h,v 2.1 2003/10/27 19:21:00 mann Exp $
\r
5 * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts.
\r
6 * Enhancements Copyright 1992-95 Free Software Foundation, Inc.
\r
8 * The following terms apply to Digital Equipment Corporation's copyright
\r
9 * interest in XBoard:
\r
10 * ------------------------------------------------------------------------
\r
11 * All Rights Reserved
\r
13 * Permission to use, copy, modify, and distribute this software and its
\r
14 * documentation for any purpose and without fee is hereby granted,
\r
15 * provided that the above copyright notice appear in all copies and that
\r
16 * both that copyright notice and this permission notice appear in
\r
17 * supporting documentation, and that the name of Digital not be
\r
18 * used in advertising or publicity pertaining to distribution of the
\r
19 * software without specific, written prior permission.
\r
21 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
\r
22 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
\r
23 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
\r
24 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
\r
25 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
\r
26 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
\r
28 * ------------------------------------------------------------------------
\r
30 * The following terms apply to the enhanced version of XBoard distributed
\r
31 * by the Free Software Foundation:
\r
32 * ------------------------------------------------------------------------
\r
33 * This program is free software; you can redistribute it and/or modify
\r
34 * it under the terms of the GNU General Public License as published by
\r
35 * the Free Software Foundation; either version 2 of the License, or
\r
36 * (at your option) any later version.
\r
38 * This program is distributed in the hope that it will be useful,
\r
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
41 * GNU General Public License for more details.
\r
43 * You should have received a copy of the GNU General Public License
\r
44 * along with this program; if not, write to the Free Software
\r
45 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
46 * ------------------------------------------------------------------------
\r
49 extern ChessSquare PromoPiece P((ChessMove moveType));
\r
50 extern ChessMove PromoCharToMoveType P((int whiteOnMove, int promoChar));
\r
51 extern char PieceToChar P((ChessSquare p));
\r
52 extern ChessSquare CharToPiece P((int c));
\r
54 extern void CopyBoard P((Board to, Board from));
\r
55 extern int CompareBoards P((Board board1, Board board2));
\r
57 typedef void (*MoveCallback) P((Board board, int flags, ChessMove kind,
\r
58 int rf, int ff, int rt, int ft,
\r
61 /* Values for flags arguments */
\r
62 #define F_WHITE_ON_MOVE 1
\r
63 #define F_WHITE_KCASTLE_OK 2
\r
64 #define F_WHITE_QCASTLE_OK 4
\r
65 #define F_BLACK_KCASTLE_OK 8
\r
66 #define F_BLACK_QCASTLE_OK 16
\r
67 #define F_ALL_CASTLE_OK (F_WHITE_KCASTLE_OK | F_WHITE_QCASTLE_OK | \
\r
68 F_BLACK_KCASTLE_OK | F_BLACK_QCASTLE_OK)
\r
69 #define F_IGNORE_CHECK 32
\r
70 #define F_KRIEGSPIEL_CAPTURE 64 /* pawns can try to capture invisible pieces */
\r
71 #define F_ATOMIC_CAPTURE 128 /* capturing piece explodes, destroying itself
\r
72 and all non-pawns on adjacent squares;
\r
73 destroying your own king is illegal */
\r
75 /* Special epfile values. [HGM] positive values are non-reversible moves! */
\r
76 #define EP_NONE (-4) /* [HGM] Tricky! order matters: */
\r
77 #define EP_UNKNOWN (-1) /* >= EP_UNKNOWN spils rep-draw */
\r
78 #define EP_CAPTURE (-2) /* <= EP_NONE is reversible move */
\r
79 #define EP_PAWN_MOVE (-3)
\r
80 #define EP_REP_DRAW (-15)
\r
81 #define EP_RULE_DRAW (-14)
\r
82 #define EP_INSUF_DRAW (-13)
\r
83 #define EP_DRAWS (-10)
\r
85 /* Call callback once for each pseudo-legal move in the given
\r
86 position, except castling moves. A move is pseudo-legal if it is
\r
87 legal, or if it would be legal except that it leaves the king in
\r
88 check. In the arguments, epfile is EP_NONE if the previous move
\r
89 was not a double pawn push, or the file 0..7 if it was, or
\r
90 EP_UNKNOWN if we don't know and want to allow all e.p. captures.
\r
91 Promotion moves generated are to Queen only.
\r
93 extern void GenPseudoLegal P((Board board, int flags, int epfile,
\r
94 MoveCallback callback, VOIDSTAR closure));
\r
96 /* Like GenPseudoLegal, but include castling moves and (unless
\r
97 F_IGNORE_CHECK is set in the flags) omit moves that would leave the
\r
98 king in check. The CASTLE_OK flags are true if castling is not yet
\r
99 ruled out by a move of the king or rook. Return TRUE if the player
\r
100 on move is currently in check and F_IGNORE_CHECK is not set.
\r
102 extern int GenLegal P((Board board, int flags, int epfile,
\r
103 char castlingRights[], /* [HGM] */
\r
104 MoveCallback callback, VOIDSTAR closure));
\r
106 /* If the player on move were to move from (rf, ff) to (rt, ft), would
\r
107 he leave himself in check? Or if rf == -1, is the player on move
\r
108 in check now? enPassant must be TRUE if the indicated move is an
\r
109 e.p. capture. The possibility of castling out of a check along the
\r
110 back rank is not accounted for (i.e., we still return nonzero), as
\r
111 this is illegal anyway. Return value is the number of times the
\r
112 king is in check. */
\r
113 extern int CheckTest P((Board board, int flags,
\r
114 int rf, int ff, int rt, int ft, int enPassant));
\r
116 /* Is a move from (rf, ff) to (rt, ft) legal for the player whom the
\r
117 flags say is on move? Other arguments as in GenPseudoLegal.
\r
118 Returns the type of move made, taking promoChar into account. */
\r
119 extern ChessMove LegalityTest P((Board board, int flags, int epfile,
\r
120 char castlingRights[], /* [HGM] */
\r
121 int rf, int ff, int rt, int ft,
\r
126 #define MT_CHECKMATE 2
\r
127 #define MT_STALEMATE 3
\r
129 /* Return MT_NONE, MT_CHECK, MT_CHECKMATE, or MT_STALEMATE */
\r
130 extern int MateTest P((Board board, int flags, int epfile,
\r
131 char castlingRights[])); /* [HGM] */
\r
135 ChessSquare pieceIn; /* EmptySquare if unknown */
\r
136 int rfIn, ffIn, rtIn, ftIn; /* -1 if unknown */
\r
137 int promoCharIn; /* NULLCHAR if unknown */
\r
138 /* Output data for matched move */
\r
141 int rf, ff, rt, ft;
\r
142 int promoChar; /* 'q' if a promotion and promoCharIn was NULLCHAR */
\r
143 int count; /* Number of possibilities found */
\r
144 } DisambiguateClosure;
\r
146 /* Disambiguate a partially-known move */
\r
147 void Disambiguate P((Board board, int flags, int epfile,
\r
148 DisambiguateClosure *closure));
\r
151 /* Convert coordinates to normal algebraic notation.
\r
152 promoChar must be NULLCHAR or '.' if not a promotion.
\r
154 ChessMove CoordsToAlgebraic P((Board board, int flags, int epfile,
\r
155 int rf, int ff, int rt, int ft,
\r
156 int promoChar, char out[MOVE_LEN]));
\r