[comp.sources.games] v06i020: gnugo - game of GO from the GNU folks, Part02/03

games@tekred.CNA.TEK.COM (03/14/89)

Submitted-by: Man Lung Li <manli@sun2.cs.uh.edu>
Posting-number: Volume 6, Issue 20
Archive-name: gnugo/Part02



#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 2 (of 3)."
# Contents:  Makefile count.c endgame.c exambord.c findcolr.c
#   findnext.c findopen.c findpatn.c findwinr.c fioe.c genmove.c
#   getmove.c main.c objs opening.c sethand.c showinst.c
# Wrapped by billr@saab on Mon Mar 13 11:05:00 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(772 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# program to play the game of Go (Wei-Chi)
X#	makefile modified 3/13/89 billr@saab.cna.tek.com
X
XSRC = count.c countlib.c endgame.c eval.c exambord.c findcolr.c \
X      findnext.c findopen.c findpatn.c findsavr.c findwinr.c \
X      fioe.c genmove.c getij.c getmove.c initmark.c main.c matchpat.c \
X      opening.c openregn.c random.c seed.c sethand.c \
X      showbord.c showinst.c suicide.c
X
XOBJ = count.o countlib.o endgame.o eval.o exambord.o findcolr.o \
X      findnext.o findopen.o findpatn.o findsavr.o findwinr.o \
X      fioe.o genmove.o getij.o getmove.o initmark.o main.o matchpat.o \
X      opening.o openregn.o random.o seed.o sethand.o \
X      showbord.o showinst.o suicide.o
X
XPRG = gnugo
X
XCFLAGS = -O
X
X$(PRG) : $(OBJ)
X	$(CC) $(OBJ) -o $@
X
Xmatchpat.o : patterns.c
END_OF_FILE
if test 772 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'count.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'count.c'\"
else
echo shar: Extracting \"'count.c'\" \(2530 characters\)
sed "s/^X//" >'count.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
X#define EMPTY 0
X
Xextern unsigned char p[19][19], ml[19][19];
Xextern int lib;
X
Xcount(i, j, color)
X/* count liberty of color piece at i, j */
Xint i, j, color;
X{
X/* set current piece as marked */
X ml[i][j] = EMPTY;
X
X/* check North neighbor */
X if (i != EMPTY)
X   {
X    if ((p[i - 1][j] == EMPTY) && ml[i - 1][j])
X      {
X       ++lib;
X       ml[i - 1][j] = EMPTY;
X     }
X    else
X       if ((p[i - 1][j] == color) && ml[i - 1][j])
X	  count(i - 1, j, color);
X  }
X/* check South neighbor */
X if (i != 18)
X   {
X    if ((p[i + 1][j] == EMPTY) && ml[i + 1][j])
X      {
X       ++lib;
X       ml[i + 1][j] = EMPTY;
X     }
X    else
X       if ((p[i + 1][j] == color) && ml[i + 1][j])
X	  count(i + 1, j, color);
X  }
X/* check West neighbor */
X if (j != EMPTY)
X   {
X    if ((p[i][j - 1] == EMPTY) && ml[i][j - 1])
X      {
X       ++lib;
X       ml[i][j - 1] = EMPTY;
X     }
X    else
X       if ((p[i][j - 1] == color) && ml[i][j - 1])
X	  count(i, j - 1, color);
X  }
X/* check East neighbor */
X if (j != 18)
X   {
X    if ((p[i][j + 1] == EMPTY) && ml[i][j + 1])
X      {
X       ++lib;
X       ml[i][j + 1] = EMPTY;
X     }
X    else
X       if ((p[i][j + 1] == color) && ml[i][j + 1])
X	  count(i, j + 1, color);
X  }
X}  /* end count */
END_OF_FILE
if test 2530 -ne `wc -c <'count.c'`; then
    echo shar: \"'count.c'\" unpacked with wrong size!
fi
# end of 'count.c'
fi
if test -f 'endgame.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'endgame.c'\"
else
echo shar: Extracting \"'endgame.c'\" \(3325 characters\)
sed "s/^X//" >'endgame.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
X#define EMPTY 0
X
Xextern unsigned char p[19][19];
Xextern int mymove, umove;
Xextern int mk, uk;  /* piece captured */
X
Xendgame()
X/* count pieces and announce the winner */
X{
X char an[10];
X int i, j, mtot, utot, cont;
X
X printf("\nTo count score, we need the following steps:\n");
X printf("First, I need you to remove all dead pieces on the board.\n");
X printf("Second, I need you to fill in neutral territories with ");
X printf("pieces.\n");
X printf("Last, I will fill in all pieces and anounce the winner.\n");
X
X/* remove dead pieces */
X printf("\nFirst, you should enter the dead pieces (blank and white) to");
X printf(" be removed.  Enter\n");
X printf(" 'stop' when you have finished.\n");
X
X cont = 1;
X do {
X     printf("Dead piece? ");
X     scanf("%s", an);
X     if (strcmp(an, "stop"))
X       {
X	getij(an, &i, &j);
X	if (p[i][j] == mymove)
X	  {
X	   p[i][j] = EMPTY;
X	   mk++;
X	 }
X	else
X	   if (p[i][j] == umove)
X	     {
X	      p[i][j] = EMPTY;
X	      uk++;
X	    }
X	showboard();
X      }
X    else
X       cont = 0;
X   }
X while (cont);
X
X/* fill in neutral */
X printf("Next, you need to fill in pieces (black and white) in all neutral");
X printf(" territories.\n");
X printf("Enter your and my pieces alternately and enter 'stop' when finish\n");
X cont = 1;
X
X do {
X     printf("Your piece? ");
X     scanf("%s", an);
X     if (strcmp(an, "stop"))
X       {
X	getij(an, &i, &j);
X	p[i][j] = umove;
X	printf("My piece? ");
X	scanf("%s", an);
X	getij(an, &i, &j);
X	p[i][j] = mymove;
X	showboard();
X      }
X     else
X	cont = 0;
X   }
X  while (cont);
X
X/* set empty to side they belong to */
X  for (i = 0; i < 19; i++)
X     for (j = 0; j < 19; j++)
X	if (p[i][j] == EMPTY)
X	   p[i][j] = findcolor(i, j);
X
X/* count total */
X  mtot = 0;  utot = 0;
X  for (i = 0; i < 19; i++)
X     for (j = 0; j < 19; j++)
X	if (p[i][j] == mymove)
X	  ++mtot;
X	else
X	   if (p[i][j] == umove)
X	     ++utot;
X
X  showboard();
X  printf("Your total number of pieces %d\n", utot);
X  printf("My total number of pieces %d\n", mtot);
X
X}  /* end endgame */
X
END_OF_FILE
if test 3325 -ne `wc -c <'endgame.c'`; then
    echo shar: \"'endgame.c'\" unpacked with wrong size!
