-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.h
16 lines (15 loc) · 1.01 KB
/
rules.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#define NEIGHBOURS \
neighbours += (j > 0 && prev_field[index - 1] == ALIVE); \
neighbours += (j < W - 1 && prev_field[index + 1] == ALIVE); \
neighbours += (i > 0 && prev_field[index - W] == ALIVE); \
neighbours += (i < H - 1 && prev_field[index + W] == ALIVE); \
\
neighbours += (j > 0 && i > 0 && prev_field[index - W - 1] == ALIVE); \
neighbours += (j > 0 && i < H - 1 && prev_field[index + W - 1] == ALIVE); \
neighbours += (j < W - 1 && i < H - 1 && prev_field[index + W + 1] == ALIVE); \
neighbours += (j < W - 1 && i > 0 && prev_field[index - W + 1] == ALIVE);
#define RULE \
if (neighbours / 2 == 1) \
field[index] = ALIVE; \
else \
field[index] = prev_field[index] == 0 ? 0 : prev_field[index] - 1;