diff --git a/project/test_game/main_test_game.c b/project/test_game/main_test_game.c index 93310d0..9388ae2 100644 --- a/project/test_game/main_test_game.c +++ b/project/test_game/main_test_game.c @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) printf("RGU Game Test\n\n"); rgu_game *game = rgu_game_new(); - rgu_game_run(game, 0, 0, 0, 0); + rgu_game_run(game, 0, 0, 0); rgu_game_del(game); return 0; diff --git a/src/rgu/rgu_game.c b/src/rgu/rgu_game.c index d13b0ad..1a336e1 100644 --- a/src/rgu/rgu_game.c +++ b/src/rgu/rgu_game.c @@ -112,17 +112,23 @@ uint8_t rgu_game_run(rgu_game *self, char *name[2], uint8_t isAI[2], benchmarking = 0; /* AI benchmarking mode. - * `benchmarking = 1` suppresses most print messages. */ + * `benchmarking = 1` suppresses all print messages. */ if (name && lookAhead && score) isAI[0] = isAI[1] = benchmarking = 1; if (!benchmarking) { printf(">>> Welcome to the Royal Game of Ur <<<\n\n"); + + name = (char**) calloc(2, sizeof(char*)); + lookAhead = (uint8_t*) calloc(1, sizeof(uint8_t)); + score = (int16_t*) calloc(1, sizeof(int16_t)); uint8_t i; for (i=0; i<2; i++) { + name[i] = calloc(1, sizeof(char)*(STRLEN+1)); + printf("What is your name, player %s? >", (i == 0 ? "one" : "two")); scanf(STRFMT, name[i]); @@ -166,6 +172,7 @@ uint8_t rgu_game_run(rgu_game *self, char *name[2], "board.\nTo quit early, input capital \'Q\'.\n"); } + /* GAME LOOP */ while (winner == NONE && !quit) { /* Deep copy torture test @@ -261,7 +268,7 @@ uint8_t rgu_game_run(rgu_game *self, char *name[2], if (!benchmarking) printf("\n"); winner = rgu_board_getWinner(self->board); - } + } /* END GAME LOOP */ if (winner != NONE) { @@ -279,6 +286,15 @@ uint8_t rgu_game_run(rgu_game *self, char *name[2], { printf("Sorry to see you leave early...\n"); } + + if (!benchmarking) + { + uint8_t i; + for (i=0; i<2; i++) free(name[i]); + free(name); + free(lookAhead); + free(score); + } } else {