X-Git-Url: https://git.piment-noir.org/?p=Project_algorithmic_C.git;a=blobdiff_plain;f=lib%2Fothello.c;h=4e03069f0ee50981863601fb178ef5f93c49f1d3;hp=4f1b83ec52cd1b8cda16f1696b85c56a9e499b4b;hb=21b9239c8a14c5f9b5553d1f6a583307971b26e6;hpb=f8be19baab695a99afd806d64aae4c92d09c33ab diff --git a/lib/othello.c b/lib/othello.c index 4f1b83e..4e03069 100644 --- a/lib/othello.c +++ b/lib/othello.c @@ -24,7 +24,7 @@ #include "debug.h" unsigned int current_player(unsigned int round_count) { - + if (round_count % 2 != 0) { return player_two; } else { @@ -46,11 +46,11 @@ unsigned int current_opponent(unsigned int current_player) { * | * 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]; } @@ -87,7 +87,7 @@ void set_pawn(int y, int x, unsigned int type, unsigned int pawn_array[board_siz /* 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)) { @@ -199,7 +199,7 @@ static unsigned int count_pawn_to_reverse_one_direction(int y, int x, int direct 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; @@ -221,11 +221,11 @@ static unsigned int reverse_one_direction(int y, int x, int direction, unsigned /* 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) { @@ -245,7 +245,7 @@ unsigned int valid_shot(int y, int x, unsigned int current_player, unsigned int 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; }