[comp.sources.games] v11i066: igo - Internet Go V7.0, Part01/02

billr@saab.CNA.TEK.COM (Bill Randle) (11/20/90)

Submitted-by: Adrian Mariano <theorem@blake.u.washington.edu>
Posting-number: Volume 11, Issue 66
Archive-name: igo/Part01
Environment: BSD Unix, INET sockets

	[Previously posted in one of the alt.sources groups.]

[[                          INTERNET GO 7.0
                                  by
                  Greg Hale (hale@scam.berkeley.edu)
          and Adrian Mariano (adrian@milton.u.washinton.edu)

The long awaited new version of Internet Go is now out!  
Internet Go is a program which allows to users to play realtime go 
games over Internet.
        
This new version includes:

	the board can be dislayed with inverse video
	the black stone character can be specified at runtime
	games can be logged to a file in Smart-Go format (mgt)
	games can be restored from a Smart-Go file
	assorted bug fixes

The program still requires a BSD Unix.


Mail questions and requests to either:
	Greg Hale (hale@scam.berkeley.edu)
	Adrian Mariano (adrian@milton.u.washinton.edu)

Send mail to adrian@milton.u.washington.edu to be added to the list
of active Go players.]]

#! /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 2)."
# Contents:  README MANIFEST Makefile connect.c doother.c file.c go.6
#   go.h main.c opts.c
# Wrapped by billr@saab on Fri Nov 16 10:44:31 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(2767 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X        Copyright 1990      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
XTo make the Internet GO board type:
X
X    make
X
XIf you get re-defined errors from connect.c, remove the lines near the top
Xbetween and including the #ifndef.
X
XBy default, the program will install at   .    
XTo change this, modify the BINDIR variable in the Makefile.
XIt will install the manual page in MANDIR (default:   . ).
X
XIf you want the long help option to work, you will need to change
Xthe HELP_CMD in go.h to reference the correct directory.
X
X
XHave fun and please report all bugs to: 
X            Greg Hale (hale@scam.berkeley.edu)
X         or Adrian Mariano (theorem@blake.u.washington.edu)
X
XP.S.  Be sure to add yourself to the internet go players list by sending 
X      mail to theorem@blake.u.washington.edu.
X
X-----------
XChanges:
X
X11/15/87 (v 1.2)
X	Add command line arguements, variable board size, handicapping.
X	Select the port available to the user in case
X	several games are running at once to avoid collisions.
X
X11/23/87 (v 1.5)
X	-c option for command line welcome message.  Show last move
X	command (key is '/').  Beeps when a message is sent.  Nomove.c
X	modified; some compilers thought the expression was too complicated.
X
X11/27/87 (v 1.6)
X	Keep track of stregth and wins in a default file in user's home
X	directory.  Use this to determine sides and handicapping.
X	I/O problems (when selecting socket and stdin) fixed.
X
X1/30/88 (v 2.0)
X	Add demo mode and optional beeping. 
X
X2/10/88 (v 2.1)
X	Change in arguments, modification to strength and scoring
X	algorithm.  A bug in declining that had led to lock up was fixed.
X	Among other options, KOMI was added to scoring.
X
X4/13/88 (v 4.2)
X        Fixed scoring and option bug
X
X1/30/90 (v 5.0)
X	Add coordinates to the side of the board.  Show captured stones.
X	At the end of the game, clear the screen using
X	carriage returns instead of Clear() BEFORE the score info is printed.
X
X2/15/90
X	Interface is cleaned up, synchonization for load games,
X	Exit the message section by ^D,
X	and restore saved game.
X
X7/17/90 (v 7.0)
X        Added move by move game logging to Smart-Go, and restore from 
X	   Smart-Go files.  
X	Added inverse video and made it easy to redefine black stone character.
X	Added number keys for movement
X	Handicap information is only used if the -E option is specified
X	Cleaned up options.
X
X
X
X
X
X
END_OF_FILE
if test 2767 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(1478 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X MANIFEST                   1	This shipping list
X Makefile                   1	
X README                     1	
X backup.c                   2	
X changes.c                  2	
X chkmve.c                   2	
X connect.c                  1	
X curse.c                    2	
X del.c                      2	
X dohand.c                   2	
X doloop.c                   2	
X doother.c                  1	
X exit.c                     2	
X file.c                     1	
X fill.c                     2	
X go.6                       1	
X go.c                       2	
X go.h                       1	
X handicap.c                 2	
X help.c                     2	
X init.c                     2	
X initboard.c                2	
X kill.c                     2	
X life.c                     2	
X loop.c                     2	
X looputil.c                 2	
X main.c                     1	
X mesg.c                     2	
X movecur.c                  2	
X moveto.c                   2	
X nomove.c                   2	
X opts.c                     1	
X plt.c                      2	
X printboard.c               2	
X putpiece.c                 2	
X score.c                    2	
X setboard.c                 2	
X status.c                   2	
X std.disclaimer             2	
X strength.c                 2	
X tally.c                    2	
X traps.c                    2	
X util.c                     2	
X var.c                      2	
END_OF_FILE
if test 1478 -ne `wc -c <'MANIFEST'`; then
    echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(2747 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# Makefile for Go version 7.0
X# by Greg Hale
X# Monday, June 8, 1987
X# Modified by Jeff Boscole ( aesop@blake.acs.washington.edu )  8/31/89
X# Modified by Adrian Mariano ( theorem@blake.u.washington.edu ) 7/13/90
X
XCFLAGS= -w -DINVERSE=${INVERSE} -DBLACK=${BLACK} -DVERSION="\"Go 7.0\""
X
X# Video options.  Set INVERSE to 128 to set default to inverse video
X# or set it to 0 to get normal video as default.  Set BLACK to the
X# default character for black stones.
X
XINVERSE = 0
X
XBLACK = "'@'"
X
X# destination manual pages
XMANSRC=go.6
XMAN=go.doc
X
X# destination directory vvvvvvv ---  put your directory here  vvvvvvvvvvvv |
XMANDIR= .
XBINDIR= .
X
X# PROGRAM NAMES        ^^^^^^^^ ---  put your directory here  ^^^^^^^^^^^^ |
XGO=go
XSHAR=shar
XSHARCHIVE=inetgo.sh
X
XFORMATTER=format
X
X# files which make up the shell archive along with sources
XFILES = README Makefile $(MANSRC) 
X
XMOBJECTS = chkmve.o \
X        curse.o \
X        doloop.o \
X        exit.o \
X        go.o \
X        init.o \
X        loop.o \
X        mesg.o \
X        movecur.o \
X        moveto.o \
X        plt.o \
X        printboard.o \
X        status.o \
X        traps.o \
X        util.o
X
XSHARED = changes.o \
X        connect.o \
X        backup.o \
X        del.o \
X        dohand.o \
X        doother.o \
X        file.o \
X        fill.o \
X        handicap.o \
X        initboard.o \
X        kill.o \
X        life.o \
X        looputil.o \
X        main.o \
X        setboard.o \
X        strength.o \
X        tally.o \
X        help.o \
X        opts.o \
X        putpiece.o \
X        score.o \
X        var.o \
X        nomove.o
X
XSRCS =  backup.c changes.c chkmve.c \
X        connect.c curse.c del.c \
X        dohand.c doloop.c doother.c \
X        exit.c file.c  fill.c \
X        go.c  handicap.c  help.c \
X        init.c  initboard.c  kill.c \
X        life.c  loop.c \
X        looputil.c  main.c  mesg.c \
X        movecur.c  moveto.c  nomove.c \
X        opts.c \
X        plt.c \
X        printboard.c \
X        putpiece.c \
X        score.c \
X        setboard.c \
X        status.c \
X        strength.c \
X        tally.c \
X        traps.c \
X        util.c \
X        var.c
X
XHDRS =	go.h \
X	std.disclaimer
X
Xall: $(GO) $(MAN)
X
X$(GO): $(MOBJECTS) $(SHARED)
X	@echo "loading $(GO)..."
X	@cc $(MOBJECTS) $(SHARED) -lcurses -ltermlib -o $(BINDIR)/$(GO);
X	@echo "done."
X
X$(MAN): $(MANSRC)
X	@echo -n "typesetting manual..."
X	@nroff -man $(MANSRC) > $(MANDIR)/$(MAN)
X	@echo "done."
X
Xtags:
X	ctags *.c *.h
X
Xclean:
X	@echo -n "removing extra files..."
X	@-rm -f *.o $(GO) $(SHARCHIVE) $(SHARCHIVE).Z
X	@echo "done."
X
Xmake:
X	mkmf -d
X
Xarchive:
X	shar -c $(FILES) $(SRCS) $(HDRS) > $(SHARCHIVE)
X
X# alternate for new archive program
Xarchive1:
X	shar -m 100000 -f $(SHARCHIVE) $(FILES) $(SRCS) $(HDRS)
X
X$(MOBJECTS): go.h
X$(SHARED): go.h
END_OF_FILE
if test 2747 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'connect.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'connect.c'\"
else
echo shar: Extracting \"'connect.c'\" \(5415 characters\)
sed "s/^X//" >'connect.c' <<'END_OF_FILE'
X#include "std.disclaimer"
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,
X                   *getpwuid ();
X    char   *hishostname,
X           *index (), *getpw (), *malloc ();
X    char   *hisaddr,
X           *myaddr;
X    int     hislen,
X            mylen;
X    u_long iaddr;
X    uid_t getuid ();
X    u_short hashport (), hashaddr ();
X    char   *copyhost ();
X    int     s,
X            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	}
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    }
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
X	    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    }
X    else
X	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	}
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	    }
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	    }
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)
Xchar   *s;
Xu_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,
X       *h2;
X{
X    auto unsigned long  l1,
X                        l2;
X
X    bcopy (h1, &l1, sizeof l1);
X    bcopy (h2, &l2, sizeof l2);
X
X    if (l1 < l2)
X	return - 1;
X    else
X	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}
END_OF_FILE
if test 5415 -ne `wc -c <'connect.c'`; then
    echo shar: \"'connect.c'\" unpacked with wrong size!
