home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnuch40.zip / gnuchess-4.0.pl79 / src / ataks.c next >
C/C++ Source or Header  |  1998-09-28  |  2KB  |  70 lines

  1. /*
  2.  * ataks.c - C 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. #include "gnuchess.h"
  26. void
  27. ataks (SHORT side, SHORT *a)
  28.  
  29. /*
  30.  * Fill array atak[][] with info about ataks to a square.  Bits 8-15 are set
  31.  * if the piece (king..pawn) ataks the square.  Bits 0-7 contain a count of
  32.  * total ataks to the square.
  33.  */
  34.  
  35. {
  36.   register SHORT u, c, sq;
  37.   register UCHAR *ppos, *pdir;
  38.   SHORT i, piece, *PL;
  39.  
  40.   memset ((UCHAR *) a, 0, 64 * sizeof (a[0]));
  41.   PL = PieceList[side];
  42.   for (i = PieceCnt[side]; i >= 0; i--)
  43.     {
  44.       sq = PL[i];
  45.       piece = board[sq];
  46.       c = control[piece];
  47.       if (sweep[piece])
  48.     {
  49.       ppos = nextpos[piece][sq];
  50.       pdir = nextdir[piece][sq];
  51.       u = ppos[sq];
  52.       do
  53.         {
  54.           a[u] = ((a[u]+1) | c);
  55.           u = ((color[u] == neutral) ? ppos[u] : pdir[u]);
  56.       } while (u != sq);
  57.     }
  58.       else
  59.     {
  60.       pdir = nextdir[ptype[side][piece]][sq];
  61.       u = pdir[sq];        /* follow captures thread for pawns */
  62.       do
  63.         {
  64.           a[u] = ((a[u]+1) | c);
  65.           u = pdir[u];
  66.       } while (u != sq);
  67.     }
  68.     }
  69. }
  70.