summaryrefslogtreecommitdiff
path: root/src/game_loop.c
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2022-01-17 17:58:28 -0500
committerRobby Zambito <contact@robbyzambito.me>2022-01-17 17:58:28 -0500
commit59627145631f254191ce1b9de561c8ba0ddc889e (patch)
treefe6c45083da7ce34bb93f67fe22bf6877c47b918 /src/game_loop.c
parent6a9badff9bfbbdd7f54f018d3117c1778ecaa74e (diff)
Successfully read a move from scheme
Also was able to print the current board from scheme, so we should be able to do basic analysis at least. Should add more primitives for use from scheme.
Diffstat (limited to 'src/game_loop.c')
-rw-r--r--src/game_loop.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/game_loop.c b/src/game_loop.c
index 26cb988..67c9ea0 100644
--- a/src/game_loop.c
+++ b/src/game_loop.c
@@ -40,46 +40,46 @@ struct move (*player_one_get_move)();
struct move (*player_two_get_move)();
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;
+ char *player_one_strategy_path,
+ char *player_two_strategy_path) {
+ struct move move = {-1, -1};
+
+ if ((current_player == WHITE && player_one_strategy_path == NULL) ||
+ (current_player == BLACK && player_two_strategy_path == NULL)) {
+ move = prompt_get_move(current_player);
+ } else if (current_player == WHITE) {
+ move = get_scm_move(player_one_strategy_path);
+ } else if (current_player == BLACK) {
+ move = get_scm_move(player_two_strategy_path);
+ }
+
+ return move;
}
-enum player_color game_loop(FILE *player_one_strategy,
- FILE *player_two_strategy) {
- initialize_board();
+enum player_color game_loop(char *player_one_strategy_path,
+ char *player_two_strategy_path) {
+ initialize_board();
- if (player_one_strategy == NULL || player_two_strategy == NULL) {
- using_history();
- }
+ if (player_one_strategy_path == NULL || player_two_strategy_path == NULL) {
+ using_history();
+ }
- current_player = WHITE;
+ current_player = WHITE;
#define other_player (current_player == WHITE ? BLACK : WHITE)
- while (has_valid_moves(current_player)) {
- struct move move = current_player_move(current_player, player_one_strategy,
- player_two_strategy);
- if (apply_move(get_board(), current_player, move)) {
- current_player = other_player;
- }
+ while (has_valid_moves(current_player)) {
+ struct move move = current_player_move(current_player, player_one_strategy_path,
+ player_two_strategy_path);
+ if (apply_move(get_board(), current_player, move)) {
+ current_player = other_player;
}
+ }
#undef other_player
- if (player_one_strategy == NULL || player_two_strategy == NULL) {
- rl_clear_history();
- }
+ if (player_one_strategy_path == NULL || player_two_strategy_path == NULL) {
+ rl_clear_history();
+ }
- return get_winner();
+ return get_winner();
}