diff options
Diffstat (limited to 'src/move.c')
-rw-r--r-- | src/move.c | 47 |
1 files changed, 36 insertions, 11 deletions
@@ -53,11 +53,6 @@ static char *prompt_player(enum player_color current_player) { } } -/*static void inner_main(void *closure, int argc, char **argv) {*/ - /*(void)closure;*/ - /*scm_shell(argc, argv);*/ -/*}*/ - struct move prompt_get_move(enum player_color current_player) { // Initialize move to an invalid move. struct move move = {-1, -1}; @@ -72,7 +67,7 @@ struct move prompt_get_move(enum player_color current_player) { print_help(); } else if (STREQ(input, "p")) { print_board(); - /*} else if (STREQ(input, "g")) {*/ + /*} else if (STREQ(input, "g")) {*/ /*int argc = 1;*/ /*char **argv = calloc(1, sizeof(char *));*/ /*argv[0] = "othello";*/ @@ -95,7 +90,8 @@ struct move prompt_get_move(enum player_color current_player) { } /* Returns true if the move was valid */ -bool apply_move(enum player_color **board, enum player_color current_player, struct move move) { +bool apply_move(enum player_color **board, enum player_color current_player, + struct move move) { // The move must be a positive position. if (move.row < 0 || move.col < 0) { @@ -179,11 +175,40 @@ bool apply_move(enum player_color **board, enum player_color current_player, str return flipped_up || flipped_down || flipped_left || flipped_right; } -struct move get_scm_move(FILE *strategy) { +// Return the current board as a list of lists +static SCM scm_get_board(void) { + enum player_color **board = get_board(); + // 2D list of empty spaces + SCM scm_board = + scm_make_list(scm_from_int(8), scm_make_list(scm_from_int(0), NULL)); + for (int i = 0; i < 8; i++) { + for (int j = 7; j >= 0; j--) { + if (board[i][j] == WHITE) { + scm_list_set_x(scm_board, scm_from_int(i), + scm_cons(scm_c_eval_string("'w"), + scm_list_ref(scm_board, scm_from_int(i)))); + } else if (board[i][j] == BLACK) { + scm_list_set_x(scm_board, scm_from_int(i), + scm_cons(scm_c_eval_string("'b"), + scm_list_ref(scm_board, scm_from_int(i)))); + } else { + scm_list_set_x(scm_board, scm_from_int(i), + scm_cons(scm_c_eval_string("'e"), + scm_list_ref(scm_board, scm_from_int(i)))); + } + } + } + return scm_board; +} + +struct move get_scm_move(char *strategy_path) { // Initialize move to an invalid move. struct move move = {-1, -1}; + scm_init_guile(); + scm_c_define_gsubr("get-board", 0, 0, 0, scm_get_board); + + SCM scm_move = scm_c_primitive_load(strategy_path); + move.row = scm_to_int(scm_car(scm_move)); + move.col = scm_to_int(scm_cdr(scm_move)); return move; - (void)strategy; } - - |