fi
# end of 'endgame.c'
fi
if test -f 'exambord.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'exambord.c'\"
else
echo shar: Extracting \"'exambord.c'\" \(2453 characters\)
sed "s/^X//" >'exambord.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
X#define EMPTY 0
X
Xextern unsigned char p[19][19], l[19][19];
Xextern int mymove;
Xextern int mik, mjk, uik, ujk, mk, uk;  /* piece captured */
X
Xexamboard(color)
X/* examine pieces */
Xint color;
X  {
X   int i, j, n;
X
X
X/* find liberty of each piece */
X   eval(color);
X
X/* initialize piece captured */
X   if (color == mymove)
X     {
X      mik = -1;
X      mjk = -1;
X    }
X   else
X     {
X      uik = -1;
X      ujk = -1;
X    }
X   n = 0; /* The number of captures this move for Ko purposes */
X
X/* remove all piece of zero liberty */
X   for (i = 0; i < 19; i++)
X     for (j = 0; j < 19; j++)
X       if ((p[i][j] == color) && (l[i][j] == 0))
X	 {
X	  p[i][j] = EMPTY;
X/* record piece captured */
X	  if (color == mymove)
X	    {
X	     mik = i;
X	     mjk = j;
X	     ++mk;
X	   }
X	  else
X	    {
X	     uik = i;
X	     ujk = j;
X	     ++uk;
X	   }
X	  ++n;  /* increment number of captures on this move */
X	}
X/* reset to -1 if more than one stone captured since  no Ko possible */
X   if (color == mymove && n > 1)
X     {
X       mik = -1;   
X       mjk = -1;
X     }
X   else if ( n > 1 )
X     {
X       uik = -1;
X       ujk = -1;
X     }
X}  /* end examboard */
X
END_OF_FILE
if test 2453 -ne `wc -c <'exambord.c'`; then
    echo shar: \"'exambord.c'\" unpacked with wrong size!
fi
# end of 'exambord.c'
fi
if test -f 'findcolr.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'findcolr.c'\"
else
echo shar: Extracting \"'findcolr.c'\" \(2385 characters\)
sed "s/^X//" >'findcolr.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
X#define EMPTY 0
X
Xextern unsigned char p[19][19];
X
Xfindcolor(i, j)
X/* find color for empty piece */
Xint i, j;
X{
X int k, color1, color2;
X
X/* check North neighbor */
X color1 = 0;
X k = i;
X do --k;
X while ((p[k][j] == EMPTY) && (k > 0));
X color1 = p[k][j];
X
X/* check South neighbor */
X color2 = 0;
X k = i;
X do k++;
X while ((p[k][j] == EMPTY) && (k < 18));
X color2 = p[k][j];
X
X if (color1)
X   {
X    if ((color1 == color2) || (color2 == 0))
X       return color1;
X    else
X       return 0;  /* cannot determine */
X  }
X else
X    if (color2)
X       return color2;
X    else  /* both zero */
X       {
X/* check West neighbor */
X	color1 = 0;
X	k = j;
X	do --k;
X	while ((p[i][k] == EMPTY) && (k > 0));
X	color1 = p[i][k];
X
X/* check East neighbor */
X	color2 = 0;
X	k = j;
X	do k++;
X	while ((p[i][k] == EMPTY) && (k < 18));
X	color2 = p[i][k];
X
X	if (color1)
X	  {
X	   if ((color1 == color2) || (color2 == 0))
X	      return color1;
X	   else
X	      return 0;  /* cannot determine */
X	 }
X	else
X	   if (color2)
X	      return color2;
X	   else
X	      return 0;
X      }
X}  /* end findcolor */
X
END_OF_FILE
if test 2385 -ne `wc -c <'findcolr.c'`; then
    echo shar: \"'findcolr.c'\" unpacked with wrong size!
