#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 3 (of 7)."
# Contents:  Makefile arg.c declare.h extract.c frontend.c
#   geneban1/0080aaa.tie license.h portable.c portable.h slicers.c
#   soup_in soup_in.h trand.c
# Wrapped by ray@life on Mon Nov  4 22:56:32 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(6117 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# Makefile_sccsid: @(#)Makefile	1.19	10/28/91
X
X## edit the following variables to tailor this Makefile to the system
X## you want to install tierra on. (hint: if your `make' complains
X## about missing values for any variable that is commented out, just
X## give it a null value, ie: VAR =<Return>
X
X## Destination: set as appropriate for your system. it currently assumes
X## you are building the system in a directory called /usera/tierra
X#
XDEST	      = /usera/tierra
X
X## Almond: uncomment the following lines if you want to build almond
X## NOTE: almond is not included in this beta-test distribution. do not
X## uncomment or change this section!!!
X#
X# ALMONDDIR     = $(DEST)/src/almond
X# AL_CFLAGS	= -DSOCKETS -I$(ALMONDDIR)
X# AL_LIBS	=
X# AL_HDRS	= $(ALMONDDIR)/allayer.h \
X#		$(ALMONDDIR)/allayerp.h \
X#		$(ALMONDDIR)/alrequests.h \
X#		$(ALMONDDIR)/tlayer.h \
X#		$(ALMONDDIR)/tlayerp.h \
X#		$(ALMONDDIR)/comm.h \
X#		$(ALMONDDIR)/commp.h
X# AL_OBJS	= $(ALMONDDIR)/tlayer.o \
X#		$(ALMONDDIR)/tlcomm.o \
X#		$(ALMONDDIR)/allayer.o \
X#		$(ALMONDDIR)/allcomm.o \
X#		$(ALMONDDIR)/comm.o
X# AL_SRCS	= $(ALMONDDIR)/tlayer.c \
X#		$(ALMONDDIR)/tlcomm.c \
X#		$(ALMONDDIR)/allayer.c \
X#		$(ALMONDDIR)/allcomm.c \
X#		$(ALMONDDIR)/comm.c
X
X
X## Tierra: uncomment the following lines as appropriate to build tierra
X#
XTIERRADIR     = $(DEST)/src/tierra
X
X## Instruction Set: uncomment your choice of instruction sets
X#
X## Tom Ray's original instruction set 1
XINST	= 1
X
X## OS type: uncomment the lines OSFLAGS and LIBS below for the operating
X## system and/or machine type most closely resembling yours, if you port
X## tierra to a system significantly different from any of these or 
X## one marked "not tested", please send us any changes you needed to
X## make to get it working.
X#
X# Sun Workstations: choose Sun3 or Sun4
X# other systems running Berkeley 4.2 or 4.3: choose bsd 4.3
X#
X# SGI Iris: choose IRIX
X# AT&T SysIII: choose Sys3 (not tested)
X# AT&T SysV: choose SysV   (not tested)
X#
X# IBM RS/6000: choose RS6000 (not tested)
X
X## Sun3 -------------------------------------
X#
X# OSFLAGS	= -fswitch
X# LIBS	= -lm
X#
X## Sun4 -------------------------------------
X#
X# OSFLAGS	=
X# LIBS	= -lm
X#
X## bsd 4.3 ----------------------------------
X#
X# OSFLAGS	=
X# LIBS	= -lm
X
X## IRIX -------------------------------------
X#
XOSFLAGS	= -D_BSD_SIGNALS
XLIBS	= -lm -lsun
X#
X## Sys3 -------------------------------------
X#  (untested)
X# OSFLAGS	= -D_BSD_SIGNALS
X# LIBS	= -lm
X#
X## SysV -------------------------------------
X#  (untested)
X# OSFLAGS	= -D_BSD_SIGNALS
X# LIBS	= -lm
X
X## RS6000 -----------------------------------
X# (untested)
X# OSFLAGS	= -D_BSD_SIGNALS
X# LIBS	= -lm
X#
X##
X
X## Optimization: set as appropriate for your compiler
X## for debugging you should (usually) set this to -g
X## to perform code optimization this setting is (usually) -O or -O<digit>
X#
XOPTIMIZ	= -g
X
X## Flags to be passed to the linker (usually cc). Add any special requirements
X## for your system. this is hopefully oniform enough that there is no need
X## to include all of the possibilities under the OS section. if you are using
X## optimization, you may want to add -s to strip symbol tables and thus create 
X## a smaller binary.
X#
XLDFLAGS	= $(OPTIMIZ)
X
X## you shouldn't have to change anything below this line.
X## (if you are lucky, and the gods of technology aren't angry with you...)
X
XCFLAGS	= -w $(OPTIMIZ) -DINST=$(INST) $(OSFLAGS) $(AL_CFLAGS)
X
XEXTHDRS	      = /usr/include/arpa/inet.h \
X		/usr/include/ctype.h \
X		/usr/include/errno.h \
X		/usr/include/fcntl.h \
X		/usr/include/limits.h \
X		/usr/include/malloc.h \
X		/usr/include/math.h \
X		/usr/include/memory.h \
X		/usr/include/netdb.h \
X		/usr/include/netinet/in.h \
X		/usr/include/rpcsvc/ypclnt.h \
X		/usr/include/stdio.h \
X		/usr/include/stdlib.h \
X		/usr/include/string.h \
X		/usr/include/sys/errno.h \
X		/usr/include/sys/fcntlcom.h \
X		/usr/include/sys/param.h \
X		/usr/include/sys/signal.h \
X		/usr/include/sys/socket.h \
X		/usr/include/sys/stat.h \
X		/usr/include/sys/sysmacros.h \
X		/usr/include/sys/time.h \
X		/usr/include/sys/types.h \
X		/usr/include/time.h \
X
XHDRS	      = declare.h extern.h portable.h tierra.h debug.h $(AL_HDRS)
X
XLINKER	      = cc 
X
XMAKEFILE      = Makefile
X
XPROGRAM	      = tierra 
X
XOBJS      = bookeep.o \
X		extract.o \
X		genebank.o \
X		genio.o \
X		parse.o \
X                frontend.o \
X		instruct.o \
X		memalloc.o \
X		portable.o \
X		queues.o \
X		slicers.o \
X		tierra.o \
X		trand.o \
X		tsetup.o \
X		$(AL_OBJS)
X
XSRCS      = bookeep.c \
X		extract.c \
X		genebank.c \
X		genio.c \
X		parse.c \
X		frontend.c \
X		instruct.c \
X		memalloc.c \
X		portable.c \
X		queues.c \
X		slicers.c \
X		tierra.c \
X		trand.c \
X		tsetup.c \
X		$(AL_SRCS)
X
XDOCS      = README.T1 README.T2 arg.1
X
XARGOBJ	  = arg.o genio.o portable.o frontend.o $(AL_OBJS)
X
Xall:;
X	@echo "   "
X	@echo " Tierra Artificial Life system "
X	@echo "   "
X	@echo " Please edit this Makefile, "
X	@echo " un-commenting the line(s) for your machine type / OS. "
X	@echo " and choice of options. "
X	@echo "   "
X	@echo " Then say:  " 
X	@echo " make programs  " 
X	@echo "   " 
X
Xtierra:   $(OBJS)
X		$(LINKER) $(LDFLAGS) $(OBJS) $(LIBS) -o tierra
X
Xarg:      $(ARGOBJ) 
X		$(LINKER) $(LDFLAGS) $(ARGOBJ) $(LIBS) -o arg
X
Xclean:;		rm -f *.o  
X		rm -f $(ALMONDDIR)/*.o
X
Xdepend:;	mkmf -f $(MAKEFILE) PROGRAM=$(PROGRAM) DEST=$(DEST)
X
Xindex:;		ctags -wx $(HDRS) $(SRCS)
X
Xinstall:	$(PROGRAM)
X		install -s $(PROGRAM) $(DEST)
X
Xprint:;		$(PRINT) $(HDRS) $(SRCS)
X
Xprograms:       tierra arg
X
Xtags:           $(HDRS) $(SRCS); ctags $(HDRS) $(SRCS)
X
Xupdate:		$(DEST)/$(PROGRAM)
X
X#distrib:	$(SRCS) $(HDRS) $(DOCS) arg.c Makefile
X#		cp $(SRCS) $(HDRS) $(DOCS) arg.c Makefile $(DEST)/src/distrib
X#		cd $(DEST)/src/distrib; 
X
X$(DEST)/$(PROGRAM): $(PROGRAM)
X		@make -f $(MAKEFILE) DEST=$(DEST) install
X###
Xtlayer.o : $(ALMONDDIR)/tlayer.c
X	cc -c $(CFLAGS) $(ALMONDDIR)/tlayer.c
X
Xtlcomm.o : $(ALMONDDIR)/tlcomm.c
X	cc -c $(CFLAGS) $(ALMONDDIR)/tlcomm.c
X
Xallayer.o : $(ALMONDDIR)/allayer.c
X	cc -c $(CFLAGS) $(ALMONDDIR)/allayer.c
X
Xallcomm.o : $(ALMONDDIR)/allcomm.c
X	cc -c $(CFLAGS) $(ALMONDDIR)/allcomm.c
X
Xcomm.o : $(ALMONDDIR)/comm.c
X	cc -c $(CFLAGS) $(ALMONDDIR)/comm.c
X
END_OF_FILE
if test 6117 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'arg.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'arg.c'\"
else
echo shar: Extracting \"'arg.c'\" \(3906 characters\)
sed "s/^X//" >'arg.c' <<'END_OF_FILE'
X/* arg.c  4-10-91  bookeeping functions for the tierra simulator */
X/** Tierra Simulator V3.0: Copyright (c) 1991 Tom Uffner **/
X#include "license.h"
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)arg.c	1.6     9/19/91";
X#endif
X
X#include "tierra.h"
X#include "declare.h"
X#include "arginst.h"
X#include <errno.h>
X
X#ifdef unix
Xchar *malloc();
X#endif
X
Xint  hangup = 0;
X
Xint main(argc, argv)
X    int   argc;
X    char  *argv[];
X{
X    I8s  com, *mod, *u = "usage:  arg c|r[vo12] afile size file [file...]\n\
X\targ x[vo12] afile [genotype [genotype...]]\n\targ t[v] afile\n";
X    I8s  *file = 0, hbuf[5];
X    int i, v = 0, o = 0, f = 1, size = 0;
X    FILE *afp = 0;
X#ifdef __TURBOC__
X    float  z = sin(0);
X#endif
X
X    struct g_list *g = 0;
X    head_t head;
X    indx_t *indx;
X
X    if (argc < 3) {
X	fprintf(stderr, u);
X	exit(1);
X    }
X    switch (com = *argv[1]) {
X    case 'c':
X    case 'r':
X	if (argc < 5) {
X	    fprintf(stderr, u);
X	    exit(2);
X	}
X	if (!sscanf(argv[3], "%d", &size)) {
X	    fprintf(stderr, u);
X	    exit(3);
X	}
X    case 't':
X    case 'x':
X	break;
X    default:
X	fprintf(stderr, u);
X	exit(4);
X    }
X    for (mod = ++argv[1]; *mod; mod++)
X	switch (*mod) {
X	case 'v':
X	    ++v;
X	    break;
X	case 'o':
X	    ++o;
X	    break;
X	case '1':
X	case '2':
X	case '3':
X	case '4':
X	case '5':
X	case '6':
X	case '7':
X	case '8':
X	case '9':
X	    f = *mod - '0';
X	    break;
X	default:
X	    fprintf(stderr, u);
X	    exit(5);
X	}
X    file = argv[2];
X
X    switch (com) {
X    case 'c':
X	fprintf(stdout, "creating archive \"%s\"\n", file);
X    case 'r':
X	if (!(afp = open_ar(file, size, f, com == 'c' ? 1 : 0))) {
X	    perror(argv[0]);
X	    exit(6);
X	}
X	head = read_head(afp);
X	indx = read_indx(afp, &head);
X	g = (struct g_list *) calloc(1, sizeof(struct g_list));
X	for (i=4; i < argc; i++) {
X	    int j;
X	    o ? GetGenFormat(g, argv[i]) : GetAscGen(g, argv[i]);
X	    if (head.size != g->gen.size) {
X		fprintf(stderr, "%s is wrong size\n", g->gen.label);
X		continue;
X	    }
X	    j = add_gen(afp, &head, &indx, g);
X	    if (v)
X		; /* verbose mode */
X	    else fprintf(stdout, "%c - %s\n", j?'r':'a', g->gen.label);
X	}
X	free(g);
X	fclose(afp);
X	break;
X    case 't':
X	if (!(afp = fopen(file, "rb"))) {
X	    perror(argv[0]);
X	    exit(7);
X	}
X	head = read_head(afp);
X	if (strncmp(head.magic, "tie", 3) || head.magic[3] - '0' != f) {
X	    fprintf(stderr, "%s: bad magic number", *argv);
X	    exit(8);
X	}
X	indx = read_indx(afp, &head);
X        hbuf[0] = head.magic[0]; hbuf[1] = head.magic[1];
X        hbuf[2] = head.magic[2]; hbuf[3] = head.magic[3]; hbuf[4] = 0;
X	fprintf(stdout, "Format: %s, Size: %d, # of entries: %d\n\n",
X            hbuf, head.size, head.n);
X	for (i = 0; i < head.n; i++)
X	    if (v)
X		; /* verbose mode */
X	    else fprintf(stdout, "%.3s\n", indx[i].gen);
X	break;
X    case 'x':
X	if (!(afp = fopen(file, "rb"))) {
X	    perror(argv[0]);
X	    exit(9);
X	}
X	head = read_head(afp);
X	if (strncmp(head.magic, "tie", 3) || head.magic[3] - '0' != f) {
X	    fprintf(stderr, "%s: bad magic number", *argv);
X	    exit(10);
X	}
X	indx = read_indx(afp, &head);
X	if (argc > 3)
X	    for (i=3; i<argc; i++) {
X		int j;
X		if ((j = find_gen(indx, argv[i], head.n)) == head.n) {
X		    fprintf(stderr, "%s not in archive\n", argv[i]);
X		    continue;
X		}
X		g = get_gen(afp, &head, &indx[j], j);
X		file = malloc(8);
X                sprintf(file, "%04d%s", head.size, g->gen.label);
X		o ? WritGenFile(g, file) : WritAscFile(g, file);
X		if (v)
X		    ; /* verbose mode */
X		else fprintf(stdout, "x - %s\n", g->gen.label);
X		free(file);
X		free(g->genome);
X		free(g);
X	    }
X	else
X	   for (i=0; i<head.n; i++) {
X		g = get_gen(afp, &head, &indx[i], i);
X		file = malloc(12);
X                sprintf(file, "%04d%s", head.size, g->gen.label);
X		o ? WritGenFile(g, file) : WritAscFile(g, file);
X		if (v)
X		    ; /* verbose mode */
X		else fprintf(stdout, "x - %s\n", g->gen.label);
X		free(file);
X		free(g->genome);
X		free(g);
X	    }
X	break;
X    }
X}
END_OF_FILE
if test 3906 -ne `wc -c <'arg.c'`; then
    echo shar: \"'arg.c'\" unpacked with wrong size!
