[comp.sources.games] v04i005: xgo - go for curses or X-windows, Part01/04

games@tekred.TEK.COM (04/09/88)

Submitted by: Greg Hale <sting.berkeley.edu!hale@ucbvax>
Comp.sources.games: Volume 4, Issue 5
Archive-name: xgo/Part01


	[From the author...	-br]
	[[This version runs under unix on a text terminal and on
	  an X display.  It allows two people to play Go at different
	  terminals and sites at real time, and allow saving, restoring,
	  scoring, and demonstration modes during the game.  Estimated
	  ranks are kept track of and handicaps are given.  Either can
	  be changed at any time from the command line.]]

#! /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 1 (of 4)."
# Contents:  README MANIFEST XButton.h connect.c doother.c file.c games
#   go.6 go.doc xstatus.c
# Wrapped by billr@saab on Fri Apr  8 14:27:14 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f README -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"README\"
else
echo shar: Extracting \"README\" \(3051 characters\)
sed "s/^X//" >README <<'END_OF_README'
XGo is the ancient oriental strategy game which has become very popular
Xall over the world in the last few years.  'go' runs on a text
Xscreen and 'xgo' runs on an X display.  The programs interact
Xbetween 2 players over the network, allowing two people far away to
Xplay a game together.
X
X
XTo make the go and xgo programs, type:
X    make
X
XTo install them, type:
X    make install
X
X
XIf you only want the Ascii version to be made, type:
X    make go
Xthen:
X    make installgo
X
Xyou may have to change the permissions on the ./games directory
Xif you want people to be able to read it.
X
XThere have been problems with some systems with variables
Xnot being defined.  If you get re-defined errors from
Xconnect.c, just remove the lines near the top between and
Xincluding the #ifndef.
X
XBy default, this will install the programs in /usr/public.
XYou may change this by modifying the BINDIR variable
Xin the Makefile.
XIt will also install the man page in MANDIR (default:
X/usr/man/manl).
XThe go.players file is a file for users to put their names and
Xranks in, so prospective players can look for opponents.
XIt gets installed in ETCDIR (also /usr/public, by default).
X
XThis is a preliminary version, so it may still have a few bugs in it.
XIf you want full source code, comments will be available at some
Xlater time.
X
X
XHave fun,
XGreg Hale
X
XP.S.  I am considering putting together a larger player list.  If you
Xare interested, send names to me at my address given in the man page.
X(Please include what the letter is for.)
X
X**********************************************************************
XChanges:
X
X11/15/87 (v 1.2)
X	Added command line arguements, variable board size, handicapping.
X	Also the port to be selected is available to the user in case
X	several games are running at once and you want to avoid collisions.
X	Makefile modified so that the text version can be made without
X	the X version.  README and documentation updated accordingly.
X
X11/23/87 (v 1.5)
X	-c option for command line welcome message.  Show last move
X	command (key is '/').  Go beeps when a message is sent.  Nomove.c
X	modified- some compilers thought the expression was too
X	complicated.  The makefile was cleaned up of all useless
X	dependencies.
X
X
X11/27/87 (v 1.6)
X	Stregth and wins kept track of in a default file in the
X	home directory of the user.  It uses this to determine
X	sides and handicapping.  I/O problems in the text version
X	fixed- the old one crashed when both the socket and stdin
X	selected.
X
X	Because of protocol changes, earlier versions are
X	incompatable.
X
X1/30/88 (v 2.0)
X	The demonstation mode and optional beeping was added.
X	No more bugs have been found, reported, or suspected.
X
X	Because of protocol changes, earlier versions are
X	incompatable.
X
X2/10/88 (v 2.1)
X	Change in arguments, modification to strength and scoring
X	algorithm.  A bug in declining led to lock up and other
X	such nonsense and was fixed.  More command line options
X	and KOMI added to scoring.
X
X$Log:	README,v $
X# Revision 1.2  88/03/10  12:15:25  hale
X# Just commented on installation of ./games.
X# 
X
END_OF_README
if test 3051 -ne `wc -c <README`; then
    echo shar: \"README\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f MANIFEST -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"MANIFEST\"
else
echo shar: Extracting \"MANIFEST\" \(3264 characters\)
sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X MANIFEST                  1	This shipping list
X Makefile                  2	
X README                    1	
X XButton.h                 1	
X Xblack.h                  3	
X Xcursblk.h                3	
X Xcursmsk.h                3	
X Xcurswht.h                3	
X Xd.h                      4	
X Xdl.h                     3	
X Xdr.h                     3	
X Xfbl.h                    3	
X Xfwh.h                    3	
X Xintersect.h              3	
X Xl.h                      3	
X Xmask.h                   3	
X Xmask0.h                  3	
X Xneu.h                    3	
X Xpiecemask.h              3	
X Xpoint.h                  3	
X Xr.h                      3	
X Xu.h                      4	
X Xul.h                     3	
X Xur.h                     3	
X Xwhite.h                  3	
X backup.c                  3	
X changes.c                 2	
X chkmve.c                  3	
X connect.c                 1	
X curse.c                   2	
X del.c                     4	
X dohand.c                  4	
X doloop.c                  2	
X doother.c                 1	
X exit.c                    4	
X file.c                    1	
X fill.c                    4	
X games                     1	
X games/Proto               4	
X games/Proto.blk           4	
X games/README              4	
X games/enig.1k.1           4	
X games/enig.2k.1           4	
X games/g.10k.2             4	
X games/g.11k.1             4	
X games/g.12k.1             4	
X games/g.15k.1             4	
X games/g.15k.2             4	
X games/g.9k.1              4	
X games/save.10k            4	
X games/save.10k.1          4	
X go.6                      1	
X go.c                      4	
X go.doc                    1	
X go.h                      2	
X go.players                3	
X handicap.c                4	
X help.c                    3	
X info                      3	
X init.c                    3	
X initboard.c               4	
X kill.c                    4	
X killit.c                  4	
X life.c                    2	
X loop.c                    3	
X looputil.c                3	
X main.c                    2	
X mesg.c                    2	
X mesg.h                    3	
X movecur.c                 4	
X moveto.c                  4	
X nomove.c                  4	
X opts.c                    2	
X plt.c                     4	
X printboard.c              3	
X putpiece.c                2	
X score.c                   2	
X setboard.c                4	
X status.c                  4	
X strength.c                2	
X tally.c                   4	
X traps.c                   3	
X util.c                    4	
X var.c                     3	
X xbit.c                    2	
X xclick.c                  2	
X xexit.c                   4	
X xexpose.c                 2	
X xgo.c                     4	
X xgo.h                     3	
X xinit.c                   4	
X xinitloop.c               2	
X xio.c                     3	
X xkeyp.c                   4	
X xloop.c                   2	
X xmesg.c                   2	
X xpiecenum.h               4	
X xplt.c                    4	
X xprintboard.c             4	
X xstatus.c                 1	
X xtraps.c                  4	
X xutil.c                   3	
X xvar.c                    4	
X xwin.h                    3	
X xwindow.c                 2	
END_OF_MANIFEST
if test 3264 -ne `wc -c <MANIFEST`; then
    echo shar: \"MANIFEST\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f XButton.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"XButton.h\"