fi
# end of 'connect.c'
fi
if test -f 'doother.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'doother.c'\"
else
echo shar: Extracting \"'doother.c'\" \(5351 characters\)
sed "s/^X//" >'doother.c' <<'END_OF_FILE'
X#include "std.disclaimer"
X#include "go.h"
X
Xextern int  loadflg;
Xextern char loadname[];
X
XDoOther () {
X    extern int  lastx,
X                lasty;
X    int     x,
X            y,
X            cur;
X    RECV (buf);
X    if (!strcmp (buf, MSCORE)) {
X	doscore ();
X    }
X    else
X	if (!strcmp (buf, MACCEPT)) {
X	    Score ();
X	}
X	else
X	    if (!strcmp (buf, MEXIT)) {
X		homemes ();
X		addmes ("- bye bye!");
X		SetStat (EXIT);
X	    }
X	    else
X		if (!strcmp (buf, MDECLINE)) {
X		    homemes ();
X		    addmes ("- Other player has declined.");
X		    addmes ("-        Please resume play.");
X		    Beep ();
X		    disable = 0;
X		    dodecline ();
X
X		}
X		else
X		    if (!strcmp (buf, MQUIT)) {
X			DoQuit ();
X		    }
X		    else
X			if (!strcmp (buf, MCANCEL)) {
X			    docancel ();
X			}
X			else
X			    if (!strcmp (buf, MPLAY)) {
X				doplay ();
X				printscore ();
X			    }
X			    else
X				if (!strcmp (buf, MMOVE)) {
X				    Beep ();
X				    savelast ();
X				    GetCoord (&x, &y);
X				    readint (&cur);
X
X				    lastx = x;
X				    lasty = y;
X				    setboard (x, y, cur + 1);
X				    Kill (x, y, cur + 1);
X				    Plt (&board, x, y);
X				    refresh ();
X				    dolog (x, y, cur + 1);
X				    printscore ();
X				    blink (x, y, cur + 1);
X				    NextPlr ();
X				    saveboard0 ();
X				}
X				else
X				    if (!strcmp (buf, MLOAD)) {
X					doReceiveLoad ();
X				    }
X				    else
X					if (!strcmp (buf, MDELETE)) {
X					    GetCoord (&x, &y);
X					    deletes (x, y);
X					}
X					else
X					    if (!strcmp (buf, MCLEAR)) {
X						doclear ();
X					    }
X					    else
X						if (!strcmp (buf, MPASS)) {
X						    homemes ();
X						    addmes ("- Other player passed.");
X						    NextPlr ();
X						}
X						else
X						    if (!strcmp (buf, MMESSAGE)) {
X							RECV (buf);
X							/* if (beepflg) Beep(); */
X							addtalk (buf);
X						    }
X						    else
X							if (!strcmp (buf, MHANDICAP)) {
X							    GetCoord (&x, &y);
X							    readint (&cur);
X							    if (cur != b (x, y)) {
X           if (AreWe(HANDICAP)) {
X              extern int handicaps;
X              if (cur) handicaps++;
X              else handicaps--;
X           }
X								b (x, y) = cur;
X								Plt (&board, x, y);
X								dolog (x, y, cur);
X							    }
X							    printscore ();
X							}
X							else
X							    if (!strcmp (buf, MSWITCH)) {
X								doswitch ();
X							    }
X							    else
X								if (!strcmp (buf, MRESIGN)) {
X								    doresign (false);
X								}
X}
X
Xdoresign (isme)
Xint     isme;
X{
X    iwon = !isme;
X    savestr ();
X    homemes ();
X    Beep ();
X    if (iwon) {
X	addmes ("The other player resigned.");
X	GetAKey ();
X	clear ();
X        refresh ();
X	printf ("\nYou won by resignation.\n");
X    }
X    else {
X	addmes ("You resigned.");
X	GetAKey ();
X	clear ();
X        refresh ();
X	printf ("\nYou lost by resignation.\n");
X    }
X    Exit ();
X}
X
Xsetcurplr () {
X    int     x,
X            y;
X    for (x = 0; x < MAXX; x++)
X	for (y = 0; y < MAXY; y++)
X	    if (b (x, y)) {
X		curplr = 1;
X		return (0);
X	    }
X}
X
X/* print out the messages to start scoring */
Xscoremes () {
X    homemes ();
X    addmes ("- Please score now.");
X    addmes ("   - Cancel returns to play.");
X    addmes ("   - Select dead groups.");
X    addmes ("   - Quit determines winner.");
X    Beep ();
X}
X
Xdosave () {
X    savegame ();
X    homemes ();
X    addmes ("Game saved.");
X}
X
Xdoplay () {
X    extern int  loadflg;
X    homemes ();
X    addmes ("- Please begin play.");
X    Beep ();
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,
X        y;
X{
X    if (b (x, y)) {
X	deletes (x, y);
X	SEND (MDELETE);
X	SendCoord (x, y);
X    }
X    else
X	Beep ();
X}
X
X
Xdoswitch () {
X    player = !player;
X    printscore ();
X  /* initmesg() ; */
X}
X
Xdodecline () {
X   extern int mesflg,curx,cury,tcury;
X   int curxbak,curybak,mesgbak,tcurybak;
X   curxbak=curx;
X   curybak=cury;
X   mesgbak=mesflg;
X   tcurybak=tcury;
X    restboard ();
X    ClrStat (SCORE);
X    SetStat (PLAY);
X    PrintBoard (&board);
X   mesflg=mesgbak;
X   tcury=tcurybak;
X
X   curx=curxbak;
X   cury=curybak;
X}
X
Xdocancel () {
X   extern int mesflg,curx,cury,tcury;
X   int curxbak,curybak,mesgbak,tcurybak;
X   curxbak=curx;
X   curybak=cury;
X   mesgbak=mesflg;
X   tcurybak=tcury;
X    restboard ();
X    ClrStat (SCORE);
X    SetStat (PLAY);
X    PrintBoard (&board);
X
X    refresh ();
X    homemes ();
X    addmes ("- Scoring is cancelled.");
X    addmes ("-     Resume play.");
X   mesflg=mesgbak;
X   tcury=tcurybak;
X
X   curx=curxbak;
X   cury=curybak;
X}
X
Xdoscore () {
X    SetStat (SCORE);
X    ClrStat (PLAY);
X    scoremes ();
X    saveboard ();
X}
X
X
X
Xdodemo (x, y, bu)
Xint     x,
X        y,
X        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	    }
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    int     x,
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    hama[0] = hama[1] = 0;
X}
X
Xdoclearboard () {
X    CLEAR ();
X    InitBoard (&board);
X    hama[0] = hama[1] = 0;
X    PrintBoard (&board);
X}
END_OF_FILE
if test 5351 -ne `wc -c <'doother.c'`; then
    echo shar: \"'doother.c'\" unpacked with wrong size!
