summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/valid_moves.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/valid_moves.c b/src/valid_moves.c
index 7f7658c..dca1a0f 100644
--- a/src/valid_moves.c
+++ b/src/valid_moves.c
@@ -23,11 +23,17 @@
bool is_valid_move(const enum player_color board[8][8],
const enum player_color current_player,
const struct move move) {
- // The move must be a positive position
+ // The move must be a positive position.
if (move.row < 0 || move.col < 0) {
return false;
}
- // The move must be an empty spot to be valid
+
+ // The move must be below the upper bounds of the board.
+ if (move.row >= 8 || move.col >= 8) {
+ return false;
+ }
+
+ // The move must be an empty spot to be valid.
if (board[move.row][move.col] != EMPTY) {
return false;
}
@@ -40,6 +46,9 @@ bool is_valid_move(const enum player_color board[8][8],
bool is_valid_right = false;
#define check_valid_direction(direction_bool, start, end_cond, step, cur_pos) \
+ /* This if statement ensures that we don't check after one direction is \
+ * already valid. \
+ */ \
if (!is_valid_up && !is_valid_down && !is_valid_left && !is_valid_right) { \
bool would_flip_oppenent = false; \
bool has_other_end = false; \