home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / games / gnugo / c / findnext < prev    next >
Encoding:
Text File  |  1995-03-11  |  3.9 KB  |  183 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. #include "header.h"
  36. #include <stdio.h>
  37.  
  38. int findnextmove(m, n, i, j, val, minlib)
  39. /* find new move i, j from group containing m, n */
  40. int m, n, *i, *j, *val, minlib;
  41.  {
  42.   int ti, tj, tval;
  43.   int found = 0;
  44.  
  45.   *i = -1;   *j = -1;    *val = -1;
  46. /* mark current position */
  47.   ma[m][n] = 1;
  48.  
  49. /* check North neighbor */
  50.   if (m != 0)
  51.      if (p[m - 1][n] == EMPTY)
  52.       {
  53.        ti = m - 1;
  54.        tj = n;
  55.        lib = 0;
  56.        countlib(ti, tj, mymove);
  57.        tval = fval(lib, minlib);
  58.        found = 1;
  59.       }
  60.      else
  61.        if ((p[m - 1][n] == mymove) && !ma[m - 1][n])
  62.      if (findnextmove(m - 1, n, &ti, &tj, &tval, minlib))
  63.         found = 1;
  64.  
  65.   if (found)
  66.     {
  67.      found = 0;
  68.      if (tval > *val)
  69.        {
  70.     *val = tval;
  71.     *i = ti;
  72.     *j = tj;
  73.       }
  74.      if (minlib == 1) return 1;
  75.    }
  76.  
  77. /* check South neighbor */
  78.   if (m != 18)
  79.      if (p[m + 1][n] == EMPTY)
  80.       {
  81.        ti = m + 1;
  82.        tj = n;
  83.        lib = 0;
  84.        countlib(ti, tj, mymove);
  85.        tval = fval(lib, minlib);
  86.        found = 1;
  87.       }
  88.      else
  89.        if ((p[m + 1][n] == mymove) && !ma[m + 1][n])
  90.       if (findnextmove(m + 1, n, &ti, &tj, &tval, minlib))
  91.          found = 1;
  92.  
  93.   if (found)
  94.     {
  95.      found = 0;
  96.      if (tval > *val)
  97.        {
  98.     *val = tval;
  99.     *i = ti;
  100.     *j = tj;
  101.       }
  102.      if (minlib == 1) return 1;
  103.    }
  104.  
  105. /* check West neighbor */
  106.   if (n != 0)
  107.      if (p[m][n - 1] == EMPTY)
  108.       {
  109.        ti = m;
  110.        tj = n - 1;
  111.        lib = 0;
  112.        countlib(ti, tj, mymove);
  113.        tval = fval(lib, minlib);
  114.        found = 1;
  115.       }
  116.      else
  117.        if ((p[m][n - 1] == mymove) && !ma[m][n - 1])
  118.       if (findnextmove(m, n - 1, &ti, &tj, &tval, minlib))
  119.           found = 1;
  120.  
  121.   if (found)
  122.     {
  123.      found = 0;
  124.      if (tval > *val)
  125.        {
  126.     *val = tval;
  127.     *i = ti;
  128.     *j = tj;
  129.       }
  130.      if (minlib == 1) return 1;
  131.    }
  132.  
  133. /* check East neighbor */
  134.   if (n != 18)
  135.      if (p[m][n + 1] == EMPTY)
  136.       {
  137.        ti = m;
  138.        tj = n + 1;
  139.        lib = 0;
  140.        countlib(ti, tj, mymove);
  141.        tval = fval(lib, minlib);
  142.        found = 1;
  143.       }
  144.      else
  145.        if ((p[m][n + 1] == mymove) && !ma[m][n + 1])
  146.       if (findnextmove(m, n + 1, &ti, &tj, &tval, minlib))
  147.           found = 1;
  148.  
  149.   if (found)
  150.     {
  151.      found = 0;
  152.      if (tval > *val)
  153.        {
  154.     *val = tval;
  155.     *i = ti;
  156.     *j = tj;
  157.       }
  158.      if (minlib == 1) return 1;
  159.    }
  160.  
  161.  if (*val > 0)    /* found next move */
  162.     return 1;
  163.  else    /* next move failed */
  164.     return 0;
  165. }  /* end findnextmove */
  166.  
  167.  
  168. int fval(newlib, minlib)
  169. /* evaluate new move */
  170. int newlib, minlib;
  171. {
  172.  int k, val;
  173.  
  174.  if (newlib <= minlib)
  175.     val = -1;
  176.  else
  177.    {
  178.     k = newlib - minlib;
  179.     val = 40 + (k - 1) * 50 / (minlib * minlib * minlib);
  180.   }
  181.  return val;
  182. }  /* end fval */
  183.