76 lines
1.7 KiB
Plaintext
76 lines
1.7 KiB
Plaintext
class Cell {
|
|
int col;
|
|
int dec;
|
|
|
|
Cell(int c, float possibility, int dd, int cc) {
|
|
if (c == 0) {
|
|
boolean skip = false;
|
|
if (possibility == 0) {
|
|
skip = true;
|
|
col = 0;
|
|
}
|
|
if (skip == false) {
|
|
if (random(1) >= 1-possibility) {
|
|
col = 1;
|
|
} else {
|
|
col = 0;
|
|
}
|
|
dec = round(random(1,2));
|
|
}
|
|
} else if (c == 1) {
|
|
col = cc;
|
|
dec = dd;
|
|
}
|
|
}
|
|
|
|
int aliveCheck(int x, int y, int scl, int w2, int h2) {
|
|
int alive = 0, reds = 0, blues = 0;
|
|
|
|
for (int i = -1; i < 2; i++) {
|
|
for (int j = -1; j < 2; j++) {
|
|
int cols = (w2/scl), rows = (h2/scl);
|
|
PVector pos = new PVector((x+i+cols)%cols, (y+j+rows)%rows);
|
|
if (gol.cells[int(pos.x)][int(pos.y)].col == 1) {
|
|
if (gol.cells[int(pos.x)][int(pos.y)].dec == 1) {
|
|
blues++;
|
|
} else {
|
|
reds++;
|
|
}
|
|
}
|
|
alive += gol.cells[int(pos.x)][int(pos.y)].col;
|
|
}
|
|
}
|
|
alive -= col;
|
|
if (col == 0 && alive == 3) { // (alive == 1 || alive == 3 || alive == 5 || alive == 7)
|
|
//return 4;
|
|
if (reds > blues) {
|
|
return 3;
|
|
} else if (blues > reds) {
|
|
return 2;
|
|
} else if (blues == reds) {
|
|
return 4;
|
|
} else {
|
|
return 0;
|
|
}
|
|
} else if (col == 1 && (alive < 2 || alive > 3)) { // alive == 0 || alive == 2 || alive == 4 || alive == 6 ||alive == 8
|
|
return 0;
|
|
} else {
|
|
return col;
|
|
}
|
|
}
|
|
|
|
color colCheck() {
|
|
color temp = color(0);
|
|
if (col == 1) {
|
|
if (dec == 1) {
|
|
temp = color(0,0,255);
|
|
} else if (dec == 2) {
|
|
temp = color(255,0,0);
|
|
} else if (dec == 3) {
|
|
temp = color(255);
|
|
}
|
|
}
|
|
return temp;
|
|
}
|
|
}
|