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* player_msg
= "Joueur %d (%s) joue !";
21 char* winner_msg
= "Joueur %d (%s) gagne !";
22 char* draw_msg
= "Egalite !";
24 /* linked list of the history shots */
25 //struct shots_history_list_s shots_history;
26 //INIT_LIST_HEAD(&shots_history.list);
27 /* linked list of black playable shots */
28 struct shots_list_s black_playable_shots
;
29 INIT_LIST_HEAD(&black_playable_shots
.list
);
30 /* linked list of white playable shots */
31 struct shots_list_s white_playable_shots
;
32 INIT_LIST_HEAD(&white_playable_shots
.list
);
34 unsigned int pawns
[board_size
][board_size
] = {
41 if (has_colors() == false) {
43 printf("Votre terminal ne supporte pas les couleurs.\n");
47 getmaxyx(stdscr
, row
, col
);
48 if (row
< min_y
|| col
< min_x
) {
50 printf("Votre terminal est trop petit pour afficher ce jeu.\n");
51 printf("Merci d'agrandir la fenetre de votre terminal.\n");
60 /* base coordinates to center the board */
61 int board_center_y
= center_y
- 26/2;
62 int board_center_x
= center_x
- 42/2;
65 print_board(board_center_y
, board_center_x
);
66 print_pawns(board_center_y
, board_center_x
, pawns
);
68 mvprintw(center_y
- 26/2 - 4, (center_x
- strlen(title_msg
)/2), title_msg
);
70 player
= current_player(round
);
72 if (player
== player_one
) {
73 mvprintw(center_y
- 26/2 - 2, center_x
- snprintf(NULL
, 0, player_msg
, player
, "noir")/2, player_msg
, player
, "noir");
75 mvprintw(center_y
- 26/2 - 2, center_x
- snprintf(NULL
, 0, player_msg
, player
, "blanc")/2, player_msg
, player
, "blanc");
78 nb_white
= count_pawns_type(pawns
, white
);
79 nb_black
= count_pawns_type(pawns
, black
);
81 mvprintw(center_y
, center_x
- 42/2 - snprintf(NULL
, 0, score_msg
, "noirs", nb_black
) - 2, score_msg
, "noirs", nb_black
);
82 mvprintw(center_y
, center_x
+ 42/2 + 2, score_msg
, "blancs", nb_white
);
84 display_array(1, 1, pawns
);
88 bool input_ok
= false;
92 char* prompt_msg
= "Prochain pion ? (ligne colonne - chiffre lettre):";
93 int prmt_rt
= prompt_values(stdscr
, center_y
+ 26/2 + 1, center_x
- strlen(prompt_msg
)/2, prompt_msg
, &y
, &x_char
);
94 int x
= map_col_letter_to_index(x_char
);
95 if (valid_shot(y
, x
, player
, pawns
) > 0 && prmt_rt
== 1) {
100 round
++; /* increment the round count */
102 /* here are all the end of the game conditions */
103 if (is_board_full(pawns
)) {
104 unsigned int winner
= eval_winner(nb_white
, nb_black
);
106 if (winner
== player_one
) {
107 mvprintw(center_y
- 26/2 - 2, center_x
- snprintf(NULL
, 0, winner_msg
, winner
, "noir"), winner_msg
, winner
, "noir");
109 mvprintw(center_y
- 26/2 - 2, center_x
- snprintf(NULL
, 0, winner_msg
, winner
, "blanc"), winner_msg
, winner
, "blanc");
112 mvprintw(center_y
- 26/2 - 2, (center_x
- strlen(draw_msg
)/2), draw_msg
);
114 /* print and implement restart possibility */
115 exit_condition
= true;
120 } while (!exit_condition
);