fi
# end of 'doother.c'
fi
if test -f 'file.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'file.c'\"
else
echo shar: Extracting \"'file.c'\" \(6695 characters\)
sed "s/^X//" >'file.c' <<'END_OF_FILE'
X#include "std.disclaimer"
X#include "go.h"
X#include <strings.h>
X#include <sys/file.h>
X
X
X/* save file */
X
XFILE *sf;
Xint initload;
Xint commenting=0;
X
Xchar input_buffer[MAXBUF];
X
Xextern int beepflg,  status;
Xextern int handicaps;
Xextern int dimensions,  myport;
Xextern char *arg0;
Xextern int logflg;
Xextern FILE *logfile;
X
X/*
X * file format:
X
X#<board dimension> #<curplr: 0/1> #<black's prisoners> #<white's prisoners> #<cursor x> #<cursor y>
X<options= Rxx -> right justify with x being width Bxx -> 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
Xtestsave()
X{
X	char buf[2];
X	getLine("Save Game (y/n)? ",buf,1);
X	if (buf[0] =='y')
X		savegame();
X        printf("\n");
X}
X
Xsavegame()
X{
X	extern char *opponent;
X	int fd;
X	int x,y;
X
X	getLine("Save as <ret exits>:",input_buffer,MAXBUF-1);
X	if (input_buffer[0]) {
X		/* sprintf(input_buffer,"go.save.%s",opponent); */
X
X		sf = fopen(input_buffer,"w");
X		if (!sf) badload("Can't create file.");
X
X		/*fprintf(sf,"#!%s/%s -m -l\n", BINDIR, arg0);*/
X		fprintf(sf, "%d %d %d %d %d %d %d\n",
X		dimensions, curplr, hama[0], hama[1], cx, cy, player);
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\n");
X		fclose(sf);
X	}
X}
X
XdoReceiveLoad()
X{
X	extern int loadflg;
X	extern char loadname[];
X	loadflg = true;
X	loadname[0] = 0;
X	readint(&hama[0]);
X	readint(&hama[1]);
X	readint(&curplr);
X	readint(&dimensions);
X	readint(&player);
X	MAXX = MAXY = dimensions;
X	DoRedraw();
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	getbuf(1);
X	sscanf(input_buffer, "%d %d %d %d %d %d %d",
X	&dimensions, &curplr, &hama[0], &hama[1], &cx, &cy, &player);
X
X
X
X	MAXX = MAXY = lj= bj = dimensions;
X	if (!initload) {
X		initload=1;
X		PrintBoard(&board);
X	} 
X	else {
X		SEND(MCLEAR);
X		doclear();
X	}
X
X
X	homemes();
X	if (!curplr) addmes("== Black to play.");
X	else addmes("== White to play.");
X
X	done = 0;
X	do {
X		getbuf(1);
X		if (input_buffer[0]=='R' || input_buffer[0]=='r') {
X			lj = atoi (input_buffer+1);
X			if (lj < 1 || lj > dimensions)
X				lj = dimensions;
X		} 
X		else if (input_buffer[0]=='B' || input_buffer[0]=='b') {
X			bj = atoi (input_buffer+1);
X			if (bj < 1 || bj > dimensions)
X				bj = dimensions;
X		} 
X		else done++;
X	} 
X	while (!done);
X
X	SEND(MLOAD);
X	sendint(hama[0]);
X	sendint(hama[1]);
X	sendint(curplr);
X	sendint(dimensions);
X	sendint(!player);
X
X	while (input_buffer[0] != '(')
X		getbuf(1);
X
X	getbuf(1);
X	done = 0;
X	x = dimensions - lj;
X	y = dimensions - bj;
X	cp = input_buffer;
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		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 = input_buffer; 
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 = input_buffer;
X		}
X		if (y>=dimensions)
X			done++;
X	}
X	/* Read in and display comments */
X	while (fgets(input_buffer,MAXBUF,sf)!=NULL && input_buffer[0]=='%') {
X		if (input_buffer[0]=='%') {
X			char *cc;
X			cc = index (input_buffer,'\n');
X			if (cc!=NULL) *cc = '\0';
X			addmes(input_buffer+1);			/* display the message */
X		}
X		input_buffer[0]='\0';				/* is this neccessary? */
X	}
X
X	fclose(sf);
X}
X
Xgetbuf(err)
Xint err;
X{
X	do {
X		if (fgets(input_buffer,MAXBUF,sf) == NULL)
X			if (err) badload("Bad Data/End of file reached early.");
X	} 
X	while (input_buffer[0]=='\n' || input_buffer[0]=='\0' || input_buffer[0]==';' || input_buffer[0] == '#');
X}
X
Xbadload(s)
Xchar *s;
X{
X	homemes();
X	addmes(s);
X	Beep();
X	GetAKey();
X	SEND(MEXIT);
X	Exit();
X}
X
Xdoload()
X{
X	extern char loadname[];
X	extern int loadflg;
X
X	int x,y;
X	if (!loadname[0])
X		getLine("Load which file?",loadname,40);
X	loadflg = loadname[0];
X	if (loadflg)
X		restgame(loadname);
X	return 1;
X}
X
X
Xaddapiece(str,c)
Xchar *str;
Xint c;
X{
X  int x,y;
X
X  fprintf(stderr,"%s\n",str);
X  while (str[0]=='[' && str[3]==']' && str[1]>='a' && str[1]<='s' &&
X        str[2]>='a' && str[2]<='s')
X  {
X    x=str[1]-'a';
X    y=str[2]-'a';
X    if (c==2) {
X         if (b(x,y)==1) 
X            DoHand(x,y,0);
X         else if (b(x,y)==2)
X            DoHand(x,y,1);
X    }
X    else DoHand(x,y,c);
X    str+=4;
X  }
X}
X
X
Xloadlog() 
X{
X   char instr[1024];
X   int cur;
X   extern int logflg;
X
X   logflg=0;
X   PrintBoard(&board);
X   fseek(logfile,0,0);
X   while (!feof(logfile)){
X      fgets(instr,1023,logfile);
X      if (!strncmp(instr,"Black[",6)) addapiece(instr+5,0);
X      else if (!strncmp(instr,"AddBlack[",9)) addapiece(instr+8,0);
X      else if (!strncmp(instr,"White[",6)) addapiece(instr+5,1);
X      else if (!strncmp(instr,"AddWhite[",9)) addapiece(instr+8,1);
X      else if (!strncmp(instr,"AddEmpty[",9)) addapiece(instr+8,2);
X   }
X   logflg++;
X}
X
X
Xint openlog()
X{
X	extern char logname[];
X	extern int logflg;
X	int d;
X	char c;
X
X	if (logfile=fopen(logname,"r+")) {
X		loadlog();
X		fseek(logfile,0,2);
X 	if (ftell(logfile)) {
X			d = (-1) ;
X			fseek(logfile,d,2);
X			do {
X				d--;
X				c=fgetc(logfile);
X			} 
X			while ((!fseek(logfile,d,2))&&((c!=')') && (c!=']')));
X			if (c==')') d++;
X			else d=0;
X		}
X		fseek(logfile,d,2);
X		return 1;
X	}
X	else if (logfile=fopen(logname,"a+")) { 
X		fprintf(logfile,"(\n;\nGaMe[1]\nVieW[]\nSiZe[%d]\n",dimensions);
X		return 0;
X	} 
X	else {
X		SEND(MEXIT);
X		logflg=0;
X		fprintf(stderr,"Error opening logfile\n\n");
X		Exit();
X	}
X}
X
X
X
Xchar *Player[]={
X	"AddEmpty","Black","White"};
X
Xdolog(x,y,color)
Xint x,y,color;
X{ 
X	if (logflg) {
X		if (commenting) {
X			commenting=0;
X			fprintf(logfile,"]\n");
X		}
X		fprintf(logfile,";\n%s[%c%c]\n",Player[color],x+'a',y+'a');
X		fflush(logfile);
X	}
X}
X
X
Xcloselog()
X{
X	if (logflg){
X		if (commenting) fprintf(logfile,"]\n");
X		fprintf(logfile,")\n");
X		fclose(logfile);
X	}
X}        
X
X
Xlogcomment(comm,player)
Xchar *comm;
Xint player;
X
X{
X	extern char *myname, *hisname;
X	extern int usemess;
X
X	if ((logflg) && (usemess) && (*comm) && (*comm!='\\')) {
X		if (!commenting) fputs("Comment[",logfile);
X		if ((player==1) && (commenting!=1))
X			fprintf(logfile, "\n%s:",myname);
X		else if ((player==2) && (commenting != 2))
X			fprintf(logfile, "\n%s:",hisname);
X		commenting=player;
X		fputc(' ',logfile);
X		for(;*comm;comm++){
X			if ((*comm==')')||(*comm=='(')||(*comm=='[')||(*comm==']'))
X				fputc('\\',logfile);
X			fputc(*comm,logfile);
X		}
X	}
X}
X
X
END_OF_FILE
if test 6695 -ne `wc -c <'file.c'`; then
    echo shar: \"'file.c'\" unpacked with wrong size!