fi
# end of 'findcolr.c'
fi
if test -f 'findnext.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'findnext.c'\"
else
echo shar: Extracting \"'findnext.c'\" \(4049 characters\)
sed "s/^X//" >'findnext.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
X#define EMPTY 0
X
Xextern unsigned char p[19][19], ma[19][19];
Xextern int mymove;
Xextern int lib;
X
Xfindnextmove(m, n, i, j, val, minlib)
X/* find new move i, j from group containing m, n */
Xint m, n, *i, *j, *val, minlib;
X {
X  int ti, tj, tval;
X  int found = 0;
X
X  *i = -1;   *j = -1;	*val = -1;
X/* mark current position */
X  ma[m][n] = 1;
X
X/* check North neighbor */
X  if (m != 0)
X     if (p[m - 1][n] == EMPTY)
X      {
X       ti = m - 1;
X       tj = n;
X       lib = 0;
X       countlib(ti, tj, mymove);
X       tval = fval(lib, minlib);
X       found = 1;
X      }
X     else
X       if ((p[m - 1][n] == mymove) && !ma[m - 1][n])
X	 if (findnextmove(m - 1, n, &ti, &tj, &tval, minlib))
X	    found = 1;
X
X  if (found)
X    {
X     found = 0;
X     if (tval > *val)
X       {
X	*val = tval;
X	*i = ti;
X	*j = tj;
X      }
X     if (minlib == 1) return 1;
X   }
X
X/* check South neighbor */
X  if (m != 18)
X     if (p[m + 1][n] == EMPTY)
X      {
X       ti = m + 1;
X       tj = n;
X       lib = 0;
X       countlib(ti, tj, mymove);
X       tval = fval(lib, minlib);
X       found = 1;
X      }
X     else
X       if ((p[m + 1][n] == mymove) && !ma[m + 1][n])
X	  if (findnextmove(m + 1, n, &ti, &tj, &tval, minlib))
X	     found = 1;
X
X  if (found)
X    {
X     found = 0;
X     if (tval > *val)
X       {
X	*val = tval;
X	*i = ti;
X	*j = tj;
X      }
X     if (minlib == 1) return 1;
X   }
X
X/* check West neighbor */
X  if (n != 0)
X     if (p[m][n - 1] == EMPTY)
X      {
X       ti = m;
X       tj = n - 1;
X       lib = 0;
X       countlib(ti, tj, mymove);
X       tval = fval(lib, minlib);
X       found = 1;
X      }
X     else
X       if ((p[m][n - 1] == mymove) && !ma[m][n - 1])
X	  if (findnextmove(m, n - 1, &ti, &tj, &tval, minlib))
X	      found = 1;
X
X  if (found)
X    {
X     found = 0;
X     if (tval > *val)
X       {
X	*val = tval;
X	*i = ti;
X	*j = tj;
X      }
X     if (minlib == 1) return 1;
X   }
X
X/* check East neighbor */
X  if (n != 18)
X     if (p[m][n + 1] == EMPTY)
X      {
X       ti = m;
X       tj = n + 1;
X       lib = 0;
X       countlib(ti, tj, mymove);
X       tval = fval(lib, minlib);
X       found = 1;
X      }
X     else
X       if ((p[m][n + 1] == mymove) && !ma[m][n + 1])
X	  if (findnextmove(m, n + 1, &ti, &tj, &tval, minlib))
X	      found = 1;
X
X  if (found)
X    {
X     found = 0;
X     if (tval > *val)
X       {
X	*val = tval;
X	*i = ti;
X	*j = tj;
X      }
X     if (minlib == 1) return 1;
X   }
X
X if (*val > 0)	/* found next move */
X    return 1;
X else	/* next move failed */
X    return 0;
X}  /* end findnextmove */
X
X
Xfval(newlib, minlib)
X/* evaluate new move */
Xint newlib, minlib;
X{
X int k, val;
X
X if (newlib <= minlib)
X    val = -1;
X else
X   {
X    k = newlib - minlib;
X    val = 40 + (k - 1) * 50 / (minlib * minlib * minlib);
X  }
X return val;
X}  /* end fval */
END_OF_FILE
if test 4049 -ne `wc -c <'findnext.c'`; then
    echo shar: \"'findnext.c'\" unpacked with wrong size!
fi
# end of 'findnext.c'
fi
if test -f 'findopen.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'findopen.c'\"
else
echo shar: Extracting \"'findopen.c'\" \(3130 characters\)
sed "s/^X//" >'findopen.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
X#define EMPTY 0
X
Xextern unsigned char p[19][19], ma[19][19];
Xextern int mik, mjk;  /* piece captured */
X
Xfindopen(m, n, i, j, color, minlib, ct)
X/* find all open spaces i, j from m, n */
Xint m, n, i[], j[], color, minlib, *ct;
X{
X/* mark this one */
X ma[m][n] = 1;
X
X/* check North neighbor */
X if (m != 0)
X   {
X    if ((p[m - 1][n] == EMPTY) && (((m - 1) != mik) || (n != mjk)))
X      {
X       i[*ct] = m - 1;
X       j[*ct] = n;
X       ++*ct;
X       if (*ct == minlib) return 1;
X     }
X    else
X      if ((p[m - 1][n] == color) && !ma[m - 1][n])
X	 if (findopen(m - 1, n, i, j, color, minlib, ct) && (*ct == minlib))
X	    return 1;
X  }
X
X/* check South neighbor */
X if (m != 18)
X   {
X    if ((p[m + 1][n] == EMPTY) && (((m + 1) != mik) || (n != mjk)))
X      {
X       i[*ct] = m + 1;
X       j[*ct] = n;
X       ++*ct;
X       if (*ct == minlib) return 1;
X     }
X    else
X      if ((p[m + 1][n] == color) && !ma[m + 1][n])
X	 if (findopen(m + 1, n, i, j, color, minlib, ct) && (*ct == minlib))
X	    return 1;
X  }
X
X/* check West neighbor */
X if (n != 0)
X   {
X    if ((p[m][n - 1] == EMPTY) && ((m != mik) || ((n - 1) != mjk)))
X      {
X       i[*ct] = m;
X       j[*ct] = n - 1;
X       ++*ct;
X       if (*ct == minlib) return 1;
X     }
X    else
X      if ((p[m][n - 1] == color) && !ma[m][n - 1])
X	 if (findopen(m, n - 1, i, j, color, minlib, ct) && (*ct == minlib))
X	    return 1;
X  }
X
X/* check East neighbor */
X if (n != 18)
X   {
X    if ((p[m][n + 1] == EMPTY) && ((m != mik) || ((n + 1) != mjk)))
X      {
X       i[*ct] = m;
X       j[*ct] = n + 1;
X       ++*ct;
X       if (*ct == minlib) return 1;
X     }
X    else
X      if ((p[m][n + 1] == color) && !ma[m][n + 1])
X	 if (findopen(m, n + 1, i, j, color, minlib, ct) && (*ct == minlib))
X	    return 1;
X  }
X
X/* fail to find open space */
X return 0;
X}  /* end findopen */
END_OF_FILE
if test 3130 -ne `wc -c <'findopen.c'`; then
    echo shar: \"'findopen.c'\" unpacked with wrong size!
