diff options
Diffstat (limited to 'src/move.c')
-rw-r--r-- | src/move.c | 96 |
1 files changed, 84 insertions, 12 deletions
@@ -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 + |