home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnuch40.zip / gnuchess-4.0.pl79 / src / ataks.h < prev    next >
Text File  |  1998-09-28  |  2KB  |  95 lines

  1. /*
  2.  * ataks.h - Header source for GNU CHESS
  3.  *
  4.  * Copyright (c) 1985-1996 Stuart Cracraft, John Stanback,
  5.  *                         Daryl Baker, Conor McCarthy,
  6.  *                         Mike McGann, Chua Kong Sian
  7.  * Copyright (c) 1985-1996 Free Software Foundation
  8.  *
  9.  * This file is part of GNU CHESS.
  10.  *
  11.  * GNU Chess is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2, or (at your option)
  14.  * any later version.
  15.  *
  16.  * GNU Chess is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with GNU Chess; see the file COPYING.  If not, write to
  23.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25. inline
  26. static
  27. int
  28. SqAtakd (register short sq, short side)
  29.  
  30. /*
  31.  * See if any piece with color 'side' ataks sq.  First check pawns then
  32.  * Queen, Bishop, Rook and King and last Knight.
  33.  */
  34.  
  35. {
  36.   register short u;
  37.   register UCHAR *ppos, *pdir;
  38.   short xside;
  39.  
  40.   xside = side ^ 1;
  41.   pdir = nextdir[ptype[xside][pawn]][sq];
  42.   u = pdir[sq];            /* follow captures thread */
  43.   if (u != sq)
  44.     {
  45.       if (board[u] == pawn && color[u] == side)
  46.     return (true);
  47.       u = pdir[u];
  48.       if (u != sq && board[u] == pawn && color[u] == side)
  49.     return (true);
  50.     }
  51.   /* king capture */
  52.   if (distance (sq, PieceList[side][0]) == 1)
  53.     return (true);
  54.   /* try a queen bishop capture */
  55.   ppos = nextpos[bishop][sq];
  56.   pdir = nextdir[bishop][sq];
  57.   u = ppos[sq];
  58.   do
  59.     {
  60.       if (color[u] == neutral)
  61.     u = ppos[u];
  62.       else
  63.     {
  64.       if (color[u] == side && (board[u] == queen || board[u] == bishop))
  65.         return (true);
  66.       u = pdir[u];
  67.     }
  68.   } while (u != sq);
  69.   /* try a queen rook capture */
  70.   ppos = nextpos[rook][sq];
  71.   pdir = nextdir[rook][sq];
  72.   u = ppos[sq];
  73.   do
  74.     {
  75.       if (color[u] == neutral)
  76.     u = ppos[u];
  77.       else
  78.     {
  79.       if (color[u] == side && (board[u] == queen || board[u] == rook))
  80.         return (true);
  81.       u = pdir[u];
  82.     }
  83.   } while (u != sq);
  84.   /* try a knight capture */
  85.   pdir = nextdir[knight][sq];
  86.   u = pdir[sq];
  87.   do
  88.     {
  89.       if (color[u] == side && board[u] == knight)
  90.     return (true);
  91.       u = pdir[u];
  92.   } while (u != sq);
  93.   return (false);
  94. }
  95.