Skip to content

Commit

Permalink
Fixed test_game bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kirklange committed May 12, 2018
1 parent fcb2caf commit 0acf604
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion project/test_game/main_test_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 18 additions & 2 deletions src/rgu/rgu_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
{
Expand Down

0 comments on commit 0acf604

Please sign in to comment.