home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / Games / NeXTGo-3.0-MIS / count.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-06  |  1.4 KB  |  76 lines

  1. #include "comment.header"
  2.  
  3. /* $Id: count.c,v 1.3 1997/07/06 19:34:52 ergo Exp $ */
  4.  
  5. /*
  6.  * $Log: count.c,v $
  7.  * Revision 1.3  1997/07/06 19:34:52  ergo
  8.  * actual version
  9.  *
  10.  * Revision 1.2  1997/05/04 18:56:58  ergo
  11.  * added time control for moves
  12.  *
  13.  */
  14.  
  15. #define EMPTY 0
  16.  
  17. extern unsigned char p[19][19], ml[19][19];
  18. extern int lib, MAXX, MAXY;
  19.  
  20. void count(int i, int j, int color)
  21.      /* count liberty of color piece at i, j */
  22. {
  23.   /* set current piece as marked */
  24.   ml[i][j] = EMPTY;
  25.   
  26.   /* check North neighbor */
  27.   if (i != EMPTY)
  28.     {
  29.       if ((p[i - 1][j] == EMPTY) && ml[i - 1][j])
  30.     {
  31.       ++lib;
  32.       ml[i - 1][j] = EMPTY;
  33.     }
  34.       else
  35.     if ((p[i - 1][j] == color) && ml[i - 1][j])
  36.       count(i - 1, j, color);
  37.     }
  38.   /* check South neighbor */
  39.   if (i != MAXX - 1)
  40.     {
  41.       if ((p[i + 1][j] == EMPTY) && ml[i + 1][j])
  42.     {
  43.       ++lib;
  44.       ml[i + 1][j] = EMPTY;
  45.     }
  46.       else
  47.     if ((p[i + 1][j] == color) && ml[i + 1][j])
  48.       count(i + 1, j, color);
  49.     }
  50.   /* check West neighbor */
  51.   if (j != EMPTY)
  52.     {
  53.       if ((p[i][j - 1] == EMPTY) && ml[i][j - 1])
  54.     {
  55.       ++lib;
  56.       ml[i][j - 1] = EMPTY;
  57.     }
  58.       else
  59.     if ((p[i][j - 1] == color) && ml[i][j - 1])
  60.       count(i, j - 1, color);
  61.     }
  62.   /* check East neighbor */
  63.   if (j != MAXY - 1)
  64.     {
  65.       if ((p[i][j + 1] == EMPTY) && ml[i][j + 1])
  66.     {
  67.       ++lib;
  68.       ml[i][j + 1] = EMPTY;
  69.     }
  70.       else
  71.     if ((p[i][j + 1] == color) && ml[i][j + 1])
  72.       count(i, j + 1, color);
  73.     }
  74. }  /* end count */
  75.  
  76.