fi
# end of 'arg.c'
fi
if test -f 'declare.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'declare.h'\"
else
echo shar: Extracting \"'declare.h'\" \(4076 characters\)
sed "s/^X//" >'declare.h' <<'END_OF_FILE'
X/* declare.h  19-8-91  global variable declarations */
X/*** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray ***/
X
X#include "license.h"
X
X/*
X#ifndef lint
Xstatic char  sccsid[] = "@(#)declare.h	1.29 10/6/91";
X#endif
X*/
X
X#ifndef  LDECLAR_H
X#define  LDECLAR_H
X
XFILE  *oufr;
XHpInst  soup;
Xstruct ArgInstDef  aid[32]; /* instruction definition for arg.c */
XI32s  AverageSize;  /* average size of cells in soup */
XI32s  BottomReap; /* index of cell at bottom of reaper queue, last to die */
XI32s  BrkupCou; /* count of output files break.n */
XI32s  BrkupCum; /* cumulative count of bytes output to break.n */
XI32s  comsoc;
XI32s  CountFlaw;  /* counter for flaw random number */
XI32s  CountMovMut; /* keep track of time since last mov_mut */
XI32s  CountMutRate; /* keep track of time since last mut */
XI32s  debug_switch;
Xstruct event  DistNext; /* time of next disturbance */
Xstruct event  Disturb;  /* time of disturbance */
XI32s  extr;  /* which cell to isolate */
XI32s  ExtractCount; /* count of cells manually extracted */
XI32s  FirstOutDisk; /* has OutDisk been called */
XI32s  fragment;  /* 0 = memory is not fragmented  1 = memory is fragmented  */
XI32s  FreeBlocks;  /* number of free blocks of memory */
Xdouble Generations;/* count of elapsed generations (AvgPop/TimeBirth-Death) */
XI8s  **GenInList; /* pointers to soup_in genome names */
XI8s  *GenInBuf;   /* buffer containing soup_in genome names */
Xstruct event  InstExe;  /* counter of instructions executed */
Xstruct inst  is;  /* structure for passing info between parse and execute */
XI32s  isolate;  /* isolate the genome of the cell extr */
Xstruct event  LastDiv;  /* instructions executed at last divide */
XI8s   mes[7][80];    /* array of strings for message passing to front end */
XI32s  num_gen;       /* present number of genotypes saved to disk */
XI32s  num_genq;      /* present number of genotypes in RAM bank */
XI32s  num_genl;      /* present number of genotypes in *gl lists */
XI32s  NumSiz;       /* present number of sizes saved to disk */
XI32s  NumSizq;      /* present number of sizes in RAM bank */
XI32s  NumSizl;      /* present number of sizes in *sl list */
XI32s  PhotonSize; /* number of instructions in photon */
XI32s  RandIx1, RandIx2, RandIx3; /* for trand() */
XI32s  RateFlaw; /* frequency of flaws */
XI32s  RateMovMut;  /* 1 / frequency of mutations per mov event */
XI32s  RateMut;  /* number of instructions per mutations */
XI32s  reaped;    /* 0 = reaper has not killed, 1 = reaper has killed */
XI32s  runflag;
XI32s  siz_sl;  /* allocated size of *sl array */
XI8s   SLASH;  /* in DOS = \ = 92, in unix = / = 47 */
XI8s   soup_fn[85];  /* place for soup_in filename */
XI32s  SoupBot;  /* index of FreeMem struct for bottom of soup memory */
XI32s  SoupTop;  /* index of FreeMem struct for top of soup memory */
XI32s  ThisSlice;  /* index of cell that is currently active */
XI32s  TimeBirth;  /* count of births in each million instruction */
XI32s  TimeDeath;  /* count of deaths in each million instruction */
Xdouble TimePop;   /* sum of ttime * NumCells for each million instructions */
XI32s  TopReap;    /* index of cell at top of reaper queue, next to die */
XI32s  TotFlaw;  /* total number of flaws in this run */
XI32s  TotMovMut;  /* total number of move mutations in this run */
XI32s  TotMut;  /* total number of background mutations in this run */
XI32u  ONE;         /* a constant */
XInstruction  PhotonInst[80];  /* instructional representation of photon */
XInd   FreeMemCurrent;  /* current amount of free memory in soup */
XInd   Search_limit;  /* limit on how far address instructions will search */
XPcells  cells;  /* cells array */
XPmf     FreeMem;  /* free memory array */
XPgl     gl;  /* list of genotypes for genebanker */
XPsl     sl;  /* list of unique size classes, number of gts */
Xdouble  TrandArray[98]; /* for trand() */
Xstruct LastOut  lo;  /* last data output to disk */
Xstruct gl_index  gq_bot;  /* bottom of gene queue */
Xstruct gl_index  gq_top;  /* top of gene queue */
Xvoid (*slicer)();
X
X#ifdef __TURBOC__
Xextern unsigned  _stklen = 32768;
X#endif
X
X#endif
END_OF_FILE
if test 4076 -ne `wc -c <'declare.h'`; then
    echo shar: \"'declare.h'\" unpacked with wrong size!
