home *** CD-ROM | disk | FTP | other *** search
/ Dream 44 / Amiga_Dream_44.iso / RiscPc / jeux / ArcBoard004.arc / !GNUChessX / src / c / ataks next >
Text File  |  1995-07-02  |  2KB  |  68 lines

  1. /*
  2.  * ataks.c - C source for GNU CHESS
  3.  *
  4.  * Copyright (c) 1988,1989,1990 John Stanback
  5.  * Copyright (c) 1992 Free Software Foundation
  6.  *
  7.  * This file is part of GNU CHESS.
  8.  *
  9.  * GNU Chess is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2, or (at your option)
  12.  * any later version.
  13.  *
  14.  * GNU Chess is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with GNU Chess; see the file COPYING.  If not, write to
  21.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23. #include "gnuchess.h"
  24. void
  25. ataks (SHORT side, SHORT *a)
  26.  
  27. /*
  28.  * Fill array atak[][] with info about ataks to a square.  Bits 8-15 are set
  29.  * if the piece (king..pawn) ataks the square.  Bits 0-7 contain a count of
  30.  * total ataks to the square.
  31.  */
  32.  
  33. {
  34.   register SHORT u, c, sq;
  35.   register UCHAR *ppos, *pdir;
  36.   SHORT i, piece, *PL;
  37.  
  38.   memset ((UCHAR *) a, 0, 64 * sizeof (a[0]));
  39.   PL = PieceList[side];
  40.   for (i = PieceCnt[side]; i >= 0; i--)
  41.     {
  42.       sq = PL[i];
  43.       piece = board[sq];
  44.       c = control[piece];
  45.       if (sweep[piece])
  46.     {
  47.       ppos = nextpos[piece][sq];
  48.       pdir = nextdir[piece][sq];
  49.       u = ppos[sq];
  50.       do
  51.         {
  52.           a[u] = ((a[u]+1) | c);
  53.           u = ((color[u] == neutral) ? ppos[u] : pdir[u]);
  54.       } while (u != sq);
  55.     }
  56.       else
  57.     {
  58.       pdir = nextdir[ptype[side][piece]][sq];
  59.       u = pdir[sq];        /* follow captures thread for pawns */
  60.       do
  61.         {
  62.           a[u] = ((a[u]+1) | c);
  63.           u = pdir[u];
  64.       } while (u != sq);
  65.     }
  66.     }
  67. }
  68.