diff options
author | Robby Zambito <contact@robbyzambito.me> | 2022-01-05 22:38:24 -0500 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2022-01-05 22:38:24 -0500 |
commit | 58324035132009869c406d486605be98725c83f1 (patch) | |
tree | 1ceeca62c7c690caa797440b6a25d72833049bb6 /src/game_loop.c | |
parent | 6a35a3cffd976f6fa9d96759e2f2bb0f784b92ac (diff) |
Open strategy files and pass them to the game loop
Also fixed a bug where we could have gone off the upper bounds of the
board.
Diffstat (limited to 'src/game_loop.c')
-rw-r--r-- | src/game_loop.c | 29 |
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(); } |