summaryrefslogtreecommitdiff
path: root/src/game_loop.c
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2022-01-21 20:00:28 -0500
committerRobby Zambito <contact@robbyzambito.me>2022-01-21 20:00:28 -0500
commit42a6b86d27751b3dec95dd64b4996ea13ad58a10 (patch)
treeb2b79175d89e589fab3f4dbdb5d63199dc79fc55 /src/game_loop.c
parent560016b243bc52f721153272a3809f6271215a25 (diff)
Added Scheme procedure to easily get the other player
Diffstat (limited to 'src/game_loop.c')
-rw-r--r--src/game_loop.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/game_loop.c b/src/game_loop.c
index 2c70ce2..2af20bd 100644
--- a/src/game_loop.c
+++ b/src/game_loop.c
@@ -34,11 +34,18 @@
#define STREQ(a, b) (strcmp(a, b) == 0)
static enum player_color current_player;
+#define other_player (current_player == WHITE ? BLACK : WHITE)
enum player_color get_current_player(void) { return current_player; }
-SCM scm_get_current_player(void) {
- switch (current_player) {
+SCM scm_get_current_player() {
+ return scm_player_from_c_player(current_player);
+}
+
+SCM scm_get_other_player() { return scm_player_from_c_player(other_player); }
+
+SCM scm_player_from_c_player(enum player_color player) {
+ switch (player) {
case WHITE:
return scm_from_utf8_symbol("white");
case BLACK:
@@ -85,7 +92,6 @@ enum player_color game_loop(char *player_one_strategy_path,
}
current_player = WHITE;
-#define other_player (current_player == WHITE ? BLACK : WHITE)
while (has_valid_moves(get_board(), current_player)) {
struct move move = current_player_move(
@@ -95,11 +101,11 @@ enum player_color game_loop(char *player_one_strategy_path,
}
}
-#undef other_player
-
if (player_one_strategy_path == NULL || player_two_strategy_path == NULL) {
rl_clear_history();
}
return get_winner(get_board(), current_player, white_score, black_score);
}
+
+#undef other_player