]> git.friedersdorff.com Git - max/gol.git/blobdiff - gol.c
MINIMAL implementation. Single glider gun
[max/gol.git] / gol.c
diff --git a/gol.c b/gol.c
index 0ad687da31ac3e0ca85e7e1f6373ce051524bce6..eba691465dce3df4c21208363d93c9ce50590eba 100644 (file)
--- a/gol.c
+++ b/gol.c
@@ -1,6 +1,7 @@
 #include <SDL2/SDL.h>
 #include <stdio.h>
 #include "array.h"
+#include "tick.h"
 
 void quit(int e_st)
 {
@@ -8,8 +9,76 @@ void quit(int e_st)
        exit(e_st);
 }
 
+void init_state(struct gol_board *state); 
+
+void init_state(struct gol_board *state) {
+       // Create the initial state. This is a glider gun (hopefully)
+       gol_vivify(state, 12, 0);
+       gol_vivify(state, 13, 0);
+       gol_vivify(state, 11, 1);
+       gol_vivify(state, 15, 1);
+       gol_vivify(state, 10, 2);
+       gol_vivify(state, 16, 2);
+       gol_vivify(state, 24, 2);
+       gol_vivify(state, 0, 3);
+       gol_vivify(state, 1, 3);
+       gol_vivify(state, 10, 3);
+       gol_vivify(state, 14, 3);
+       gol_vivify(state, 16, 3);
+       gol_vivify(state, 17, 3);
+       gol_vivify(state, 22, 3);
+       gol_vivify(state, 24, 3);
+       gol_vivify(state, 0, 4);
+       gol_vivify(state, 1, 4);
+       gol_vivify(state, 10, 4);
+       gol_vivify(state, 16, 4);
+       gol_vivify(state, 20, 4);
+       gol_vivify(state, 21, 4);
+       gol_vivify(state, 11, 5);
+       gol_vivify(state, 15, 5);
+       gol_vivify(state, 20, 5);
+       gol_vivify(state, 21, 5);
+       gol_vivify(state, 34, 5);
+       gol_vivify(state, 35, 5);
+       gol_vivify(state, 12, 6);
+       gol_vivify(state, 13, 6);
+       gol_vivify(state, 20, 6);
+       gol_vivify(state, 21, 6);
+       gol_vivify(state, 34, 6);
+       gol_vivify(state, 35, 6);
+       gol_vivify(state, 22, 7);
+       gol_vivify(state, 24, 7);
+       gol_vivify(state, 24, 7);
+}
+
 int main(int argc, char* args[])
 {
+       struct gol_board state = {
+               .live_cells = malloc(10 * sizeof(typeof(*state.live_cells))),
+               .n = 0,
+               .size = 10,
+               .max_x = 0,
+               .min_x = 0,
+               .max_y = 0,
+               .min_y = 0
+       };
+       if (!state.live_cells) {
+               return 1;
+       }
+       
+       init_state(&state);
+       
+       for (unsigned int i = 0; i < 1000; ++i) {
+               printf("Generation %d\n", i);
+               for (unsigned int j = 0; j < state.n; j += 2) {
+                       printf("(%d, %d)\n", state.live_cells[j],
+                               state.live_cells[j + 1]);
+               }
+               printf("\n");
+               gol_tick(&state);
+       }
+
+
        SDL_Window* window = NULL;
        SDL_Surface* screen = NULL;