summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2021-11-25 08:52:42 -0500
committerRobby Zambito <contact@robbyzambito.me>2021-11-25 08:52:42 -0500
commit2e7d4399fd3c3c4a31fd7c673037701232dd259f (patch)
tree1397267e77d1a5fc3f814823aba6ad201ce1a61f
parentc523507224275b09f275755c26df5bd19cc8358c (diff)
Add history for readline
Also removed unused function
-rw-r--r--src/game_loop.c18
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;