fi
# end of 'file.c'
fi
if test -f 'go.6' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'go.6'\"
else
echo shar: Extracting \"'go.6'\" \(14185 characters\)
sed "s/^X//" >'go.6' <<'END_OF_FILE'
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.
XIf rogue keys are not one's "cup of tea" then the numeric keypad 
X.B [12346789] 
Xmay be used:
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 one is by
Xappearing next to the player status at the bottom of the screen.
XIn the
X.B X
Xversion,
Xthe top message window indicates
Xwhich player one is.
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 respective player strengths
Xin a file in the 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 the player strength,
Xstarting at 35 kyu = value -5,
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
XVersions of Inet GO prior to 7.0 take the difference in
Xplayer strengths from the info in '.go_strength' 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.
XInet GO version 7.0 and future versions do -not- set handicapping 
Xautomatically in the initial display window unless players specify the -E
Xoption on the run-time command line. 
X.LP
XNote: One may set rank with command line options.
X.LP
XIf any player does not like the rank assigned by computer automation,
Xthe handicap stones may be changed manually,
Xas well as player 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.LP
X.TP 8
X.B -h
XPrint out this help file for go.
X.LP
X.TP 8
X.B -d
XSet the display to a remote display.
XUse this command if doing rlogin from a console onto a remote
Xdisplay before playing.
XIf via rlogin to a remote sun to play,
Xtype ``xgo -d <your-display:0> user@host'' to have
Xthe board appear on display screen.
X.LP
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.LP
X.TP 8
X.B -q
XQuiet -- don't issue any beeps. 
X.LP
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.LP
X.TP 8
X.B -n
XSet the number of times to blink a piece.
XThis is useful for various screen-display speeds.
X.LP
X.TP 8 
X.B -E
XUse the handicapping info from the respective .go_strength files.
XIf both players specify -E then the .go_strength file info is used
Xto calculate a correct handicapping on the display at initialization.
XIf one of the players is using a former version of Inet GO previous
Xto release version 7.0, then the .go_strength files will be used.
XIf both players are using Inet GO release version 7.0, or subsequent
Xreleases, then the the initial display will, by default, show -no-
Xhandicapping stones.   To provide for an initial handicap setting -other-
Xthan a value calculated from the respective .go_strength files, do not
Xspecify -E, but use the -H option.   
X.LP
X.TP 8
X.B -c 
XGives an opening message and credits. 
X.LP
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.LP
X.TP 8
X.B -r
XGive the program's approximation of player rank and wins.
X.LP
X.TP 8
X.B -R
XModify current player rank.  
X``go -R 5 k'' would set player rank to 5 kyu (amateur).
X``go -R 5 d'' would set player rank to 5 dan (middle ranks).
X``go -R 5 p'' would set player rank to 5 professional dan (highest ranks).
X``go -R +'' would increase player rank by one.
X``go -R -'' would decrease player rank by one.
XThe lowest rank is 35 kyu,
Xclimbing to 1 kyu.
XThen one may become 1 dan (Shodan),
Xincreasing to 7 dan.
XLastly,
Xthe professional ranks go from 1 to 9 professional dan.
XThese 51 rankings are linked to 51 states of Buddha consciousness.
X.LP
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.
XYou will be prompted for a filename.
X.LP
X.TP 8
X.B -L
XInitiate game-logging to the 'Smart-GO' file format.
X``-L sgfile'' will output the game-record as the game is played.
XIf the specified file already exists, it will be loaded as 
Xa 'Smart-GO' file.   This
Xoption is intended to restore logged games, rather than to read Smart-Go
Xfiles in general.  Only the AddBlack, AddWhite, AddEmpty, White, and Black
XSmart-Go commands are supported.  Variations will be superimposed. 
XThis takes precedence over the -l option
Xfor restoring a game.
X.LP
X.TP 8
X.B -a
XDo not include the player messages from the
Xdiscussion windows in the 'Smart-GO' game record.
X.LP
X.TP 8
X.B -V
XFlip (invert) the video orientation opposite to
Xwhatever the default compile options were.
X.LP
X.TP 8
X.B -B
XUse ascii code number, or char for displaying the Black stones.
X(e.g.  -B 42, or -B \\* gives the '*' character).
X.LP
X.LP
X.B Setting/unsetting 
X.B stones
X.B during play:
XEach mouse button and the 'z' and 'x' keys
Xset/unset stones on the board.
X.LP
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,
Xthe players are not allowed to play a point when the 
Xcorresponding group will have no liberties at the end of
Xthe turn.  This is the "no suicide" rule.
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,
Xone may attach 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 owned as territory 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 a 
Xpurchase of go literature if one intends to enjoy
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$(HOME)/.go_strength	a file kept in the player's home directory keeping track of 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
XA SiZe[xx] statement in a Smart-Go file will be ignored.
X.LP
XSmart-Go files must not contain variations
X.LP
XIf both players specify -L on files that contain game data, 
Xthe two games will be superimposed.
X.LP
XSend further bug reports to "theorem@blake.u.washington.edu",
X"...!ucbvax!scam!hale" or "hale@scam.Berkeley.EDU"
X.fi
X.sp
X.SH AUTHORS
XGreg Hale (hale@scam.berkeley.edu)
X.LP
XAdrian Mariano (theorem@blake.u.washington.edu)
X.sp
X.SH "SEE ALSO"
Xrn 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
END_OF_FILE
if test 14185 -ne `wc -c <'go.6'`; then
    echo shar: \"'go.6'\" unpacked with wrong size!
