glider and spaceship

This commit is contained in:
robelix 2018-01-21 19:44:42 +01:00
parent e4c6f3c56b
commit c257e09232
1 changed files with 31 additions and 3 deletions

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() {
pinMode(LATCHPIN, OUTPUT);
pinMode(DATAPIN, OUTPUT);
@ -173,7 +189,7 @@ bool gol_getstate(int x, int y) {
y=7;
}
if (y>7) {
y=7;
y=0;
}
return bitRead(gol_last[x],y);
}
@ -272,7 +288,7 @@ void gol_step() {
// main loop
int mode = 0;
#define NRMODES 1
#define NRMODES 3
void switchmode( ){
mode = random(NRMODES);
@ -282,6 +298,14 @@ void switchmode( ){
gol_stepcount = 0;
gol_setup();
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) {
case 0: // game of life
if (gol_stepcount >200) {
case 1:
case 2:
if (gol_stepcount >100) {
switchmode();
}
if (gol_deadcount > 12) {
@ -305,6 +331,8 @@ void loop() {
switch(mode) {
case 0: // game of life
case 1:
case 2:
gol_step();
break;