#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;
}
bool exit_condition = false;
unsigned int nb_white = 0, nb_black = 0;
- char* title_msg = "Jeu Othello";
- char* score_msg = "Pions %s: %d";
- char* invalid_move_msg = "Coup invalide";
- char* player_msg = "Joueur %d (%s) joue !";
- char* winner_msg = "Joueur %d (%s) gagne !";
- char* draw_msg = "Egalite !";
- char* exit_msg = "Pressez une touche pour sortir ou \'r\' pour rejouer";
-
+ const char* title_msg = "Jeu Othello";
+ const char* score_msg = "Pions %s: %d";
+ const char* invalid_move_msg = "Coup invalide";
+ const char* player_msg = "Joueur %d (%s) joue !";
+ const char* winner_msg = "Joueur %d (%s) gagne !";
+ const char* draw_msg = "Egalite !";
+ const char* exit_msg = "Pressez une touche pour sortir ou \'r\' pour rejouer";
+
/* linked list of playable shots */
struct shots_list_s playable_shots;
INIT_LIST_HEAD(&playable_shots.list);
nb_white = count_pawns_type(pawns, white);
nb_black = count_pawns_type(pawns, black);
-
+
mvprintw(center_y, center_x - 42/2 - snprintf(NULL, 0, score_msg, "noirs", nb_black) - 2, score_msg, "noirs", nb_black);
mvprintw(center_y, center_x + 42/2 + 2, score_msg, "blancs", nb_white);
-
+
//display_array(1, 1, pawns);
int y;
do {
y = 0;
x_char = "";
- char* prompt_msg = "Prochain pion ? (ligne colonne - chiffre lettre):";
+ const char* prompt_msg = "Prochain pion ? (ligne colonne - chiffre lettre):";
int prmt_rt = prompt_values(stdscr, center_y + 26/2 + 1, (center_x - strlen(prompt_msg)/2), prompt_msg, &y, &x_char);
int x = map_col_letter_to_index(x_char);
nb_pawns_reversed = valid_shot(y, x, player, pawns);
clear();
}
}
-
+
refresh();
} while (!exit_condition);
-
+
endwin();
exit(EXIT_SUCCESS);