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 unsigned int pawns
[board_size
][board_size
] = {{}};
25 pawns
[board_size
][board_size
] = init_pawns(pawns
);
28 if (has_colors() == false) {
30 printf("Votre terminal ne supporte pas les couleurs.\n");
34 getmaxyx(stdscr
, row
, col
);
35 if (row
< min_y
|| col
< min_x
) {
37 printf("Votre terminal est trop petit pour afficher le jeu.\n");
38 printf("Merci d'agrandir la fenetre de votre terminal.\n");
41 /* FIXME: fail if the screen size is too small */
48 /* base coordinates to center the board */
49 int board_center_y
= center_y
- 26/2;
50 int board_center_x
= center_x
- 42/2;
53 print_board(board_center_y
, board_center_x
);
54 print_pawns(board_center_y
, board_center_x
, pawns
);
56 mvprintw(center_y
- 26/2 - 4, (center_x
- strlen(title_msg
)/2), title_msg
);
58 player
= current_player(round
);
60 if (player
== player_one
) {
61 mvprintw(center_y
- 26/2 - 2, center_x
- snprintf(NULL
, 0, player_msg
, player
, "noir")/2, player_msg
, player
, "noir");
63 mvprintw(center_y
- 26/2 - 2, center_x
- snprintf(NULL
, 0, player_msg
, player
, "blanc")/2, player_msg
, player
, "blanc");
66 nb_white
= count_pawn_type(pawns
, white
);
67 nb_black
= count_pawn_type(pawns
, black
);
69 mvprintw(center_y
, center_x
- 42/2 - snprintf(NULL
, 0, score_msg
, "noirs", nb_black
) - 2, score_msg
, "noirs", nb_black
);
70 mvprintw(center_y
, center_x
+ 42/2 + 2, score_msg
, "blancs", nb_white
);
74 bool input_ok
= false;
78 char* prompt_msg
= "Prochain pion ? (ligne colonne - chiffre lettre):";
79 int prmt_rt
= prompt_values(stdscr
, center_y
+ 26/2 + 1, center_x
- strlen(prompt_msg
)/2, prompt_msg
, &y
, &x
);
80 if (is_valid_input(y
, map_col_letter_to_index(x
), pawns
) && prmt_rt
== 1) {
84 pawns
[board_size
][board_size
] = set_pawn(y
, map_col_letter_to_index(x
), player
, pawns
);
85 struct shots_history_list_s shots_history
;
86 INIT_LIST_HEAD(&shots_history
.list
);
87 struct shots_history_list_s shots_elmt
;
88 shots_elmt
.pawn_array_member
= &pawns
[y
-1][x
-1];
89 list_add(&shots_elmt
.list
, &shots_history
.list
);
91 round
++; /* increment the round count */
95 /* here are all the end of the game conditions */
96 //if (is_board_full(pawns) || (round == 60)) {
97 if (is_board_full(pawns
)) {
98 int winner
= eval_winner(nb_white
, nb_black
);
100 if (winner
== player_one
) {
101 mvprintw(center_y
- 26/2 - 2, center_x
- snprintf(NULL
, 0, winner_msg
, winner
, "noir"), winner_msg
, winner
, "noir");
103 mvprintw(center_y
- 26/2 - 2, center_x
- snprintf(NULL
, 0, winner_msg
, winner
, "blanc"), winner_msg
, winner
, "blanc");
106 mvprintw(center_y
- 26/2 - 2, (center_x
- strlen(draw_msg
)/2), draw_msg
);
108 /* print and implement restart possibility */
109 exit_condition
= true;
112 } while (!exit_condition
);