Skip to content

Commit

Permalink
replaced integer arrays by char arrays to save memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Judro committed Nov 23, 2022
1 parent 792d2bb commit 0d760f4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <time.h>
#include <unistd.h>
typedef struct myGame {
int *mines;
int *select;
int *floating;
char *mines;
char *select;
char *floating;
int width;
int height;
int length;
Expand All @@ -23,9 +23,9 @@ Game *g_new(int width, int height, int minesamount) {
Game *g = calloc(1, sizeof(Game));
int length = width * height;
int total = 0;
int *mines = malloc(length * sizeof(int));
int *select = malloc(length * sizeof(int));
int *floating = malloc(length * sizeof(int));
char *mines = malloc(length * sizeof(char));
char *select = malloc(length * sizeof(char));
char *floating = malloc(length * sizeof(char));
double minesp = (double)minesamount / (double)length;
srand48(time(0));
for (int i = 0; i < length; i++) {
Expand Down Expand Up @@ -134,7 +134,7 @@ GPrintable *g_printable(Game *g) {
gp->fields[i] = EIGHT;
break;
default:
break;
break;
}
} else {
gp->fields[i] = UNTOUCHED;
Expand Down Expand Up @@ -189,7 +189,7 @@ GPrintable *g_printable_gameover(Game *g) {
gp->fields[i] = EIGHT;
break;
default:
break;
break;
}
}
}
Expand Down

0 comments on commit 0d760f4

Please sign in to comment.