home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / szachy / gnu / amyboard-3.2.pl2 / moves.h < prev    next >
C/C++ Source or Header  |  1995-03-08  |  6KB  |  142 lines

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