fi
# end of 'findopen.c'
fi
if test -f 'findpatn.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'findpatn.c'\"
else
echo shar: Extracting \"'findpatn.c'\" \(4315 characters\)
sed "s/^X//" >'findpatn.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
X#define EMPTY 0
X
Xextern unsigned char p[19][19];
Xextern int mymove, umove;
Xextern int opn[9];
X
Xfindpatn(i, j, val)
X/* find pattern to match for next move */
Xint *i, *j, *val;
X{
X int m, n;
X int ti, tj, tval;
X static int cnd, mtype;  /* game tree node number, move type */
X/* mtype = 0, basic; 1, inverted; 2, reflected; 3, inverted & reflected */
X
X/* open game then occupy corners */
X if (opn[4])   /* continue last move */
X   {
X    opn[4] = 0;  /* clear flag */
X    if (opening(i, j, &cnd, mtype)) opn[4] = 1; /* more move then reset flag */
X    if (p[*i][*j] == EMPTY)  /* valid move */
X      {
X       *val = 80;
X       return 1;
X     }
X    else
X      opn[4] = 0;
X  }
X
X if (opn[0])   /* Northwest corner */
X   {
X    opn[0] = 0;  /* clear flag */
X    if (openregion(0, 0, 5, 5))
X      {
X       cnd = 0;
X       mtype = 0;
X       opening(i, j, &cnd, mtype);  /* get new node for next move */
X       if (opening(i, j, &cnd, mtype)) opn[4] = 1;
X       *val = 80;
X       return 1;
X     }
X }
X
X if (opn[1])   /* Southwest corner */
X   {
X    opn[1] = 0;
X    if (openregion(13, 0, 18, 5))
X      {
X       cnd = 0;
X       mtype = 1;
X       opening(i, j, &cnd, mtype);  /* get new node for next move */
X       if (opening(i, j, &cnd, mtype)) opn[4] = 1;
X       *val = 80;
X       return 1;
X     }
X  }
X
X if (opn[2])   /* Northeast corner */
X   {
X    opn[2] = 0;
X    if (openregion(0, 13, 5, 18))
X      {
X       cnd = 0;
X       mtype = 2;
X       opening(i, j, &cnd, mtype);  /* get new node for next move */
X       if (opening(i, j, &cnd, mtype)) opn[4] = 1;
X       *val = 80;
X       return 1;
X     }
X  }
X
X if (opn[3])   /* Northeast corner */
X   {
X    opn[3] = 0;
X    if (openregion(13, 13, 18, 18))
X      {
X       cnd = 0;
X       mtype = 3;
X       opening(i, j, &cnd, mtype);  /* get new node for next move */
X       if (opening(i, j, &cnd, mtype)) opn[4] = 1;
X       *val = 80;
X       return 1;
X     }
X  }
X
X/* occupy edges */
X if (opn[5])   /* North edge */
X   {
X    opn[5] = 0;
X    if (openregion(0, 6, 4, 11))
X      {
X       *i = 3;
X       *j = 9;
X       *val = 80;
X       return 1;
X     }
X  }
X
X if (opn[6])   /* South edge */
X   {
X    opn[6] = 0;
X    if (openregion(18, 6, 14, 11))
X      {
X       *i = 15;
X       *j = 9;
X       *val = 80;
X       return 1;
X     }
X  }
X
X if (opn[7])   /* West edge */
X   {
X    opn[7] = 0;
X    if (openregion(6, 0, 11, 4))
X      {
X       *i = 9;
X       *j = 3;
X       *val = 80;
X       return 1;
X     }
X  }
X
X if (opn[8])   /* East edge */
X   {
X    opn[8] = 0;
X    if (openregion(6, 18, 11, 14))
X      {
X       *i = 9;
X       *j = 15;
X       *val = 80;
X       return 1;
X     }
X  }
X
X *i = -1;
X *j = -1;
X *val = -1;
X
X/* find local pattern */
X for (m = 0; m < 19; m++)
X   for (n = 0; n < 19; n++)
X     if ((p[m][n] == mymove) &&
X         (matchpat(m, n, &ti, &tj, &tval) && (tval > *val)))
X       {
X        *val = tval;
X        *i = ti;
X        *j = tj;
X      }
X if (*val > 0)  /* pattern found */
X    return 1;
X else  /* no match found */
X    return 0;
X}  /* end findpatn */
END_OF_FILE
if test 4315 -ne `wc -c <'findpatn.c'`; then
    echo shar: \"'findpatn.c'\" unpacked with wrong size!