else
echo shar: Extracting \"XButton.h\" \(2049 characters\)
sed "s/^X//" >XButton.h <<'END_OF_XButton.h'
X/*
X * $Header: XButton.h,v 1.2 88/02/13 12:55:45 hale Exp $
X */
X
X/*
X
X        Copyright 1987      Greg Hale
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X
X#define XButton_width 80
X#define XButton_height 30
Xstatic short XButton_bits[] = {
X   0x0000, 0x0000, 0x0000, 0x0000,
X   0x0000, 0xffc0, 0xffff, 0xffff,
X   0xffff, 0x03ff, 0x0030, 0x0000,
X   0x0000, 0x0000, 0x0c00, 0xffc8,
X   0xffff, 0xffff, 0xffff, 0x13ff,
X   0x0024, 0x0000, 0x0000, 0x0000,
X   0x2400, 0x0014, 0x0000, 0x0000,
X   0x0000, 0x2800, 0x000a, 0x0000,
X   0x0000, 0x0000, 0x5000, 0x000a,
X   0x0000, 0x0000, 0x0000, 0x5000,
X   0x000a, 0x0000, 0x0000, 0x0000,
X   0x5000, 0x000a, 0x0000, 0x0000,
X   0x0000, 0x5000, 0x000a, 0x0000,
X   0x0000, 0x0000, 0x5000, 0x000a,
X   0x0000, 0x0000, 0x0000, 0x5000,
X   0x000a, 0x0000, 0x0000, 0x0000,
X   0x5000, 0x000a, 0x0000, 0x0000,
X   0x0000, 0x5000, 0x000a, 0x0000,
X   0x0000, 0x0000, 0x5000, 0x000a,
X   0x0000, 0x0000, 0x0000, 0x5000,
X   0x000a, 0x0000, 0x0000, 0x0000,
X   0x5000, 0x000a, 0x0000, 0x0000,
X   0x0000, 0x5000, 0x000a, 0x0000,
X   0x0000, 0x0000, 0x5000, 0x000a,
X   0x0000, 0x0000, 0x0000, 0x5000,
X   0x000a, 0x0000, 0x0000, 0x0000,
X   0x5000, 0x000a, 0x0000, 0x0000,
X   0x0000, 0x5000, 0x000a, 0x0000,
X   0x0000, 0x0000, 0x5000, 0x000a,
X   0x0000, 0x0000, 0x0000, 0x5000,
X   0x0014, 0x0000, 0x0000, 0x0000,
X   0x2800, 0x0024, 0x0000, 0x0000,
X   0x0000, 0x2400, 0xffc8, 0xffff,
X   0xffff, 0xffff, 0x13ff, 0x0030,
X   0x0000, 0x0000, 0x0000, 0x0c00,
X   0xffc0, 0xffff, 0xffff, 0xffff,
X   0x03ff, 0x0000, 0x0000, 0x0000,
X   0x0000, 0x0000};
X/*
X * $Log:	XButton.h,v $
X * Revision 1.2  88/02/13  12:55:45  hale
X * added logging.
X * 
X */
X
END_OF_XButton.h
if test 2049 -ne `wc -c <XButton.h`; then
    echo shar: \"XButton.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f connect.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"connect.c\"
else
echo shar: Extracting \"connect.c\" \(5470 characters\)
sed "s/^X//" >connect.c <<'END_OF_connect.c'
X/*
X * $Header: connect.c,v 1.2 88/02/13 12:43:37 hale Exp $
X */
X
X/*
X
X        Copyright 1987      Greg Hale
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X
X#include "go.h"
X#include <sys/param.h>
X#include <netinet/in.h>
X#include <netdb.h>
X#include <pwd.h>
X#include <errno.h>
X
X/*
X * Some systems do not have these defined in the include files.
X */
X#ifndef MAXHOSTNAMELEN
X#define MAXHOSTNAMELEN 256
Xtypedef short uid_t;
X#endif
X
Xchar *opponent;
Xchar myhostname[MAXHOSTNAMELEN+1];
Xextern char *myname;
X
Xextern int errno;
X
XFILE *inp, *out;
X
Xconnectport (oppon, port)
Xchar *oppon;
Xu_short port;
X{
X	struct sockaddr_in addr;
X	struct hostent *host;
X	struct passwd *mypasswd, *getpwuid();
X	char *hishostname, *index(), *getpw(), *malloc();
X	char *hisaddr, *myaddr;
X	int hislen, mylen;
X	u_long iaddr;
X	uid_t getuid();
X	u_short hashport(), hashaddr();
X	char *copyhost();
X	int s, i;
X
X	opponent = oppon;
X	if (gethostname (myhostname, MAXHOSTNAMELEN) < 0)
X		error ("gethostname in connectport");
X	host = gethostbyname(myhostname);
X	if (host == NULL) {
X		errno = 0;
X		error("don't know my own name.");
X	}
X	mylen = host->h_length;
X	myaddr = copyhost(host);
X	if (hishostname = index (oppon, '@')) {
X		*hishostname++ = '\0';        /* separate user and host */
X		if (hishostname[0] >= '0' && hishostname[0] <= '9') {
X			iaddr = inet_addr(hishostname);
X			hisaddr = (char *)&iaddr;
X			hislen = sizeof iaddr;
X		} else {
X			host = gethostbyname(hishostname);
X			if (host == NULL) {
X				errno = 0;
X				error("Unknown host");
X			}
X			hislen = host->h_length;
X			hisaddr = copyhost(host);
X			hishostname = host->h_name;
X		}
X	} else {
X		hislen = mylen;
X		hisaddr = myaddr;
X		hishostname = myhostname;
X	}
X	mypasswd = getpwuid ((int) getuid());
X	myname = mypasswd -> pw_name;
X
X	if (iamserver == UNSET)
X		if (i = strcmp (myname, oppon))
X			iamserver = (i < 0);
X		else if (i = comparehost(myaddr, hisaddr, mylen))
X			iamserver = (i < 0);
X	if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0)
X		error ("socket in connectport");
X	bzero ((char *) &addr, sizeof (addr));
X	if (port != 0) {
X		if (port > 1000) {
X			errno = 0;
X			error ("bad port number");
X		}
X	} else if (iamserver) {
X		port = hashaddr(myaddr, port, mylen);
X		port = hashaddr(hisaddr, port, hislen);
X		port = hashport(myname, port);
X		port = hashport(oppon, port);
X	} else {
X		port = hashaddr(hisaddr, port, hislen);
X		port = hashaddr(myaddr, port, mylen);
X		port = hashport(oppon, port);
X		port = hashport(myname, port);
X	}
X	port += 3000;
X	addr.sin_family = AF_INET;
X	addr.sin_port = htons (port);
X
X	connectmes();
X
X	if (iamserver) {
X		s = sock;
X		if (bind (s, /*(char *)*/ &addr, sizeof (addr)) < 0)
X			if (errno == EADDRINUSE && iamserver == UNSET) {
X				/* hope other player is server */
X				iamserver = FALSE;
X				close (s);
X				if ((sock = socket (AF_INET, SOCK_STREAM, 0))
X				    < 0)
X					error ("socket in connectport");
X			} else
X				error ("bind in connectport");
X		if (iamserver) {
X			if (listen (s, 1) < 0)
X				error ("listen in connectport");
X			while ((sock = accept (s, (struct sockaddr_in *) NULL,
X			    (int *) NULL)) < 0)
X				if (errno != EINTR)
X					error ("accept in connectport");
X			close(s);
X		}
X	}
X	if (!iamserver) {
X		bcopy (hisaddr, (char *) &addr.sin_addr, hislen);
X		while (connect (sock, /*(char *)*/ &addr, sizeof (addr)) < 0)
X			if ( errno == EINTR || errno == ECONNREFUSED) {
X				close (sock);
X				sleep(2);
X				if ((sock = socket (AF_INET, SOCK_STREAM, 0))
X				    < 0)
X					error ("socket in connectport");
X			} else
X				error ("connect in connectport");
X	}
X	if ((s = dup(sock)) < 0)
X		error("dup");
X	if ((inp = fdopen(sock, "r")) == NULL)
X		error("fdopen");
X	if ((out = fdopen(s, "w")) == NULL)
X		error("fdopen");
X	setlinebuf(out);
X
X	sockmask[1] = 1 << sock;
X}
X
Xu_short hashport (s, port)
X	char *s;
X	u_short port;
X{
X	while (*s)
X		port = (port << 1) + *s++;
X	return (port & 0x7fff);
X}
X
X/*
X * addr is in network byte order.
X */
Xu_short hashaddr(addr, port, len)
Xu_short port;
Xchar *addr;
X{
X
X	while (len--)
X		port = (port << 1) + *addr++;
X	return (port & 0x7fff);
X}
X
Xchar *copyhost(host)
Xstruct hostent *host;
X{
X	char *ret;
X
X	ret = malloc(host->h_length);
X	if (ret == NULL)
X		error("malloc");
X	bcopy(host->h_addr, ret, host->h_length);
X
X	return ret;
X}
X
Xcomparehost(h1, h2, len)
Xchar *h1, *h2;
X{
X	auto unsigned long l1, l2;
X
X	bcopy(h1, &l1, sizeof l1);
X	bcopy(h2, &l2, sizeof l2);
X
X	if (l1 < l2)
X		return -1;
X	else if (l1 > l2)
X		return 1;
X	return 0;
X}
X
X
Xreceive(mes)
Xchar *mes;
X{
X	char num[4];
X	int u;
X	num[3]='\0';
X	if (read (sock,num,3) != 3) {
X		error("\n\nError- bad transmission\n");
X		getch();
X	}
X	u=read(sock,mes,atoi(num));
X	mes[u]='\0';
X	if (u !=  atoi(num)){
X		error("\n\nRECEIVE: length does not match.\n");
X	}
X}
X
X
Xsendit(mes)
Xchar *mes;
X{
X	char tbuf[MAXBUF];
X	sprintf(tbuf,"%03d%s",strlen(mes),mes);
X	write(sock,tbuf,strlen(tbuf));
X}
X
Xreadint(i)
Xint *i;
X{
X	RECV(buf);
X	*i = atoi (buf);
X}
X
Xsendint(i)
Xint i;
X{
X	sprintf(buf,"%d",i);
X	SEND(buf);
X}
X
X/*
X * $Log:	connect.c,v $
X * Revision 1.2  88/02/13  12:43:37  hale
X * modified command line lookup of opponents name and saved as variable.
X * 
X */
X
END_OF_connect.c
if test 5470 -ne `wc -c <connect.c`; then
    echo shar: \"connect.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f doother.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doother.c\"
