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

  1. #include "comment.header"
  2.  
  3. /* $Id: findnext.c,v 1.3 1997/07/06 19:34:55 ergo Exp $ */
  4.  
  5. /*
  6.  * $Log: findnext.c,v $
  7.  * Revision 1.3  1997/07/06 19:34:55  ergo
  8.  * actual version
  9.  *
  10.  * Revision 1.2  1997/05/04 18:57:00  ergo
  11.  * added time control for moves
  12.  *
  13.  */
  14.  
  15. #define EMPTY 0
  16.  
  17. extern unsigned char p[19][19], ma[19][19];
  18. extern int currentStone, MAXX, MAXY;
  19. extern int lib;
  20. extern countlib(int,int,int);
  21.  
  22. int fval(int newlib, int minlib)
  23.      /* evaluate new move */
  24. {
  25.   int k, val;
  26.   
  27.   if (newlib <= minlib)
  28.     val = -1;
  29.   else
  30.     {
  31.       k = newlib - minlib;
  32.       val = 40 + (k - 1) * 50 / (minlib * minlib * minlib);
  33.     }
  34.   return val;
  35. }  /* end fval */
  36.  
  37.  
  38. int findnextmove(int m, int n, int *i, int *j, int *val, int minlib)
  39.      /* find new move i, j from group containing m, n */
  40. {
  41.   int ti, tj, tval;
  42.   int found = 0;
  43.   
  44.   *i = -1;   *j = -1;    *val = -1;
  45.   /* mark current position */
  46.   ma[m][n] = 1;
  47.   
  48.   /* check North neighbor */
  49.   if (m != 0)
  50.     if (p[m - 1][n] == EMPTY)
  51.       {
  52.     ti = m - 1;
  53.     tj = n;
  54.     lib = 0;
  55.     countlib(ti, tj, currentStone);
  56.     tval = fval(lib, minlib);
  57.     found = 1;
  58.       }
  59.     else
  60.       if ((p[m - 1][n] == currentStone) && !ma[m - 1][n])
  61.     if (findnextmove(m - 1, n, &ti, &tj, &tval, minlib))
  62.       found = 1;
  63.   
  64.   if (found)
  65.     {
  66.       found = 0;
  67.       if (tval > *val)
  68.     {
  69.       *val = tval;
  70.       *i = ti;
  71.       *j = tj;
  72.     }
  73.       if (minlib == 1) return 1;
  74.     }
  75.   
  76.   /* check South neighbor */
  77.   if (m != MAXY - 1)
  78.     if (p[m + 1][n] == EMPTY)
  79.       {
  80.     ti = m + 1;
  81.     tj = n;
  82.     lib = 0;
  83.     countlib(ti, tj, currentStone);
  84.     tval = fval(lib, minlib);
  85.     found = 1;
  86.       }
  87.     else
  88.       if ((p[m + 1][n] == currentStone) && !ma[m + 1][n])
  89.     if (findnextmove(m + 1, n, &ti, &tj, &tval, minlib))
  90.       found = 1;
  91.   
  92.   if (found)
  93.     {
  94.       found = 0;
  95.       if (tval > *val)
  96.     {
  97.       *val = tval;
  98.       *i = ti;
  99.       *j = tj;
  100.     }
  101.       if (minlib == 1) return 1;
  102.     }
  103.   
  104.   /* check West neighbor */
  105.   if (n != 0)
  106.     if (p[m][n - 1] == EMPTY)
  107.       {
  108.     ti = m;
  109.     tj = n - 1;
  110.     lib = 0;
  111.     countlib(ti, tj, currentStone);
  112.     tval = fval(lib, minlib);
  113.     found = 1;
  114.       }
  115.     else
  116.       if ((p[m][n - 1] == currentStone) && !ma[m][n - 1])
  117.     if (findnextmove(m, n - 1, &ti, &tj, &tval, minlib))
  118.       found = 1;
  119.   
  120.   if (found)
  121.     {
  122.       found = 0;
  123.       if (tval > *val)
  124.     {
  125.       *val = tval;
  126.       *i = ti;
  127.       *j = tj;
  128.     }
  129.       if (minlib == 1) return 1;
  130.     }
  131.   
  132.   /* check East neighbor */
  133.   if (n != MAXX - 1)
  134.     if (p[m][n + 1] == EMPTY)
  135.       {
  136.     ti = m;
  137.     tj = n + 1;
  138.     lib = 0;
  139.     countlib(ti, tj, currentStone);
  140.     tval = fval(lib, minlib);
  141.     found = 1;
  142.       }
  143.     else
  144.       if ((p[m][n + 1] == currentStone) && !ma[m][n + 1])
  145.     if (findnextmove(m, n + 1, &ti, &tj, &tval, minlib))
  146.       found = 1;
  147.   
  148.   if (found)
  149.     {
  150.       found = 0;
  151.       if (tval > *val)
  152.     {
  153.       *val = tval;
  154.       *i = ti;
  155.       *j = tj;
  156.     }
  157.       if (minlib == 1) return 1;
  158.     }
  159.   
  160.   if (*val > 0)    /* found next move */
  161.     return 1;
  162.   else    /* next move failed */
  163.     return 0;
  164. }  /* end findnextmove */
  165.  
  166.