diff --git a/Plague.g1a b/Plague.g1a index fefbe92..8fd3ccb 100644 Binary files a/Plague.g1a and b/Plague.g1a differ diff --git a/src/core.h b/src/core.h index 196644d..66956ed 100644 --- a/src/core.h +++ b/src/core.h @@ -14,8 +14,9 @@ // Number of planes on screen #define NB_PLANES 5 -struct grid { - +struct grid +{ + // 64, 128 int height, width; // Use grid.data[i + j * grid.width] instead of grid.data[i][j] diff --git a/src/display_engine.c b/src/display_engine.c index b511339..e58d63f 100644 --- a/src/display_engine.c +++ b/src/display_engine.c @@ -8,7 +8,7 @@ void display_background(const int background) { extern const bopti_image_t img_bground; - dsubimage(0, 0, &img_bground, 0, 65 * (background - 1), 128, 64, DIMAGE_NONE); + if (background != 6) dsubimage(0, 0, &img_bground, 0, 65 * (background - 1), 128, 64, DIMAGE_NONE); } @@ -29,7 +29,7 @@ void display_foreground(const int background, const struct game *current_game) { for (int j = 0; j < current_game->grid.height; j ++) { - if (current_game->grid.data[i + j * current_game->grid.width] != 0 && world[i][j] != 0) dpixel(i, j, C_BLACK); + if (current_game->grid.data[i + j * current_game->grid.width] == 1 && world[i][j] != 0) dpixel(i, j, C_BLACK); } } @@ -47,7 +47,7 @@ void display_foreground(const int background, const struct game *current_game) { for (int j = 0; j < 50; j ++) { - if (current_game->grid.data[i + j * current_game->grid.width] != 0 && world[i][j] != 0) dpixel(i, j, C_BLACK); + if (current_game->grid.data[i + j * current_game->grid.width] == 1 && world[i][j] != 0) dpixel(i, j, C_BLACK); } } diff --git a/src/epidemic_engine.c b/src/epidemic_engine.c index 93c8790..d15b50b 100644 --- a/src/epidemic_engine.c +++ b/src/epidemic_engine.c @@ -2,14 +2,10 @@ #include "epidemic_engine.h" -#include -#include - - int grid_get(const struct grid epidemic_grid, const int i, const int j) { - if (i < 0 || j < 0 || i >= epidemic_grid.width || j >= epidemic_grid.height) return epidemic_grid.data[i + j * epidemic_grid.width]; - return 0; + if (i < 0 || j < 0 || i >= epidemic_grid.width || j >= epidemic_grid.height) return 0; + else return epidemic_grid.data[i + j * epidemic_grid.width]; } @@ -18,43 +14,41 @@ bool can_become_infected(const struct grid epidemic_grid, const int mutations_se extern const unsigned int world[64][128]; // In case of water, low or high temperature - if (world[j][i] == 0 && mutations_selected[2] != 3) return false; + /*if (world[j][i] == 0 && mutations_selected[2] != 3) return false; if (world[j][i] == 1 && mutations_selected[1] != 0 && mutations_selected[1] != 4) return false; - if (world[j][i] == 3 && mutations_selected[1] != 1 && mutations_selected[1] != 4) return false; + if (world[j][i] == 3 && mutations_selected[1] != 1 && mutations_selected[1] != 4) return false;*/ // Test cases around return grid_get(epidemic_grid, i - 1, j) == 1 || grid_get(epidemic_grid, i + 1, j) == 1 || grid_get(epidemic_grid, i, j - 1) == 1 || grid_get(epidemic_grid, i, j + 1) == 1; } -bool bernoulli(const float p) +bool bernoulli(const int p) { - return (rand() / 2147483647) <= p; + return (rand() % 101) <= p; } void epidemic_simulation(struct game *current_game) { srand(15510); - double contagion_rate = current_game->contagion / 100; - double lethality_rate = current_game->lethality / 100; - double healed_rate = current_game->research / current_game->limit; - dclear(C_WHITE); - dprint(5, 5, C_BLACK, "HR:%lf", healed_rate); - dupdate(); - getkey(); + int healed_rate = 100 * (current_game->research / current_game->limit); for (int i = 0; i < current_game->grid.width; i ++) { for (int j = 0; j < current_game->grid.height; j ++) { + current_game->grid.data[i + j * current_game->grid.width] = 1; + + /* switch (current_game->grid.data[i + j * current_game->grid.width]) { // Healthy - case 0: - if (can_become_infected(current_game->grid, current_game->mutations_selected, i, j) - && bernoulli(contagion_rate)) + case 0: + + // Become infected + if (can_become_infected(current_game->grid, current_game->mutations_selected, i, j) && bernoulli(current_game->contagion)) { current_game->grid.data[i + j * current_game->grid.width] = 1; current_game->humans[0] --; @@ -74,15 +68,15 @@ void epidemic_simulation(struct game *current_game) } // Become dead - else if (bernoulli(lethality_rate)) + else if (bernoulli(current_game->lethality)) { current_game->grid.data[i + j * current_game->grid.width] = 3; current_game->humans[1] --; current_game->humans[3] ++; } break; - } + }*/ } } -} \ No newline at end of file +} diff --git a/src/epidemic_engine.h b/src/epidemic_engine.h index b217ff5..a2cdd80 100644 --- a/src/epidemic_engine.h +++ b/src/epidemic_engine.h @@ -10,7 +10,7 @@ bool can_become_infected(const struct grid epidemic_grid, const int mutations_selected[3], const int i, const int j); // bernoulli : simulate a random event -bool bernoulli(const float p); +bool bernoulli(const int p); // epidemic_simulation : simulate the propagation of the virus void epidemic_simulation(struct game *current_game); diff --git a/src/main.c b/src/main.c index a59da4b..bbc5f77 100644 --- a/src/main.c +++ b/src/main.c @@ -67,6 +67,12 @@ int main(void) /* allocate memory */ current_game.grid.data = calloc(current_game.grid.width * current_game.grid.height, sizeof(uint8_t)); + if (current_game.grid.data == NULL) + { + const char *msg[5] = {"CALLOC", "FAILED", "", "", ""}; + message(msg); + } + current_game.grid.data[95 + 20 * current_game.grid.width] = 1; current_game.humans[0] = (current_game.grid.width * current_game.grid.height) - 1;