#include "debug.h"
unsigned int current_player(unsigned int round_count) {
-
+
if (round_count % 2 != 0) {
return player_two;
} else {
* |
* y
* |
- * v
+ * v
* The origin O has (1, 1) coordinates */
unsigned int get_box_value(int y, int x, unsigned int pawn_array[board_size][board_size]) {
-
+
return pawn_array[y-1][x-1];
}
/* reverse the pawn at (y, x) coordinates if it exists */
static void reverse_pawn(int y, int x, unsigned int pawn_array[board_size][board_size]) {
-
+
if (is_box_type(y, x, pawn_array, black)) {
set_pawn(y, x, white, pawn_array);
} else if (is_box_type(y, x, pawn_array, white)) {
return nb_pawns_reversed;
}
-/* revert the pawns if needed in one direction */
+/* revert the pawns if needed in one direction */
static unsigned int reverse_one_direction(int y, int x, int direction, unsigned int current_player, unsigned int pawn_array[board_size][board_size], bool dry_run) {
unsigned int nb_pawns_reversed = 0;
int moving_y = y, moving_x = x;
/* loop optimized version of valid_shot changing nothing to the pawns 2D array */
static bool is_legal_shot(int y, int x, unsigned int current_player, unsigned int pawn_array[board_size][board_size]) {
unsigned int nb_pawns_reversed = 0;
-
+
if (!is_valid_coordinates(y, x) || !is_box_type(y, x, pawn_array, empty)) {
return false;
}
-
+
for (unsigned int direction = north; direction <= north_west; direction++) {
nb_pawns_reversed += reverse_one_direction(y, x, direction, current_player, pawn_array, true);
if (nb_pawns_reversed > 0) {
for (unsigned int direction = north; direction <= north_west; direction++) {
nb_pawns_reversed += reverse_one_direction(y, x, direction, current_player, pawn_array, false);
}
-
+
if (nb_pawns_reversed == 0) {
return 0;
}