11 int min_y
= 26 + 6, min_x
= 42 + 14 + 15 + 4;
13 unsigned int round
= 0;
14 unsigned int player
= player_one
; /* first player is black */
15 bool exit_condition
= false;
16 unsigned int nb_white
= 0, nb_black
= 0;
18 char* title_msg
= "Jeu Othello";
19 char* score_msg
= "Pions %s: %d";
20 char* invalid_move_msg
= "Coup invalide";
21 char* player_msg
= "Joueur %d (%s) joue !";
22 char* winner_msg
= "Joueur %d (%s) gagne !";
23 char* draw_msg
= "Egalite !";
24 char* exit_msg
= "Pressez une touche pour sortir ou \'r\' pour rejouer";
26 /* linked list of the history shots */
27 //struct shots_history_list_s shots_history;
28 //INIT_LIST_HEAD(&shots_history.list);
29 /* linked list of black playable shots */
30 struct shots_list_s black_playable_shots
;
31 INIT_LIST_HEAD(&black_playable_shots
.list
);
32 /* linked list of white playable shots */
33 struct shots_list_s white_playable_shots
;
34 INIT_LIST_HEAD(&white_playable_shots
.list
);
36 unsigned int pawns
[board_size
][board_size
] = {
43 if (has_colors() == false) {
45 printf("Votre terminal ne supporte pas les couleurs.\n");
49 getmaxyx(stdscr
, row
, col
);
50 if (row
< min_y
|| col
< min_x
) {
52 printf("Votre terminal est trop petit pour afficher ce jeu.\n");
53 printf("Merci d'agrandir la fenetre de votre terminal.\n");
62 /* base coordinates to center the board */
63 int board_center_y
= center_y
- 26/2;
64 int board_center_x
= center_x
- 42/2;
67 print_board(board_center_y
, board_center_x
);
68 print_pawns(board_center_y
, board_center_x
, pawns
);
70 mvprintw(center_y
- 26/2 - 4, (center_x
- strlen(title_msg
)/2), title_msg
);
72 player
= current_player(round
);
74 if (player
== player_one
) {
75 mvprintw(center_y
- 26/2 - 2, center_x
- snprintf(NULL
, 0, player_msg
, player
, "noir")/2, player_msg
, player
, "noir");
77 mvprintw(center_y
- 26/2 - 2, center_x
- snprintf(NULL
, 0, player_msg
, player
, "blanc")/2, player_msg
, player
, "blanc");
80 nb_white
= count_pawns_type(pawns
, white
);
81 nb_black
= count_pawns_type(pawns
, black
);
83 mvprintw(center_y
, center_x
- 42/2 - snprintf(NULL
, 0, score_msg
, "noirs", nb_black
) - 2, score_msg
, "noirs", nb_black
);
84 mvprintw(center_y
, center_x
+ 42/2 + 2, score_msg
, "blancs", nb_white
);
86 //display_array(1, 1, pawns);
90 bool input_ok
= false;
91 unsigned int nb_pawns_reversed
= 0;
95 char* prompt_msg
= "Prochain pion ? (ligne colonne - chiffre lettre):";
96 int prmt_rt
= prompt_values(stdscr
, center_y
+ 26/2 + 1, (center_x
- strlen(prompt_msg
)/2), prompt_msg
, &y
, &x_char
);
97 int x
= map_col_letter_to_index(x_char
);
98 nb_pawns_reversed
= valid_shot(y
, x
, player
, pawns
);
99 if (nb_pawns_reversed
> 0 && prmt_rt
== 1) {
103 mvprintw(center_y
+ 26/2 + 4, (center_x
- strlen(invalid_move_msg
)/2), invalid_move_msg
);
107 round
++; /* increment the round count */
109 /* here are all the end of the game conditions */
110 if (is_board_full(pawns
)) {
111 print_board(board_center_y
, board_center_x
);
112 /* print the updated pawns before exiting */
113 print_pawns(board_center_y
, board_center_x
, pawns
);
114 unsigned int winner
= eval_winner(nb_white
, nb_black
);
116 if (winner
== player_one
) {
117 mvprintw(center_y
- 26/2 - 2, center_x
- snprintf(NULL
, 0, winner_msg
, winner
, "noir")/2, winner_msg
, winner
, "noir");
119 mvprintw(center_y
- 26/2 - 2, center_x
- snprintf(NULL
, 0, winner_msg
, winner
, "blanc")/2, winner_msg
, winner
, "blanc");
122 mvprintw(center_y
- 26/2 - 2, (center_x
- strlen(draw_msg
)/2), draw_msg
);
124 mvprintw(center_y
+ 26/2 + 1, (center_x
- strlen(exit_msg
)/2), exit_msg
);
125 exit_condition
= true;
126 /* getch() is blocking */
127 int key_exit
= getch();
128 if (key_exit
== 'r') {
131 nb_white
= nb_black
= 0;
132 /* FIXME: do not seem properly reset the pawns 2D array */
134 exit_condition
= false;
141 } while (!exit_condition
);