fi
# end of 'declare.h'
fi
if test -f 'extract.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'extract.c'\"
else
echo shar: Extracting \"'extract.c'\" \(2598 characters\)
sed "s/^X//" >'extract.c' <<'END_OF_FILE'
X/* extract.c  28-10-91  genome extraction for the Tierra simulator */
X/** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
X
X#include "license.h"
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)extract.c	2.7	10/8/91";
X#endif
X
X#include "tierra.h"
X#include "extern.h"
X
Xvoid extract(ci)
X    I32s  ci;
X{
X    Pcells  ce = cells + ci;
X    I8s   file[80];
X    I16u  i, j;
X    I32s  size;
X    Ind  ip;
X    Pgl  g;
X    Psl  ts;
X
X    isolate = 0;
X    if (GeneBnker)
X#ifdef IBM3090
X        sprintf(file,"%04ld.gen.d", ce->d.gen.size);
X#else
X        sprintf(file,"%s%04ld.gen", GenebankPath, ce->d.gen.size);
X#endif
X    else
X#ifdef IBM3090
X        sprintf(file,"mut%ld.gen.d", ++ExtractCount);
X#else
X        sprintf(file,"mut%ld", ++ExtractCount);
X#endif
X    size = ce->d.gen.size;
X    if (GeneBnker)
X    {   ts = sl + ce->d.gli.si;
X        g = ts->g + ce->d.gli.gi;
X    }
X    else
X    {   g = (Pgl) thcalloc(1, sizeof(struct g_list));
X        g->bits = 0;
X        g->gen = ce->d.gen;
X        g->parent = ce->d.parent;
X        g->d1 = ce->d.d1;
X        g->d2.inst = ce->d.inst + 1 - ce->d.d1.inst;
X        g->d2.flags = ce->d.flags - ce->d.d1.flags;
X        g->d2.mov_daught = ce->d.mov_daught;
X        g->d2.BreedTrue = 2;
X        g->originI = InstExe;
X        g->originC = time(NULL);
X        g->MaxPropPop = g->MaxPropInst = -1;
X#ifdef COMMENTS
X        g->comments = (I8s  *) thcalloc(2,sizeof(I8s));
X        strcpy(g->comments,"\n");
X#else
X        g->comments = 0;
X#endif
X        g->ploidy = ce->d.ploidy;
X        g->track = ce->c.tr;
X        g->genome = (HpInst) thcalloc(g->gen.size,sizeof(Instruction));
X        g->gbits  = (HpGenB) thcalloc(g->gen.size,sizeof(GenBits));
X        for (i = 0, ip = ce->mm.p; ip < ce->mm.p + size; i++, ip++)
X        {   for(j = 0; j < g->ploidy; j++)
X             /* g->genome[i] = fetch(ip); */
X                g->genome[i][j] = soup[ip][j];
X        }
X    }
X    if (!GeneBnker)
X        sprintf(mes[0],"extract: about to save genome %04ld%s",
X            g->gen.size, g->gen.label);
X    else
X        sprintf(mes[0],"extract: about to save genome %04ld%s = %ld",
X            g->gen.size, g->gen.label, g->pop);
X    FEMessage(1);
X    if (GeneBnker)
X    {   FILE *fp;
X        head_t head;
X        indx_t *indx;
X	
X        fp = open_ar(file, ce->d.gen.size, INST, 0);
X        head = read_head(fp);
X        indx = read_indx(fp, &head);
X        add_gen(fp, &head, &indx, g);
X        free(indx);
X        fclose(fp);
X    }
X    else
X    {   WritGenFile(g,file);
X        if (g->genome) thfree(g->genome);
X        if (g->comments) thfree(g->comments);
X        thfree(g);
X    }
X}
END_OF_FILE
if test 2598 -ne `wc -c <'extract.c'`; then
    echo shar: \"'extract.c'\" unpacked with wrong size!
