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

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