fi
# end of 'findpatn.c'
fi
if test -f 'findwinr.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'findwinr.c'\"
else
echo shar: Extracting \"'findwinr.c'\" \(2716 characters\)
sed "s/^X//" >'findwinr.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
X#define EMPTY 0
X
Xextern unsigned char p[19][19], l[19][19];
Xextern int mymove, umove;
Xextern int lib;
X
Xfindwinner(i, j, val)
X/* find opponent piece to capture or attack */
Xint *i, *j, *val;
X{
X int m, n, ti[3], tj[3], tval, ct, u, v, lib1;
X
X *i = -1;   *j = -1;   *val = -1;
X
X/* find opponent with liberty less than four */
X for (m = 0; m < 19; m++)
X   for (n = 0; n < 19; n++)
X     if ((p[m][n] == umove) && (l[m][n] < 4))
X       {
X	ct = 0;
X	initmark();
X	if (findopen(m, n, ti, tj, umove, l[m][n], &ct))
X	  {
X	   if (l[m][n] == 1)
X	     {
X	      if (*val < 120)
X		{
X		 *val = 120;
X		 *i = ti[0];
X		 *j = tj[0];
X	       }
X	    }
X	   else
X	     for (u = 0; u < l[m][n]; u++)
X	       for (v = 0; v < l[m][n]; v++)
X		  if (u != v)
X		    {
X		     lib = 0;
X		     countlib(ti[u], tj[u], mymove);
X		     if (lib > 0) /* valid move */
X		       {
X                        lib1 = lib;
X			p[ti[u]][tj[u]] = mymove;
X		    /* look ahead opponent move */
X			lib = 0;
X			countlib(ti[v], tj[v], umove);
X			if ((lib1 == 1) && (lib > 0))
X                          tval = 0;
X                        else
X                          tval = 120 - 20 * lib;
X			if (*val < tval)
X			  {
X			   *val = tval;
X			   *i = ti[u];
X			   *j = tj[u];
X			 }
X			p[ti[u]][tj[u]] = EMPTY;
X		      }
X		   }
X	 }
X      }
X if (*val > 0)	/* find move */
X    return 1;
X else  /* fail to find winner */
X    return 0;
X}  /* end findwinner */
END_OF_FILE
if test 2716 -ne `wc -c <'findwinr.c'`; then
    echo shar: \"'findwinr.c'\" unpacked with wrong size!
fi
# end of 'findwinr.c'
fi
if test -f 'fioe.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'fioe.c'\"
else
echo shar: Extracting \"'fioe.c'\" \(2585 characters\)
sed "s/^X//" >'fioe.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
Xextern unsigned char p[19][19];
Xextern int mymove;
X
Xfioe(i, j)
X
Xint i, j;
X{
X/* check top edge */
X if (i == 0)
X   {
X    if ((j == 0) && ((p[1][0] == mymove) && (p[0][1] == mymove))) return 1;
X    if ((j == 18) && ((p[1][18] == mymove) && (p[0][17] == mymove))) return 1;
X    if ((p[1][j] == mymove) &&
X	((p[0][j - 1] == mymove) && (p[0][j + 1] == mymove))) return 1;
X    else
X       return 0;
X  }
X/* check bottom edge */
X if (i == 18)
X   {
X    if ((j == 0) && ((p[17][0] == mymove) && (p[18][1] == mymove))) return 1;
X    if ((j == 18) && ((p[17][18] == mymove) && (p[18][17] == mymove))) return 1;
X    if ((p[17][j] == mymove) &&
X	((p[18][j - 1] == mymove) && (p[18][j + 1] == mymove)))
X       return 1;
X    else
X       return 0;
X  }
X/* check left edge */
X if (j == 0)
X    if ((p[i][1] == mymove) &&
X	((p[i - 1] [0] == mymove) && (p[i + 1][0] == mymove)))
X       return 1;
X    else
X       return 0;
X/* check right edge */
X if (j == 18)
X    if ((p[i][17] == mymove) &&
X	((p[i - 1] [18] == mymove) && (p[i + 1][18] == mymove)))
X       return 1;
X    else
X       return 0;
X/* check center pieces */
X if (((p[i][j - 1] == mymove) && (p[i][j + 1] == mymove)) &&
X     ((p[i - 1][j] == mymove) && (p[i + 1][j] == mymove)))
X    return 1;
X else
X    return 0;
X}  /* fioe */
END_OF_FILE
if test 2585 -ne `wc -c <'fioe.c'`; then
    echo shar: \"'fioe.c'\" unpacked with wrong size!
