home *** CD-ROM | disk | FTP | other *** search
/ The Best of Select: Games 3 / cd.iso / os2 / pmgnuchs / ataks.c next >
Text File  |  1994-02-22  |  2KB  |  73 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 <os2.h>
  24. #include "gnuchess.h"
  25. void
  26. ataks (short int side, short int *a)
  27.  
  28. /*
  29.  * Fill array atak[][] with info about ataks to a square.  Bits 8-15 are set
  30.  * if the piece (king..pawn) ataks the square.  Bits 0-7 contain a count of
  31.  * total ataks to the square.
  32.  */
  33.  
  34. {
  35.   register short u, c, sq;
  36.   register unsigned char *ppos, *pdir;
  37.   short i, piece, *PL;
  38.  
  39. #ifdef NOMEMSET
  40.   for (u = 64; u; a[--u] = 0) ;
  41. #else
  42.   memset ((char *) a, 0, 64 * sizeof (a[0]));
  43. #endif /* NOMEMSET */
  44.   PL = PieceList[side];
  45.   for (i = PieceCnt[side]; i >= 0; i--)
  46.     {
  47.       sq = PL[i];
  48.       piece = board[sq];
  49.       c = control[piece];
  50.       if (sweep[piece])
  51.     {
  52.       ppos = nextpos[piece][sq];
  53.       pdir = nextdir[piece][sq];
  54.       u = ppos[sq];
  55.       do
  56.         {
  57.           a[u] = ((a[u]+1) | c);
  58.           u = ((color[u] == neutral) ? ppos[u] : pdir[u]);
  59.       } while (u != sq);
  60.     }
  61.       else
  62.     {
  63.       pdir = nextdir[ptype[side][piece]][sq];
  64.       u = pdir[sq];        /* follow captures thread for pawns */
  65.       do
  66.         {
  67.           a[u] = ((a[u]+1) | c);
  68.           u = pdir[u];
  69.       } while (u != sq);
  70.     }
  71.     }
  72. }
  73.