diff options
Diffstat (limited to 'src/move.c')
-rw-r--r-- | src/move.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -280,3 +280,35 @@ struct move get_scm_move(char *strategy_path) { return scm_move_to_c_move(scm_move); } + +bool is_valid_move(enum player_color **board, + const enum player_color current_player, + const struct move move) { + if (current_player == EMPTY) { + return false; + } + + // Make a copy of the input board. This is done because we lean on the logic + // that exists in apply_move to check if a move is valid. We don't want to + // necessarily mutate the board yet though. + enum player_color **b = copy_board(board); + // Apply the move to the copy of the board. + bool res = apply_move(b, current_player, move); + + free_board(b); + + return res; +} + +bool has_valid_moves(enum player_color **board, + const enum player_color current_player) { + bool result = false; + struct move move; + for (move.row = 0; move.row < 8 && !result; move.row++) { + for (move.col = 0; move.col < 8 && !result; move.col++) { + result = is_valid_move(board, current_player, move); + } + } + + return result; +} |