* @param pawn_array array of played pawns
* @return pawn integer type
*/
-unsigned int get_box_value(int y, int x, unsigned int pawn_array[board_size][board_size]) {
+unsigned int get_box_value(unsigned int y, unsigned int x, unsigned int pawn_array[board_size][board_size]) {
return pawn_array[y-1][x-1];
}
-bool is_box_type(int y, int x, unsigned int pawn_array[board_size][board_size], unsigned int type) {
+bool is_box_type(unsigned int y, unsigned int x, unsigned int pawn_array[board_size][board_size], unsigned int type) {
if (type > 2) {
return NULL;
}
}
-static bool is_valid_coordinates(int y, int x) {
+static bool is_valid_coordinates(unsigned int y, unsigned int x) {
if ((y > 0 && y < board_size + 1) && \
(x > 0 && x < board_size + 1)) {
* @param type [description]
* @param pawn_array [description]
*/
-void set_pawn(int y, int x, unsigned int type, unsigned int pawn_array[board_size][board_size]) {
+void set_pawn(unsigned int y, unsigned int x, unsigned int type, unsigned int pawn_array[board_size][board_size]) {
if (type > 0 && type < 3 && \
is_valid_coordinates(y, x)) {
}
/* 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]) {
+static void reverse_pawn(unsigned int y, unsigned 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);
void zero_pawns(unsigned int pawn_array[board_size][board_size]) {
- for (int i = 1; i <= board_size; i++) {
- for (int j = 1; j <= board_size; j++) {
+ for (unsigned int i = 1; i <= board_size; i++) {
+ for (unsigned int j = 1; j <= board_size; j++) {
set_pawn(i, j, empty, pawn_array);
}
}
if (type > 2) {
return 0;
}
- for (int i = 1; i <= board_size; i++) {
- for (int j = 1; j <= board_size; j++) {
+ for (unsigned int i = 1; i <= board_size; i++) {
+ for (unsigned int j = 1; j <= board_size; j++) {
if (is_box_type(i, j, pawn_array, type)) {
count++;
}
return count;
}
-static void direction_to_coordinates(unsigned int direction, int* start_y, int* start_x) {
+static void direction_to_coordinates(unsigned int direction, unsigned int* start_y, unsigned int* start_x) {
if (direction == north) {
*start_y = *start_y - 1;
bool is_board_full(unsigned int pawn_array[board_size][board_size]) {
/* an alternate method is to test the round count vs. 60 */
- for (int i = 1; i <= board_size; i++) {
- for (int j = 1; j <= board_size; j++) {
+ for (unsigned int i = 1; i <= board_size; i++) {
+ for (unsigned int j = 1; j <= board_size; j++) {
if (is_box_type(i, j, pawn_array , empty)) {
return false;
}
}
}
-static unsigned int count_pawn_to_reverse_one_direction(int y, int x, unsigned int direction, unsigned int current_player, unsigned int pawn_array[board_size][board_size]) {
+static unsigned int count_pawn_to_reverse_one_direction(unsigned int y, unsigned int x, unsigned int direction, unsigned int current_player, unsigned int pawn_array[board_size][board_size]) {
unsigned int nb_pawns_reversed = 0;
- int moving_y = y, moving_x = x;
+ unsigned int moving_y = y, moving_x = x;
/* count the pawns to reverse in the chosen direction */
direction_to_coordinates(direction, &moving_y, &moving_x);
}
/* revert the pawns if needed in one direction */
-static unsigned int reverse_one_direction(int y, int x, unsigned int direction, unsigned int current_player, unsigned int pawn_array[board_size][board_size], bool dry_run) {
+static unsigned int reverse_one_direction(unsigned int y, unsigned int x, unsigned 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;
+ unsigned int moving_y = y, moving_x = x;
nb_pawns_reversed = count_pawn_to_reverse_one_direction(moving_y, moving_x, direction, current_player, pawn_array);
}
/* loop optimized version of valid_shot function changing nothing to the pawns 2D array */
-bool is_legal_shot(int y, int x, unsigned int current_player, unsigned int pawn_array[board_size][board_size]) {
+bool is_legal_shot(unsigned int y, unsigned 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)) {
}
/* play the shot if legal and flip or reverse the necessary pawns */
-unsigned int valid_shot(int y, int x, unsigned int current_player, unsigned int pawn_array[board_size][board_size]) {
+unsigned int valid_shot(unsigned int y, unsigned 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)) {
/* linked list of can play shots */
struct shots_list_s {
struct list_head list;
- int y;
- int x;
+ unsigned int y;
+ unsigned int x;
unsigned int type; /* can be white or black or hint allowed or hint_fordidden */
};
void zero_pawns(unsigned int pawn_array[board_size][board_size]);
void init_pawns(unsigned int pawn_array[board_size][board_size]);
-unsigned int get_box_value(int y, int x, unsigned int pawn_array[board_size][board_size]);
-void set_pawn(int y, int x, unsigned int type, unsigned int pawn_array[board_size][board_size]);
+unsigned int get_box_value(unsigned int y, unsigned int x, unsigned int pawn_array[board_size][board_size]);
+void set_pawn(unsigned int y, unsigned int x, unsigned int type, unsigned int pawn_array[board_size][board_size]);
-bool is_box_type(int y, int x, unsigned int pawn_array[board_size][board_size], unsigned int type);
+bool is_box_type(unsigned int y, unsigned int x, unsigned int pawn_array[board_size][board_size], unsigned int type);
bool is_board_full(unsigned int pawn_array[board_size][board_size]);
unsigned int count_pawns_type(unsigned int pawn_array[board_size][board_size], unsigned int type);
-bool is_legal_shot(int y, int x, unsigned int current_player, unsigned int pawn_array[board_size][board_size]);
-unsigned int valid_shot(int y, int x, unsigned int current_player, unsigned int pawn_array[board_size][board_size]);
+bool is_legal_shot(unsigned int y, unsigned int x, unsigned int current_player, unsigned int pawn_array[board_size][board_size]);
+unsigned int valid_shot(unsigned int y, unsigned int x, unsigned int current_player, unsigned int pawn_array[board_size][board_size]);
void build_playable_shots_list(unsigned int current_player, struct shots_list_s* shots_list, unsigned int pawn_array[board_size][board_size]);
void free_shots_list(struct shots_list_s* shots_list);