diff options
Diffstat (limited to 'src/game_loop.c')
-rw-r--r-- | src/game_loop.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/game_loop.c b/src/game_loop.c index 2af20bd..cc20454 100644 --- a/src/game_loop.c +++ b/src/game_loop.c @@ -67,12 +67,15 @@ enum player_color scm_player_to_c_player(SCM player) { static struct move current_player_move(enum player_color current_player, char *player_one_strategy_path, - char *player_two_strategy_path) { + char *player_two_strategy_path, + struct move *flipped_by_last_turn, + size_t flipped_by_last_turn_length) { 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); + move = prompt_get_move(current_player, flipped_by_last_turn, + flipped_by_last_turn_length); } else if (current_player == WHITE) { move = get_scm_move(player_one_strategy_path); } else if (current_player == BLACK) { @@ -93,10 +96,18 @@ enum player_color game_loop(char *player_one_strategy_path, current_player = WHITE; + struct move *flipped_by_last_turn = malloc(sizeof(struct move)); + size_t flipped_by_last_turn_length = 0; + size_t flipped_by_last_turn_capacity = 1; + while (has_valid_moves(get_board(), 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, player_one_strategy_path, player_two_strategy_path, + flipped_by_last_turn, flipped_by_last_turn_length); + + if ((flipped_by_last_turn_length = apply_move( + get_board(), current_player, move, &flipped_by_last_turn, + &flipped_by_last_turn_capacity))) { current_player = other_player; } } @@ -105,6 +116,8 @@ enum player_color game_loop(char *player_one_strategy_path, rl_clear_history(); } + free(flipped_by_last_turn); + return get_winner(get_board(), current_player, white_score, black_score); } |