diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game_loop.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/game_loop.c b/src/game_loop.c index 0ba2be6..a5f1fe0 100644 --- a/src/game_loop.c +++ b/src/game_loop.c @@ -20,6 +20,7 @@ #include <errno.h> #include <libguile.h> +#include <readline/history.h> #include <readline/readline.h> #include <stdio.h> #include <stdlib.h> @@ -45,17 +46,6 @@ static enum player_color other_player(enum player_color current_player) { } } -static int player_number_from_color(enum player_color player) { - switch (player) { - case WHITE: - return 1; - case BLACK: - return 2; - default: - return -1; - } -} - static char *prompt_player(enum player_color current_player) { switch (current_player) { case WHITE: @@ -81,6 +71,7 @@ static void print_help() { } static void inner_main(void *closure, int argc, char **argv) { + (void)closure; scm_shell(argc, argv); } @@ -94,6 +85,7 @@ static struct move prompt_get_move(enum player_color board[8][8], char *input = readline(prompt); if (input != NULL) { + add_history(input); if (STREQ(input, "h")) { print_help(); } else if (STREQ(input, "p")) { @@ -110,6 +102,7 @@ static struct move prompt_get_move(enum player_color board[8][8], } } else { // If input was NULL, we have reached an EOF and would like to exit. + free(input); exit(0); } @@ -185,6 +178,7 @@ const enum player_color **get_board(void) { } enum player_color game_loop(enum player_color init_board[8][8]) { + using_history(); // Start with the initial board. for (int i = 0; i < 8; i++) { @@ -209,6 +203,8 @@ enum player_color game_loop(enum player_color init_board[8][8]) { } } + rl_clear_history(); + return white_score > black_score ? WHITE : black_score > white_score ? BLACK : EMPTY; |