fi
# end of 'go.6'
fi
if test -f 'go.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'go.h'\"
else
echo shar: Extracting \"'go.h'\" \(2347 characters\)
sed "s/^X//" >'go.h' <<'END_OF_FILE'
X#include "std.disclaimer"
X#include <curses.h>
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <errno.h>
X
X#define MSCORE		"SCORE"
X#define MQUIT		"QUIT"
X#define MEXIT		"EXIT"
X#define MCANCEL		"CANCEL"
X#define MPLAY		"PLAY"
X#define MMOVE		"MOVE"
X#define MHANDICAP	"HANDICAP"
X#define MMESSAGE	"MESSAGE"
X#define MDELETE		"DELETE"
X#define MPASS		"PASS"
X#define MACCEPT		"ACCEPT"
X#define MDECLINE	"DECLINE"
X#define MSWITCH		"SWITCH"
X#define MSIZE		"SIZE"
X#define MHAND		"HANDI"
X#define MSTR		"STREN"
X#define MMODE		"MODE"
X#define MRESIGN		"RESIGN"
X#define MLOAD		"LOAD"
X#define MCLEAR		"CLEAR"
X
X#define	HELP_CMD "/usr/ucb/more /usr/public/go.doc"
X
X#define MAXDIM 19		/* maximum dimension */
X#define MINDIM 9		/* minimum board dimension */
X#define DEFAULTPORT 525		/* default port to connect with */
X
X#define GOFILE "/.go_strength"	/* information on player's strength */
X#define DEFAULTSTR 1		/* default strength if never played */
X#define MAXSTR 48		/* count from 1... maxstr */
X#define WINSUP 6		/* how many wins (losses) in a row are needed to
X* go up a rank if you are weaker than
X* the other player. */
X#define KOMI	5.5		/* standard komi- add to white at end of game */
X
X
X#define P1 1			/* board types - player 1 pieces */
X#define P2 2			/* player 2 pieces */
X#define NONE 0			/* nothing */
X#define MARK 3			/* neutral/marks for searches */
X
X
X#define FASTMOVE 3		/* speed with <shift><dir> */
X#define REDRAW '\014'		/* ^l */
X#define MAXBUF 200		/* maximum line buffer */
X
X#define DEBUG(m) 
X
X
X#define WHEN break; case
X#define OTHERWISE break; default
X#define and &&
X#define or ||
X
X#define true 1
X#define false 0
X#define UNSET 2
X
X
X#define error(x) { fprintf(stderr,x); testsave(); Exit(); }
X
X#define SEND(m)  sendit(m)
X#define RECV(m) receive(m)
X
Xtypedef struct { 
X	char d[MAXDIM][MAXDIM]; 
X} 
XBOARD;
X#define b(x1,y1) board.d[x1][y1]	/* JOE CODE- lazy hack. */
X#define m(x2,y2) marks.d[x2][y2]	/* my apologies */
X
X#define HITAKEYMES "[Hit any key]"
X
X#define SCORE		0x1		/* state values */
X#define QUIT		0x2
X#define EXIT		0x4
X#define REDRAWING	0x8
X#define CANCEL		0x10
X#define PLAY		0x20
X#define HANDICAP	0x40
X
Xextern BOARD backup,board,marks;
Xextern int curplr,hama[],MAXX,MAXY,cx,cy;
Xextern int disable,myturn,sock,sockmask[],status,player,dimensions;
Xextern char *blanks;
Xextern char pieces[], buf[];
Xextern bool iamserver;
Xextern int iwon;
X
END_OF_FILE
if test 2347 -ne `wc -c <'go.h'`; then
    echo shar: \"'go.h'\" unpacked with wrong size!
