-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneration.h
40 lines (33 loc) · 1.14 KB
/
generation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "defs.h"
struct Cells{
unsigned currentCell;
unsigned top, topRight, topLeft;
unsigned bottom, bottomRight, bottomLeft;
unsigned left, right;
};
int cellStatus(struct Cells cell){
int living = cell.top + cell.bottom + cell.left + cell.right + cell.topLeft + cell.topRight + cell.bottomRight + cell.bottomLeft;
if (cell.currentCell){
if (living <= 1 || living >= 4) return 0;
if (living == 2 || living == 3) return 1;
} else {
return (living == 3) ? 1 : 0;
}
}
void generation(unsigned width, unsigned height, unsigned u[width][height]){
unsigned new[width][height];
struct Cells cell;
for_position {
cell.currentCell = u[line][column];
cell.top = u[line - 1][column];
cell.bottom = u[line + 1][column];
cell.left = u[line][column - 1];
cell.right = u[line][column + 1];
cell.topLeft = u[line - 1][column - 1];
cell.topRight = u[line - 1][column + 1];
cell.bottomLeft = u[line + 1][column - 1];
cell.bottomRight = u[line + 1][column + 1];
new[line][column] = cellStatus(cell);
}
for_line for_column u[line][column] = new[line][column];
}