Add draw function in model.c

This commit is contained in:
Yorick Barbanneau 2021-10-15 17:01:32 +02:00
parent f2bc1a2c12
commit 64c85567d9

View file

@ -313,3 +313,56 @@ void save_a_utictactoe_to_file(FILE *p_f, s_utictactoe *p_uttt){
}
}
}
void draw_ith_line_of_ttt(s_tictactoe *p_ttt, uint line) {
assert(p_ttt);
printf("%c%c%c", p_ttt->content[line * TICTACTOE_WIDTH],
p_ttt->content[line * TICTACTOE_WIDTH + 1],
p_ttt->content[line * TICTACTOE_WIDTH + 2]);
}
void draw_tictactoe(s_tictactoe *p_ttt) {
assert(p_ttt);
for (uint line = 0; line < TICTACTOE_WIDTH; line++) {
draw_ith_line_of_ttt(p_ttt, line);
printf("\n");
}
}
void draw_utictactoe_history(s_utictactoe *p_uttt) {
assert(p_uttt);
char *e_location_name[] = {"TL", "TC", "TR", "ML", "MC", "MR",
"BL", "BC", "BR", "FREE", "NONE"};
list_element_s_move *tmp = p_uttt->history;
while (tmp != NULL) {
if (tmp->last_move) {
printf(" - %s %s %c \n", e_location_name[tmp->last_move->inner_position],
e_location_name[tmp->last_move->outer_position],
tmp->last_move->player);
}
tmp = tmp->next;
}
}
void draw_utictactoe(s_utictactoe *p_uttt) {
assert(p_uttt);
if (p_uttt->inception_level == 1) {
draw_tictactoe(p_uttt->outer_tictactoe);
} else {
for (uint id_ttt = 0; id_ttt < TICTACTOE_SIZE;
id_ttt = id_ttt + TICTACTOE_WIDTH) {
for (uint line = 0; line < TICTACTOE_WIDTH; line++) {
draw_ith_line_of_ttt(p_uttt->inner_tictactoes[id_ttt], line);
printf("|");
draw_ith_line_of_ttt(p_uttt->inner_tictactoes[id_ttt + 1], line);
printf("|");
draw_ith_line_of_ttt(p_uttt->inner_tictactoes[id_ttt + 2], line);
printf("\n");
}
if (id_ttt + TICTACTOE_WIDTH < TICTACTOE_SIZE) {
printf("-----------");
printf("\n");
}
}
}
printf("\n####\n");
}