#include "raylib.h" #include #include #include #include typedef struct { int width; int height; int **data; } State; void initializeState(State *state) { state->data = malloc(state->height * sizeof (int *)); for (int i=0; i < state->height; i++) { int *row = malloc(state->width * sizeof (int)); for (int j=0; j < state->width; j++) { row[j] = 0; } state->data[i] = row; } } void copyState(State *dest, State *src) { for(int i=0; iheight; i++) { int *destRow = dest->data[i]; int *srcRow = src->data[i]; memcpy(destRow, srcRow, dest->width * sizeof(int)); } } void freeStateData(State *state) { for (int i=0; i < state->height; i++) { free(state->data[i]); } free(state->data); } void printState(State *state) { for (int i=0; iheight; i++) { for (int j=0; jwidth; j++) { printf("%d ", state->data[i][j]); } printf("\n"); } } int main(void) { const int pixSize = 5; const int padding = 2; const int height = 80; const int width = 100; const int space = pixSize + (2 * padding); const int winHeight = space * height; const int winWidth = space * width; State currState = {.height = height, .width = width}; initializeState(&currState); State nextState = {.height = height, .width = width}; initializeState(&nextState); srand(time(NULL)); int prob = 30; for (int i=0; i 0 && j > 0) { n1 = currState.data[i - 1][j - 1]; n2 = currState.data[i - 1][j]; n4 = currState.data[i][j - 1]; } if (i > 0 && j < width-1) { n3 = currState.data[i - 1][j + 1]; } if (i < height-1 && j < width-1) { n5 = currState.data[i][j + 1]; n7 = currState.data[i + 1][j]; } if (i < height-1 && j > 0) { n6 = currState.data[i + 1][j - 1]; } if (i < height-1 && j < width-1) { n8 = currState.data[i + 1][j + 1]; } int total = n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8; if (total < 2 && currState.data[i][j]) nextState.data[i][j] = false; if (total > 3 && currState.data[i][j]) nextState.data[i][j] = false; if ((total == 2 || total == 3) && currState.data[i][j]) nextState.data[i][j] = true; if (total == 3 && !currState.data[i][j]) nextState.data[i][j] = true; } } } if (isRunning) { copyState(&currState, &nextState); } EndDrawing(); } freeStateData(&currState); freeStateData(&nextState); CloseWindow(); return 0; }