glider and spaceship

This commit is contained in:
robelix 2018-01-21 19:44:42 +01:00
parent e4c6f3c56b
commit c257e09232

View file

@ -145,6 +145,22 @@ void gol_setup() {
} }
} }
static byte gol_glider[8] = {4,5,6,0,0,0,0,0};
void gol_setup_glider() {
gol_deadcount = 0;
for (int i=0; i<8; i++) {
gol_last[i] = gol_glider[i];
}
}
static byte gol_spaceship[8] = {12,28,26,14,4,0,0,0};
void gol_setup_spaceship() {
gol_deadcount = 0;
for (int i=0; i<8; i++) {
gol_last[i] = gol_spaceship[i];
}
}
void setup() { void setup() {
pinMode(LATCHPIN, OUTPUT); pinMode(LATCHPIN, OUTPUT);
pinMode(DATAPIN, OUTPUT); pinMode(DATAPIN, OUTPUT);
@ -173,7 +189,7 @@ bool gol_getstate(int x, int y) {
y=7; y=7;
} }
if (y>7) { if (y>7) {
y=7; y=0;
} }
return bitRead(gol_last[x],y); return bitRead(gol_last[x],y);
} }
@ -272,7 +288,7 @@ void gol_step() {
// main loop // main loop
int mode = 0; int mode = 0;
#define NRMODES 1 #define NRMODES 3
void switchmode( ){ void switchmode( ){
mode = random(NRMODES); mode = random(NRMODES);
@ -282,6 +298,14 @@ void switchmode( ){
gol_stepcount = 0; gol_stepcount = 0;
gol_setup(); gol_setup();
break; break;
case 1: // gol glider;
gol_stepcount = 0;
gol_setup_glider();
break;
case 2: // gol spaceship
gol_stepcount = 0;
gol_setup_spaceship();
break;
} }
} }
@ -294,7 +318,9 @@ void loop() {
switch(mode) { switch(mode) {
case 0: // game of life case 0: // game of life
if (gol_stepcount >200) { case 1:
case 2:
if (gol_stepcount >100) {
switchmode(); switchmode();
} }
if (gol_deadcount > 12) { if (gol_deadcount > 12) {
@ -305,6 +331,8 @@ void loop() {
switch(mode) { switch(mode) {
case 0: // game of life case 0: // game of life
case 1:
case 2:
gol_step(); gol_step();
break; break;