commit e093d775a076a83df6c9c6764f96ae2b25c2875f
parent 6f160593ce5caa4db311d3eafce03dde9c387536
Author: aabacchus <ben@bvnf.space>
Date: Sun, 20 Feb 2022 14:16:48 +0000
Revert "make the board wrap around like a torus"
This reverts commit 532da220dbb29fb0d09cdce2473634074c487812.
Diffstat:
M | rules.c | | | 22 | ++++++++++++++-------- |
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/rules.c b/rules.c
@@ -41,14 +41,8 @@ evolve(short *cells, int nx, int ny) {
int
alive(int x, int y, short *cells, int nx, int ny) {
- if (y < 0)
- y += ny;
- else if (y >= ny)
- y -= ny;
- if (x < 0)
- x += nx;
- else if (x >= nx)
- x -= nx;
+ if (y < 0 || y >= ny || x < 0 || x >= nx)
+ return WHATS_OUTSIDE;
return (int) *(cells + y * nx + x);
}
@@ -57,7 +51,19 @@ neighbours(int x, int y, short *cells, int nx, int ny) {
int n = 0;
int x0, y0;
for (y0 = y - 1; y0 <= y + 1; y0++) {
+ /*
+ if (y0 < 0 || y0 >= ny) {
+ n += WHATS_OUTSIDE;
+ continue;
+ }
+ */
for (x0 = x - 1; x0 <= x + 1; x0++) {
+ /*
+ if (x0 < 0 || x0 >= nx) {
+ n += WHATS_OUTSIDE;
+ continue;
+ }
+ */
if (alive(x0, y0, cells, nx, ny))
n++;
}