fi
# end of 'fioe.c'
fi
if test -f 'genmove.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'genmove.c'\"
else
echo shar: Extracting \"'genmove.c'\" \(3395 characters\)
sed "s/^X//" >'genmove.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
X#define EMPTY 0
X#define MAXTRY 400
X
Xextern unsigned char p[19][19];
Xextern int mymove, umove;
Xextern int rd, lib, pass;
X
Xgenmove(i, j)
X/* generate computer move */
Xint *i, *j;
X  {
X   int ti, tj, tval;
X   char a;
X   int ii, m, n, val;
X   int try = 0;   /* number of try */
X
X/* initialize move and value */
X   *i = -1;  *j = -1;  val = -1;
X
X/* re-evaluate liberty of opponent pieces */
X   eval(umove);
X
X/* find opponent piece to capture or attack */
X   if (findwinner(&ti, &tj, &tval))
X       if (tval > val)
X	 {
X	  val = tval;
X	  *i = ti;
X	  *j = tj;
X	}
X
X/* save any piece if threaten */
X   if (findsaver(&ti, &tj, &tval))
X       if (tval > val)
X	 {
X	  val = tval;
X	  *i = ti;
X	  *j = tj;
X	}
X
X/* try match local play pattern for new move */
X   if (findpatn(&ti, &tj, &tval))
X       if (tval > val)
X	 {
X	  val = tval;
X	  *i = ti;
X	  *j = tj;
X	}
X
X/* no urgent move then do random move */
X   if (val < 0)
X       do {
X	   random(&rd);
X	   *i = rd % 19;
X/* avoid low line  and center region */
X	   if ((*i < 2) || (*i > 16) || ((*i > 5) && (*i < 13)))
X	     {
X	      random(&rd);
X	      *i = rd % 19;
X	      if ((*i < 2) || (*i > 16))
X		{
X		 random(&rd);
X		 *i = rd % 19;
X	       }
X	    }
X	   random(&rd);
X	   *j = rd % 19;
X/* avoid low line and center region */
X	   if ((*j < 2) || (*j > 16) || ((*j > 5) && (*j < 13)))
X	     {
X	      random(&rd);
X	      *j = rd % 19;
X	      if ((*j < 2) || (*j > 16))
X		{
X		 random(&rd);
X		 *j = rd % 19;
X	       }
X	    }
X	    lib = 0;
X	    countlib(*i, *j, mymove);
X       }
X/* avoid illegal move, liberty one or suicide, fill in own eye */
X       while ((++try < MAXTRY)
X	      && ((p[*i][*j] != EMPTY) || (lib < 2) || fioe(*i, *j)));
X
X   if (try >= MAXTRY)  /* computer pass */
X     {
X      pass++;
X      printf("I pass.\n");
X      *i = -1;
X    }
X   else   /* find valid move */
X     {
X      pass = 0;      
X      printf("my move: ");
X      if (*j < 8)
X	 a = *j + 65;
X      else
X	 a = *j + 66;
X      printf("%c", a);
X      ii = 19 - *i;
X      if (ii < 10)
X	 printf("%1d\n", ii);
X      else
X	 printf("%2d\n", ii);
X    }
X}  /* end genmove */
END_OF_FILE
if test 3395 -ne `wc -c <'genmove.c'`; then
    echo shar: \"'genmove.c'\" unpacked with wrong size!
fi
# end of 'genmove.c'
fi
if test -f 'getmove.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'getmove.c'\"
else
echo shar: Extracting \"'getmove.c'\" \(2630 characters\)
sed "s/^X//" >'getmove.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
X#define EMPTY 0
X
Xextern unsigned char p[19][19];
Xextern int mymove, umove;
Xextern int play, pass;
Xextern int mk, uk;	/* piece captured */
Xextern int opn[9];
X
Xgetmove(move, i, j)
X/* interpret response of human move to board position */
Xchar move[];
Xint *i, *j;
X  {
X   FILE *fp;
X   int m, n;
X
X   if (strcmp(move, "stop") == 0)
X/* stop game */
X      play = 0;
X   else
X     {
X      if (strcmp(move, "save") == 0)
X/* save data and stop game */
X	{
X	 fp = fopen("gnugo.dat", "w");
X/* save board configuration */
X	 for (m = 0; m < 19; m++)
X	   for (n = 0; n < 19; n++)
X	       fprintf(fp, "%c", p[m][n]);
X/* my color, pieces captured */
X         fprintf(fp, "%d %d %d ", mymove, mk, uk);
X/* opening pattern flags */
X         for (m = 0; m < 9; m++)
X           fprintf(fp, "%d ", opn[m]);
X
X	 fclose(fp);
X	 play = -1;
X       }
X      else
X	{
X	 if (strcmp(move, "pass") == 0)
X/* human pass */
X	   {
X	    pass++;
X	    *i = -1;   /* signal pass */
X	  }
X	 else
X	   {
X	    pass = 0;
X/* move[0] from A to T, move[1] move[2] from 1 to 19 */
X/* convert move to coordinate */
X	    if (!getij(move, i, j) || (p[*i][*j] != EMPTY) || suicide(*i, *j))
X	      {
X	       printf("illegal move !\n");
X	       printf("your move? ");
X	       scanf("%s", move);
X	       getmove(move, i, j);
X	     }
X	 }
X       }
X    }
X}  /* end getmove */
END_OF_FILE
if test 2630 -ne `wc -c <'getmove.c'`; then
    echo shar: \"'getmove.c'\" unpacked with wrong size!