fi
# end of 'go.h'
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'\" \(2613 characters\)
sed "s/^X//" >'main.c' <<'END_OF_FILE'
X#include "std.disclaimer"
X/*
X    Go written by Greg Hale (April 20 1987)
X*/
X
X#include "go.h"
X#include <ctype.h>
X#include <signal.h>
X#include <strings.h>
X
Xbool iamserver = UNSET;
Xlong    random ();
Xlong    time ();
Xchar   *arg0;
X
X
Xmain0 (argc, argv, envp)
Xint     argc;
Xchar  **argv,
X      **envp;
X{
X    extern int  loadflg,
X                logflg,
X                myport;
X    extern char loadname[],
X               *hisname;
X    int     port,
X            i,
X            j,
X            trap_cdump (), trap_sigint (), tstp (), ts_tp ();
X    char   *p,
X           *malloc ();
X
X/*   arg0 = (arg0 = rindex (argv[0], '/')) ? arg0 + 1 : argv[0];*/
X
X    port = myport;
X
X    signal (SIGINT, SIG_IGN);
X    signal (SIGPIPE, SIG_IGN);
X    srandom (time ((long *) NULL));
X
X    Init ();
X
X    signal (SIGINT, trap_sigint);
X    setcore (trap_cdump);	/* set up the core dump trap */
X
X    p = hisname;		/* used to be argv[argc-1] */
X    connectport (p, port);
X    doneconnectmes ();
X
X    player = iamserver;
X    printscore ();
X    initmesg ();
X    Synchronize ();
X    if (!((logflg && openlog ()) || (loadflg && doload ()))) {
X	PrintBoard (&board);
X	sethandi ();
X    }
X
X    Loop ();
X
X    testsave ();
X    clear();
X    refresh();
X
X    Exit ();
X}
X
X
X/*
X * Make sure all game parameters match in programs
X */
XSynchronize () {
X    extern int  strength,
X                opponstr,
X                handin,
X                handicaps;
X    int     temp;
X    extern char *myname;
X
X
X    swap (MSTR, strength, &opponstr,
X	    "Incompatable version: strength not sent from other program.\n");
X
X    swap (MMODE, 1, &temp, "Incompatable version: demoflag not sent from other program.\n");
X
X
X    swap (MSIZE, dimensions, &temp,
X	    "Incompatable verison: size not sent from other program.\n");
X    if (temp < dimensions)
X	dimensions = temp;
X    /* dimensions = dimensions / 2 * 2 + 1; */
X    MAXX = MAXY = dimensions;
X    handin = (dimensions > 12) ? 3 : 2;
X
X    swap (MHAND, handicaps, &temp,
X	    "Incompatable verison: # of handicaps not sent from other program.\n");
X    if (temp >= 0 || handicaps >= 0) {
X	handicaps = (temp > handicaps ? temp : handicaps);
X    }
X    else {
X	temp = opponstr - strength;
X	handicaps = (temp > 0 ? temp : -temp);
X	handicaps = (handicaps * dimensions * dimensions) / (19 * 19);
X	if (temp)
X	    player = temp > 0;
X    }
X
X}
X
X
Xswap (mesg, s, r, err)
Xchar   *mesg,
X       *err;
Xint    *r,
X        s;
X{
X    char    line[100];
X    int     temp;
X
X    SEND (mesg);
X    RECV (line);
X    if (strcmp (line, mesg)) {
X	error (err);
X    }
X
X    sprintf (line, "%d", s);
X    SEND (line);
X
X    RECV (line);
X    *r = atoi (line);
X}
END_OF_FILE
if test 2613 -ne `wc -c <'main.c'`; then
    echo shar: \"'main.c'\" unpacked with wrong size!
