summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2022-01-05 22:38:24 -0500
committerRobby Zambito <contact@robbyzambito.me>2022-01-05 22:38:24 -0500
commit58324035132009869c406d486605be98725c83f1 (patch)
tree1ceeca62c7c690caa797440b6a25d72833049bb6 /src
parent6a35a3cffd976f6fa9d96759e2f2bb0f784b92ac (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')
-rw-r--r--src/game_loop.c29
-rw-r--r--src/valid_moves.c2
2 files changed, 27 insertions, 4 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();
}
diff --git a/src/valid_moves.c b/src/valid_moves.c
index bd53833..e8e72f6 100644
--- a/src/valid_moves.c
+++ b/src/valid_moves.c
@@ -31,7 +31,7 @@ bool is_valid_move(const enum player_color current_player,
}
// The move must be below the upper bounds of the board.
- if (move.row >= 8 || move.col >= 8) {
+ if (move.row > 8 || move.col > 8) {
return false;
}