First commit with view

This commit is contained in:
Yorick Barbanneau 2021-10-15 17:26:48 +02:00
parent 64c85567d9
commit 8656f37eab
3 changed files with 26 additions and 14 deletions

View file

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5) 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 ".") set(CMAKE_INSTALL_PREFIX ".")
include_directories(include) include_directories(include)
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) #set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
project(utictactoe) 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)

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5) 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 ".") set(CMAKE_INSTALL_PREFIX ".")
include_directories(../include) include_directories(../include)
project(utictactoe) project(utictactoe)
add_executable(${PROJECT_NAME} utictactoe.c model.c) add_executable(${PROJECT_NAME} utictactoe.c model.c view.c)

View file

@ -8,6 +8,7 @@
#include "utictactoe.h" #include "utictactoe.h"
#include "common.h" #include "common.h"
#include "model.h" #include "model.h"
#include "view.h"
#define OPTIONAL_ARGUMENT_IS_PRESENT \ #define OPTIONAL_ARGUMENT_IS_PRESENT \
((optarg == NULL && optind < argc && argv[optind][0] != '-') \ ((optarg == NULL && optind < argc && argv[optind][0] != '-') \
@ -140,24 +141,35 @@ int main(int argc, char* argv[]) {
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
} }
FILE *f = fopen("save.txt", "w+"); s_utictactoe *s = create_empty_utictactoe(1);
s_utictactoe *s = create_empty_utictactoe(2); //replace by 2 for uttt play
s_move *m = create_empty_move(); 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) { while (s->outer_tictactoe->winner == NOBODY) {
draw_utictactoe(s);
m->player = get_next_player_to_play(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); play_move(s, m);
m->outer_position = m->inner_position;
} }
free_view(v);
draw_utictactoe(s); draw_utictactoe(s);
draw_utictactoe_history(s); draw_utictactoe_history(s);
save_a_utictactoe_to_file(f, s);
printf("The winner is : %c\n", s->outer_tictactoe->winner); printf("The winner is : %c\n", s->outer_tictactoe->winner);
free_move(m); free_move(m);
free_utictactoe(s); 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);
} }