fi
# end of 'extract.c'
fi
if test -f 'frontend.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'frontend.c'\"
else
echo shar: Extracting \"'frontend.c'\" \(2371 characters\)
sed "s/^X//" >'frontend.c' <<'END_OF_FILE'
X/* frontend.c  28-10-91  Artificial Life simulator frontend routines */
X/** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
X
X#include "license.h"
X
X/* frontend rationale:  to have a common set of functions for passing info
X   from Tierra to the front end.  Any particular front end will likely
X   use only a subset of all frontend functions.  Those functions that a
X   particular front end does not use, will either have to be implemented
X   here as dummy functions, or they will have to be ifdef'ed where they
X   are called from Tierra */
X
X#ifndef lint
Xstatic char     sccsid[] = "%W% %G%";
X#endif
X
X#include "tierra.h"
X#include "extern.h"
X
X#if FRONTEND == STDIO  /* STDIO == 0 */
X
Xvoid FEStartup() /* called immediately after the soup_in file is read */
X{                    /* an opportunity to interactively set soup_in vars */
X}
X
Xvoid  FEMessage(n)
XI8s  n;
X{   I8s  i;
X
X    for(i = 0; i < n; i++)
X        printf("%s\n", mes[i]);
X    fflush(stdout);
X}
X
Xvoid  FEError(n)
XI8s  n;
X{   I8s  i;
X
X    for(i = 0; i < n; i++)
X        fprintf(stderr, "%s\n", mes[i]);
X    fflush(stderr);
X}
X
Xvoid  FEPlan(MaxPop, MaxMem, MaxGenPop, MaxGenMem)
XI32s  MaxPop, MaxMem;
Xstruct genotype  *MaxGenPop, *MaxGenMem;
X{   long int  tp;
X
X    tp = time(NULL);
X    printf("InstExeC = %ld  Generations = %.0f  NumCells = %ld  %s",
X        InstExe.m, Generations, NumCells, ctime(&tp));
X    if (InstExe.m)
X        printf("    births = %ld  deaths = %ld  AvgPop = %.0f  \
X            AvgSize = %ld\n", TimeBirth, TimeDeath, TimePop, AverageSize);
X    printf("    RateMut = %ld  RateMovMut = %ld  RateFlaw = %ld\n",
X        RateMut, RateMovMut, RateFlaw);
X    printf("    num_gen = %ld  num_genq = %ld  num_genl = %ld  \
X        AverageSize = %ld\n", num_gen, num_genq, num_genl, AverageSize);
X    if (GeneBnker && InstExe.m)
X        printf("    MaxGenPop = %ld%s = %ld  MaxGenMem = %ld%s = %ld\n",
X            MaxGenPop->size, MaxGenPop->label, MaxPop,
X            MaxGenMem->size, MaxGenMem->label, MaxMem / MaxGenMem->size);
X    fflush(stdout);
X}
X
X#endif /* FRONTEND == STDIO == 0 */
X
X
X#if FRONTEND == GREENLEAF  /* GREENLEAF == 1 */
X
Xvoid FEStartup()
X{   ;
X}
X
Xvoid  FEMessage(n)
XI8s  n;
X{
X}
X
Xvoid  FEError(n)
XI8s  n;
X{
X}
X
Xvoid  FEPlan(MaxPop, MaxMem, MaxGenPop, MaxGenMem)
XI32s  MaxPop, MaxMem;
Xstruct genotype  *MaxGenPop, *MaxGenMem;
X{
X}
X
X#endif /* FRONTEND == GREENLEAF == 1 */
X
END_OF_FILE
if test 2371 -ne `wc -c <'frontend.c'`; then
    echo shar: \"'frontend.c'\" unpacked with wrong size!
fi
# end of 'frontend.c'
fi
if test -f 'geneban1/0080aaa.tie' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'geneban1/0080aaa.tie'\"
else
echo shar: Extracting \"'geneban1/0080aaa.tie'\" \(2394 characters\)
sed "s/^X//" >'geneban1/0080aaa.tie' <<'END_OF_FILE'
X
Xformat: 1  bits: 45750471  EXsh TCsh TPs MFsofh MTdf MB
Xgenotype: 0080aaa  parent genotype: 6666god
X1st_daughter:  flags: 0  inst: 827  mov_daught: 80  breed_true: 1
X2nd_daughter:  flags: 0  inst: 809  mov_daught: 80  breed_true: 1
XInstExe.m: 0  InstExe.i: 0  origin: 662270168  Wed Dec 26 22:56:08 1990
XMaxPropPop: 0.8306  MaxPropInst: 0.4239
Xploidy: 1  track: 0
X
Xtrack 0: prot
X          xwr
Xnop_1   ; 010 110 01   0
Xnop_1   ; 010 110 01   1
Xnop_1   ; 010 110 01   2
Xnop_1   ; 010 110 01   3
Xzero    ; 010 110 04   4
Xor1     ; 010 110 02   5
Xshl     ; 010 110 03   6
Xshl     ; 010 110 03   7
Xmov_cd  ; 010 110 18   8
Xadrb    ; 010 110 1c   9
Xnop_0   ; 010 100 00  10
Xnop_0   ; 010 100 00  11
Xnop_0   ; 010 100 00  12
Xnop_0   ; 010 100 00  13
Xsub_ac  ; 010 110 07  14
Xmov_ab  ; 010 110 19  15
Xadrf    ; 010 110 1d  16
Xnop_0   ; 010 100 00  17
Xnop_0   ; 010 100 00  18
Xnop_0   ; 010 100 00  19
Xnop_1   ; 010 100 01  20
Xinc_a   ; 010 110 08  21
Xsub_ab  ; 010 110 06  22
Xnop_1   ; 010 110 01  23
Xnop_1   ; 010 110 01  24
Xnop_0   ; 010 110 00  25
Xnop_1   ; 010 110 01  26
Xmal     ; 010 110 1e  27
Xcall    ; 010 110 16  28
Xnop_0   ; 010 100 00  29
Xnop_0   ; 010 100 00  30
Xnop_1   ; 010 100 01  31
Xnop_1   ; 010 100 01  32
Xdivide  ; 010 110 1f  33
Xjmp     ; 010 110 14  34
Xnop_0   ; 010 100 00  35
Xnop_0   ; 010 100 00  36
Xnop_1   ; 010 100 01  37
Xnop_0   ; 010 100 00  38
Xif_cz   ; 010 000 05  39
Xnop_1   ; 010 110 01  40
Xnop_1   ; 010 110 01  41
Xnop_0   ; 010 110 00  42
Xnop_0   ; 010 110 00  43
Xpush_ax ; 010 110 0c  44
Xpush_bx ; 010 110 0d  45
Xpush_cx ; 010 110 0e  46
Xnop_1   ; 010 110 01  47
Xnop_0   ; 010 110 00  48
Xnop_1   ; 010 110 01  49
Xnop_0   ; 010 110 00  50
Xmov_iab ; 010 110 1a  51
Xdec_c   ; 010 110 0a  52
Xif_cz   ; 010 110 05  53
Xjmp     ; 010 110 14  54
Xnop_0   ; 010 110 00  55
Xnop_1   ; 010 110 01  56
Xnop_0   ; 010 110 00  57
Xnop_0   ; 010 110 00  58
Xinc_a   ; 010 110 08  59
Xinc_b   ; 010 110 09  60
Xjmp     ; 010 110 14  61
Xnop_0   ; 010 100 00  62
Xnop_1   ; 010 100 01  63
Xnop_0   ; 010 100 00  64
Xnop_1   ; 010 100 01  65
Xif_cz   ; 010 000 05  66
Xnop_1   ; 010 110 01  67
Xnop_0   ; 010 110 00  68
Xnop_1   ; 010 110 01  69
Xnop_1   ; 010 110 01  70
Xpop_cx  ; 010 110 12  71
Xpop_bx  ; 010 110 11  72
Xpop_ax  ; 010 110 10  73
Xret     ; 010 110 17  74
Xnop_1   ; 010 100 01  75
Xnop_1   ; 010 100 01  76
Xnop_1   ; 010 100 01  77
Xnop_0   ; 010 100 00  78
Xif_cz   ; 010 000 05  79
END_OF_FILE
if test 2394 -ne `wc -c <'geneban1/0080aaa.tie'`; then
    echo shar: \"'geneban1/0080aaa.tie'\" unpacked with wrong size!
fi
# end of 'geneban1/0080aaa.tie'
fi
if test -f 'license.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'license.h'\"
else
echo shar: Extracting \"'license.h'\" \(2530 characters\)
sed "s/^X//" >'license.h' <<'END_OF_FILE'
X/* 
X * Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray
X * 
X * by Tom Ray, ray@brahms.udel.edu (the bulk of the code)
X *    Tom Uffner, tom@genie.slhs.udel.edu (rework of genebanker & assembler)
X *    Dan Pirone, cocteau@life.slhs.udel.edu (the interrupt handler)
X *    Marc Cygnus, cygnus@udel.edu (connections to the ALmond monitor)
X * 
X * This code and documentation is copyrighted and is not in the public domain.
X * All rights reserved.  This package may be freely copied and distributed
X * without fees, subject to the following restrictions:
X * 
X * - This notice may not be removed or altered.
X * 
X * - You may not try to make money by distributing the package or by using the
X *   process that the code creates.
X * 
X * - You may not prevent others from copying it freely.
X * 
X * - You may not distribute modified versions without clearly documenting your
X *   changes and notifying the principal author.
X * 
X * - The origin of this software must not be misrepresented, either by
X *   explicit claim or by omission.  Since few users ever read sources,
X *   credits must appear in the documentation.
X * 
X * - Altered versions must be plainly marked as such, and must not be
X *   misrepresented as being the original software.  Since few users ever read
X *   sources, credits must appear in the documentation.
X * 
X * - The University and the authors are not responsible for the
X *   consequences of use of this software, no matter how awful, even if they
X *   arise from flaws in it.
X * 
X * - Neither the name of the University, nor the authors of
X *   the code may be used to endorse or promote products derived from this
X *   software without specific prior written permission.
X * 
X * - The provision of support and software updates is at our discretion.
X * 
X * Please contact Tom Ray (full address below) if you have
X * questions or would like an exception to any of the above restrictions.
X * 
X * If you make changes to the code, or have suggestions for changes,
X * let us know!  If we use your suggestion, you will receive full credit
X * of course.
X * 
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X *
X *    Tom Ray
X *    University of Delaware
X *    School of Life & Health Sciences
X *    Newark, Delaware  19716
X *    ray@tierra.slhs.udel.edu
X *    ray@life.slhs.udel.edu
X *    ray@brahms.udel.edu
X *    302-451-2281 (FAX)
X *    302-451-2753 (Phone)
X */
END_OF_FILE
if test 2530 -ne `wc -c <'license.h'`; then
    echo shar: \"'license.h'\" unpacked with wrong size!
