summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2022-01-22 13:58:36 -0500
committerRobby Zambito <contact@robbyzambito.me>2022-01-22 13:58:36 -0500
commit73d04c6bb63274451ed16bfe19df3d40c319f7e9 (patch)
tree611a0747ae46360d9609e4a7d54bd9d377e1fb8a
parent7bece69333072f1f1fed7653c97226452d9208b6 (diff)
Added diagonal moves
-rw-r--r--src/move.c96
1 files 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 +