Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

v06i021: gnugo - game of GO from the GNU folks, Part03/03

114 views
Skip to first unread message

ga...@tekred.cna.tek.com

unread,
Mar 13, 1989, 2:47:46 PM3/13/89
to
Submitted-by: Man Lung Li <ma...@sun2.cs.uh.edu>
Posting-number: Volume 6, Issue 21
Archive-name: gnugo/Part03

#! /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 3 (of 3)."
# Contents: countlib.c eval.c findsavr.c getij.c initmark.c openregn.c
# random.c seed.c suicide.c
# Wrapped by billr@saab on Mon Mar 13 11:05:01 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'countlib.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'countlib.c'\"
else
echo shar: Extracting \"'countlib.c'\" \(1639 characters\)
sed "s/^X//" >'countlib.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: ma...@cs.uh.edu (Internet)
X cos...@uhvax1.bitnet (BITNET)
X 70070,404 (CompuServe)
X*/
X
X#include <stdio.h>
X
Xextern unsigned char ml[19][19];
X
Xcountlib(m, n, color)
X/* count liberty of color piece at m, n */
Xint m, n, color;
X{
X int i, j;
X
X/* set all piece as unmarked */
X for (i = 0; i < 19; i++)
X for (j = 0; j < 19; j++)
X ml[i][j] = 1;
X
X/* count liberty of current piece */
X count(m, n, color);
X} /* end countlib */
X
END_OF_FILE
if test 1639 -ne `wc -c <'countlib.c'`; then
echo shar: \"'countlib.c'\" unpacked with wrong size!
fi
# end of 'countlib.c'
fi
if test -f 'eval.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'eval.c'\"
else
echo shar: Extracting \"'eval.c'\" \(1659 characters\)
sed "s/^X//" >'eval.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: ma...@cs.uh.edu (Internet)
X cos...@uhvax1.bitnet (BITNET)
X 70070,404 (CompuServe)
X*/
X
X#include <stdio.h>
X
Xextern unsigned char p[19][19], l[19][19];
Xextern int lib;
X
Xeval(color)
X/* evaluate liberty of color pieces */
Xint color;
X {
X int i, j;
X
X/* find liberty of each piece */
X for (i = 0; i < 19; i++)
X for (j = 0; j < 19; j++)
X if (p[i][j] == color)
X {
X lib = 0;
X countlib(i, j, color);
X l[i][j] = lib;
X }
X} /* end eval */
END_OF_FILE
if test 1659 -ne `wc -c <'eval.c'`; then
echo shar: \"'eval.c'\" unpacked with wrong size!
fi
# end of 'eval.c'
fi
if test -f 'findsavr.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'findsavr.c'\"
else
echo shar: Extracting \"'findsavr.c'\" \(2075 characters\)
sed "s/^X//" >'findsavr.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: ma...@cs.uh.edu (Internet)
X cos...@uhvax1.bitnet (BITNET)
X 70070,404 (CompuServe)
X
X
X
X*/
X
X#include <stdio.h>
X
Xextern unsigned char p[19][19], l[19][19];
Xextern int mymove;
X
Xfindsaver(i, j, val)
X/* find move if any pieces is threaten */
Xint *i, *j, *val;
X {
X int m, n, minlib;
X int ti, tj, tval;
X
X *i = -1; *j = -1; *val = -1;
X for (minlib = 1; minlib < 4; minlib++)
X {
X/* count piece with minimum liberty */
X for (m = 0; m < 19; m++)
X for (n = 0; n < 19; n++)
X if ((p[m][n] == mymove) && (l[m][n] == minlib))
X/* find move to save pieces */
X {
X initmark();
X if (findnextmove(m, n, &ti, &tj, &tval, minlib) && (tval > *val))
X {
X *val = tval;
X *i = ti;
X *j = tj;
X }
X }
X }
X if (*val > 0) /* find move */
X return 1;
X else /* move not found */
X return 0;
X } /* findsaver */
END_OF_FILE
if test 2075 -ne `wc -c <'findsavr.c'`; then
echo shar: \"'findsavr.c'\" unpacked with wrong size!
fi
# end of 'findsavr.c'
fi
if test -f 'getij.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'getij.c'\"
else
echo shar: Extracting \"'getij.c'\" \(1904 characters\)
sed "s/^X//" >'getij.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: ma...@cs.uh.edu (Internet)
X cos...@uhvax1.bitnet (BITNET)
X 70070,404 (CompuServe)
X*/
X
X#include <stdio.h>
X
Xgetij(move, i, j)
X/* convert string input to i, j coordinate */
Xchar move[];
Xint *i, *j;
X{
X int k;
X
X if ((move[0] >= 65) && (move[0] <= 72))
X *j = move[0] - 65;
X else
X if ((move[0] >= 74) && (move[0] <= 84))
X *j = move[0] - 66;
X else
X if ((move[0] >= 97) && (move[0] <= 104))
X *j = move[0] - 97;
X else
X if ((move[0] >= 106) && (move[0] <= 116))
X *j = move[0] - 98;
X else
X return 0;
X k = move[1] - 48;
X if (move[2]) k = k * 10 + move[2] - 48;
X *i = 19 - k;
X if ((*i >= 0) && (*i <= 18))
X return 1;
X else
X return 0;
X} /* end getij */
END_OF_FILE
if test 1904 -ne `wc -c <'getij.c'`; then
echo shar: \"'getij.c'\" unpacked with wrong size!
fi
# end of 'getij.c'
fi
if test -f 'initmark.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'initmark.c'\"
else
echo shar: Extracting \"'initmark.c'\" \(1498 characters\)
sed "s/^X//" >'initmark.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: ma...@cs.uh.edu (Internet)
X cos...@uhvax1.bitnet (BITNET)
X 70070,404 (CompuServe)
X*/
X
Xextern unsigned char ma[19][19];
X
Xinitmark()
X/* initialize all marking with zero */
X{
Xint i, j;
X
X for (i = 0; i < 19; i++)
X for (j = 0; j < 19; j++)
X ma[i][j] = 0;
X} /* end initmark */
X
END_OF_FILE
if test 1498 -ne `wc -c <'initmark.c'`; then
echo shar: \"'initmark.c'\" unpacked with wrong size!
fi
# end of 'initmark.c'
fi
if test -f 'openregn.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'openregn.c'\"
else
echo shar: Extracting \"'openregn.c'\" \(1915 characters\)
sed "s/^X//" >'openregn.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: ma...@cs.uh.edu (Internet)
X cos...@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
Xopenregion(i1, j1, i2, j2)
X/* check if region from i1, j1 to i2, j2 is open */
Xint i1, j1, i2, j2;
X
X{
X int minx, maxx, miny, maxy, x, y;
X
X/* exchange upper and lower limits */
X
X if (i1 < i2)
X {
X miny = i1;
X maxy = i2;
X }
X else
X {
X miny = i2;
X maxy = i1;
X }
X
X if (j1 < j2)
X {
X minx = j1;
X maxx = j2;
X }
X else
X {
X minx = j2;
X maxx = j1;
X }
X
X/* check for empty region */
X for (y = miny; y <= maxy; y++)
X for (x = minx; x <= maxx; x++)
X if (p[y][x] != EMPTY) return 0;
X return 1;
X} /* end openregion */
X
END_OF_FILE
if test 1915 -ne `wc -c <'openregn.c'`; then
echo shar: \"'openregn.c'\" unpacked with wrong size!
fi
# end of 'openregn.c'
fi
if test -f 'random.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'random.c'\"
else
echo shar: Extracting \"'random.c'\" \(1481 characters\)
sed "s/^X//" >'random.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: ma...@cs.uh.edu (Internet)
X cos...@uhvax1.bitnet (BITNET)
X 70070,404 (CompuServe)
X*/
X
Xrandom(i)
X/* random number generator */
Xint *i;
X {
X if (*i == 0)
X seed(i);
X else
X {
X *i = *i * 137 % 3833;
X if (*i < 0) *i = -*i;
X }
X} /* end random */
X
END_OF_FILE
if test 1481 -ne `wc -c <'random.c'`; then
echo shar: \"'random.c'\" unpacked with wrong size!
fi
# end of 'random.c'
fi
if test -f 'seed.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'seed.c'\"
else
echo shar: Extracting \"'seed.c'\" \(1926 characters\)
sed "s/^X//" >'seed.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: ma...@cs.uh.edu (Internet)
X cos...@uhvax1.bitnet (BITNET)
X 70070,404 (CompuServe)
X*/
X
X/*
X#define IBM 8086
X*/
X
X#define SUN 68000
X
X#include <stdio.h>
X
X#ifdef SUN
X
X#include <sys/time.h>
X
X#endif
X
X#ifdef IBM
X
Xseed(i)
X/* start seed of random number generator for PC */
X/* Computer Innovation C86 compiler version */
Xint *i;
X {
X struct regval {int ax, bx, cx, dx, si, di, ds, es;};
X struct regval sreg, rreg;
X
X sreg.ax = 0x2c00;
X sysint21(&sreg, &rreg);
X *i = rreg.dx;
X} /* end seed */
X#endif
X
X
X#ifdef SUN
X
Xseed(i)
X/* start seed of random number generator for Sun */
Xint *i;
X {
X struct timeval tp;
X struct timezone tzp;
X
X gettimeofday(&tp, &tzp);
X *i = tp.tv_usec;
X} /* end seed */
X
X#endif
X
END_OF_FILE
if test 1926 -ne `wc -c <'seed.c'`; then
echo shar: \"'seed.c'\" unpacked with wrong size!
fi
# end of 'seed.c'
fi
if test -f 'suicide.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'suicide.c'\"
else
echo shar: Extracting \"'suicide.c'\" \(2260 characters\)
sed "s/^X//" >'suicide.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: ma...@cs.uh.edu (Internet)
X cos...@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;
Xextern int uik, ujk; /* piece captured */
X
Xsuicide(i, j)
X/* check for suicide move of opponent at p[i][j] */
Xint i, j;
X{
X int m, n, k;
X
X/* check liberty of new move */
X lib = 0;
X countlib(i, j, umove);
X if (lib == 0)
X/* new move is suicide then check if kill my pieces and Ko possibility */
X {
X/* assume alive */
X p[i][j] = umove;
X
X/* check my pieces */
X eval(mymove);
X k = 0;
X
X for (m = 0; m < 19; m++)
X for (n = 0; n < 19; n++)
X/* count pieces will be killed */
X if ((p[m][n] == mymove) && !l[m][n]) ++k;
X
X if ((k == 0) || (k == 1 && ((i == uik) && (j == ujk))))
X/* either no effect on my pieces or an illegal Ko take back */
X {
X p[i][j] = EMPTY; /* restore to open */
X return 1;
X }
X else
X/* good move */
X return 0;
X }
X else
X/* valid move */
X return 0;
X} /* end suicide */
X
END_OF_FILE
if test 2260 -ne `wc -c <'suicide.c'`; then
echo shar: \"'suicide.c'\" unpacked with wrong size!
fi
# end of 'suicide.c'
fi
echo shar: End of archive 3 \(of 3\).
cp /dev/null ark3isdone
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

0 new messages