home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / Games / NeXTGo / Source / findsavr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1977-12-27  |  2.3 KB  |  86 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.   NeXT version by John Neil
  9.   */
  10. /*
  11.   This program is free software; you can redistribute it and/or modify
  12.   it under the terms of the GNU General Public License as published by
  13.   the Free Software Foundation - version 1.
  14.   
  15.   This program is distributed in the hope that it will be useful,
  16.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.   GNU General Public License in file COPYING for more details.
  19.   
  20.   You should have received a copy of the GNU General Public License
  21.   along with this program; if not, write to the Free Software
  22.   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.   
  24.   Please report any bug/fix, modification, suggestion to
  25.   
  26.   mail address:   Man L. Li
  27.   Dept. of Computer Science
  28.   University of Houston
  29.   4800 Calhoun Road
  30.   Houston, TX 77004
  31.   
  32.   e-mail address: manli@cs.uh.edu         (Internet)
  33.   coscgbn@uhvax1.bitnet   (BITNET)
  34.   70070,404               (CompuServe)
  35.   
  36.  
  37. For the NeXT version, please report any bug/fix, modification, suggestion to
  38.  
  39. mail address:   John Neil
  40.                 Mathematics Department
  41.                 Portland State University
  42.                 PO Box 751
  43.                 Portland, OR  97207
  44.  
  45. e-mail address: neil@math.mth.pdx.edu  (Internet)
  46.                 neil@psuorvm.bitnet    (BITNET)
  47.   
  48.   
  49.   */
  50.  
  51. extern unsigned char p[19][19], l[19][19];
  52. extern int currentStone, MAXX, MAXY;
  53. extern void initmark();
  54. extern int findnextmove(int,int,int*,int*,int*,int);
  55.  
  56. int findsaver(int *i, int *j, int *val)
  57.      /* find move if any pieces are threatened */
  58. {
  59.   int m, n, minlib;
  60.   int ti, tj, tval;
  61.   
  62.   *i = -1;   *j = -1;     *val = -1;
  63.   for (minlib = 1; minlib < 4; minlib++)
  64.     {
  65.       /* count piece with minimum liberty */
  66.       for (m = 0; m < MAXX; m++)
  67.     for (n = 0; n < MAXY; n++)
  68.       if ((p[m][n] == currentStone) && (l[m][n] == minlib))
  69.         /* find move to save pieces */
  70.         {
  71.           initmark();
  72.           if (findnextmove(m, n, &ti, &tj, &tval, minlib) && (tval > *val))
  73.         {
  74.           *val = tval;
  75.           *i = ti;
  76.           *j = tj;
  77.         }
  78.         }
  79.     }
  80.   if (*val > 0)   /* find move */
  81.     return 1;
  82.   else        /* move not found */
  83.     return 0;
  84. }  /* findsaver */
  85.  
  86.