home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / games / gnugo / c / findwinr < prev    next >
Encoding:
Text File  |  1995-03-11  |  2.6 KB  |  99 lines

  1. /*
  2.                 GNU GO - the game of Go (Wei-Chi)
  3.                 Version 1.1   last revised 3-1-89
  4.            Copyright (C) Free Software Foundation, Inc.
  5.                       written by Man L. Li
  6.                       modified by Wayne Iba
  7.                     documented by Bob Webber
  8. */
  9. /*
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation - version 1.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License in file COPYING for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. Please report any bug/fix, modification, suggestion to
  24.  
  25. mail address:   Man L. Li
  26.                 Dept. of Computer Science
  27.                 University of Houston
  28.                 4800 Calhoun Road
  29.                 Houston, TX 77004
  30.  
  31. e-mail address: manli@cs.uh.edu         (Internet)
  32.                 coscgbn@uhvax1.bitnet   (BITNET)
  33.                 70070,404               (CompuServe)
  34. */
  35.  
  36. #include <stdio.h>
  37. #include "header.h"
  38.  
  39. int findwinner(i, j, val)
  40. /* find opponent piece to capture or attack */
  41. int *i, *j, *val;
  42. {
  43.  int m, n, ti[3], tj[3], tval, ct, u, v, lib1;
  44.  
  45.  *i = -1;   *j = -1;   *val = -1;
  46.  
  47. /* find opponent with liberty less than four */
  48.  for (m = 0; m < 19; m++)
  49.    for (n = 0; n < 19; n++)
  50.      if ((p[m][n] == umove) && (l[m][n] < 4))
  51.        {
  52.     ct = 0;
  53.     initmark();
  54.     if (findopen(m, n, ti, tj, umove, l[m][n], &ct))
  55.       {
  56.        if (l[m][n] == 1)
  57.          {
  58.           if (*val < 120)
  59.         {
  60.          *val = 120;
  61.          *i = ti[0];
  62.          *j = tj[0];
  63.            }
  64.         }
  65.        else
  66.          for (u = 0; u < l[m][n]; u++)
  67.            for (v = 0; v < l[m][n]; v++)
  68.           if (u != v)
  69.             {
  70.              lib = 0;
  71.              countlib(ti[u], tj[u], mymove);
  72.              if (lib > 0) /* valid move */
  73.                {
  74.                         lib1 = lib;
  75.             p[ti[u]][tj[u]] = mymove;
  76.             /* look ahead opponent move */
  77.             lib = 0;
  78.             countlib(ti[v], tj[v], umove);
  79.             if ((lib1 == 1) && (lib > 0))
  80.                           tval = 0;
  81.                         else
  82.                           tval = 120 - 20 * lib;
  83.             if (*val < tval)
  84.               {
  85.                *val = tval;
  86.                *i = ti[u];
  87.                *j = tj[u];
  88.              }
  89.             p[ti[u]][tj[u]] = EMPTY;
  90.               }
  91.            }
  92.      }
  93.       }
  94.  if (*val > 0)    /* find move */
  95.     return 1;
  96.  else  /* fail to find winner */
  97.     return 0;
  98. }  /* end findwinner */
  99.