From 73d04c6bb63274451ed16bfe19df3d40c319f7e9 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sat, 22 Jan 2022 13:58:36 -0500 Subject: Added diagonal moves --- src/move.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 84 insertions(+), 12 deletions(-) diff --git a/src/move.c b/src/move.c index 2bdba41..b6d9ff5 100644 --- a/src/move.c +++ b/src/move.c @@ -206,18 +206,90 @@ int apply_move(enum player_color **board, enum player_color current_player, done_flipping_right = true; } - /*if (!done_flipping_up_left &&) {*/ - /*done_flipping_up_left = true;*/ - /*}*/ - /*if (!done_flipping_up_right &&) {*/ - /*done_flipping_up_right = true;*/ - /*}*/ - /*if (!done_flipping_down_left &&) {*/ - /*done_flipping_down_left = true;*/ - /*}*/ - /*if (!done_flipping_down_right &&) {*/ - /*done_flipping_down_right = true;*/ - /*}*/ + if (!done_flipping_up_left && (move.row - i >= 0) && (move.col - i >= 0) && + board[move.row - i][move.col - i] == current_player) { + + if (i > 1) { + bool flippable = true; + for (int j = 1; flippable && j < i; j++) { + if (board[move.row - j][move.col - j] == EMPTY) { + flippable = false; + } + } + + if (flippable) { + for (int j = 0; j < i; j++) { + board[move.row - j][move.col - j] = current_player; + num_flipped_up_left++; + } + } + } + + done_flipping_up_left = true; + } + if (!done_flipping_up_right && (move.row - i >= 0) && (move.col + i < 8) && + board[move.row - i][move.col + i] == current_player) { + + if (i > 1) { + bool flippable = true; + for (int j = 1; flippable && j < i; j++) { + if (board[move.row - j][move.col + j] == EMPTY) { + flippable = false; + } + } + + if (flippable) { + for (int j = 0; j < i; j++) { + board[move.row - j][move.col + j] = current_player; + num_flipped_up_right++; + } + } + } + + done_flipping_up_right = true; + } + if (!done_flipping_down_left && (move.row + i < 8) && (move.col - i >= 0) && + board[move.row + i][move.col - i] == current_player) { + + if (i > 1) { + bool flippable = true; + for (int j = 1; flippable && j < i; j++) { + if (board[move.row + j][move.col - j] == EMPTY) { + flippable = false; + } + } + + if (flippable) { + for (int j = 0; j < i; j++) { + board[move.row + j][move.col - j] = current_player; + num_flipped_down_left++; + } + } + } + + done_flipping_down_left = true; + } + if (!done_flipping_down_right && (move.row + i < 8) && (move.col + i < 8) && + board[move.row + i][move.col + i] == current_player) { + + if (i > 1) { + bool flippable = true; + for (int j = 1; flippable && j < i; j++) { + if (board[move.row + j][move.col + j] == EMPTY) { + flippable = false; + } + } + + if (flippable) { + for (int j = 0; j < i; j++) { + board[move.row + j][move.col + j] = current_player; + num_flipped_down_right++; + } + } + } + + done_flipping_down_right = true; + } } return num_flipped_up + num_flipped_down + num_flipped_left + -- cgit v1.2.3