Skip to content

Instantly share code, notes, and snippets.

@andrewrcollins
Created January 4, 2012 16:29
Show Gist options
  • Save andrewrcollins/1560814 to your computer and use it in GitHub Desktop.
Save andrewrcollins/1560814 to your computer and use it in GitHub Desktop.
#TJHSST ~ Wire World and WETH
/*
Wires, Electron Tails, and Heads.
W.E.T.H.
A cellular automaton written in response to an article
in the Computer Recreation section of Scientific American.
Cellular automatons are rule based systems which include
the now famous game of LIFE, and its ancestors.
In WETH there are four different types of cells.
Electron Head
Electron Tail
Wire
Empty
When updating the automaton certain rules govern what
happens.
1. An Empty cell will stay an Empty cell.
2. A Wire cell will turn into an Electron Head cell if
it has more than zero(0) Electron Head cells within one
space of it, including diagonals, and less than three(3)
Electron Head cells adjacent to it.
3. An Electron Head cell will turn into an Electron Tail
cell after one time step.
4. An Electron Tail cell will turn into a Wire cell after
one time step.
From this simple list of rules one might expect this automaton
to be rather useless, but to the sharp mind one can see that this
is a rule that will play a major role in how the system works.
Here are some examples of interesting structures.
Test them out by running the .EXEcutable file called WETH.EXE
and entering them in.
E -> Electron Head cell
T -> Electron Tail cell
W -> Wire Cell
-> Empty Cell
WW This is a 'Diode'. The structure will let this Electron
EWWW WWWW flow through, but if an Electron Head cell is placed on
WW the other end it won't pass through because of Rule #2.
ET This is a the simplest 'Battery', that I have come up with.
W WWW The idea is that the Electron Head circles around the
triangle formed by the ETW combination.
WWWWWE
W W By sending this Electron Head cell through the structure
WW W it will become a 'Battery'. Once again because of Rule #2
WWWW this circuit works.
WW
If you are able to find other structures that seem amusing or just
weird write me a letter, or send a message to me on any Greater
Washington D.C(202) or Northern Virginia(703) Bulletin Boards.
Written by Andy Collins on September 13, 1990.
*/
#include <stdio.h> /* STanDard Input Output */
#include <conio.h> /* CONsole Input Output */
/*#include <mouse.h>*/
/* Header file mouse functions and procedures. */
#define Empty 0
#define Head 1
#define Tail 2
#define Wire 3
#define Maxx 20
#define Maxy 10
#define Maxz 2
#define MaxNeighbors 3
#define EmptyChr (char)250
#define EmptyCol (LIGHTGRAY | BLACK * 16)
#define HeadChr (char)219
#define HeadCol (LIGHTRED | BLACK * 16)
#define TailChr (char)176
#define TailCol (RED | BLACK * 16)
#define WireChr (char)197
#define WireCol (LIGHTGREEN | BLACK * 16)
typedef int Cell;
Cell CellArray[Maxz][Maxy][Maxx];
int Old=0,New=1;
main()
{
int cellx,celly;
setall(CellArray,Empty);
for(celly=0;celly<Maxx;celly++) {
set(CellArray,1,celly,Wire);
set(CellArray,2,celly,Wire);
set(CellArray,celly,1,Wire);
set(CellArray,celly,2,Wire);
}
set(CellArray,3,3,Head);
while(!kbhit()) {
process(CellArray);
display(CellArray);
}
}
int set(array,celly,cellx,value)
Cell array[Maxz][Maxy][Maxx];
int celly,cellx;
Cell value;
{
if((celly>-1)&&(celly<Maxy)&&(cellx>-1)&&(cellx<Maxx)) {
array[Old][celly][cellx]=value;
array[New][celly][cellx]=value;
}
else return 0;
return 1;
}
int setall(array,value)
Cell array[Maxz][Maxy][Maxx];
Cell value;
{
int cellx,celly;
for(celly=0;celly<Maxy;celly++)
for(cellx=0;cellx<Maxx;cellx++) {
array[New][celly][cellx]=value;
array[Old][celly][cellx]=value;
}
return 1;
}
int getneighbor(array,celly,cellx)
Cell array[Maxz][Maxy][Maxx];
int celly,cellx;
{
int cnt=0,tmpx,tmpy;
for(tmpy=(-1);tmpy<2;tmpy++)
for(tmpx=(-1);tmpx<2;tmpx++)
if(((tmpy+celly)>-1)&&((tmpy+celly)<Maxy)&&
((tmpx+cellx)>-1)&&((tmpx+cellx)<Maxx))
if(array[Old][celly+tmpy][cellx+tmpx]==Head)
cnt++;
return cnt;
}
int process(array)
Cell array[Maxz][Maxy][Maxx];
{
int cellx,celly,neighbors;
for(celly=0;celly<Maxy;celly++)
for(cellx=0;cellx<Maxx;cellx++) {
switch(array[Old][celly][cellx]) {
case Head :
array[New][celly][cellx]=Tail;
break;
case Tail :
array[New][celly][cellx]=Wire;
break;
case Wire :
neighbors=getneighbor(array,celly,cellx);
if((neighbors<MaxNeighbors)&&(neighbors>0))
array[New][celly][cellx]=Head;
else
array[New][celly][cellx]=Wire;
break;
case Empty :
array[New][celly][cellx]=Empty;
break;
}
}
Old=!Old;
New=!New;
return 1;
}
int display(array)
Cell array[Maxz][Maxy][Maxx];
{
int cellx,celly;
for(celly=0;celly<Maxy;celly++) {
gotoxy(1,celly+1);
for(cellx=0;cellx<Maxx;cellx++) {
switch(array[New][celly][cellx]) {
case Head :
textattr(HeadCol);
putch(HeadChr);
break;
case Tail :
textattr(TailCol);
putch(TailChr);
break;
case Wire :
textattr(WireCol);
putch(WireChr);
break;
case Empty :
textattr(EmptyCol);
putch(EmptyChr);
break;
}
}
}
}
/*
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
Wire World
Reading in the data file.
Started November 28 (?),1991
Most work done on December 3,1991
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* The states used in Wire World. */
#define WIRE 0
#define HEAD 1
#define NOTHEAD 2
#define TAIL 3
#define EMPTY 4
#define MAXSTATE 5
/* Options/Informative constants. */
#define DATA 0
#define START 1
#define STOP 2
#define SIZEX 3
#define SIZEY 4
#define NAME 5
#define REM 6
#define MAXOTHER 7
/* The strings which correspond to the constants above. */
char *states[] = { "WIRE","HEAD","NOTHEAD","TAIL","EMPTY" };
char *other[] = { "DATA","START","STOP","SIZEX","SIZEY","NAME","REM" };
/* Misc. */
#define TRUE 1
#define FALSE 0
#define SIZEXY 6
#define DATASTOP 7
#define NAMEEND 8
/* A sample data file.
Cut this out into some other file, and then run this program on it.
REM Nobody cares what we put here, it doesn't matter.
REM This is a REMark block
NAME DIODERL
REM NAME is the identifier which mean the next field is this
REM gate's name.
SIZEX 4
SIZEY 3
REM The above two must appear together, but not in this order,
REM you could go SIZEY then SIZEX
START
REM START means now we're getting busy.
DATA 1 1 WIRE
DATA 2 2 WIRE
DATA 3 3 WIRE
DATA 4 3 WIRE
DATA 3 2 WIRE
REM All the DATA entries are used to place states into the
REM array that is SIZEXxSIZEY.
STOP
REM STOP means we is done with this gate.
NAME AND
SIZEX 5
SIZEY 5
START
DATA 1 1 WIRE
DATA 2 2 WIRE
DATA 4 3 WIRE
DATA 5 5 WIRE
STOP
*/
/* Basic data type used to store a gate. */
struct gatetype {
/* name is the gate's name, "NOT", "AND", "NOR", etc. */
char *name;
/* data is a pointer to the allocated array used to store the
gate's structure. sizex and sizey are the dimensions of the
arrray data points to. */
int *data,sizex,sizey;
};
/* Function prototypes. */
int loadgates(struct gatetype *,int *),displaygate(struct gatetype *);
main()
{
struct gatetype *gatelist=NULL;
int gatecnt=0,cnt;
loadgates(gatelist,&gatecnt);
for(cnt=0;cnt<gatecnt;cnt++) {
printf("GateID : %-4d\n",cnt);
displaygate((gatelist+cnt*sizeof(struct gatetype)));
}
}
/* The idea is that we read in a data file which lists all the
gates we have defined so far. An allocated array is passed by
via gatelist, the number of gates actually read in from the
file is returned in gatecnt. */
int loadgates(gatelist,gatecnt)
struct gatetype *gatelist;
int *gatecnt;
{
FILE *datafile;
char oneline[80],*option,*data;
int fieldcnt,expect,endofdata,state,ystate,xstate;
struct gatetype gate;
/* Read in the data file's name. */
printf("Enter data file name\n-> ");
scanf("%s",oneline);
/* Open the data file for reading or exit on error. */
datafile=fopen(oneline,"r");
if(datafile==NULL) {
fprintf(stderr,"error opening data file\n");
exit(1);
}
/* Begin reading in data file one line at a time. */
endofdata=feof(datafile);
/* Our original expectations of what we will first see. */
expect=NAMEEND;
while(endofdata==FALSE) {
/* Read in one line of the data file. */
fgets(oneline,80,datafile);
/* Break input into component string tokens using strtok.
First grab out the option identifier, this should be
one of the strings in the other array. */
option=strtok(oneline," \t\n");
/* Now find out which option this is. */
for(fieldcnt=0;fieldcnt<MAXOTHER;fieldcnt++)
if(stricmp(option,other[fieldcnt])==0)
break;
/* Now we know we have to see which option we are looking at. */
switch(fieldcnt) {
case NAME :
/* If we weren't expecting to be here we shouldn't be here. */
if(expect!=NAMEEND) {
fprintf(stderr,"error in data file\n");
exit(1);
}
/* Now we can expect to see a gate being defined. Initialize the
gate's values. */
gate.data=NULL;
gate.sizex=0;
gate.sizey=0;
/* Read in the next field, the name field, and duplicate this into
the gate's name variable. */
data=strtok(NULL," \t\n");
gate.name=strdup(data);
/* From here we should now expect to see either a SIZEX or a SIZEY
option field, if we don't there will be trouble. */
expect=SIZEXY;
break;
case START :
if(expect!=START) {
fprintf(stderr,"error in data file\n");
exit(1);
}
/* We now have what we need, allocate the space for the data array. */
gate.data=(int *)malloc(sizeof(int)*gate.sizex*gate.sizey);
/* Now clear out this new data array, fill it with EMPTYs. */
for(ystate=0;ystate<gate.sizey;ystate++)
for(xstate=0;xstate<gate.sizex;xstate++)
*(gate.data+ystate*gate.sizex+xstate)=EMPTY;
expect=DATASTOP;
break;
case STOP :
if(expect!=DATASTOP) {
fprintf(stderr,"error in data file\n");
exit(1);
}
/* Now we know we can start closing up shop, which includes adding
the ust created gate to the list of gates, and incrementing the
gatecnt. */
displaygate(&gate);
free(gate.data);
/*---------> <-------------*/
expect=NAMEEND;
break;
case SIZEX :
if(expect!=SIZEX&&expect!=SIZEXY) {
fprintf(stderr,"error in data file\n");
exit(1);
}
data=strtok(NULL," \t\n");
gate.sizex=atoi(data);
if(expect==SIZEXY)
expect=SIZEY;
else
expect=START;
break;
case SIZEY :
if(expect!=SIZEY&&expect!=SIZEXY) {
fprintf(stderr,"error in data file\n");
exit(1);
}
data=strtok(NULL," \t\n");
gate.sizey=atoi(data);
if(expect==SIZEXY)
expect=SIZEX;
else
expect=START;
break;
case DATA :
if(expect!=DATASTOP) {
fprintf(stderr,"error in data file\n");
exit(1);
}
/* ----------> <------- Add error checking */
data=strtok(NULL," \t\n");
xstate=atoi(data)-1;
data=strtok(NULL," \t\n");
ystate=atoi(data)-1;
data=strtok(NULL," \t\n");
/* Search for the corresponding state value. */
for(state=0;state<MAXSTATE;state++)
if(stricmp(data,states[state])==0)
break;
if(state==MAXSTATE) {
fprintf(stderr,"error in data file\n");
exit(1);
}
/* Now place this new state into the data array. */
*(gate.data+ystate*gate.sizex+xstate)=state;
/* --------------> <------------ */
expect=DATASTOP;
break;
case REM :
/* Disregard remarks. */
break;
case MAXOTHER :
/* If indeed fieldcnt is equal to MAXOTHER than the option we were
trying to corelate with our list is not even in our list of options. */
fprintf(stderr,"unknown option\n");
exit(1);
break;
}
endofdata=feof(datafile);
}
fclose(datafile);
}
int displaygate(gate)
struct gatetype *gate;
{
int cntx,cnty;
char *line;
if(gate!=NULL) {
line=(char *)malloc(sizeof(char)*gate->sizex+1);
line[gate->sizex]=0;
memset(line,(int)'-',gate->sizex);
printf("NAME : %-15s SIZEX : %-3d SIZEY : %-3d\n",
gate->name,gate->sizex,gate->sizey);
puts(line);
for(cnty=0;cnty<gate->sizey;cnty++) {
for(cntx=0;cntx<gate->sizex;cntx++)
putchar((*(gate->data+cnty*gate->sizex+cntx)==EMPTY) ? '.' : '#');
puts("");
}
puts(line);
free(line);
return 0;
}
return 1;
}
/* head, tail, and wire game. */
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <mouse.h>
/* ?????C is character value for ????? */
/* A '@' means that it is not in the ACSII standard characters (32..127) */
/* A '$' means that the character is a control character (0..31) */
/* Color constants found in conio.h, ?????A is attribute value for ????? */
/* This program will work on IBM and compatibles that have extended ASCII */
#define NONE 0
#define NONEC 250 /* ASCII value for the display character ( @ ) */
#define NONEA LIGHTGRAY
#define HEAD 1
#define HEADC 219 /* ASCII value for the display character ( @ ) */
#define HEADA LIGHTRED
#define TAIL 2
#define TAILC 178 /* ASCII value for the display character ( @ ) */
#define TAILA YELLOW
#define WIRE 3
#define WIREC 254 /* ASCII value for the display character ( @ ) */
#define WIREA CYAN
#define SOURCE 4
#define SOURCEC 83 /* ASCII value for the display character ('S') */
#define SOURCEA LIGHTGREEN
#define DIODEA LIGHTMAGENTA
#define LEFT 5
#define LEFTC 17 /* ASCII value for the display character ( $ ) */
#define RIGHT 6
#define RIGHTC 16 /* ASCII value for the display character ( $ ) */
#define UP 7
#define UPC 30 /* ASCII value for the display character ( $ ) */
#define DOWN 8
#define DOWNC 31 /* ASCII value for the display character ( $ ) */
#define DIODEHA RED
#define LEFTH LEFT + (HEAD * 8)
#define RIGHTH RIGHT + (HEAD * 8)
#define UPH UP + (HEAD * 8)
#define DOWNH DOWN + (HEAD * 8)
#define DIODETA DARKGRAY
#define LEFTT LEFT + (TAIL * 8)
#define RIGHTT RIGHT + (TAIL * 8)
#define UPT UP + (TAIL * 8)
#define DOWNT DOWN + (TAIL * 8)
#define NOTA YELLOW
#define UPNOT 9
#define UPNOTC 94 /* ASCII value for the display character ('^') */
#define DOWNNOT 10
#define DOWNNOTC 86 /* ASCII value for the display character ('V') */
#define LEFTNOT 11
#define LEFTNOTC 60 /* ASCII value for the display character ('<') */
#define RIGHTNOT 12
#define RIGHTNOTC 62 /* ASCII value for the display character ('>') */
#define NOTHA BROWN
#define UPNOTH UPNOT + (HEAD * 8)
#define DOWNNOTH DOWNNOT + (HEAD * 8)
#define LEFTNOTH LEFTNOT + (HEAD * 8)
#define RIGHTNOTH RIGHTNOT + (HEAD * 8)
#define NOTTA YELLOW + (BROWN * 16)
#define UPNOTT UPNOT + (TAIL * 8)
#define DOWNNOTT DOWNNOT + (TAIL * 8)
#define LEFTNOTT LEFTNOT + (TAIL * 8)
#define RIGHTNOTT RIGHTNOT + (TAIL * 8)
#define YSIZE 10 /* Specify the Y array size */
#define XSIZE 30 /* Specify the X array size */
int init(),neighbor(),process(),display();
int gd[2][XSIZE][YSIZE],gdx,gdy,curr=0;
int Qx=70,Qy=15,go=0,cell=1,Cx=10,Cy=17;
main()
{
int tmx,tmy;
show();
killcurs();
clrscr();
hide();
gotoxy(Qx,Qy);
putch('Q');
gotoxy(Cx,Cy);
textcolor(NONEA);
putch((char)NONEC);
textcolor(HEADA);
putch((char)HEADC);
textcolor(TAILA);
putch((char)TAILC);
textcolor(WIREA);
putch((char)WIREC);
textcolor(SOURCEA);
putch((char)SOURCEC);
textcolor(DIODEA);
putch((char)LEFTC);
putch((char)RIGHTC);
putch((char)UPC);
putch((char)DOWNC);
textcolor(NOTA);
putch((char)UPNOTC);
putch((char)DOWNNOTC);
putch((char)LEFTNOTC);
putch((char)RIGHTNOTC);
show();
init();
while(chkquit()) {
tmx=mousex()-1;
tmy=mousey()-1;
switch(mouseb()) {
case 7 :
init();
break;
case 4 :
if((tmx<=XSIZE)&&(tmy<=YSIZE)) {
gd[curr][tmx][tmy]=cell;
gd[!curr][tmx][tmy]=cell;
display();
}
break;
case 1 :
go=1;
break;
case 2 :
go=0;
break;
}
if(go) {
process();
display();
}
}
hide();
findcurs();
clrscr();
}
int init(void)
{
for(gdx=0;gdx<XSIZE;gdx++)
for(gdy=0;gdy<YSIZE;gdy++) {
gd[curr][gdx][gdy]=NONE;
gd[!curr][gdx][gdy]=NONE;
}
}
int neighbor(x,y)
int x,y;
{
int tx,ty,cnt;
cnt=0;
for(tx=-1;tx<2;tx++)
for(ty=-1;ty<2;ty++) {
if(((tx+x)>=0)&&((tx+x)<XSIZE)&&((ty+y)>=0)&&((ty+y)<YSIZE)) {
if((gd[curr][tx+x][ty+y]==HEAD)||(gd[curr][tx+x][ty+y]==SOURCE))
cnt++;
}
}
for(tx=-1;tx<2;tx++)
if(((tx+x)>=0)&&((tx+x)<XSIZE)&&((y+1)<YSIZE)&&((y-1)>=0)) {
if(gd[curr][tx+x][y+1]==UPH)
cnt++;
if(gd[curr][tx+x][y-1]==DOWNH)
cnt++;
if(gd[curr][tx+x][y+1]==UPNOTH)
cnt++;
if(gd[curr][tx+x][y-1]==DOWNNOTH)
cnt++;
}
for(ty=-1;ty<2;ty++)
if(((ty+y)>=0)&&((ty+y)<YSIZE)&&((x+1)<XSIZE)&&((x-1)>=0)) {
if(gd[curr][x-1][ty+y]==RIGHTH)
cnt++;
if(gd[curr][x+1][ty+y]==LEFTH)
cnt++;
if(gd[curr][x-1][ty+y]==RIGHTNOTH)
cnt++;
if(gd[curr][x+1][ty+y]==LEFTNOTH)
cnt++;
}
return cnt;
}
int neighbors(x,y,diode)
int x,y,diode;
{
int tx,ty,cnt,direction;
cnt=0;
switch(diode) {
case UP :
case UPNOT :
case LEFT :
case LEFTNOT :
direction=1;
break;
case DOWN :
case DOWNNOT :
case RIGHT :
case RIGHTNOT :
direction=-1;
break;
}
switch(diode) {
case UP :
case DOWN :
case UPNOT :
case DOWNNOT :
for(tx=-1;tx<2;tx++)
if(((tx+x)>=0)&&((tx+x)<XSIZE)&&((y+direction)<YSIZE)) {
if((gd[curr][tx+x][y+direction]==HEAD)||
(gd[curr][tx+x][y+direction]==SOURCE)||
((gd[curr][tx+x][y+direction]>=LEFTH)&&
(gd[curr][tx+x][y+direction]<=DOWNH)))
cnt++;
}
break;
case LEFT :
case RIGHT :
case LEFTNOT :
case RIGHTNOT :
for(ty=-1;ty<2;ty++)
if(((ty+y)>=0)&&((ty+y)<YSIZE)&&((x+direction)<XSIZE)) {
if((gd[curr][x+direction][ty+y]==HEAD)||
(gd[curr][x+direction][ty+y]==SOURCE)||
((gd[curr][tx+x][y+direction]>=LEFTH)&&
(gd[curr][tx+x][y+direction]<=DOWNH)))
cnt++;
}
break;
}
return cnt;
}
int process(void)
{
int tmp,rx,ry,ex,ey;
tmp=0;
for(gdx=0;gdx<XSIZE;gdx++) {
for(gdy=0;gdy<YSIZE;gdy++) {
switch(gd[curr][gdx][gdy]) {
case WIRE :
tmp=neighbor(gdx,gdy);
if((tmp>0)&&(tmp<3)) gd[!curr][gdx][gdy]=HEAD;
else gd[!curr][gdx][gdy]=WIRE;
break;
case HEAD :
gd[!curr][gdx][gdy]=TAIL;
break;
case TAIL :
gd[!curr][gdx][gdy]=WIRE;
break;
case UP :
tmp=neighbors(gdx,gdy,UP);
if((tmp>0)&&(tmp<3)) gd[!curr][gdx][gdy]=UPH;
else gd[!curr][gdx][gdy]=UP;
break;
case DOWN :
tmp=neighbors(gdx,gdy,DOWN);
if((tmp>0)&&(tmp<3)) gd[!curr][gdx][gdy]=DOWNH;
else gd[!curr][gdx][gdy]=DOWN;
break;
case LEFT :
tmp=neighbors(gdx,gdy,LEFT);
if((tmp>0)&&(tmp<3)) gd[!curr][gdx][gdy]=LEFTH;
else gd[!curr][gdx][gdy]=LEFT;
break;
case RIGHT :
tmp=neighbors(gdx,gdy,RIGHT);
if((tmp>0)&&(tmp<3)) gd[!curr][gdx][gdy]=RIGHTH;
else gd[!curr][gdx][gdy]=RIGHT;
break;
case UPH :
gd[!curr][gdx][gdy]=UPT;
break;
case DOWNH :
gd[!curr][gdx][gdy]=DOWNT;
break;
case LEFTH :
gd[!curr][gdx][gdy]=LEFTT;
break;
case RIGHTH :
gd[!curr][gdx][gdy]=RIGHTT;
break;
case UPT :
gd[!curr][gdx][gdy]=UP;
break;
case DOWNT :
gd[!curr][gdx][gdy]=DOWN;
break;
case LEFTT :
gd[!curr][gdx][gdy]=LEFT;
break;
case RIGHTT :
gd[!curr][gdx][gdy]=RIGHT;
break;
case UPNOT :
tmp=neighbors(gdx,gdy,UPNOT);
if((tmp==0)||(tmp>=3)) gd[!curr][gdx][gdy]=UPNOTH;
else gd[!curr][gdx][gdy]=UPNOT;
break;
case DOWNNOT :
tmp=neighbors(gdx,gdy,DOWNNOT);
if((tmp==0)||(tmp>=3)) gd[!curr][gdx][gdy]=DOWNNOTH;
else gd[!curr][gdx][gdy]=DOWNNOT;
break;
case LEFTNOT :
tmp=neighbors(gdx,gdy,LEFTNOT);
if((tmp==0)||(tmp>=3)) gd[!curr][gdx][gdy]=LEFTNOTH;
else gd[!curr][gdx][gdy]=LEFTNOT;
break;
case RIGHTNOT :
tmp=neighbors(gdx,gdy,RIGHTNOT);
if((tmp==0)||(tmp>=3)) gd[!curr][gdx][gdy]=RIGHTNOTH;
else gd[!curr][gdx][gdy]=RIGHTNOT;
break;
case UPNOTH :
tmp=neighbors(gdx,gdy,UPNOT);
if((tmp==0)||(tmp>=3)) gd[!curr][gdx][gdy]=UPNOTH;
else gd[!curr][gdx][gdy]=UPNOT;
break;
case DOWNNOTH :
tmp=neighbors(gdx,gdy,DOWNNOT);
if((tmp==0)||(tmp>=3)) gd[!curr][gdx][gdy]=DOWNNOTH;
else gd[!curr][gdx][gdy]=DOWNNOT;
break;
case LEFTNOTH :
tmp=neighbors(gdx,gdy,LEFTNOT);
if((tmp==0)||(tmp>=3)) gd[!curr][gdx][gdy]=LEFTNOTH;
else gd[!curr][gdx][gdy]=LEFTNOT;
break;
case RIGHTNOTH :
tmp=neighbors(gdx,gdy,RIGHTNOT);
if((tmp==0)||(tmp>=3)) gd[!curr][gdx][gdy]=RIGHTNOTH;
else gd[!curr][gdx][gdy]=RIGHTNOT;
break;
case UPNOTT :
tmp=neighbors(gdx,gdy,UPNOT);
if((tmp==0)||(tmp>=3)) gd[!curr][gdx][gdy]=UPNOTH;
else gd[!curr][gdx][gdy]=UPNOT;
break;
case DOWNNOTT :
tmp=neighbors(gdx,gdy,DOWNNOT);
if((tmp==0)||(tmp>=3)) gd[!curr][gdx][gdy]=DOWNNOTH;
else gd[!curr][gdx][gdy]=DOWNNOT;
break;
case LEFTNOTT :
tmp=neighbors(gdx,gdy,LEFTNOT);
if((tmp==0)||(tmp>=3)) gd[!curr][gdx][gdy]=LEFTNOTH;
else gd[!curr][gdx][gdy]=LEFTNOT;
break;
case RIGHTNOTT :
tmp=neighbors(gdx,gdy,RIGHTNOT);
if((tmp==0)||(tmp>=3)) gd[!curr][gdx][gdy]=RIGHTNOTH;
else gd[!curr][gdx][gdy]=RIGHTNOT;
break;
}
}
}
curr=!curr;
}
int display(void)
{
hide();
gotoxy(1,1);
for(gdy=0;gdy<YSIZE;gdy++) {
for(gdx=0;gdx<XSIZE;gdx++) {
switch(gd[curr][gdx][gdy]) {
case NONE :
textcolor(NONEA);
putch((char)NONEC);
break;
case HEAD :
textcolor(HEADA);
putch((char)HEADC);
break;
case TAIL :
textcolor(TAILA);
putch((char)TAILC);
break;
case WIRE :
textcolor(WIREA);
putch((char)WIREC);
break;
case SOURCE :
textcolor(SOURCEA);
putch((char)SOURCEC);
break;
case UP :
textcolor(DIODEA);
putch((char)UPC);
break;
case DOWN :
textcolor(DIODEA);
putch((char)DOWNC);
break;
case LEFT :
textcolor(DIODEA);
putch((char)LEFTC);
break;
case RIGHT :
textcolor(DIODEA);
putch((char)RIGHTC);
break;
case UPH :
textcolor(DIODEHA);
putch((char)UPC);
break;
case DOWNH :
textcolor(DIODEHA);
putch((char)DOWNC);
break;
case LEFTH :
textcolor(DIODEHA);
putch((char)LEFTC);
break;
case RIGHTH :
textcolor(DIODEHA);
putch((char)RIGHTC);
break;
case UPT :
textcolor(DIODETA);
putch((char)UPC);
break;
case DOWNT :
textcolor(DIODETA);
putch((char)DOWNC);
break;
case LEFTT :
textcolor(DIODETA);
putch((char)LEFTC);
break;
case RIGHTT :
textcolor(DIODETA);
putch((char)RIGHTC);
break;
case UPNOT :
textcolor(NOTA);
putch((char)UPNOTC);
break;
case DOWNNOT :
textcolor(NOTA);
putch((char)DOWNNOTC);
break;
case LEFTNOT :
textcolor(NOTA);
putch((char)LEFTNOTC);
break;
case RIGHTNOT :
textcolor(NOTA);
putch((char)RIGHTNOTC);
break;
case UPNOTH :
textcolor(NOTHA);
putch((char)UPNOTC);
break;
case DOWNNOTH :
textcolor(NOTHA);
putch((char)DOWNNOTC);
break;
case LEFTNOTH :
textcolor(NOTHA);
putch((char)LEFTNOTC);
break;
case RIGHTNOTH :
textcolor(NOTHA);
putch((char)RIGHTNOTC);
break;
case UPNOTT :
textcolor(NOTTA);
putch((char)UPNOTC);
break;
case DOWNNOTT :
textcolor(NOTTA);
putch((char)DOWNNOTC);
break;
case LEFTNOTT :
textcolor(NOTTA);
putch((char)LEFTNOTC);
break;
case RIGHTNOTT :
textcolor(NOTTA);
putch((char)RIGHTNOTC);
break;
}
}
printf("\n");
}
show();
}
int chkquit(void)
{
int tmpx,tmpy;
tmpx=mousex();
tmpy=mousey();
if(mouseb()==3) {
if((tmpx==Qx)&&(tmpy==Qy)) return 0;
}
if((mouseb()==4)&&(tmpy==Cy)&&(tmpx>=Cx)&&(tmpx<=(Cx+13))) {
cell=(tmpx-Cx);
}
return 1;
}
@andrewrcollins
Copy link
Author

These are two C programs found on old 5.25 floppy disks from when I was a huge nerd at Thomas Jefferson High School for Science and Technology in the computer systems lab between 1988 and 1992.

Anyone can do whatever they'd like to with them--if anything.

And, yes, I am still a huge nerd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment