home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / go / prog / nextgo23.taz / nextgo23 / NeXTGo / findopen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  2.1 KB  |  94 lines

  1. #include "comment.header"
  2.  
  3. #define EMPTY 0
  4. #define BLACKSTONE 2
  5.  
  6. extern unsigned char p[19][19], ma[19][19];
  7. extern int MAXX, MAXY;
  8. extern int currentStone, blackCapturedKoI, blackCapturedKoJ;  /* piece captured */
  9. extern int whiteCapturedKoI, whiteCapturedKoJ;
  10.  
  11. int findopen(int m, int n, int i[], int j[], int color, int minlib, int *ct)
  12.      /* find all open spaces i, j from m, n */
  13. {
  14.   int mik, mjk;
  15.   
  16.   if (currentStone == BLACKSTONE) {
  17.     mik = blackCapturedKoI;
  18.     mjk = blackCapturedKoJ;
  19.   } else {
  20.     mik = whiteCapturedKoI;
  21.     mjk = whiteCapturedKoJ;
  22.   }
  23.   
  24.   /* mark this one */
  25.   ma[m][n] = 1;
  26.   
  27.   /* check North neighbor */
  28.   if (m != 0)
  29.     {
  30.       if ((p[m - 1][n] == EMPTY) && (((m - 1) != mik) || (n != mjk)))
  31.     {
  32.       i[*ct] = m - 1;
  33.       j[*ct] = n;
  34.       ++*ct;
  35.       if (*ct == minlib) return 1;
  36.     }
  37.       else
  38.     if ((p[m - 1][n] == color) && !ma[m - 1][n])
  39.       if (findopen(m - 1, n, i, j, color, minlib, ct) && (*ct == minlib))
  40.         return 1;
  41.     }
  42.   
  43.   /* check South neighbor */
  44.   if (m != MAXY - 1)
  45.     {
  46.       if ((p[m + 1][n] == EMPTY) && (((m + 1) != mik) || (n != mjk)))
  47.     {
  48.       i[*ct] = m + 1;
  49.       j[*ct] = n;
  50.       ++*ct;
  51.       if (*ct == minlib) return 1;
  52.     }
  53.       else
  54.     if ((p[m + 1][n] == color) && !ma[m + 1][n])
  55.       if (findopen(m + 1, n, i, j, color, minlib, ct) && (*ct == minlib))
  56.         return 1;
  57.     }
  58.   
  59.   /* check West neighbor */
  60.   if (n != 0)
  61.     {
  62.       if ((p[m][n - 1] == EMPTY) && ((m != mik) || ((n - 1) != mjk)))
  63.     {
  64.       i[*ct] = m;
  65.       j[*ct] = n - 1;
  66.       ++*ct;
  67.       if (*ct == minlib) return 1;
  68.     }
  69.       else
  70.     if ((p[m][n - 1] == color) && !ma[m][n - 1])
  71.       if (findopen(m, n - 1, i, j, color, minlib, ct) && (*ct == minlib))
  72.         return 1;
  73.     }
  74.   
  75.   /* check East neighbor */
  76.   if (n != MAXX - 1)
  77.     {
  78.       if ((p[m][n + 1] == EMPTY) && ((m != mik) || ((n + 1) != mjk)))
  79.     {
  80.       i[*ct] = m;
  81.       j[*ct] = n + 1;
  82.       ++*ct;
  83.       if (*ct == minlib) return 1;
  84.     }
  85.       else
  86.     if ((p[m][n + 1] == color) && !ma[m][n + 1])
  87.       if (findopen(m, n + 1, i, j, color, minlib, ct) && (*ct == minlib))
  88.         return 1;
  89.     }
  90.   
  91.   /* fail to find open space */
  92.   return 0;
  93. }  /* end findopen */
  94.