fi
# end of 'license.h'
fi
if test -f 'portable.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'portable.c'\"
else
echo shar: Extracting \"'portable.c'\" \(6878 characters\)
sed "s/^X//" >'portable.c' <<'END_OF_FILE'
X/* portable.c  28-10-91  conditionally compiled functions for portability */
X/** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
X
X#include "license.h"
X
X#ifndef lint
Xstatic char     portable_sccsid[] = "%W%	%G%";
X#endif
X
X#include <stdio.h>
X#include "tierra.h"
X#include "extern.h"
X
X#ifdef SOCKETS
X#include "allayer.h"
X#endif
X
X/* free for arrays of greater than 64K */
Xvoid thfree(ptr)
XI8s Hp  ptr;
X{
X#ifdef __TURBOC__
X    farfree(ptr);
X#endif
X
X#ifdef OS2_MC
X    DosFreeSeg((I16u) ptr >> 16);
X#endif
X
X#ifdef unix
X
X#ifdef SOCKETS
X    ALFree( (char *)ptr );
X#else
X    free(ptr);
X#endif	/* SOCKETS */
X
X#endif
X
X#ifdef IBM3090
X    free(ptr);
X#endif
X}
X
X/* realloc for arrays of greater than 64K */
XI8s Hp threalloc(ptr, siz)
XI8s Hp  ptr;
XI32u    siz;
X{
X#ifdef __TURBOC__
X/* note: due to a bug, Borland's Turbo C V 2.0 farrealloc() does not work */
X/*
X    if (siz > 65535)
X    {   sprintf(mes[0], "You have been caught by the Borland Turbo C V2.0");
X        sprintf(mes[1], "farrealloc bug.  To avoid this bug you must make");
X        sprintf(mes[2], "the initial size of the Cells array large enough");
X        sprintf(mes[3], "that it doesn't have to be reallocated.");
X        sprintf(mes[4], "suggestion: CellsSize = SoupSize / 100");
X        FEError(5);
X        exit(1);
X    }
X*/
X    return (I8s  Hp) farrealloc(ptr,siz);
X#endif
X
X#ifdef OS2_MC
X    I16u     NumSegs, Remain, Selector;
X    I8s  Hp  tp;
X
X    NumSegs = (I16u) siz / 65536ul;
X    Remain  = (I16u) siz % 65536ul;
X    Selector = ((I16u) ptr >> 16);
X    DosReallocHuge(NumSegs,Remain,Selector);
X    return (void Hp) ptr;
X#endif
X
X#ifdef unix
X    I8s *  tp;
X
X#ifdef SOCKETS
X    tp = (I8s *) ALRealloc(ptr,siz);
X#else
X    tp = (I8s *) realloc(ptr,siz);
X#endif	/* SOCKETS */
X    if(tp == NULL)
X    {
X#ifdef SOCKETS
X        sprintf(mes[0],"threalloc error: ALRealloc failed");
X#else
X        sprintf(mes[0],"threalloc error: realloc failed");
X#endif	/* SOCKETS */
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X/*      WriteSoup(1); */
X        exit(0);
X    }
X    return tp;
X
X#endif /* unix */
X
X#ifdef IBM3090
X    return (I8s  *) realloc(ptr,siz);
X#endif
X}
X
X/* calloc for arrays of greater than 64K */
XI8s Hp thcalloc(num, siz)
XI32u   num;
XI32u   siz;
X{
X#ifdef __TURBOC__
X    return (I8s Hp) farcalloc(num,siz);
X#endif
X
X#ifdef OS2_MC
X    I32u     HugeSize, i, ASize;
X    I16u     NumSegs, Remain, rc;
X    I8s Hp  tp;
X    SEL      Selector;
X
X    HugeSize = num * siz;
X    i = HugeSize / 65536ul;
X    NumSegs = (I16u) i;
X    Remain  = (I16u) HugeSize % 65536ul;
X    rc = DosAllocHuge(NumSegs,Remain,&Selector,3 * NumSegs,0);
X    if(rc)
X    {   sprintf(mes[0],"DosAllocHuge error = %u", rc);
X        FEMessage(1);
X        exit(1);
X    }
X    tp = (I8s Hp) ((I32u ) Selector << 16);
X    for(i = 0; i < HugeSize; i++)
X    {   *(tp + i) = (I8s) 0;
X    }
X    return (I8s Hp) tp;
X#endif
X
X#ifdef unix
X    I8s *  tp;
X
X#ifdef SOCKETS
X    tp = (I8s *) ALCalloc(num, siz);
X#else
X    tp = (I8s *) calloc(num, siz);
X#endif	/* SOCKETS */
X    if(tp == NULL)
X    {
X#ifdef SOCKETS
X        sprintf(mes[0],"threalloc error: ALCalloc failed");
X#else
X        sprintf(mes[0],"threalloc error: calloc failed");
X#endif	/* SOCKETS */
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X/*      WriteSoup(1); */
X        exit(0);
X    }
X    return tp;
X
X#endif /* unix */
X
X#ifdef IBM3090
X    return (I8s  *) calloc(num,siz);
X#endif
X}
X
XI32u tfread(ptr, size, n, stream)
XI8s Hp  ptr;
XI32s  size, n;
XFILE  *stream;
X{   I32u  r_size = 0;
X#ifdef __TURBOC__
X    I32s  segs, rem, i = 0;
X
X    segs = n / (I32s) UINT_MAX;
X    rem  = n % (I32s) UINT_MAX;
X    if(segs) for(i = 0; i < segs; i++)
X        r_size += fread((I8s *) ((I8s Hp) ptr + (i * size *
X            (I32s) UINT_MAX)), (I16u) size, (I16u) UINT_MAX, stream);
X    if(rem) r_size += fread((I8s *) ((I8s Hp) ptr + (segs * size *
X            (I32s) UINT_MAX)), (I16u) size, (I16u) rem, stream);
X    if(r_size != n)
X    {   sprintf(mes[0],"tfread inconsistency: n = %ld  r_size = %ld",
X            n, r_size);
X        FEMessage(1);
X    }
X    return r_size;
X#endif
X
X#ifdef OS2_MC
X    I32s  segs, rem, i = 0;
X
X    segs = n / (I32s) UINT_MAX;
X    rem  = n % (I32s) UINT_MAX;
X    if(segs) for(i = 0; i < segs; i++)
X        r_size += fread((I8s *) ((I8s Hp) ptr + (i * size *
X            (I32s) UINT_MAX)), (I16u) size, (I16u) UINT_MAX, stream);
X    if(rem) r_size += fread((I8s *) ((I8s Hp) ptr + (segs * size *
X            (I32s) UINT_MAX)), (I16u) size, (I16u) rem, stream);
X    if(r_size != n)
X    {   sprintf(mes[0],"tfread inconsistency: n = %ld  r_size = %ld",
X            n, r_size);
X        FEMessage(1);
X    }
X    return r_size;
X#endif
X
X#ifdef unix
X    r_size = fread(ptr, size, n, stream);
X    if(r_size != n)
X    {   sprintf(mes[0],"tfread inconsistency: n = %ld  r_size = %ld",
X            n, r_size);
X        FEMessage(1);
X    }
X    return r_size;
X#endif
X
X#ifdef IBM3090
X    r_size = fread(ptr, size, n, stream);
X    if(r_size != n)
X    {   sprintf(mes[0],"tfread inconsistency: n = %ld  r_size = %ld",
X            n, r_size);
X        FEMessage(1);
X    }
X    return r_size;
X#endif
X}
X
XI32u tfwrite(ptr, size, n, stream)
XI8s Hp  ptr;
XI32s  size, n;
XFILE *  stream;
X{   I32u  r_size = 0;
X#ifdef __TURBOC__
X    I32s  segs, rem, i = 0;
X
X    segs = n / (I32s) UINT_MAX;
X    rem  = n % (I32s) UINT_MAX;
X    if(segs) for(i = 0; i < segs; i++)
X        r_size += fwrite((const I8s *) ((I8s Hp) ptr + (i * size *
X            (I32s) UINT_MAX)), (I16u) size, (I16u) UINT_MAX, stream);
X    if(rem) r_size += fwrite((const I8s *) ((I8s Hp) ptr + (segs * size *
X        (I32s) UINT_MAX)), (I16u) size, (I16u) rem, stream);
X    return r_size;
X#endif
X
X#ifdef OS2_MC
X    I32s  segs, rem, i = 0;
X
X    segs = n / (I32s) UINT_MAX;
X    rem  = n % (I32s) UINT_MAX;
X    if(segs) for(i = 0; i < segs; i++)
X        r_size += fwrite((const I8s *) ((I8s Hp) ptr + (i * size *
X            (I32s) UINT_MAX)), (I16u) size, (I16u) UINT_MAX, stream);
X    if(rem) r_size += fwrite((const I8s *) ((I8s Hp) ptr + (segs * size *
X        (I32s) UINT_MAX)), (I16u) size, (I16u) rem, stream);
X    return r_size;
X#endif
X
X#ifdef unix
X    r_size = fwrite(ptr, size, n, stream);
X    if(r_size != n)
X    {   sprintf(mes[0],"tfwrite inconsistency: n = %ld  r_size = %ld",
X            n, r_size);
X        FEMessage(1);
X    }
X    return r_size;
X#endif
X
X#ifdef IBM3090
X    r_size = fwrite(ptr, size, n, stream);
X    if(r_size != n)
X    {   sprintf(mes[0],"tfwrite inconsistency: n = %ld  r_size = %ld",
X            n, r_size);
X        FEMessage(1);
X    }
X    return r_size;
X#endif
X}
X
XI32u ffs(x) 
XI32s x;
X{
XI32u i, j;
X    for (i=32, j=1<<i-1; j && !(x&j); i--, j>>=1);
X    return i;
X}
END_OF_FILE
if test 6878 -ne `wc -c <'portable.c'`; then
    echo shar: \"'portable.c'\" unpacked with wrong size!
