summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2022-01-21 17:49:09 -0500
committerRobby Zambito <contact@robbyzambito.me>2022-01-21 17:49:09 -0500
commita5706c0be5778b911b061deca501271fc2bf2c07 (patch)
tree1087eb740715e692820ff1e275cf61a7ca1b0ea8 /src
parent199b2ff1b66bf2e12c9bf0b55a895a5555cc52f7 (diff)
Add command line argument to print the final board as a scheme object
This could be useful to create a machine learning AI, which uses the final board for training. Also bubble up the final score and present it at the end of the game.
Diffstat (limited to 'src')
-rw-r--r--src/board.c11
-rw-r--r--src/game_loop.c5
2 files changed, 6 insertions, 10 deletions
diff --git a/src/board.c b/src/board.c
index 88c7dff..aec166a 100644
--- a/src/board.c
+++ b/src/board.c
@@ -29,9 +29,7 @@ static enum player_color **board;
enum player_color **get_board() { return board; }
-SCM scm_get_board() {
- return scm_board_from_c_board(board);
-}
+SCM scm_get_board() { return scm_board_from_c_board(board); }
void initialize_board() {
board = calloc(8, sizeof(enum player_color *));
@@ -75,9 +73,7 @@ enum player_color get_winner(enum player_color **board,
*black_score = bs;
}
- return white_score > black_score ? WHITE
- : black_score > white_score ? BLACK
- : EMPTY;
+ return ws > bs ? WHITE : bs > ws ? BLACK : EMPTY;
}
SCM scm_get_winner(SCM scm_board, SCM scm_current_player) {
@@ -112,8 +108,7 @@ void free_board(enum player_color **board) {
SCM scm_board_from_c_board(enum player_color **board) {
// 2D list of empty rows
- SCM scm_board =
- scm_make_list(scm_from_int(8), SCM_EOL);
+ SCM scm_board = scm_make_list(scm_from_int(8), SCM_EOL);
for (int i = 0; i < 8; i++) {
// cons up each row.
diff --git a/src/game_loop.c b/src/game_loop.c
index f52bdb7..2c70ce2 100644
--- a/src/game_loop.c
+++ b/src/game_loop.c
@@ -76,7 +76,8 @@ static struct move current_player_move(enum player_color current_player,
}
enum player_color game_loop(char *player_one_strategy_path,
- char *player_two_strategy_path) {
+ char *player_two_strategy_path, int *white_score,
+ int *black_score) {
initialize_board();
if (player_one_strategy_path == NULL || player_two_strategy_path == NULL) {
@@ -100,5 +101,5 @@ enum player_color game_loop(char *player_one_strategy_path,
rl_clear_history();
}
- return get_winner(get_board(), current_player, NULL, NULL);
+ return get_winner(get_board(), current_player, white_score, black_score);
}