home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gnushogi-1.1 / src / ataks.c next >
Encoding:
C/C++ Source or Header  |  1993-04-16  |  2.0 KB  |  77 lines

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