home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / games / gnugo / c / count next >
Encoding:
Text File  |  1995-03-11  |  2.4 KB  |  96 lines

  1. /*
  2.                 GNU GO - the game of Go (Wei-Chi)
  3.                 Version 1.1   last revised 3-1-89
  4.            Copyright (C) Free Software Foundation, Inc.
  5.                       written by Man L. Li
  6.                       modified by Wayne Iba
  7.                     documented by Bob Webber
  8. */
  9. /*
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation - version 1.
  13.  
  14. This program 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 in file COPYING for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. Please report any bug/fix, modification, suggestion to
  24.  
  25. mail address:   Man L. Li
  26.                 Dept. of Computer Science
  27.                 University of Houston
  28.                 4800 Calhoun Road
  29.                 Houston, TX 77004
  30.  
  31. e-mail address: manli@cs.uh.edu         (Internet)
  32.                 coscgbn@uhvax1.bitnet   (BITNET)
  33.                 70070,404               (CompuServe)
  34. */
  35. #include "header.h"
  36. #include <stdio.h>
  37.   
  38. int lib;
  39.  
  40. void count(i, j, color)
  41. /* count liberty of color piece at i, j */
  42. int i, j, color;
  43. {
  44. /* set current piece as marked */
  45.  ml[i][j] = EMPTY;
  46.  
  47. /* check North neighbor */
  48.  if (i != EMPTY)
  49.    {
  50.     if ((p[i - 1][j] == EMPTY) && ml[i - 1][j])
  51.       {
  52.        ++lib;
  53.        ml[i - 1][j] = EMPTY;
  54.      }
  55.     else
  56.        if ((p[i - 1][j] == color) && ml[i - 1][j])
  57.       count(i - 1, j, color);
  58.   }
  59. /* check South neighbor */
  60.  if (i != 18)
  61.    {
  62.     if ((p[i + 1][j] == EMPTY) && ml[i + 1][j])
  63.       {
  64.        ++lib;
  65.        ml[i + 1][j] = EMPTY;
  66.      }
  67.     else
  68.        if ((p[i + 1][j] == color) && ml[i + 1][j])
  69.       count(i + 1, j, color);
  70.   }
  71. /* check West neighbor */
  72.  if (j != EMPTY)
  73.    {
  74.     if ((p[i][j - 1] == EMPTY) && ml[i][j - 1])
  75.       {
  76.        ++lib;
  77.        ml[i][j - 1] = EMPTY;
  78.      }
  79.     else
  80.        if ((p[i][j - 1] == color) && ml[i][j - 1])
  81.       count(i, j - 1, color);
  82.   }
  83. /* check East neighbor */
  84.  if (j != 18)
  85.    {
  86.     if ((p[i][j + 1] == EMPTY) && ml[i][j + 1])
  87.       {
  88.        ++lib;
  89.        ml[i][j + 1] = EMPTY;
  90.      }
  91.     else
  92.        if ((p[i][j + 1] == color) && ml[i][j + 1])
  93.       count(i, j + 1, color);
  94.   }
  95. }  /* end count */
  96.