fi
# end of 'portable.c'
fi
if test -f 'portable.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'portable.h'\"
else
echo shar: Extracting \"'portable.h'\" \(3191 characters\)
sed "s/^X//" >'portable.h' <<'END_OF_FILE'
X/* portable.h 28-10-91  definitions for portability */
X/** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
X
X#include "license.h"
X
X/*
X#ifndef lint
Xstatic char     sccsid[] = "%W%     %G%";
X#endif
X*/
X
X#ifndef PORTABLE_H
X#define PORTABLE_H
X
X#ifdef __TURBOC__
X
X#include <stdlib.h>
X#include <limits.h>
X#include <alloc.h>
X#include <dir.h>
X#include <dos.h>
X#include <mem.h>
X#define ANSI
X#define Hp     huge  *
X#define Fp     far   *
X#define Np     near  *
Xtypedef signed char      I8s;   /*  8 bit integer */
Xtypedef unsigned char    I8u;   /*  8 bit integer */
Xtypedef signed int       I16s;  /* 16 bit integer */
Xtypedef unsigned int     I16u;  /* 16 bit integer */
Xtypedef signed long      I32s;  /* 32 bit integer */
Xtypedef unsigned long    I32u;  /* 32 bit integer */
X
X#endif /* __TURBOC__ */
X
X#ifdef MSDOS /* always defined by Microsoft C compiler & NDPC compiler */
X             /* Microsoft C sets _osmode == OS2_MODE or DOS_MODE */
X
X             /* for OS/2: */
X             /* #define OS2_MC
X                #define INCL_DOS
X                #include <os2.h>
X                #include <limits.h>
X                #include <stdlib.h>  */
X
X#define ANSI
X#define Hp     huge  *
X#define Fp     far   *
X#define Np     near  *
Xtypedef signed char      I8s;   /*  8 bit integer */
Xtypedef unsigned char    I8u;   /*  8 bit integer */
Xtypedef signed int       I16s;  /* 16 bit integer */
Xtypedef unsigned int     I16u;  /* 16 bit integer */
Xtypedef signed long      I32s;  /* 32 bit integer */
Xtypedef unsigned long    I32u;  /* 32 bit integer */
X
X#endif /* MSDOS */
X
X#ifdef unix
X
X#ifdef __GNUC__
X
X#include <limits.h>
X#define ANSI
X
X#else  /* __GNUC__ not defined */
X
X#define UCHAR_MAX ((unsigned char) (~0))
X#define CHAR_MAX ((char) (UCHAR_MAX >> 1))
X#define UINT_MAX ((unsigned short) (~0))
X#define INT_MAX ((short) (UINT_MAX >> 1))
X#define ULONG_MAX ((unsigned int) (~0))
X#define LONG_MAX ((int) (ULONG_MAX >> 1))
X
X#endif /* __GNUC__ */
X
X#define Hp     *
X#define Fp     *
X#define Np     *
Xtypedef char             I8s;   /*  8 bit integer */
Xtypedef unsigned char    I8u;   /*  8 bit integer */
Xtypedef short            I16s;  /* 16 bit integer */
Xtypedef unsigned short   I16u;  /* 16 bit integer */
Xtypedef int              I32s;  /* 32 bit integer */
Xtypedef unsigned int     I32u;  /* 32 bit integer */
X
X#endif /* unix */
X
X#ifdef IBM3090
X
X#define UCHAR_MAX ((unsigned char) (~0))
X#define CHAR_MAX ((char) (UCHAR_MAX >> 1))
X#define UINT_MAX ((unsigned short) (~0))
X#define INT_MAX ((short) (UINT_MAX >> 1))
X#define ULONG_MAX ((unsigned int) (~0))
X#define LONG_MAX ((int) (ULONG_MAX >> 1))
X#define Hp     *
X#define Fp     *
X#define Np     *
Xtypedef char             I8s;   /*  8 bit integer */
Xtypedef unsigned char    I8u;   /*  8 bit integer */
Xtypedef short            I16s;  /* 16 bit integer */
Xtypedef unsigned short   I16u;  /* 16 bit integer */
Xtypedef int              I32s;  /* 32 bit integer */
Xtypedef unsigned int     I32u;  /* 32 bit integer */
X
X#endif /* IBM3090 */
X
X#ifdef ANSI           /* ANSI prototyping */
X#define P_(A) A
X#define const const
X#else                 /* non-ANSI prototyping */
X#define P_(A) ()
X#define const
X#endif
X
X#endif /* #ifndef PORTABLE_H */
END_OF_FILE
if test 3191 -ne `wc -c <'portable.h'`; then
    echo shar: \"'portable.h'\" unpacked with wrong size!
