home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / MacGnuGo 0.5e / gnugo.src / findopen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-22  |  2.2 KB  |  97 lines  |  [TEXT/R*ch]

  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. extern int getcsize(int, int);
  11.  
  12. int findopen(int m, int n, int i[], int j[], int color, int minlib, int *ct)
  13.      /* find all open spaces i, j from m, n */
  14. {
  15.   int mik, mjk;
  16.   
  17.   if (getcsize(m,n) < 2) {
  18.     if (currentStone == BLACKSTONE) {
  19.       mik = blackCapturedKoI;
  20.       mjk = blackCapturedKoJ;
  21.     } else {
  22.       mik = whiteCapturedKoI;
  23.       mjk = whiteCapturedKoJ;
  24.     }
  25.   } else { mik = mjk = -1; }
  26.   
  27.   /* mark this one */
  28.   ma[m][n] = 1;
  29.   
  30.   /* check North neighbor */
  31.   if (m != 0)
  32.     {
  33.       if ((p[m - 1][n] == EMPTY) && (((m - 1) != mik) || (n != mjk)))
  34.     {
  35.       i[*ct] = m - 1;
  36.       j[*ct] = n;
  37.       ++*ct;
  38.       if (*ct == minlib) return 1;
  39.     }
  40.       else
  41.     if ((p[m - 1][n] == color) && !ma[m - 1][n])
  42.       if (findopen(m - 1, n, i, j, color, minlib, ct) && (*ct == minlib))
  43.         return 1;
  44.     }
  45.   
  46.   /* check South neighbor */
  47.   if (m != MAXY - 1)
  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 West neighbor */
  63.   if (n != 0)
  64.     {
  65.       if ((p[m][n - 1] == EMPTY) && ((m != mik) || ((n - 1) != mjk)))
  66.     {
  67.       i[*ct] = m;
  68.       j[*ct] = n - 1;
  69.       ++*ct;
  70.       if (*ct == minlib) return 1;
  71.     }
  72.       else
  73.     if ((p[m][n - 1] == color) && !ma[m][n - 1])
  74.       if (findopen(m, n - 1, i, j, color, minlib, ct) && (*ct == minlib))
  75.         return 1;
  76.     }
  77.   
  78.   /* check East neighbor */
  79.   if (n != MAXX - 1)
  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.   /* fail to find open space */
  95.   return 0;
  96. }  /* end findopen */
  97.