fi
# end of 'main.c'
fi
if test -f 'opts.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'opts.c'\"
else
echo shar: Extracting \"'opts.c'\" \(5732 characters\)
sed "s/^X//" >'opts.c' <<'END_OF_FILE'
X#include "std.disclaimer"
X#include "go.h"
X#include <strings.h>
X#include <sys/file.h>
X
X#define ISARG(s) (!strncmp(*argv,s,strlen(s)))
X
Xint     numberblink;
X
Xparseline (argc, argv)
Xint     argc;
Xchar  **argv;
X{
X    char  **argval;
X    extern char loadname[],
X                logname[],
X               *hisname,
X               *myname;
X    extern int  beepflg,
X                strength,
X                myport,
X                handicaps;
X    extern int  loadflg;
X    extern int  inverse;
X    extern int  usemess;
X    extern int  logflg;
X    extern float    wins;
X    extern  FILE * logfile;
X
X    GetStr ();
X    inverse = INVERSE;
X    numberblink = 4;
X    handicaps = 0;
X    argval = argv;
X    dimensions = MAXDIM;
X    myport = DEFAULTPORT;
X    beepflg = 1;
X    usemess = 1;
X    hisname = NULL;
X
X    while (++argv, --argc > 0) {
X	if (ISARG ("-h")) {
X	    longhelp ();
X	}
X	else
X	    if (ISARG ("-s")) {
X		if (--argc > 0) {
X		    dimensions = atoi (*++argv);
X		    if (dimensions < 7)
X			dimensions = 7;
X		    if (dimensions > 19)
X			dimensions = 19;
X		}
X		else
X		    helpstart (argval);
X	    }
X	    else
X		if (ISARG ("-p")) {
X		    if (--argc > 0)
X			myport = atoi (*++argv);
X		    else
X			helpstart (argval);
X		}
X		else
X		    if (ISARG ("-a")) {
X			usemess = 0;
X		    }
X		    else
X			if (ISARG ("-H")) {
X			    if (--argc > 0)
X				handicaps = atoi (*++argv);
X			    else
X				helpstart (argval);
X			}
X			else
X			    if (ISARG ("-c")) {
X				changes ();
X			    }
X			    else
X				if (ISARG ("-r")) {
X				    showstr ();
X				    exit (0);
X				}
X				else
X				    if (ISARG ("-B")) {
X					if (--argc > 0) {
X					    char    black;
X					    black = atoi (*++argv);
X					    if ((black) && (black < 127))
X						pieces[1] = black + inverse;
X					    else
X						pieces[1] = (**argv) + inverse;
X					}
X					else
X					    helpstart (argval);
X				    }
X				    else
X					if (ISARG ("-E")) {
X					    handicaps = -2;
X					}
X					else
X					    if (ISARG ("-V")) {
X						char    c;
X						if (inverse) {
X						    for (c = 0; c < 6; c++)
X							pieces[c] -= 128;
X						    inverse = 0;
X						}
X						else {
X						    for (c = 0; c < 6; c++)
X							pieces[c] += 128;
X						    inverse = 128;
X						}
X					    }
X					    else
X						if (ISARG ("-q")) {
X						    beepflg = 0;
X						}
X						else
X						    if (ISARG ("-n")) {
X							if (--argc > 0) {
X							    numberblink = atoi (*++argv);
X							    if (numberblink < 0)
X								numberblink = 4;
X							}
X							else
X							    helpstart (argval);
X
X						    }
X						    else
X							if (ISARG ("-l")) {
X							    if (--argc > 0) {
X								loadflg++;
X								strcpy (loadname, *++argv);
X							    }
X							    else
X								helpstart (argval);
X							}
X							else
X							    if (ISARG ("-L")) {
X								if (--argc > 0) {
X								    logflg++;
X								    strcpy (logname, *++argv);
X								}
X								else
X								    helpstart (argval);
X							    }
X							    else
X								if (ISARG ("-R")) {
X								    wins = 0.0;
X								    if (--argc) {
X									if (*argv[1] == '+') {
X									    strength++;
X									    argv++;
X									}
X									else
X									    if (*argv[1] == '-') {
X										strength--;
X										argv++;
X
X									    }
X									    else
X										if (--argc) {
X										    switch (*argv[2]) {
X										    WHEN 'k': 
X											    strength = 31 - atoi (argv[1]);
X										    WHEN 'd': 
X											    strength = 30 + atoi (argv[1]);
X										    WHEN 'p': 
X											    strength = 39 + atoi (argv[1]);
X										    OTHERWISE: 
X											    helpstart (argval);
X										    }
X										    argv += 2;
X										}
X										else
X										    helpstart (argval);
X
X									if (strength < 1)
X									    strength = 1;
X									else
X									    if (strength > MAXSTR)
X										strength = MAXSTR;
X
X									savestr0 ();
X									exit (0);
X								    }
X								    else
X									helpstart (argval);
X								}
X								else {
X								    hisname = *argv++;
X								}
X    }
X    if (hisname == NULL)
X	helpstart (argval);
X}
X
X
Xhelpstart (argv)
Xchar   *argv[];
X{
X    fprintf (stderr, "                      %s\n", VERSION);
X    fprintf (stderr, "\nUsage:\n");
X    fprintf (stderr, "%s {opts} user[@host]\n", argv[0]);
X
X    fprintf (stderr, "{opts} is any of :\n");
X    fprintf (stderr, "-p port#               which address to meet at.\n");
X    fprintf (stderr, "-q                     quiet -- don't beep.\n");
X    fprintf (stderr, "-s size                set the board size [7-19].\n");
X    fprintf (stderr, "-n blink               set the number of times to blink a piece.\n");
X    fprintf (stderr, "-H #handicaps          set the number of handicap stones.\n");
X    fprintf (stderr, "-c                     give the opening message and credits.\n");
X    fprintf (stderr, "-l <filename>          load a saved/sample game from diagram file.\n");
X    fprintf (stderr, "-L <filename>          load or create a move by move log of game.\n");
X    fprintf (stderr, "-a                     abridged log -- don't include player messages.\n");
X#if (INVERSE==0)
X    fprintf (stderr, "-V                     use inverse video.\n");
X#else
X    fprintf (stderr, "-V                     use normal video instead of inverse.\n");
X#endif
X    fprintf (stderr, "-B {number|char}       Use ascii code number, or char for black stones.\n");
X    fprintf (stderr, "-E                     use handicap info from go_strength.\n");
X    fprintf (stderr, "OR:\n");
X    fprintf (stderr, "\"%s -r\" for your current rank.\n", argv[0]);
X    fprintf (stderr, "\"%s -h\" for help.\n", argv[0]);
X    fprintf (stderr, "\"%s -R # {k|d|p} to set your rank to # kyu/dan/pro dan respectively\n", argv[0]);
X    fprintf (stderr, "\"%s -R {+|-} to increase/decrease your rank respectively\n", argv[0]);
X    exit (0);
X}
END_OF_FILE
if test 5732 -ne `wc -c <'opts.c'`; then
    echo shar: \"'opts.c'\" unpacked with wrong size!
fi
# end of 'opts.c'
fi
echo shar: End of archive 1 \(of 2\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked both 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