summaryrefslogtreecommitdiff
path: root/src/game_loop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/game_loop.c')
-rw-r--r--src/game_loop.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/game_loop.c b/src/game_loop.c
index bdb37f5..22c624e 100644
--- a/src/game_loop.c
+++ b/src/game_loop.c
@@ -39,9 +39,30 @@ enum player_color get_current_player(void) { return current_player; }
struct move (*player_one_get_move)();
struct move (*player_two_get_move)();
-enum player_color game_loop() {
+static struct move current_player_move(enum player_color current_player,
+ FILE *player_one_strategy,
+ FILE *player_two_strategy) {
+ struct move move = {-1, -1};
+
+ if ((current_player == WHITE && player_one_strategy == NULL) ||
+ (current_player == BLACK && player_two_strategy == NULL)) {
+ move = prompt_get_move(current_player);
+ } else if (current_player == WHITE) {
+ move = get_scm_move(player_one_strategy);
+ } else if (current_player == BLACK) {
+ move = get_scm_move(player_two_strategy);
+ }
+
+ return move;
+}
+
+enum player_color game_loop(FILE *player_one_strategy,
+ FILE *player_two_strategy) {
initialize_board();
- using_history();
+
+ if (player_one_strategy == NULL || player_two_strategy == NULL) {
+ using_history();
+ }
current_player = WHITE;
#define other_player (current_player == WHITE ? BLACK : WHITE)
@@ -55,7 +76,9 @@ enum player_color game_loop() {
#undef other_player
- rl_clear_history();
+ if (player_one_strategy == NULL || player_two_strategy == NULL) {
+ rl_clear_history();
+ }
return get_winner();
}