From 64c85567d9996ec3007b325e714704dfdca0d0a7 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Fri, 15 Oct 2021 17:01:32 +0200 Subject: [PATCH] Add draw function in model.c --- src/model.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/model.c b/src/model.c index d7e5f1e..4650d36 100644 --- a/src/model.c +++ b/src/model.c @@ -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"); +}