else
echo shar: Extracting \"doother.c\" \(4745 characters\)
sed "s/^X//" >doother.c <<'END_OF_doother.c'
X/*
X * $Header: doother.c,v 1.4 88/02/19 13:48:33 hale Exp $
X */
X
X/*
X
X        Copyright 1987      Greg Hale
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X
X#include "go.h"
X
XDoOther()
X{
X	extern int beepflg,lastx,lasty;
X	int x,y,cur;
X	RECV(buf);
X	if (!strcmp(buf,MSCORE)) {
X		doscore();
X	} else if (!strcmp(buf,MACCEPT)) {
X		Score();
X	} else if (!strcmp(buf,MEXIT)) {
X		addmes("- bye bye!");
X		SetStat(EXIT);
X	} else if (!strcmp(buf,MDECLINE)) {
X		addmes("- Other player has declined.");
X		addmes("-        Please resume play.");
X		disable = 0;
X		dodecline();
X
X	} else if (!strcmp(buf,MQUIT)) {
X		DoQuit();
X	} else if (!strcmp(buf,MCANCEL)) {
X		docancel();
X	} else if (!strcmp(buf,MPLAY)) {
X		doplay();
X	} else if (!strcmp(buf,MMOVE)) {
X		if (beepflg) Beep();
X		savelast();
X		GetCoord(&x,&y);
X		readint(&cur);
X
X		lastx=x; lasty=y;
X		setboard(x,y,cur+1);
X		Kill(x,y,cur+1);
X		Plt(&board,x,y);
X		REFRESH();
X		blink(x,y,cur+1);
X		NextPlr();
X		saveboard0();
X	} else if (!strcmp(buf,MLOAD)) {
X		readint(&hama[0]);
X		readint(&hama[1]);
X		readint(&curplr);
X		readint(&dimensions);
X		MAXX = MAXY = dimensions;
X		doclearboard();
X	} else if (!strcmp(buf,MDELETE)) {
X		GetCoord(&x,&y);
X		deletes(x,y);
X	} else if (!strcmp(buf,MCLEAR)) {
X		doclear();
X	} else if (!strcmp(buf,MPASS)) {
X		addmes("- Other player passed.");
X		NextPlr();
X	} else if (!strcmp(buf,MMESSAGE)) {
X		RECV(buf);
X		if (beepflg) Beep();
X		addtalk(buf);
X	} else if (!strcmp(buf,MHANDICAP)) {
X		GetCoord(&x,&y);
X		readint(&cur);
X		if ( cur != b(x,y) ) {
X		    b(x,y)=cur;
X		    Plt(&board,x,y);
X		}
X	} else if (!strcmp(buf,MSWITCH)) {
X		doswitch();
X	} else if (!strcmp(buf,MRESIGN)) {
X		doresign(false);
X	}
X}
X
Xdoresign(isme)
Xint isme;
X{
X	iwon = !isme; 
X	savestr();
X	if (iwon) {
X		addmes("--------------------------");
X		addmes("The other player resigned.");
X		addmes("--------------------------");
X		GetAKey();
X		printf("\nYou won by resignation.\n");
X	} else  {
X		addmes("-------------");
X		addmes("You resigned.");
X		addmes("-------------");
X		GetAKey();
X		printf("\nYou lost by resignation.\n");
X	}
X	Exit();
X}
X
Xsetcurplr()
X{
X	int x,y;
X	for (x=0; x<MAXX; x++)
X		for (y=0; y<MAXY; y++) if (b(x,y)) {
X			curplr = 1;
X			return(0);
X		}
X}
X
X/* print out the messages to start scoring */
Xscoremes()
X{
X	addmes("");
X	addmes("- Please score now.");
X	addmes("   - Cancel returns to play.");
X	addmes("   - Select dead groups.");
X	addmes("   - Quit determines winner.");
X}
X
Xdosave()
X{
X	savegame();
X	fprintf(stderr,"\n\nGame saved.\n");
X	SEND(MEXIT);
X	Exit();
X}
X
Xdoplay()
X{
X	extern int loadflg;
X	addmes("- Please begin play.");
X	ClrStat(HANDICAP);
X	SetStat(PLAY);
X	if (!loadflg) {
X		hama[0]=hama[1]=0;
X		setcurplr();
X	}
X}
X
Xdoscorehit(x,y)
Xint x,y;
X{
X	if (b(x,y)) {
X		deletes(x,y);
X		SEND(MDELETE);
X		SendCoord(x,y);
X	} else Beep();
X}
X
X
Xdoswitch()
X{
X	player = !player;
X	printscore();
X	initmesg();
X}
X
Xdodecline()
X{
X	restboard();
X	ClrStat(SCORE);
X	SetStat(PLAY);
X	PrintBoard(&board);
X}
X
Xdocancel()
X{
X	restboard();
X	ClrStat(SCORE);
X	SetStat(PLAY);
X	PrintBoard(&board);
X	refresh();
X	addmes("- Scoring is cancelled.");
X	addmes("-     Resume play.");
X}
X
Xdoscore()
X{
X	SetStat(SCORE);
X	scoremes();
X	saveboard();
X}
X
X
X
Xdodemo(x,y,bu)
Xint x,y,bu;
X{
X	static curhand=0;
X	switch (bu & 3) {
X		WHEN 2:	/* left */
X			DoHand(x,y,curhand=0);
X
X		WHEN 1: /* middle */
X			if (!b(x,y)) {
X				curhand = !curhand;
X				DoHand(x,y,curhand);
X			} else {
X				DoHand(x,y,b(x,y)-1);
X			}
X
X		WHEN 0: /* right */
X			DoHand(x,y,curhand=1);
X			
X		OTHERWISE:
X			;
X	}
X}
X
Xdoclear()
X{
X	int x,y;
X	for (y=0; y<dimensions; y++)
X		for (x=0; x<dimensions; x++)
X			if (b(x,y)) {
X				b(x,y)=0;
X				Plt(&board,x,y);
X			}
X	curplr = 0;
X}
X
Xdoclearboard()
X{
X	CLEAR();
X	InitBoard(&board);
X	PrintBoard(&board);
X}
X
X/*
X * $Log:	doother.c,v $
X * Revision 1.4  88/02/19  13:48:33  hale
X * Added io changes for loading games.
X * Load game is cleaned up.  Variable board
X * sizes and formats available in save game
X * as well as printed comments.
X * 
X * Revision 1.3  88/02/14  00:22:51  hale
X * Added load file option during game to restore game to starting
X * state.  Also, clear board operation.  Restoring game puts current
X * player in sync.  With the demo mode, this is invaluable.
X * 
X * Revision 1.2  88/02/13  12:47:04  hale
X * centralized all shared routines possible (eg, dosave, dohandicap,
X * doxxx.)   Also added responses for load option.
X * 
X */
X
END_OF_doother.c
if test 4745 -ne `wc -c <doother.c`; then
    echo shar: \"doother.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f file.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"file.c\"