fi
# end of 'getmove.c'
fi
if test -f 'main.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'main.c'\"
else
echo shar: Extracting \"'main.c'\" \(4210 characters\)
sed "s/^X//" >'main.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
X#define EMPTY 0
X
Xunsigned char p[19][19], l[19][19], ma[19][19], ml[19][19];
Xint mymove, umove;
Xint rd, lib, play, pass;
Xint mik, mjk, uik, ujk, mk, uk;  /* piece captured */
Xint opn[9];  /* opening pattern flag */
X
Xmain()
X  {
X   FILE *fp;
X   int i, j;
X   char move[10], ans[5];
X   int cont = 0;
X
X/* show instruction */
X   showinst();
X
X   if ((fp = fopen("gnugo.dat", "r")) != NULL)  /* continue old game */
X     {
X      cont = 1;
X
X/* read board configuration */
X      for (i = 0; i < 19; i++)
X        for (j = 0; j < 19; j++)
X          fscanf(fp, "%c", &p[i][j]);
X
X/* read my color, pieces captured */
X      fscanf(fp, "%d %d %d ", &mymove, &mk, &uk);
X/* read opening pattern flags */
X      for (i = 0; i < 9; i++)
X        fscanf(fp, "%d ", &opn[i]);
X
X      fclose(fp);
X      umove = 3 - mymove;
X
X/* delete file */
X      unlink("gnugo.dat");
X    }
X   else
X     {
X/* init opening pattern numbers to search */
X      for (i = 0; i < 9; i++)
X        opn[i] = 1;
X      opn[4] = 0;
X
X/* init board */
X      for (i = 0; i < 19; i++)
X        for (j = 0; j < 19; j++)
X          p[i][j] = EMPTY;
X/* init global variables */
X      mk = 0;  uk = 0;
X    }
X
X/* init global variables */
X   play = 1;
X   pass = 0;
X   mik = -1; mjk = -1;
X   uik = -1; ujk = -1;
X   seed(&rd);	/* start random number seed */
X
X   if (!cont)  /* new game */
X     {
X/* ask for handicap */
X      printf("Number of handicap for black (0 to 17)? ");
X      scanf("%d", &i);
X      getchar();
X      sethand(i);
X
X/* display game board */
X      showboard();
X
X/* choose color */
X      printf("\nChoose side(b or w)? ");
X      scanf("%c",ans);
X      if (ans[0] == 'b')
X        {
X         mymove = 1;   /* computer white */
X         umove = 2;   /* human black */
X         if (i)
X	   {
X            genmove(&i, &j);   /* computer move */
X            p[i][j] = mymove;
X          }
X       }
X      else
X        {
X         mymove = 2;   /* computer black */
X         umove = 1;   /* human white */
X         if (i == 0)
X	   {
X            genmove(&i, &j);   /* computer move */
X            p[i][j] = mymove;
X          }
X       }
X    }
X
X   showboard();
X
X/* main loop */
X   while (play > 0)
X     {
X      printf("your move? ");
X      scanf("%s", move);
X      getmove(move, &i, &j);   /* read human move */
X      if (play > 0)
X	{
X	 if (i >= 0)   /* not pass */
X	   {
X	    p[i][j] = umove;
X	    examboard(mymove);	 /* remove my dead pieces */
X	  }
X	 if (pass != 2)
X	   {
X	    genmove(&i, &j);   /* computer move */
X	    if (i >= 0)   /* not pass */
X	      {
X	       p[i][j] = mymove;
X	       examboard(umove);   /* remove your dead pieces */
X	     }
X	  }
X	 showboard();
X       }
X      if (pass == 2) play = 0;	/* both pass then stop game */
X    }
X
X if (play == 0)
X   {
X/* finish game and count pieces */
X    getchar();
X    printf("Do you want to count score (y or n)? ");
X    scanf("%c",ans);
X    if (ans[0] == 'y') endgame();
X  }
X }  /* end main */
END_OF_FILE
if test 4210 -ne `wc -c <'main.c'`; then
    echo shar: \"'main.c'\" unpacked with wrong size!
fi
# end of 'main.c'
fi
if test -f 'objs' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'objs'\"
else
echo shar: Extracting \"'objs'\" \(208 characters\)
sed "s/^X//" >'objs' <<'END_OF_FILE'
XCOUNT COUNTLIB ENDGAME EVAL EXAMBORD FINDCOLR FINDNEXT FINDOPEN +
XFINDPATN FINDSAVR FINDWINR FIOE GENMOVE GETIJ GETMOVE INITMARK MAIN MATCHPAT +
XOPENING OPENREGN RANDOM SEED SETHAND SHOWBORD SHOWINST SUICIDE
END_OF_FILE
if test 208 -ne `wc -c <'objs'`; then
    echo shar: \"'objs'\" unpacked with wrong size!
fi
# end of 'objs'
fi
if test -f 'opening.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'opening.c'\"
else
echo shar: Extracting \"'opening.c'\" \(2432 characters\)
sed "s/^X//" >'opening.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
Xextern int rd;
X
Xopening(i, j, cnd, type)
X/* get move for opening from game tree */
Xint *i, *j, *cnd, type;
X{
X struct tnode {
X   int i, j, ndct, next[8];
X  };
X
X static struct tnode tree[] = {
X  {-1, -1, 8, { 1, 2, 3, 4, 5, 6, 7, 20}},	/* 0 */
X  {2, 3, 2, { 8, 9}},
X  {2, 4, 1, {10}},
X  {3, 2, 2, {11, 12}},
X  {3, 3, 6, {14, 15, 16, 17, 18, 19}},
X  {3, 4, 1, {10}},  /* 5 */
X  {4, 2, 1, {13}},
X  {4, 3, 1, {13}},
X  {4, 2, 0},
X  {4, 3, 0},
X  {3, 2, 0},  /* 10 */
X  {2, 4, 0},
X  {3, 4, 0},
X  {2, 3, 0},
X  {2, 5, 1, {10}},
X  {2, 6, 1, {10}},  /* 15 */
X  {3, 5, 1, {10}},
X  {5, 2, 1, {13}},
X  {5, 3, 1, {13}},
X  {6, 2, 1, {13}},
X  {2, 2, 0}  /* 20 */
X};
Xint m;
X
X/* get i, j */
X if ((type == 1) || (type == 3))
X    *i = 18 - tree[*cnd].i;   /* inverted */
X else
X    *i = tree[*cnd].i;
X if ((type == 2) || (type == 3))
X    *j = 18 - tree[*cnd].j;   /* reflected */
X else
X    *j = tree[*cnd].j;
X if (tree[*cnd].ndct)  /* more move */
X   {
X    random(&rd);
X    m = rd % tree[*cnd].ndct;  /* select move */
X    *cnd = tree[*cnd].next[m];	/* new	current node */
X    return 1;
X  }
X else
X    return 0;
X}  /* end opening */
X
END_OF_FILE
if test 2432 -ne `wc -c <'opening.c'`; then
    echo shar: \"'opening.c'\" unpacked with wrong size!
