home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / games / gnugo / c / findopen < prev    next >
Encoding:
Text File  |  1995-03-11  |  3.0 KB  |  113 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.  
  36. #include <stdio.h>
  37. #include "header.h"
  38.  
  39. int findopen(m, n, i, j, color, minlib, ct)
  40. /* find all open spaces i, j from m, n */
  41. int m, n, i[], j[], color, minlib, *ct;
  42. {
  43. /* mark this one */
  44.  ma[m][n] = 1;
  45.  
  46. /* check North neighbor */
  47.  if (m != 0)
  48.    {
  49.     if ((p[m - 1][n] == EMPTY) && (((m - 1) != mik) || (n != mjk)))
  50.       {
  51.        i[*ct] = m - 1;
  52.        j[*ct] = n;
  53.        ++*ct;
  54.        if (*ct == minlib) return 1;
  55.      }
  56.     else
  57.       if ((p[m - 1][n] == color) && !ma[m - 1][n])
  58.      if (findopen(m - 1, n, i, j, color, minlib, ct) && (*ct == minlib))
  59.         return 1;
  60.   }
  61.  
  62. /* check South neighbor */
  63.  if (m != 18)
  64.    {
  65.     if ((p[m + 1][n] == EMPTY) && (((m + 1) != mik) || (n != mjk)))
  66.       {
  67.        i[*ct] = m + 1;
  68.        j[*ct] = n;
  69.        ++*ct;
  70.        if (*ct == minlib) return 1;
  71.      }
  72.     else
  73.       if ((p[m + 1][n] == color) && !ma[m + 1][n])
  74.      if (findopen(m + 1, n, i, j, color, minlib, ct) && (*ct == minlib))
  75.         return 1;
  76.   }
  77.  
  78. /* check West neighbor */
  79.  if (n != 0)
  80.    {
  81.     if ((p[m][n - 1] == EMPTY) && ((m != mik) || ((n - 1) != mjk)))
  82.       {
  83.        i[*ct] = m;
  84.        j[*ct] = n - 1;
  85.        ++*ct;
  86.        if (*ct == minlib) return 1;
  87.      }
  88.     else
  89.       if ((p[m][n - 1] == color) && !ma[m][n - 1])
  90.      if (findopen(m, n - 1, i, j, color, minlib, ct) && (*ct == minlib))
  91.         return 1;
  92.   }
  93.  
  94. /* check East neighbor */
  95.  if (n != 18)
  96.    {
  97.     if ((p[m][n + 1] == EMPTY) && ((m != mik) || ((n + 1) != mjk)))
  98.       {
  99.        i[*ct] = m;
  100.        j[*ct] = n + 1;
  101.        ++*ct;
  102.        if (*ct == minlib) return 1;
  103.      }
  104.     else
  105.       if ((p[m][n + 1] == color) && !ma[m][n + 1])
  106.      if (findopen(m, n + 1, i, j, color, minlib, ct) && (*ct == minlib))
  107.         return 1;
  108.   }
  109.  
  110. /* fail to find open space */
  111.  return 0;
  112. }  /* end findopen */
  113.