else
echo shar: Extracting \"file.c\" \(4225 characters\)
sed "s/^X//" >file.c <<'END_OF_file.c'
X/*
X * $Header: file.c,v 3.0 88/03/10 12:07:24 hale Exp $
X */
X
X#include "go.h"
X#include <strings.h>
X#include <sys/file.h>
X
X/* save file */
X
XFILE *sf;
Xint initload;
X
X
Xchar buf1[MAXBUF];
X
Xextern int beepflg, demflg, status;
Xextern int handicaps;
Xextern int dimensions, changeflg, myport;
Xextern char *arg0;
X
X/*
X * file format:
X
X#<board dimension> #<curplr: 0/1>
X<0-n blank lines>
X'#'
X<options=
XRxx -> right justify with x being width
XBxx -> bottom justify with xx being height of data
X>
Xxoooxoxox..x
X..x..x......
X...x..x..xxx
X'#'
X%comments to be printed.
X%in the message window
X
X*/
X
Xstatic char *cont=".@O.....";
X
Xsavegame()
X{
X	extern char *opponent;
X	int fd;
X	int x,y;
X
X	sprintf(buf1,"go.save.%s",opponent);
X
X	fd = open ( buf1, O_CREAT | O_WRONLY, 0777);
X
X	if (fd<0) badload("Can't create file.");
X	sf = fdopen(fd,"w");
X
X	fprintf(sf, "#!%s/%s -m -l\n", BINDIR, arg0);
X	fprintf(sf, "%d %d\n", dimensions, curplr);
X	fprintf(sf,"#\n");
X	for (y=0; y<MAXY; y++) {
X	    for (x=0; x<MAXX; x++)
X		fprintf(sf, "%c ",cont[b(x,y)]);
X	    fprintf(sf,"\n");
X	}
X	fprintf(sf,"#\n");
X	fprintf(sf, "%d %d %d %d\n\n\n", hama[0], hama[1], cx, cy);
X	fclose(sf);
X}
X
X
Xrestgame(f)
Xchar *f;
X{
X	char c,*cp;
X	int x,y,done;
X	int lj, bj;
X
X
X	sf = fopen(f, "r");
X
X	while (getbuf(1), buf1[0]=='#')
X		;
X
X	if (sscanf(buf1, "%d %d", &dimensions,&curplr)==EOF)
X		badload("bad data in file");
X	curplr = !curplr;
X	if (!curplr) addmes("== Black to play.");
X	else addmes("== White to play.");
X
X	while (fgets(buf1,MAXBUF,sf) != NULL && buf1[0]!='#')
X		;
X
X	MAXX = MAXY = lj= bj = dimensions;
X	if (!initload) {
X		initload=1;
X		/* PrintBoard(&board); */
X	} else {
X		SEND(MCLEAR);
X		doclear();
X	}
X
X
X	done = 0;
X	do {
X		getbuf(1);
X		if (buf1[0]=='R' || buf1[0]=='r') {
X			lj = atoi (buf1+1);
X			if (lj < 1 || lj > dimensions)
X				lj = dimensions;
X		} else if (buf1[0]=='B' || buf1[0]=='b') {
X			bj = atoi (buf1+1);
X			if (bj < 1 || bj > dimensions)
X				bj = dimensions;
X		} else done++;
X	} while (!done);
X	SEND(MLOAD);
X	sendint(hama[0]);
X	sendint(hama[1]);
X	sendint(curplr);
X	sendint(dimensions);
X
X	done = 0;
X	x = dimensions - lj;
X	y = dimensions - bj;
X	cp = buf1;
X
X	while (!done) {
X		switch (*cp) {
X			case '.': 
X			case '0':
X				cp++;
X				sethand(x++,y,0);
X				break;
X
X			case 'O':
X			case 'o':
X			case 'w':
X			case '2':
X				cp++;
X				sethand(x++,y,2);
X				break;
X			
X			case 'X':
X			case 'x':
X			case '@':
X			case 'b':
X			case '1':
X				cp++;
X				sethand(x++,y,1);
X				break;
X
X			case '\n':
X			case ';':
X			case '\0':
X				getbuf(1);
X				cp = buf1;
X				x = dimensions - lj;
X				y++;
X				break;
X
X			case '#':
X				done++;
X				break;
X			default:
X				cp++;
X				break;
X		}
X
X		if (x>=dimensions) {
X			getbuf(1);
X			x = dimensions - lj;
X			y++;
X			cp = buf1;
X		}
X		if (y>=dimensions)
X			done++;
X	}
X
X
X	getbuf(0);
X	if (sscanf(buf1, "%d %d %d %d", &hama[0], &hama[1], &cx, &cy)!=EOF)
X		while (fgets(buf1,MAXBUF,sf)!=NULL || buf1[0]=='%') {
X			if (buf1[0]=='%') {
X				char *cc;
X				cc = index (buf1,'\n');
X				if (cc!=NULL) *cc = '\0';
X				addmes(buf1);
X			}
X			buf1[0]=' ';
X		}
X	fclose(sf);
X}
X
Xgetbuf(err)
Xint err;
X{
X	do {
X		if (fgets(buf1,MAXBUF,sf) == NULL)
X			if (err) badload("End of file reached early.");
X	} while (buf1[0]=='\n' || buf1[0]=='\0' || buf1[0]==';');
X}
X
Xbadload(s)
Xchar *s;
X{
X	addmes(s);
X	GetAKey();
X	SEND(MEXIT);
X	Exit();
X}
X
Xdoload()
X{
X	extern char *loadname;
X	int x,y;
X	addmes("--- Loading File ---");
X	restgame(loadname);
X}
X
X/*
X * $Log:	file.c,v $
X * Revision 3.0  88/03/10  12:07:24  hale
X * Added save games, a few changes to the I/O,
X * added load and clear options.  Not thouroughly tested, though, and
X * I think a few bugs are in the load code.  A library of sample problems
X * has been started and saved with the working directory.
X * 
X * Revision 1.3  88/02/19  13:48:41  hale
X * Added io changes for loading games.
X * Load game is cleaned up.  Variable board
X * sizes and formats available in save game
X * as well as printed comments.
X * 
X * Revision 1.2  88/02/14  00:22:56  hale
X * Added load file option during game to restore game to starting
X * state.  Also, clear board operation.  Restoring game puts current
X * player in sync.  With the demo mode, this is invaluable.
X * 
X * Revision 1.1  88/02/13  12:48:06  hale
X * Initial revision
X * 
X */
X
END_OF_file.c
if test 4225 -ne `wc -c <file.c`; then
    echo shar: \"file.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test ! -d games ; then
    echo shar: Creating directory \"games\"
    mkdir games
