tchanged output slightly - game-of-life - Conway's Game of Life | |
git clone git://src.adamsgaard.dk/game-of-life | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 8df6fbdf39af9ba2fd5328d41ed96d9add8cc58b | |
parent dcd40ee55dbb59b9e734f2a9d22c9bf84ab9ffb1 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Sat, 8 Mar 2014 16:47:24 +0100 | |
changed output slightly | |
Diffstat: | |
M main.c | 14 +++++++++----- | |
M utility.c | 3 +-- | |
M utility.h | 2 +- | |
3 files changed, 11 insertions(+), 8 deletions(-) | |
--- | |
diff --git a/main.c b/main.c | |
t@@ -7,12 +7,14 @@ | |
#define GOLVERSION 0.1 | |
+/*#define SHOW_NEIGHBORS*/ | |
+ | |
int main(int argc, char **argv) | |
{ | |
int **cells; | |
int **neighbors; | |
- int nx = 40; | |
- int ny = 10; | |
+ int nx = 80; | |
+ int ny = 40; | |
int c; | |
unsigned int it = 0; | |
int world_is_dead = 0; | |
t@@ -56,16 +58,18 @@ int main(int argc, char **argv) | |
random_population(cells, nx, ny, 0.5); | |
- print_cell_matrix("cells", cells, nx, ny); | |
+ print_cell_matrix(cells, nx, ny); | |
while (world_is_dead == 0) { | |
world_is_dead = find_neighbor_count(cells, neighbors, nx, ny); | |
cell_transitions(cells, neighbors, nx, ny); | |
- printf("it = %d\n", it); | |
+ printf("\n%d. generation (end with Ctrl-C)\n", it); | |
+#ifdef SHOW_NEIGHBORS | |
print_matrix("neighbors", neighbors, nx, ny); | |
- print_cell_matrix("cells", cells, nx, ny); | |
+#endif | |
+ print_cell_matrix(cells, nx, ny); | |
usleep(5e5); | |
diff --git a/utility.c b/utility.c | |
t@@ -36,10 +36,9 @@ void print_matrix(char* description, int **M, int nx, int n… | |
} | |
} | |
-void print_cell_matrix(char* description, int **M, int nx, int ny) | |
+void print_cell_matrix(int **M, int nx, int ny) | |
{ | |
int i, j; | |
- printf("%s:\n", description); | |
for (j=0; j<ny; j++) { | |
for (i=0; i<nx; i++) { | |
if (M[i][j] == 1) | |
diff --git a/utility.h b/utility.h | |
t@@ -4,6 +4,6 @@ | |
int allocate_matrix(int ***M, int nx, int ny); | |
void free_matrix(int ***M, int nx); | |
void print_matrix(char* description, int **M, int nx, int ny); | |
-void print_cell_matrix(char* description, int **M, int nx, int ny); | |
+void print_cell_matrix(int **M, int nx, int ny); | |
#endif |