fi
# end of 'opening.c'
fi
if test -f 'sethand.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'sethand.c'\"
else
echo shar: Extracting \"'sethand.c'\" \(2343 characters\)
sed "s/^X//" >'sethand.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#include <stdio.h>
X
X#define BLACK 2
X
Xextern unsigned char p[19][19];
X
Xsethand(i)
X/* set up handicap pieces */
Xint i;
X
X{
X if (i > 0)
X   {
X    p[3][3] = BLACK;
X    if (i > 1)
X      {
X       p[15][15] = BLACK;
X       if (i > 2)
X	 {
X	  p[3][15] = BLACK;
X	  if (i > 3)
X	    {
X	     p[15][3] = BLACK;
X	     if (i == 5)
X		p[9][9] = BLACK;
X	     else
X		if (i > 5)
X		  {
X		   p[9][15] = BLACK;
X		   p[9][3] = BLACK;
X		   if (i == 7)
X		      p[9][9] = BLACK;
X		   else
X		      if (i > 7)
X			{
X			 p[15][9] = BLACK;
X			 p[3][9] = BLACK;
X			 if (i > 8)
X			 p[9][9] = BLACK;
X 			 if (i > 9)
X 			   {p[2][2] = 2;
X 			    if (i > 10)
X 			      {p[16][16] = 2;
X 			       if (i > 11)
X 				 {p[2][16] = 2;
X 				  if (i > 12)
X 				    {p[16][2] = 2;
X 				     if (i > 13)
X 				       {p[6][6] = 2;
X 					if (i > 14)
X 					  {p[12][12] = 2;
X 					   if (i > 15)
X 					     {p[6][12] = 2;
X 					      if (i > 16)
X 						p[12][6] = 2;
X 					    }
X 					 }
X 				      }
X 				   }
X 				}
X 			     }
X 			  }
X		       }
X		 }
X	   }
X	}
X     }
X  }
X}  /* end sethand */
END_OF_FILE
if test 2343 -ne `wc -c <'sethand.c'`; then
    echo shar: \"'sethand.c'\" unpacked with wrong size!
fi
# end of 'sethand.c'
fi
if test -f 'showinst.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'showinst.c'\"
else
echo shar: Extracting \"'showinst.c'\" \(4230 characters\)
sed "s/^X//" >'showinst.c' <<'END_OF_FILE'
X/*
X                GNU GO - the game of Go (Wei-Chi)
X                Version 1.1   last revised 3-1-89
X           Copyright (C) Free Software Foundation, Inc.
X                      written by Man L. Li
X                      modified by Wayne Iba
X                    documented by Bob Webber
X*/
X/*
XThis program is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation - version 1.
X
XThis program is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License in file COPYING for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with this program; if not, write to the Free Software
XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XPlease report any bug/fix, modification, suggestion to
X
Xmail address:   Man L. Li
X                Dept. of Computer Science
X                University of Houston
X                4800 Calhoun Road
X                Houston, TX 77004
X
Xe-mail address: manli@cs.uh.edu         (Internet)
X                coscgbn@uhvax1.bitnet   (BITNET)
X                70070,404               (CompuServe)
X*/
X
X#define  SUN  68000
X
X#include <stdio.h>
X
Xshowinst()
X/* show program instructions */
X{
X printf("XOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOX");
X printf("OXOXOXOXOXOX\n");
X printf("O                                                                  ");
X printf("           O\n");
X printf("X                           GNU GO (Previously Hugo)               ");
X printf("           X\n");
X printf("O                           the game of Go (Wei-Chi)               ");
X printf("           O\n");
X printf("X                                                                  ");
X printf("           X\n");
X printf("O                            version 1.1    3-1-89                 ");
X printf("           O\n");
X printf("X              Copyright (C) 1989 Free Software Foundation, Inc.   ");
X printf("           X\n");
X printf("O                              Author: Man L. Li                   ");
X printf("           O\n");
X printf("X         GNU GO comes with ABSOLUTELY NO WARRANTY; see COPYING for");
X printf("           X\n");
X printf("O         detail.   This is free software, and you are welcome to  ");
X printf("           O\n");
X printf("X         redistribute it; see COPYING for copying conditions.     ");
X printf("           X\n");
X printf("O                                                                  ");
X printf("           O\n");
X
X#ifdef SUN
X
X printf("X              Please report all bugs, modifications, suggestions  ");
X printf("           X\n");
X printf("O                         to manli@cs.uh.edu  (Internet)           ");
X printf("           O\n");
X
X#endif
X
X printf("X                                                                  ");
X printf("           X\n");
X printf("OXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXO");
X printf("XOXOXOXOXOXO\n");
X printf("\n\n\n\n\n\n\n\nPress return to continue");
X getchar();
X printf("\n\nTo play this game first select number of handicap pieces (0 to");
X printf(" 17) for the\nblack side.  Next choose your color (black or white).");
X printf("  To place your piece,\nenter your move as coordinate on the board");
X printf(" in column and row.  The column\nis from 'A' to 'T'(excluding 'I').");
X printf("  The row is from 1 to 19.\n\nTo pass your move enter 'pass' for");
X printf(" your turn.  After both you and the computer\npassed the game will");
X printf(" end.  To save the board and exit enter 'save'.  The game\nwill");
X printf(" continue the next time you start the program.  To stop the game in");
X printf(" the\nmiddle of play enter 'stop' for your move.  You will be");
X printf(" asked whether you want\nto count the result of the game.  If you");
X printf(" answer 'y' then you need to remove the\nremaining dead pieces and");
X printf(" fill up neutral turf on the board as instructed.\nFinally, the");
X printf(" computer will count all pieces for both side and show the result.\n\n");
X}  /* end showinst */
X
END_OF_FILE
if test 4230 -ne `wc -c <'showinst.c'`; then
    echo shar: \"'showinst.c'\" unpacked with wrong size!
fi
# end of 'showinst.c'
fi
echo shar: End of archive 2 \(of 3\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 3 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0