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

  1. #include "comment.header"
  2.  
  3. /* $Id: findwinr.c,v 1.3 1997/07/06 19:34:59 ergo Exp $ */
  4.  
  5. /*
  6.  * $Log: findwinr.c,v $
  7.  * Revision 1.3  1997/07/06 19:34:59  ergo
  8.  * actual version
  9.  *
  10.  * Revision 1.2  1997/05/04 18:57:03  ergo
  11.  * added time control for moves
  12.  *
  13.  */
  14.  
  15. #define EMPTY 0
  16.  
  17. extern unsigned char p[19][19], l[19][19];
  18. extern int currentStone, opposingStone, MAXX, MAXY;
  19. extern int lib;
  20. extern void countlib(int,int,int);
  21. extern void initmark();
  22. extern int findopen(int,int,int[],int[],int,int,int*);
  23.  
  24. int findwinner(int *i, int *j, int *val)
  25.      /* find opponent piece to capture or attack */
  26. {
  27.   int m, n, ti[3], tj[3], tval, ct, u, v, lib1;
  28.   
  29.   *i = -1;   *j = -1;   *val = -1;
  30.   
  31.   /* find opponent with liberty less than four */
  32.   for (m = 0; m < MAXX; m++)
  33.     for (n = 0; n < MAXY; n++)
  34.       if ((p[m][n] == opposingStone) && (l[m][n] < 4))
  35.     {
  36.       ct = 0;
  37.       initmark();
  38.       if (findopen(m, n, ti, tj, opposingStone, l[m][n], &ct))
  39.         {
  40.           if (l[m][n] == 1)
  41.         {
  42.           if (*val < 120)
  43.             {
  44.               *val = 120;
  45.               *i = ti[0];
  46.               *j = tj[0];
  47.             }
  48.         }
  49.           else
  50.         for (u = 0; u < l[m][n]; u++)
  51.           for (v = 0; v < l[m][n]; v++)
  52.             if (u != v)
  53.               {
  54.             lib = 0;
  55.             countlib(ti[u], tj[u], currentStone);
  56.             if (lib > 0) /* valid move */
  57.               {
  58.                 lib1 = lib;
  59.                 p[ti[u]][tj[u]] = currentStone;
  60.                 /* look ahead opponent move */
  61.                 lib = 0;
  62.                 countlib(ti[v], tj[v], opposingStone);
  63.                 if ((lib1 == 1) && (lib > 0))
  64.                   tval = 0;
  65.                 else
  66.                   tval = 120 - 20 * lib;
  67.                 if (*val < tval)
  68.                   {
  69.                 *val = tval;
  70.                 *i = ti[u];
  71.                 *j = tj[u];
  72.                   }
  73.                 p[ti[u]][tj[u]] = EMPTY;
  74.               }
  75.               }
  76.         }
  77.     }
  78.   if (*val > 0)    /* find move */
  79.     return 1;
  80.   else  /* fail to find winner */
  81.     return 0;
  82. }  /* end findwinner */
  83.  
  84.