From 8656f37eabbf0598c603dd017d7df9147c5fa869 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Fri, 15 Oct 2021 17:26:48 +0200 Subject: [PATCH] First commit with view --- CMakeLists.txt | 4 ++-- src/CMakeLists.txt | 4 ++-- src/utictactoe.c | 32 ++++++++++++++++++++++---------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1b6ce3..2c7ce5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.5) -set(CMAKE_C_FLAGS "-std=c99 -g -Wall") +set(CMAKE_C_FLAGS "-std=c99 -lncurses -g -Wall") set(CMAKE_INSTALL_PREFIX ".") include_directories(include) #set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) project(utictactoe) -add_executable(${PROJECT_NAME} src/utictactoe.c src/model.c) +add_executable(${PROJECT_NAME} src/utictactoe.c src/model.c src/view.c) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 80462b7..4812c33 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -set(CMAKE_C_FLAGS "-std=c99 -g -Wall") +set(CMAKE_C_FLAGS "-std=c99 -lncurses -g -Wall") set(CMAKE_INSTALL_PREFIX ".") include_directories(../include) project(utictactoe) -add_executable(${PROJECT_NAME} utictactoe.c model.c) +add_executable(${PROJECT_NAME} utictactoe.c model.c view.c) diff --git a/src/utictactoe.c b/src/utictactoe.c index e1c65be..74ee33a 100644 --- a/src/utictactoe.c +++ b/src/utictactoe.c @@ -8,6 +8,7 @@ #include "utictactoe.h" #include "common.h" #include "model.h" +#include "view.h" #define OPTIONAL_ARGUMENT_IS_PRESENT \ ((optarg == NULL && optind < argc && argv[optind][0] != '-') \ @@ -140,24 +141,35 @@ int main(int argc, char* argv[]) { exit (EXIT_FAILURE); } } - FILE *f = fopen("save.txt", "w+"); - s_utictactoe *s = create_empty_utictactoe(2); //replace by 2 for uttt play + s_utictactoe *s = create_empty_utictactoe(1); s_move *m = create_empty_move(); - m->outer_position = TOPLEFT + rand() % TICTACTOE_SIZE; + p_view v = create_view(s); while (s->outer_tictactoe->winner == NOBODY) { - draw_utictactoe(s); m->player = get_next_player_to_play(s); - m->inner_position = TOPLEFT + rand() % TICTACTOE_SIZE; + m->outer_position=get_next_outer_position(s); + set_next_player_move(m,v); play_move(s, m); - m->outer_position = m->inner_position; } + free_view(v); draw_utictactoe(s); draw_utictactoe_history(s); - save_a_utictactoe_to_file(f, s); printf("The winner is : %c\n", s->outer_tictactoe->winner); free_move(m); free_utictactoe(s); - fclose(f); - return EXIT_SUCCESS; - } + s = create_empty_utictactoe(2); + m = create_empty_move(); + v = create_view(s); + while (s->outer_tictactoe->winner == NOBODY) { + m->player = get_next_player_to_play(s); + m->outer_position=get_next_outer_position(s); + set_next_player_move(m,v); + play_move(s, m); + m->outer_position = m->inner_position; + } + free_view(v); + draw_utictactoe_history(s); + printf("The winner is : %c\n", s->outer_tictactoe->winner); + free_move(m); + free_utictactoe(s); +}