fi
# end of 'portable.h'
fi
if test -f 'slicers.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'slicers.c'\"
else
echo shar: Extracting \"'slicers.c'\" \(2749 characters\)
sed "s/^X//" >'slicers.c' <<'END_OF_FILE'
X/* slicers.c  28-10-91  Artificial Life simulator */
X/** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
X
X#include "license.h"
X
X#ifndef lint
Xstatic char     sccsid[] = "%W%     %G%";
X#endif
X
X#include "tierra.h"
X#include "extern.h"
X
Xvoid SlicerPhoton()
X{   Pcells  ce;
X    I32s  size_slice;
X    Ind   a;
X    I8s   md;
X
X    do a = tlrand() % SoupSize;
X    while(IsFree(a));
X    WhichCell(a, &ThisSlice, &md);
X    size_slice = PhotonSlide(a, PhotonInst, PhotonSize, PhotonWidth);
X    size_slice = (I32s) (10. * pow((double) size_slice,(double) PhotonPow));
X    if(SizDepSlice)
X    {   ce = cells + ThisSlice;
X        size_slice = (I32s) ((double) size_slice *
X            pow((double) ce->mm.s / (double) AverageSize, (double) SlicePow));
X    }
X    TimeSlice(ThisSlice, size_slice);
X}
X
XI32s PhotonFit(a, PhotonInst, PhotonSize)
XInd  a;
XI8s  *PhotonInst;
XI32s  PhotonSize;
X{   I32s  i, j, fit, tfit = 0;
X
X    for(j = 0; j < PLOIDY; j++)
X    {   fit = 0;
X        for(i = 0; i < PhotonSize; i++)
X            if(soup[ad(a + i)][j].inst == *(PhotonInst + i)) fit++;
X        if(fit > tfit)
X            tfit = fit;
X    }
X    return tfit;
X}
X
XI32s PhotonSlide(a, PhotonInst, PhotonSize, PhotonWidth)
XInd  a;
XI8s  *PhotonInst;
XI32s  PhotonSize, PhotonWidth;
X{   I32s  i, ws2, tfit, fit = 0;
X
X    ws2 = (PhotonSize + PhotonWidth) / 2;
X    for(i = 0; i < PhotonWidth; i++)
X    {   tfit = PhotonFit(ad(a - ws2 + i), PhotonInst, PhotonSize);
X        if(tfit > fit) fit = tfit;
X    }
X    return fit;
X}
X
Xvoid PhotonTranslate(PhotonInst, PhotonWord)
XI8s  *PhotonInst;
XI8s  *PhotonWord;
X{   I32s  i;
X
X    for(i = 0; i < PhotonSize; i++)
X    {   if(*(PhotonWord + i) > 47 && *(PhotonWord + i) < 58)
X            *(PhotonInst + i) = *(PhotonWord + i) - 48;
X        else if (*(PhotonWord + i) > 96 && *(PhotonWord + i) < 119)
X            *(PhotonInst + i) = *(PhotonWord + i) - 87;
X        else *(PhotonInst + i) = 0;
X    }
X}
X
Xvoid SlicerQueue()
X{   Pcells  ce;
X    I32s  size_slice;
X
X    ce = cells + ThisSlice; /* ThisSlice is current cell in queue */
X    if(SizDepSlice)
X        size_slice = (I32s) pow((double) ce->mm.s,(double) SlicePow);
X    else size_slice = SliceSize;
X    TimeSlice(ThisSlice, size_slice);
X    IncrSliceQueue(); /* increment ThisSlice to next cell in queue */
X}
X
Xvoid RanSlicerQueue()
X{   Pcells  ce;
X    I32s  size_slice;
X
X    ce = cells + ThisSlice; /* ThisSlice is current cell in queue */
X    if(SizDepSlice)
X        size_slice = (I32s) pow((double) ce->mm.s,(double) SlicePow);
X    else size_slice = SliceSize;
X    size_slice = (I32s) SlicFixFrac * size_slice +
X        tlrand() % (I32s) ((SlicRanFrac * size_slice) + 1);
X    TimeSlice(ThisSlice, size_slice);
X    IncrSliceQueue(); /* increment ThisSlice to next cell in queue */
X}
END_OF_FILE
if test 2749 -ne `wc -c <'slicers.c'`; then
    echo shar: \"'slicers.c'\" unpacked with wrong size!
fi
# end of 'slicers.c'
fi
if test -f 'soup_in' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'soup_in'\"
else
echo shar: Extracting \"'soup_in'\" \(2668 characters\)
sed "s/^X//" >'soup_in' <<'END_OF_FILE'
Xtierra core: 4-15-91 
X
Xalive = 5            how many millions of instruction will we run
XBrkupSiz = 5120      size of output file in K, named break.1, break.2 ...
XCellsSize = 600       initial size of cells array of structures
Xdebug = 0               0 = off, 1 = on, printf statements for debugging
XDiskOut = 1            output data to disk (1 = on, 0 = off)
XDistFreq = .1       frequency of disturbance, factor of recovery time
XDistProp = .3       proportion of population affected by distrubance
XDivSameSiz = 0 cells must produce offspring of same size, to stop size change
XDivSameGen = 0 cells must produce offspring of same genotype, to stop evolution
XDropDead = 5 stop system if no reproduction in the last x million instructions
XGeneBnker = 1   turn genebanker on and off
XGenebankPath = geneban1/  path for genebanker output
XGenPerBkgMut = 12 mutation rate control by generations ("cosmic ray")
XGenPerFlaw = 16       flaw control by generations
XGenPerMovMut = 8    mutation rate control by generations (copy mutation)
Xhangup = 1            0 = exit on error, 1 = hangup on error for debugging
XMaxFreeBlocks = 500     initial number of structures for memory allocation
XMaxMalMult = 3        multiple of cell size allowed for mal()
XMinCellSize = 8       minimum size for cells
XMinTemplSize = 3       minimum size for templates
XMovPropThrDiv = .7       minimum proportion of daughter cell filled by mov
Xnew_soup = 1          1 = this a new soup, 0 = restarting an old run
XNumCells = 1      number of creatures and gaps used to inoculate new soup
XOutPath = tiedat/  path for data output
XPhotonPow = 1.5         power for photon match slice size
XPhotonWidth = 8   amount by which photons slide to find best fit
XPhotonWord = chlorophill  word used to define photon
XRamBankSiz = 20000 array size for genotypes in ram, use with genebanker
XSaveFreq = 10        frequency of saving core_out, soup_out and list
XSavThrMem = .02  threshold memory occupancy to save genotype
XSavThrPop = .02  threshold population proportion to save genotype
XSearchLimit = 5
Xseed = 0 seed for random number generator, 0 uses time to set seed
XSizDepSlice = 0  set slice size by size of creature
XSlicePow = 1    set power for slice size, use when SizDepSlice = 1
XSliceSize = 25    slice size when SizDepSlice = 0
XSliceStyle = 2   choose style of determining slice size
XSlicFixFrac = 0   fixed fraction of slice size
XSlicRanFrac = 2   random fraction of slice size
XSoupSize = 60000 size of soup in instructions
XWatchExe = 0     mark executed instructions in genome in genebank
XWatchMov = 0     set mov bits in genome in genebank
XWatchTem = 0     set template bits in genome in genebank
X
X0080aaa
END_OF_FILE
if test 2668 -ne `wc -c <'soup_in'`; then
    echo shar: \"'soup_in'\" unpacked with wrong size!
