DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T m

⟦4fb6c3fab⟧ TextFile

    Length: 3460 (0xd84)
    Types: TextFile
    Names: »main.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/X/Xgo/main.c« 

TextFile

/*
 * $Header: main.c,v 3.0 88/03/10 12:07:32 hale Exp $
 */



/*

        Copyright 1987      Greg Hale

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation.  No representations are made about the
suitability of this software for any purpose.  It is
provided "as is" without express or implied warranty.

*/


/*
    Go written by Greg Hale (April 20 1987)
*/

/* main.c */
/* #include "xgo.h" */
#include "go.h"
#include <ctype.h>
#include <signal.h>
#include <strings.h>

bool		iamserver = UNSET;
long		random();
long		time();
char		*arg0;


main0 (argc, argv, envp)
int argc;
char **argv, **envp;
{
	extern int loadflg, myport;
	extern char *loadname, *hisname;
	int port,i, j, trap_sigint(),tstp(),ts_tp();
	char *p, *malloc ();

	arg0 = (arg0 = rindex(argv[0],'/')) ? arg0+1: argv[0];

	port = myport;

	signal (SIGINT, SIG_IGN);
	signal (SIGPIPE, SIG_IGN);
	srandom (time((long *) NULL));

	Init();

	signal (SIGINT, trap_sigint);
	p = hisname;		/* used to be argv[argc-1] */
	connectport (p, port);
	doneconnectmes();

	player = iamserver;
	printscore();
	initmesg();

	Synchronize();

	if (loadflg) {
		doload();		/* load in saved game */
	} else {
		PrintBoard(&board);
		sethandi();
	}

	Loop ();
	Exit();
}


/*
 * Make sure all game parameters match in programs
 */
Synchronize()
{
	extern int demflg,strength,opponstr,handin,handicaps;
	int temp;

	swap(MSTR, strength, &opponstr,
		"Strength not sent from other program.\n");

	swap(MMODE, demflg,&temp,"Demoflag not sent from other program.\n");
	demflg |= temp;


	swap(MSIZE,dimensions,&temp,
		"Size not sent from other program.\n");
	if (temp<dimensions) dimensions = temp;
	dimensions = dimensions / 2 * 2 + 1;
	MAXX = MAXY = dimensions;
	handin = (dimensions > 12) ? 3 : 2;

	swap(MHAND,handicaps,&temp,
		"# of handicaps not sent from other program.\n");
	if (temp >0 || handicaps > 0) {
		handicaps = (temp > handicaps ? temp : handicaps);
	} else {
		temp = opponstr - strength;
		handicaps = (temp > 0 ? temp : -temp);
		handicaps = (handicaps * dimensions * dimensions) / (19 * 19);
		if (temp) player = temp > 0;
	}

}


swap(mesg,s,r,err)
char *mesg,*err;
int *r,s;
{
	char line[100];
	int temp;

	SEND(mesg);
	RECV(line);
	if (strcmp(line,mesg)) {
		error(err);
	}

	sprintf(line,"%d",s);
	SEND(line);

	RECV(line);
	*r= atoi(line);
}
/*
 * $Log:	main.c,v $
 * Revision 3.0  88/03/10  12:07:32  hale
 * Added save games, a few changes to the I/O,
 * added load and clear options.  Not thouroughly tested, though, and
 * I think a few bugs are in the load code.  A library of sample problems
 * has been started and saved with the working directory.
 * 
 * Revision 1.4  88/02/19  13:48:56  hale
 * Added io changes for loading games.
 * Load game is cleaned up.  Variable board
 * sizes and formats available in save game
 * as well as printed comments.
 * 
 * Revision 1.3  88/02/14  00:23:06  hale
 * Added load file option during game to restore game to starting
 * state.  Also, clear board operation.  Restoring game puts current
 * player in sync.  With the demo mode, this is invaluable.
 * 
 * Revision 1.2  88/02/13  12:49:59  hale
 * modified entry to have load option work and opponnents name is loaded
 * properly.
 * 
 */