This is Traffic.m in view mode; [Download] [Up]
#include <macro.h>
#include <vn.h>
#define source 0
#define car 1
#define stoplight 2
#define light 3
#import "Creature.h"
@implementation Rule:Creature
{
int time;
int speed;
}
-init
{
(time=(0 - 1)); (speed=1);
return self;
}
-step:nextgeneration n:(int *)neighbours g:graveyard
{
if( 1==1 ) { (time=(time + 1));}
if( ( type==source ) ) { if( ((time % 10) ==0) ) { BIRTH( car );}
if( 1==1 ) { CENTER;}
}
if( ( type==car ) ) { if( (speed ==1) ) { if( CANSEE( stoplight ) ) { BIRTH( stoplight ); (speed=0); CENTER;}
else { EAST; }
}
if( (speed ==0) ) { if( 1==1 ) { BIRTH( stoplight );}
if( (CANSEE( stoplight ) >1) ) { CENTER;}
else { (speed=1); EAST; }
}
}
if( ( type==light ) ) { if( (time ==29) ) { (time=0); (speed=(1 - speed));}
if( (speed ==0) ) { BIRTH( stoplight );}
if( 1==1 ) { CENTER;}
}
if( ( type==stoplight ) ) { if( (time ==0) ) { WEST;}
if( ((random() % 2) ==0) ) { DIE;}
if( 1==1 ) { CENTER;}
}
ALERT("Terminal Action not specified");
return self;
}
@end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.