fi
# end of 'soup_in'
fi
if test -f 'soup_in.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'soup_in.h'\"
else
echo shar: Extracting \"'soup_in.h'\" \(4829 characters\)
sed "s/^X//" >'soup_in.h' <<'END_OF_FILE'
X/* soup_in.h  28-10-91  Artificial Life simulator setup routines */
X/** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
X
X#include "license.h"
X
X/*
X#ifndef lint
Xstatic char     sccsid[] = "@(#)soup_in.h	1.4 10/8/91";
X#endif
X*/
X
X#ifndef SOUP_IN_H
X#define SOUP_IN_H
X
XI32s  alive = 100; /* how many millions of instruction will we run */
XI32s  BrkupSiz = 5120; /* size of output file in K: break.1, break.2 ... */
XI32s  CellsSize = 300; /* initial size of cells array of structures */
XI32s  debug = 0; /* 0 = off, 1 = on, printf statements for debugging */
XI32s  DiskOut = 1; /* output data to disk (1 = on, 0 = off) */
Xfloat  DistFreq = 1; /* frequency of disturbance, factor of recovery time */
Xfloat  DistProp = .2; /* proportion of population affected by distrubance */
XI32s  DivSameSiz = 0; /* produce offspring of same size, stop size change */
XI32s  DivSameGen = 0; /* produce offspring of same genotype, stop evolution */
XI32s  DropDead = 5; /* stop system if no reproduction in the last x million */
XI32s  GeneBnker = 1; /* turn genebanker on and off */
XI8s   GenebankPath[80] = "geneban1/"; /* path for genebanker output */
Xfloat GenPerBkgMut = 24.; /* mut rate control by generations ("cosmic ray") */
Xfloat GenPerFlaw = 48.; /* flaw control by generations */
Xfloat GenPerMovMut = 12.;/* mutation rate control by generations (copy mut) */
XI32s  hangup = 1; /* 0 = exit on error, 1 = hangup on error for debugging */
XI32s  MaxFreeBlocks = 500; /* initial # of structure for memory allocation */
Xfloat MaxMalMult = 3; /* multiple of cell size allowed for mal() */
XI32s  MinCellSize = 8; /* minimum size for cells */
XI32s  MinTemplSize = 3; /* minimum size for templates */
Xfloat  MovPropThrDiv = .7; /* min proportion of daughter cell filled by mov */
XI32s  new_soup = 1; /* 1 = this a new soup, 0 = restarting an old run */
XI32s  NumCells = 1; /* # of creatures and gaps used to inoculate new soup */
XI8s   OutPath[80] = "tiedat/"; /*  path for data output */
Xdouble  PhotonPow = 1.5; /* power for photon match slice size */
XI32s  PhotonWidth = 8; /* amount by which photons slide to find best fit */
XI8s   PhotonWord[80] = "chlorophill"; /*  word used to define photon */
XI32s  RamBankSiz = 30000; /* max num genotypes in ram, use with genebanker */
XI32s  SaveFreq = 100; /* frequency of saving core_out, soup_out and list */
Xfloat SavThrMem = .015; /* threshold memory occupancy to save genotype */
Xfloat SavThrPop = .015; /* threshold population proportion to save genotype */
XInd   SearchLimit = 5; /* */
XI32s  seed = 0;/* seed for random number generator, 0 uses time to set seed */
XI32s  SizDepSlice = 1; /* set slice size by size of creature */
Xdouble  SlicePow = 1; /* set power for slice size, use when SizDepSlice = 1 */
XI32s  SliceSize = 25; /* slice size when SizDepSlice = 0 */
XI32s  SliceStyle = 2; /* choose style of determining slice size */
Xfloat  SlicFixFrac = 0; /* fixed fraction of slice size */
Xfloat  SlicRanFrac = 2; /* random fraction of slice size */
XInd   SoupSize = 40000; /* size of soup in instructions */
XI32s  WatchExe = 0; /* mark executed instructions in genome in genebank */
XI32s  WatchMov = 0; /* set mov bits in genome in genebank */
XI32s  WatchTem = 0; /* set template bits in genome in genebank */
X
X/* an edited version of the id[INSTNUM] array must be created and placed in
X   the arginst.h file, for use by the assembler/disassembler of arg.c */
X
X#if INST == 1
X
Xstruct InstDef  id[INSTNUM] =
X    {{ 0x00, "nop_0",   nop,    pnop },
X     { 0x01, "nop_1",   nop,    pnop },
X     { 0x02, "or1",     or1,    por1 },
X     { 0x03, "shl",     shl,    pshl },
X     { 0x04, "zero",    movdd,  pzero },
X     { 0x05, "if_cz",   if_cz,  pif_cz },
X     { 0x06, "sub_ab",  math,   psub_ab },
X     { 0x07, "sub_ac",  math,   psub_ac },
X     { 0x08, "inc_a",   math,   pinc_a },
X     { 0x09, "inc_b",   math,   pinc_b },
X     { 0x0a, "dec_c",   math,   pdec_c },
X     { 0x0b, "inc_c",   math,   pinc_c },
X     { 0x0c, "push_ax", push,   ppush_ax },
X     { 0x0d, "push_bx", push,   ppush_bx },
X     { 0x0e, "push_cx", push,   ppush_cx },
X     { 0x0f, "push_dx", push,   ppush_dx },
X     { 0x10, "pop_ax",  pop,    ppop_ax },
X     { 0x11, "pop_bx",  pop,    ppop_bx },
X     { 0x12, "pop_cx",  pop,    ppop_cx },
X     { 0x13, "pop_dx",  pop,    ppop_dx },
X     { 0x14, "jmp",     adr,    ptjmp },
X     { 0x15, "jmpb",    adr,    ptjmpb },
X     { 0x16, "call",    tcall,  ptcall },
X     { 0x17, "ret",     pop,    pret },
X     { 0x18, "mov_cd",  movdd,  pmov_dc },
X     { 0x19, "mov_ab",  movdd,  pmov_ba },
X     { 0x1a, "mov_iab", movii,  pmov_iab },
X     { 0x1b, "adr",     adr,    padr },
X     { 0x1c, "adrb",    adr,    padrb },
X     { 0x1d, "adrf",    adr,    padrf },
X     { 0x1e, "mal",     malchm, pmal },
X     { 0x1f, "divide",  divide, pdivide }};
X
X#endif /* INST == 1 */
X
X#endif
END_OF_FILE
if test 4829 -ne `wc -c <'soup_in.h'`; then
    echo shar: \"'soup_in.h'\" unpacked with wrong size!
fi
# end of 'soup_in.h'
fi
if test -f 'trand.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'trand.c'\"
else
echo shar: Extracting \"'trand.c'\" \(2701 characters\)
sed "s/^X//" >'trand.c' <<'END_OF_FILE'
X/* trand.c  19-8-91  adapted from ``Numerical Recipes in C'' by Press,
XFlannery, Teukolsky and Vetterling.  Tdrand() returns a uniform random deviate
Xbetween 0.0 and 1.0.  Tlrand() returns a uniform random deviate between 0 and
X2^31 */
X
X#ifndef lint
Xstatic char     sccsid[] = "%W%     %G%";
X#endif
X
X#include "tierra.h"
X#include "extern.h"
X
XI32s tlrand() /* returns random 32 bit positive signed integer */
X{   return (I32s) (tdrand() * (double) LONG_MAX);
X}
X
XI16s tirand() /* returns random 16 bit positive signed integer */
X{   return (I16s) (tdrand() * (double) INT_MAX);
X}
X
XI16u tuirand() /* returns random 16 bit unsigned integer */
X{   return (I16u) (tdrand() * (double) UINT_MAX);
X}
X
XI8s tcrand() /* returns random 8 bit positive signed integer */
X{   return (I8s) (tdrand() * (double) CHAR_MAX);
X}
X
XI8u tucrand() /* returns random 8 bit unsigned integer */
X{   return (I8u) (tdrand() * (double) UCHAR_MAX);
X}
X
X#define M1 259200L
X#define IA1 7141L
X#define IC1 54773L
X#define RM1 (1.0/M1)
X#define M2 134456L
X#define IA2 8121L
X#define IC2 28411L
X#define RM2 (1.0/M2)
X#define M3 243000L
X#define IA3 4561L
X#define IC3 51349L
X
Xvoid tsrand(seed)
XI32s  seed;
X{   I16s  j;
X
X    RandIx1 = (IC1 + seed) % M1;       /* Seed the first routine */
X    RandIx1 = (IA1 * RandIx1 + IC1) % M1;
X    RandIx2 = RandIx1 % M2;            /* and use it to seed the second */
X    RandIx1 = (IA1 * RandIx1 + IC1) % M1;
X    RandIx3 = RandIx1 % M3;            /* and third routines. */
X    for (j = 1; j <= 97; j++)    /* Fill the table with sequential uniform */
X    {   RandIx1 = (IA1 * RandIx1 + IC1) % M1; /* deviates generated by the */
X        RandIx2 = (IA2 * RandIx2 + IC2) % M2; /* first two routines. */
X        TrandArray[j] = (RandIx1 + RandIx2 * RM2) * RM1;
X    }                    /* Low- & high-order pieces combined here */
X}
X
Xdouble tdrand()
X{   double temp;
X    I16s j;
X
X    RandIx1 = (IA1 * RandIx1 + IC1) % M1;
X                             /* Except when initializing, this is where we */
X    RandIx2 = (IA2 * RandIx2 + IC2) % M2;
X                             /* start.  Generate the next number for each */
X    RandIx3 = (IA3 * RandIx3 + IC3) % M3;                  /* sequence. */
X    j = 1 + ((97 * RandIx3) / M3);
X                       /* Use the third sequence to get an integer between */
X    if (j > 97 || j < 1) /* 1 and 97 */
X    {   sprintf(mes[0],"RAN1: This cannot happen.");
X        FEMessage(1);
X    }
X    temp = TrandArray[j];               /* Return that table entry, */
X    TrandArray[j] = (RandIx1 + RandIx2 * RM2) * RM1;  /* and refill it. */
X    return temp;
X}
X
X#undef M1
X#undef IA1
X#undef IC1
X#undef RM1
X#undef M2
X#undef IA2
X#undef IC2
X#undef RM2
X#undef M3
X#undef IA3
X#undef IC3
END_OF_FILE
if test 2701 -ne `wc -c <'trand.c'`; then
    echo shar: \"'trand.c'\" unpacked with wrong size!
fi
# end of 'trand.c'
fi
echo shar: End of archive 3 \(of 7\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 5 6 7 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 7 archives.
    echo "Please see the README file(s) 
    for detailed instructions"
    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