fi
if test -f go.6 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"go.6\"
else
echo shar: Extracting \"go.6\" \(12117 characters\)
sed "s/^X//" >go.6 <<'END_OF_go.6'
X.TH GO 6  "10 February 1988"
X.SH NAME
Xgo, xgo \- the oriental game of go
X.SH SYNOPSIS
X.B go
Xuser[@host]
X.br
X.B xgo
Xuser[@host]
X.SH DESCRIPTION
X.I Go
Xis an ancient oriental strategy game based on the capturing of territory.
XThe players alternate putting stones on the board,
Xtrying to gain as much territory as possible.
XMany different rules and variants apply to the game of go,
Xin both the play and the scoring,
Xso this program contains most of the standard concepts of
X.B Go,
Xbut not all of them.
XIf you do not know how to play,
Xit may help to find someone who does (look at the file 
X.B goplayers
X) and have him or her explain.
X.SH WHAT TO DO
XIn the text version,
Xthe standard rogue keys
X.B [hjklyubn]
Xare used for cursor movement and the space bar selects a point.
X.B [?]
Xwill give a short help list for further commands.
XIn the 
X.B X
Xversion,
Xthe mouse is used and any button selects a point.
XCommand buttons exist within the window to execute
Xthe appropriate commands.
XWhen a command is inappropriate at the given time, 
Xthe game will beep when the action is taken.
X.LP
XThe exit option exits the game at any time.
X[CTRL-C] will leave as well in either version.
XIn the
X.B X
Xversion the cursor must be in the window that ran the program.
X.LP
XIn the text version,
Xa [*] indicates which player you are by
Xappearing next to the player status at the bottom of the screen.
XIn the
X.B X
Xversion,
Xyour message window (the top one) indicates
Xwhich player you are.
XEither player can switch which player he is by selecting the switch command.
X.LP
XWhen the game begins,
Xboth players have the option of setting up the handicap until play begins.
XSelecting a point on the board puts a black piece down or
Xtakes it away if there is already one there.
XAfter setting up the handicap,
Xeither player can select the play option to begin the game.
X.LP
XNOTE- the program keeps track of your respective strengths
Xin a file in your home directory called ~/.go_strength.
XIt contains two values separated by a space and followed
Xby a carriage return.
X.LP
XThe first value is your strength,
Xstarting at 30kyu = value 0,
Xand working down to 1 kyu = value 29.
XHigher values represent dan level players.
XThe second value is the number of games won (if positive),
Xor the number of games lost (if negative).
X.LP
XCurrently the program takes the difference in
Xthe player strengths to determine handicap stones.
XFor each point difference,
Xone handicap stone is given
Xto the weaker player on a 19x19 board.
XSmaller boards reduce this handicap proportionally.
XAfter the player wins or looses several games
Xin a row,
Xhis rank changes accordingly.
X.LP
X	Note: you can set your rank with command line options.
X.LP
XIf any player does not like his rank,
Xthe handicap stones may be changed manually,
Xas well as your rank.
X.LP
XPlay begins with black if no handicap stones are put down,
Xotherwise play begins with white.
XAfterwards,
Xplay alternates until the end of the game.
XThe last move can be shown by selecting the Last command.
X.LP
XWhen a player thinks the game is over,
Xhe may select the score option.
XThis will enable scoring and both players
Xcan remove the dead groups from the board.
XIf either player disagrees with the scoring and/or wishes to resume play,
Xthe cancel option returns the game to the state just before scoring
Xand play resumes as before.
XThe player whose turn it was when scoring began resumes his turn.
XIf both players agree to scoring,
Xthe quit option should be selected by either player.
XThe other player will be queried to make sure he agrees with the scoring,
Xthe the program will print the resulting score.
X.LP
XAnother way to leave the game is via the resign option.
XWhen a player resigns,
Xthe other player is automatically declared a winner and the score
Xfiles are updated.
X.SH OPTIONS
X.TP 8
X.B none
XPrint out the options and a short explanation of each.
X.TP 8
X.B h
XPrint out this help file for go.
X.TP 8
X.B d
XSet the display to a remote display.
XUse this command if you rlogin from a console onto a remote
Xdisplay before playing.
XIf you rlogin to a remote sun to play,
Xtype ``xgo -d <your-display:0> user@host'' to have
Xthe board appear on your screen.
X.TP 8
X.B p
XSet the port to the specified port number.
XThis is so the connection can be forced to a
Xfree port if several programs are running at once.
X.TP 8
X.B s
XSet the size of the board to a value from 7 to 19.
XIf both players select a size,
Xthe smaller board will be used.
X.TP 8
X.B m
XSet the demonstration mode.
XWith this you can add and remove stones,
Xhaving them capture groups and so forth
Xfor instructional purposes.
XEach mouse button and the '1' and '2' keys
Xset different stones on the board.
X.TP 8
X.B b
XTurn on beep mode.
XThe program will beep the terminal when a message
Xcomes across or a play is made.
XThis is useful if the game is slow and you aren't watching the
Xgame every moment.
X.TP 8
X.B H
XSet the number of handicap stones to the value specified.
XIf both players select a different handicap,
Xthe larger value will be used.
X.TP 8
X.B c
XSuppress the opening message and enter the game directly.
X.TP 8
X.B r
XGive the program's approximation of your rank and wins.
X.TP 8
X.B R
XModify your current rank.  
X``go -R 5 k`` would set your rank to 5 kyu (amateur).
X``go -R 5 d`` would set your rank to 5 dan (middle ranks).
X``go -R 5 p`` would set your rank to 5 professional dan (highest ranks).
X``go -R +`` would increase your rank by one.
X``go -R -`` would decrease your rank by one.
XThe lowest rank is 30 kyu,
Xclimbing to 1 kyu.
XThen you become 1 dan,
Xincreasing to 9 dan.
XLastly,
Xthe professional ranks go from 1 to 9 professional dan.
X.TP 8
X.B l
XLoad a file.
X``-l filename'' will load a saved file.
XThe format is as follows:
Xall numbers are separated by spaces.
XThe first value is the board size (7-19).
XThe next is the current player (0-1=b/w).
XThen a `#' delimits the board info on a line by itself.
XFollowing are rows of the board with a newline at the end of each.
XAt the end of the rows is another `#' on a new line.
XThen the captured black, captured white, cursor x and y positions follow.
XThe file will be saved as go.save.[opponent player name].
XFor now,
Xyou can not run go without the other process.
XSample files and problems are in the same directory as the program
Xin the subdirectory go.samples.
X.SH ABOUT THE GAME
XIn the rest of this document,
X[O] refers to white or player two,
Xand [@] refers to black or player one.
X.LP
XSome general rules are common.
XFirst of all, liberties are the
Xfree points horizontally or vertically adjacent to a group.
XIn the following examples,
Xwhite has 0,1,2,3,4,5, and 6 liberties
Xrespectively:
X.sp
X.nf
X     (l = liberty, normally a [.])
X     (# = out of bounds)
X
X     #. @ .      #. @ .     #. @ .     #. @ .     #. l .
X     #@ O @      #@ O l     #l O l     #l O l     #l O l
X     #. @ .      #. @ .     #. @ .     #. l .     #. l .
X     ######      ######     ######     ######     ######
X
X     #. l @ .    #. l l .
X     #l O O l    #l O O l
X     #. l l .    #. l l .
X     ########    ########
X.fi
X.LP
XDuring play,
Xyou are not allowed to play a point when your
Xcorresponding group will have no liberties at the end of
Xyour turn.
X.LP
XWhen the last liberty of a group is taken away,
Xit is captured.
XThese captured stones count one point at the end of the game.
X.sp
X.nf
X     (@ plays at 1)
X     #. . . . .                #. . . . .
X     #. @ @ @ .                #. @ @ @ .
X     #@ O O O 1   --->         #@ . . . @
X     #. @ @ @ .                #. @ @ @ .
X     #. . . . .                #. . . . .
X     ##########                ##########
X.fi
X.LP
XA territory which can not be saved does not have to be removed
Xfrom the board before the end of the game.
XThe surrounding player can remove the stones during scoring mode at the end of
Xthe game without having to play it out.
X.LP
XIn these examples,
Xwhite owns the territory surrounded unconditionally.
XBlack can not fill in the last point
Xof either hole since he will not capture any stones
Xin the process.
XSome of the points may be filled,
Xbut white will eventually capture the black stones no matter
Xwhat black does.
XIf black does try this,
Xwhite will simply wait and gain points by passing.
X.sp
X.nf
X     #. . . . . . . . .    #. . . . . . . . .
X     #. . . . . . . . .    #. . . . . . . . .
X     #@ @ @ @ @ @ @ @ .    #. . . . . . . . .
X     #O O O O O O O @ .    #@ @ @ @ . . . . .
X     #. . * O . . O @ .    #O O O @ . . . . .
X     #. . O O . . O @ .    #O . O @ . . . . .
X     #. . . O . . O @ .    #. O O @ . . . . .
X     ##################    ##################
X.fi
X.LP
XIn these examples,
Xwhite does
X.B not
Xown the territory because
Xblack can fill in the remaining points and kill white.
XIt is important to understand that black will lose one or two
Xpieces in the second example,
Xbut will succeed in the end.
X.sp
X.nf
X     #. . . . . .           #. . . . . .
X     #. . . . . .           #. . . . . .
X     #@ @ @ @ . .           #@ @ @ @ @ .
X     #O O O @ . .           #O O O O @ .
X     #. . O @ . .           #. @ . O @ .
X     ############           ############
X.fi
X.LP
XIn this example,
Xif white goes first and plays the center point,
Xhe will have what is known as a cats eye and will be safe.
XIf black goes first and plays this point,
Xwhite is dead.
X.sp
X.nf
X     #. . . . . .
X     #. . . . . .
X     #@ @ @ @ @ .
X     #O O O O @ .
X     #. . . O @ .
X     ############
X.fi
X.LP
XIn all cases where a group like these can be considered dead,
Xthey can be removed from the board at the end
Xof the game without further play.
XThis of course excludes cases where the external
Xgroup will die before it has
Xa chance to kill the internal group.
X.LP
XAnother common situation is as follows:
X.sp
X.nf
X     . . . . . .
X     . . . . . .
X     . O O @ @ .
X     . O . O @ .
X     . O O @ @ .
X     . . . . . .
X.fi
X.LP
XIf black plays the empty space capturing white,
Xwhite can then capture black,
Xetc.
XThis can go on forever.
XThis situation is a
X.B KO,
Xand white is not allowed to take black immediately.
XWhite
X.B MUST
Xplay somewhere else,
Xthen if black does not fill the KO,
Xwhite can then try to take it,
Xthen black must play somewhere else.
XSooner or later,
Xsomeone should fill it before scoring is done.
X.LP
XIf there is any debate whether territory is owned by a player,
Xjust play further and the winner will prevail.
X.LP
XA good strategy in the beginning is to try to build stable
Xstructures.
XWhen something is stable,
Xyou can attack appendages
Xto it and expand safely.
XFor beginners,
Xone big strong group is better than
Xseveral spread out vulnerable groups.
X.LP
XLater,
Xtry to spread out:
Xplace one or two pieces in open territory to obtain
Xinfluence over that section of the board.
XGood Go players need only to put one piece near a
Xcorner to know that they have a good chance of owning it
Xlater.
X.LP
XAt the end of the game when scoring,
Xeach captured stone is worth one point,
Xand each point you own is one point.
XThe player with the most points wins.
XThe procedure is to erase all groups both players
Xagree have no chance of surviving.
XIf at any time a disagreement occurs,
Xeither player can cancel scoring and continue the
Xgame at the point before scoring occurred.
X.LP
XWhen all scoring is complete,
Xboth players must agree to quit and the game
Xwith print out the score.
X.LP
XAs a final note, I highly reccommend that you
Xpurchase literature on go if you plan on enjoying
Xthe game to its fullest.
XTo pass through the lower levels swiftly and correctly,
XI STRONGLY recommend the _Graded Go Problems for Beginners_
Xseries by the Ishi Press.
XAlmost any game store should be able to access it.
X.SH FILES
Xgo.doc     	this file
X.sp
X~/.go_strength	a file kept in your home directory keeping your ranks and wins.
X.sp
Xgo.players	a file set up by users to tell other players who they are.
X.sp
X.SH BUGS
X.nf
XSend bugs to "...!ucbvax!cory!hale" or "hale@cory.Berkeley.EDU"
X.fi
X.sp
X.SH AUTHOR
XGreg Hale
X.sp
X.SH "SEE ALSO"
Xreadnews rec.games.go \- a newsgroup on the game
X.br
X_Graded go problems for beginners,
Xvol 1-3._, Ishi Press.
X(Highly recommended.)
X.br
X_In the Beginning_,
XIshi Press.
X.br
X_The Treasure Chest Enigma_,
XIshi Press.
X.br
Xgo.players \- an optional file with players and ranks
X
END_OF_go.6
if test 12117 -ne `wc -c <go.6`; then
    echo shar: \"go.6\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f go.doc -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"go.doc\"
else
echo shar: Extracting \"go.doc\" \(14943 characters\)
sed "s/^X//" >go.doc <<'END_OF_go.doc'
X
X
X
XGO(6)                    GAMES AND DEMOS                    GO(6)
X
X
X
XNAME
X     go, xgo - the oriental game of go
X
XSYNOPSIS
X     go user[@host]
X     xgo user[@host]
X
XDESCRIPTION
X     _G_o is an ancient oriental strategy game based on the captur-
X     ing  of  territory.  The players alternate putting stones on
X     the board, trying to gain as  much  territory  as  possible.
X     Many  different  rules and variants apply to the game of go,
X     in both the play and the scoring, so this  program  contains
X     most  of  the  standard concepts of Go, but not all of them.
X     If you do not know how to play, it may help to find  someone
X     who  does  (look at the file goplayers ) and have him or her
X     explain.
X
XWHAT TO DO
X     In the text version, the standard rogue keys [hjklyubn]  are
X     used  for cursor movement and the space bar selects a point.
X     [?] will give a short help list for  further  commands.   In
X     the  X  version,  the mouse is used and any button selects a
X     point.  Command buttons exist within the window  to  execute
X     the  appropriate  commands.  When a command is inappropriate
X     at the given time, the game will beep  when  the  action  is
X     taken.
X
X     The exit option exits the game at any time.   [CTRL-C]  will
X     leave  as well in either version.  In the X version the cur-
X     sor must be in the window that ran the program.
X
X     In the text version, a [*] indicates which player you are by
X     appearing  next  to  the  player status at the bottom of the
X     screen.  In the X version, your message window (the top one)
X     indicates  which  player  you are.  Either player can switch
X     which player he is by selecting the switch command.
X
X     When the game begins, both players have the option  of  set-
X     ting  up  the handicap until play begins.  Selecting a point
X     on the board puts a black piece down or  takes  it  away  if
X     there  is already one there.  After setting up the handicap,
X     either player can select the play option to begin the game.
X
X     NOTE- the program keeps track of your  respective  strengths
X     in  a file in your home directory called ~/.go_strength.  It
X     contains two values separated by a space and followed  by  a
X     carriage return.
X
X     The first value is your strength, starting at 30kyu =  value
X     0,  and  working  down  to  1 kyu = value 29.  Higher values
X     represent dan level players.  The second value is the number
X
X
X
XSun Release 3.2   Last change: 10 February 1988                 1
X
X
X
X
X
X
XGO(6)                    GAMES AND DEMOS                    GO(6)
X
X
X
X     of  games won (if positive), or the number of games lost (if
X     negative).
X
X     Currently the program takes the  difference  in  the  player
X     strengths  to  determine  handicap  stones.   For each point
X     difference, one handicap stone is given to the weaker player
X     on  a 19x19 board.  Smaller boards reduce this handicap pro-
X     portionally.  After the player wins or looses several  games
X     in a row, his rank changes accordingly.
X
X          Note: you can set your rank with command line options.
X
X     If any player does not like his rank,  the  handicap  stones
X     may be changed manually, as well as your rank.
X
X     Play begins with black if no handicap stones are  put  down,
X     otherwise  play  begins with white.  Afterwards, play alter-
X     nates until the end of the game.  The last move can be shown
X     by selecting the Last command.
X
X     When a player thinks the game is over,  he  may  select  the
X     score option.  This will enable scoring and both players can
X     remove the dead groups from the  board.   If  either  player
X     disagrees with the scoring and/or wishes to resume play, the
X     cancel option returns the game  to  the  state  just  before
X     scoring  and  play resumes as before.  The player whose turn
X     it was when scoring began resumes his turn.  If both players
X     agree  to  scoring,  the  quit  option should be selected by
X     either player.  The other player will  be  queried  to  make
X     sure  he agrees with the scoring, the the program will print
X     the resulting score.
X
X     Another way to leave the game  is  via  the  resign  option.
X     When  a  player  resigns,  the other player is automatically
X     declared a winner and the score files are updated.
X
XOPTIONS
X     none    Print out the options and  a  short  explanation  of
X             each.
X
X     h       Print out this help file for go.
X
X     d       Set the display to a remote display.  Use this  com-
X             mand  if  you  rlogin  from  a console onto a remote
X             display before playing.  If you rlogin to  a  remote
X             sun   to   play,   type  ``xgo  -d  <your-display:0>
X             user@host'' to have the board appear on your screen.
X
X     p       Set the port to the specified port number.  This  is
X             so  the  connection  can be forced to a free port if
X             several programs are running at once.
X
X
X
X
XSun Release 3.2   Last change: 10 February 1988                 2
X
X
X
X
X
X
XGO(6)                    GAMES AND DEMOS                    GO(6)
X
X
X
X     s       Set the size of the board to a value from 7  to  19.
X             If  both  players  select  a size, the smaller board
X             will be used.
X
X     m       Set the demonstration mode.  With this you  can  add
X             and remove stones, having them capture groups and so
X             forth for instructional purposes.  Each mouse button
X             and the '1' and '2' keys set different stones on the
X             board.
X
X     b       Turn on beep mode.  The program will beep the termi-
X             nal  when  a message comes across or a play is made.
X             This is useful if the game is slow  and  you  aren't
X             watching the game every moment.
X
X     H       Set the number  of  handicap  stones  to  the  value
X             specified.   If both players select a different han-
X             dicap, the larger value will be used.
X
X     c       Suppress the opening  message  and  enter  the  game
X             directly.
X
X     r       Give the program's approximation of  your  rank  and
X             wins.
X
X     R       Modify your current rank. ``go -R 5  k``  would  set
X             your  rank  to 5 kyu (amateur).  ``go -R 5 d`` would
X             set your rank to 5 dan (middle ranks).   ``go  -R  5
X             p``  would  set  your  rank  to  5  professional dan
X             (highest ranks).  ``go -R +``  would  increase  your
X             rank  by  one.  ``go -R -`` would decrease your rank
X             by one.  The lowest rank is 30 kyu,  climbing  to  1
X             kyu.   Then  you  become 1 dan, increasing to 9 dan.
X             Lastly, the professional ranks go from 1 to  9  pro-
X             fessional dan.
X
X     l       Load a file.  ``-l  filename''  will  load  a  saved
X             file.   The  format  is  as follows: all numbers are
X             separated by spaces.  The first value is  the  board
X             size  (7-19).   The  next  is the current player (0-
X             1=b/w).  Then a `#' delimits the  board  info  on  a
X             line  by  itself.   Following  are rows of the board
X             with a newline at the end of each.  At  the  end  of
X             the  rows  is  another  `#' on a new line.  Then the
X             captured black, captured white, cursor x and y posi-
X             tions   follow.    The   file   will   be  saved  as
X             go.save.[opponent player name].  For  now,  you  can
X             not  run go without the other process.  Sample files
X             and problems are in the same directory as  the  pro-
X             gram in the subdirectory go.samples.
X
X
X
X
X
XSun Release 3.2   Last change: 10 February 1988                 3
X
X
X
X
X
X
XGO(6)                    GAMES AND DEMOS                    GO(6)
X
X
X
XABOUT THE GAME
X     In the rest of this document, [O] refers to white or  player
X     two, and [@] refers to black or player one.
X
X     Some general rules are common.  First of all, liberties  are
X     the  free  points  horizontally  or vertically adjacent to a
X     group.  In the following examples,  white  has  0,1,2,3,4,5,
X     and 6 liberties respectively:
X
X          (l = liberty, normally a [.])
X          (# = out of bounds)
X
X          #. @ .      #. @ .     #. @ .     #. @ .     #. l .
X          #@ O @      #@ O l     #l O l     #l O l     #l O l
X          #. @ .      #. @ .     #. @ .     #. l .     #. l .
X          ######      ######     ######     ######     ######
X
X          #. l @ .    #. l l .
X          #l O O l    #l O O l
X          #. l l .    #. l l .
X          ########    ########
X
X     During play, you are not allowed to play a point  when  your
X     corresponding  group  will  have  no liberties at the end of
X     your turn.
X
X     When the last liberty of a group is taken away, it  is  cap-
X     tured.   These captured stones count one point at the end of
X     the game.
X
X          (@ plays at 1)
X          #. . . . .                #. . . . .
X          #. @ @ @ .                #. @ @ @ .
X          #@ O O O 1   --->         #@ . . . @
X          #. @ @ @ .                #. @ @ @ .
X          #. . . . .                #. . . . .
X          ##########                ##########
X
X     A territory which can not be  saved  does  not  have  to  be
X     removed from the board before the end of the game.  The sur-
X     rounding player can remove the stones during scoring mode at
X     the end of the game without having to play it out.
X
X     In these  examples,  white  owns  the  territory  surrounded
X     unconditionally.   Black  can  not fill in the last point of
X     either hole since he will not capture any stones in the pro-
X     cess.   Some  of  the  points  may be filled, but white will
X     eventually capture the black stones  no  matter  what  black
X     does.   If  black  does try this, white will simply wait and
X     gain points by passing.
X
X          #. . . . . . . . .    #. . . . . . . . .
X
X
X
XSun Release 3.2   Last change: 10 February 1988                 4
X
X
X
X
X
X
XGO(6)                    GAMES AND DEMOS                    GO(6)
X
X
X
X          #. . . . . . . . .    #. . . . . . . . .
X          #@ @ @ @ @ @ @ @ .    #. . . . . . . . .
X          #O O O O O O O @ .    #@ @ @ @ . . . . .
X          #. . * O . . O @ .    #O O O @ . . . . .
X          #. . O O . . O @ .    #O . O @ . . . . .
X          #. . . O . . O @ .    #. O O @ . . . . .
X          ##################    ##################
X
X     In these examples, white does not own the territory  because
X     black  can  fill in the remaining points and kill white.  It
X     is important to understand that black will lose one  or  two
X     pieces in the second example, but will succeed in the end.
X
X          #. . . . . .           #. . . . . .
X          #. . . . . .           #. . . . . .
X          #@ @ @ @ . .           #@ @ @ @ @ .
X          #O O O @ . .           #O O O O @ .
X          #. . O @ . .           #. @ . O @ .
X          ############           ############
X
X     In this example, if white goes first and  plays  the  center
X     point,  he will have what is known as a cats eye and will be
X     safe.  If black goes first and plays this  point,  white  is
X     dead.
X
X          #. . . . . .
X          #. . . . . .
X          #@ @ @ @ @ .
X          #O O O O @ .
X          #. . . O @ .
X          ############
X
X     In all cases where a group  like  these  can  be  considered
X     dead,  they  can be removed from the board at the end of the
X     game without further play.  This of  course  excludes  cases
X     where  the external group will die before it has a chance to
X     kill the internal group.
X
X     Another common situation is as follows:
X
X          . . . . . .
X          . . . . . .
X          . O O @ @ .
X          . O . O @ .
X          . O O @ @ .
X          . . . . . .
X
X     If black plays the empty space capturing  white,  white  can
X     then  capture  black,  etc.   This  can go on forever.  This
X     situation is a KO, and white is not allowed  to  take  black
X     immediately.   White MUST play somewhere else, then if black
X     does not fill the KO, white can then try to  take  it,  then
X
X
X
XSun Release 3.2   Last change: 10 February 1988                 5
X
X
X
X
X
X
XGO(6)                    GAMES AND DEMOS                    GO(6)
X
X
X
X     black  must  play  somewhere else.  Sooner or later, someone
X     should fill it before scoring is done.
X
X     If there is any debate  whether  territory  is  owned  by  a
X     player, just play further and the winner will prevail.
X
X     A good strategy in the beginning is to try to  build  stable
X     structures.   When  something  is  stable,  you  can  attack
X     appendages to it and expand safely.  For beginners, one  big
X     strong  group  is  better than several spread out vulnerable
X     groups.
X
X     Later, try to spread out: place one or two  pieces  in  open
X     territory  to  obtain  influence  over  that  section of the
X     board.  Good Go players need only to put one  piece  near  a
X     corner  to  know  that  they have a good chance of owning it
X     later.
X
X     At the end of the game when scoring, each captured stone  is
X     worth  one  point, and each point you own is one point.  The
X     player with the most points wins.  The procedure is to erase
X     all  groups  both players agree have no chance of surviving.
X     If at any time a disagreement occurs, either player can can-
X     cel  scoring and continue the game at the point before scor-
X     ing occurred.
X
X     When all scoring is complete, both  players  must  agree  to
X     quit and the game with print out the score.
X
X     As a final note,  I  highly  reccommend  that  you  purchase
X     literature  on  go  if  you plan on enjoying the game to its
X     fullest.  To pass  through  the  lower  levels  swiftly  and
X     correctly,  I STRONGLY recommend the _Graded Go Problems for
X     Beginners_ series by the Ishi Press.  Almost any game  store
X     should be able to access it.
X
XFILES
X     go.doc         this file
X
X     ~/.go_strength a file kept in your  home  directory  keeping
X     your ranks and wins.
X
X     go.players     a file set up by users to tell other  players
X     who they are.
X
X
XBUGS
X     Send bugs to "...!ucbvax!cory!hale" or "hale@cory.Berkeley.EDU"
X
X
XAUTHOR
X     Greg Hale
X
X
X
XSun Release 3.2   Last change: 10 February 1988                 6
X
X
X
X
X
X
XGO(6)                    GAMES AND DEMOS                    GO(6)
X
X
X
XSEE ALSO
X     readnews rec.games.go - a newsgroup on the game
X     _Graded go problems for beginners, vol  1-3._,  Ishi  Press.
X     (Highly recommended.)
X     _In the Beginning_, Ishi Press.
X     _The Treasure Chest Enigma_, Ishi Press.
X     go.players - an optional file with players and ranks
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
XSun Release 3.2   Last change: 10 February 1988                 7
X
X
X
END_OF_go.doc
echo shar: 2 control characters may be missing from \"go.doc\"
if test 14943 -ne `wc -c <go.doc`; then
    echo shar: \"go.doc\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f xstatus.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"xstatus.c\"
else
echo shar: Extracting \"xstatus.c\" \(4257 characters\)
sed "s/^X//" >xstatus.c <<'END_OF_xstatus.c'
X/*
X * $Header: xstatus.c,v 3.0 88/03/10 12:08:10 hale Exp $
X */
X
X/*
X
X        Copyright 1987      Greg Hale
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X
X#include "xgo.h"
X
Xextern int demflg;
X
X#define WACCEPT 0
X#define WDECINE 1
X#define WSCORE 2
X#define WQUIT 3
X#define WTALLY 4
X#define WPASS 5
X#define WCANCEL 6
X#define WPLAY 7
X#define WEXIT 8
X#define WSWITCH 9
X#define WSHOW 10
X#define WRES 11
X#define WSAVE 12
X#define WLOAD 13
X#define WCLEAR 14
X
X#define ACT(x) act[x][0]=1
X#define ISACT(x) act[x][0]
X#define WASACT(x) act[x][1]
X#define redraw(x) if (!WASACT(x))
X#define iferase(x) if (WASACT(x) && !ISACT(x))
Xstatic act[20][2];
X
X
Xextern int loadflg;
X
Xupdact()
X{
X	int i;
X	for (i=0; i<20; i++) {
X		act[i][1] = act[i][0];
X		act[i][0]=0;
X	}
X}
X
XAreWe(s)
Xint s;
X{
X	return (status & s);
X}
X
XSetStat(s)
Xint s;
X{
X	status = status | s;
X	switch (s) {
X		WHEN HANDICAP:
X			updact();
X			ACT(WPLAY);
X			ACT(WSWITCH);
X			ACT(WEXIT);
X			ACT(WRES);
X			ACT(WSAVE);
X			ACT(WLOAD);
X			ACT(WCLEAR);
X			UnmapAll();
X			redraw(WPLAY) XMapWindow(Wplay);
X			redraw(WSWITCH) XMapWindow(Wswitch);
X			redraw(WEXIT) XMapWindow(Wexit);
X			redraw(WRES) XMapWindow(Wresign);
X			redraw(WSAVE) XMapWindow(Wsave);
X			redraw(WCLEAR) XMapWindow(Wclear);
X			if (loadflg) redraw(WLOAD) XMapWindow(Wload);
X		WHEN SCORE:
X			updact();
X			ACT(WQUIT);
X			ACT(WEXIT);
X			ACT(WTALLY);
X			ACT(WCANCEL);
X			ACT(WRES);
X			ACT(WSAVE);
X			ACT(WLOAD);
X			redraw(WCLEAR) XMapWindow(Wclear);
X			UnmapAll();
X			redraw(WQUIT) XMapWindow(Wquit);
X			redraw(WEXIT) XMapWindow(Wexit);
X			redraw(WTALLY) XMapWindow(Wtally);
X			redraw(WCANCEL) XMapWindow(Wcancel);
X			redraw(WRES) XMapWindow(Wresign);
X			redraw(WSAVE) XMapWindow(Wsave);
X			if (loadflg) redraw(WLOAD) XMapWindow(Wload);
X		WHEN QUIT:
X			updact();
X			ACT(WEXIT);
X			ACT(WACCEPT);
X			ACT(WDECINE);
X			UnmapAll();
X			redraw(WACCEPT) XMapWindow(Waccept);
X			redraw(WEXIT) XMapWindow(Wexit);
X			redraw(WDECINE) XMapWindow(Wdecline);
X		WHEN PLAY:
X			updact();
X			ACT(WEXIT);
X			ACT(WPASS);
X			ACT(WSCORE);
X			ACT(WSHOW);
X			ACT(WRES);
X			ACT(WSAVE);
X			ACT(WLOAD);
X			UnmapAll();
X			redraw(WPASS) XMapWindow(Wpass);
X			redraw(WSCORE) XMapWindow(Wscore);
X			redraw(WEXIT) XMapWindow(Wexit);
X			redraw(WSHOW) XMapWindow(Wshow);
X			redraw(WRES) XMapWindow(Wresign);
X			redraw(WSAVE) XMapWindow(Wsave);
X			if (loadflg) redraw(WLOAD) XMapWindow(Wload);
X		DEFAULT: ;
X	}
X}
X
XUnmapAll()
X{
X	iferase(WACCEPT) XUnmapWindow(Waccept);
X	iferase(WDECINE) XUnmapWindow(Wdecline);
X	iferase(WSCORE) XUnmapWindow(Wscore);
X	iferase(WQUIT) XUnmapWindow(Wquit);
X	iferase(WTALLY) XUnmapWindow(Wtally);
X	iferase(WPASS) XUnmapWindow(Wpass);
X	iferase(WCANCEL) XUnmapWindow(Wcancel);
X	iferase(WPLAY) XUnmapWindow(Wplay);
X	iferase(WEXIT) XUnmapWindow(Wexit);
X	iferase(WSWITCH) XUnmapWindow(Wswitch);
X	iferase(WSHOW) XUnmapWindow(Wshow);
X	iferase(WRES) XUnmapWindow(Wresign);
X	iferase(WSAVE) XUnmapWindow(Wsave);
X	iferase(WCLEAR) XUnmapWindow(Wclear);
X	if (loadflg) iferase(WLOAD) XUnmapWindow(Wload);
X}
X
XClrStat(s)
Xint s;
X{
X	status = status & ~s;
X}
X
X/*
X * $Log:	xstatus.c,v $
X * Revision 3.0  88/03/10  12:08:10  hale
X * Added save games, a few changes to the I/O,
X * added load and clear options.  Not thouroughly tested, though, and
X * I think a few bugs are in the load code.  A library of sample problems
X * has been started and saved with the working directory.
X * 
X * Revision 1.4  88/02/19  13:49:47  hale
X * Added io changes for loading games.
X * Load game is cleaned up.  Variable board
X * sizes and formats available in save game
X * as well as printed comments.
X * 
X * Revision 1.3  88/02/14  00:23:33  hale
X * Added load file option during game to restore game to starting
X * state.  Also, clear board operation.  Restoring game puts current
X * player in sync.  With the demo mode, this is invaluable.
X * 
X * Revision 1.2  88/02/13  12:55:14  hale
X * added logging.
X * 
X */
X
END_OF_xstatus.c
if test 4257 -ne `wc -c <xstatus.c`; then
    echo shar: \"xstatus.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 1 \(of 4\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 4 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 4 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