//const unsigned int board_size = 8;
const unsigned int empty = 0;
-const unsigned int white = 1;
-const unsigned int black = 2;
+const unsigned int black = 1;
+const unsigned int white = 2;
/* FIXME: reuse the two above variables would be better */
-const unsigned int player_one = 2; /* first player is black */
-const unsigned int player_two = 1;
+const unsigned int player_one = 1; /* first player is black */
+const unsigned int player_two = 2;
const unsigned int hint_allowed = 3;
const unsigned int hint_forbidden = 4;
//extern const unsigned int board_size; /* 8 */
extern const unsigned int empty; /* 0 */
-extern const unsigned int white; /* 1 */
-extern const unsigned int black; /* 2 */
+extern const unsigned int black; /* 1 */
+extern const unsigned int white; /* 2 */
extern const unsigned int player_one; /* black */
extern const unsigned int player_two; /* white */
return true;
}
+unsigned int eval_winner(unsigned int nb_white, unsigned int nb_black) {
+
+ if (nb_white > nb_black) {
+ return player_two;
+ } else if (nb_white < nb_black) {
+ return player_one;
+ } else {
+ return 0;
+ }
+}
+
void status_pawn(int y, int x, unsigned int pawn_array[board_size][board_size]) {
}
};
unsigned int current_player(unsigned int round_count);
+unsigned int eval_winner(unsigned int nb_white, unsigned int nb_black);
int** 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]);
+int** set_pawn(int y, int x, unsigned int type, unsigned int pawn_array[board_size][board_size]);
bool is_valid_input(int y, int x, 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_board_full(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]);
-int** set_pawn(int y, int x, unsigned int type, unsigned int pawn_array[board_size][board_size]);
unsigned int count_pawn_type(unsigned int pawn_array[board_size][board_size], unsigned int type);
mvprintw(y+25, x, " -----+----+----+----+----+----+----+-----");
}
+static void set_default_colors() {
+
+ init_pair(1, COLOR_WHITE, COLOR_BLACK);
+ attron(COLOR_PAIR(1));
+}
+
static void print_o(int y, int x, unsigned int type) {
if (type == black) {
mvprintw(y, x, "/\\");
mvprintw(y+1, x, "\\/");
/* reset to default */
- init_pair(1, COLOR_WHITE, COLOR_BLACK);
- attron(COLOR_PAIR(1));
+ set_default_colors();
}
/* will be used for pawn placement hints */
mvprintw(y, x, "\\/");
mvprintw(y+1, x,"/\\");
/* reset to default */
- init_pair(1, COLOR_WHITE, COLOR_BLACK);
- attron(COLOR_PAIR(1));
+ set_default_colors();
}
/* y = 1: y -> 0 x = 1: 1 -> 1
#include "debug.h"
int main() {
+ int min_y = 26, min_x = 42;
int row = 0, col = 0;
unsigned int round = 0;
unsigned int player = player_one; /* first player is black */
LIST_HEAD(shots_list);
- char* player_msg;
+ char* title_msg = "Jeu Othello";
+ char* score_white_msg = "Pions blancs: %d";
+ char* score_black_msg = "Pions noirs: %d";
+ char* player_msg = "Joueur %d joue !";
+ char* winner_msg = "Joueur %d gagne !";
+ char* draw_msg = "Egalite !";
unsigned int pawns[board_size][board_size] = {{}};
pawns[board_size][board_size] = init_pawns(pawns);
start_color();
getmaxyx(stdscr, row, col);
/* FIXME: fail if the screen size is too small */
- //noecho();
echo();
curs_set(0);
print_board(board_center_y, board_center_x);
print_pawns(board_center_y, board_center_x, pawns);
- char* title_msg = "Jeu Othello";
mvprintw(center_y - 26/2 - 4, (center_x - strlen(title_msg)/2), title_msg);
+ player = current_player(round);
+
+ mvprintw(center_y - 26/2 - 2, (center_x - strlen(player_msg)/2), player_msg, player);
+
nb_white = count_pawn_type(pawns, white);
nb_black = count_pawn_type(pawns, black);
- char* score_white_msg = "Pions blancs: %d";
mvprintw(center_y, center_x - 42/2 - strlen(score_white_msg) - 2, score_white_msg, nb_white);
- char* score_black_msg = "Pions noirs: %d";
mvprintw(center_y, center_x + 42/2 + 2, score_black_msg, nb_black);
- player = current_player(round);
-
- if (player == player_one) {
- player_msg = "Joueur un (noir) joue !";
- } else {
- player_msg = "Joueur deux (blanc) joue !";
- }
- mvprintw(center_y - 26/2 - 2, (center_x - strlen(player_msg)/2), player_msg);
-
int y;
char x;
bool input_ok = false;
refresh();
- if (is_board_full(pawns) || round == 60) {
- /* print the winnner and the restart possibility */
+ /* here are all the end of the game conditions */
+ //if (is_board_full(pawns) || round == 60) {
+ if (is_board_full(pawns)) {
+ int winner = eval_winner(nb_white, nb_black);
+ if (winner != 0) {
+ mvprintw(center_y - 26/2 - 2, (center_x - strlen(winner_msg)/2), winner_msg, winner);
+ } else {
+ mvprintw(center_y - 26/2 - 2, (center_x - strlen(draw_msg)/2), draw_msg);
+ }
+ /* print and implement restart possibility */
exit_condition = true;
}