From 2a4d904c509759efacfe0ba7b06a7d8388160b3a Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Fri, 12 Nov 2021 02:21:01 +0100 Subject: [PATCH] started game_update_flags to finish on readme --- game_test_thoguet.c | 80 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 281d009..f9f59eb 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -5,9 +5,9 @@ #include #include "game.h" #include "game_aux.h" +typedef unsigned int uint; /* ********** DUMMY ********** */ - bool test_dummy(void){ return EXIT_SUCCESS; } @@ -49,11 +49,11 @@ bool test_game_restart(void){ bool test_game_new(void){ square tab[DEFAULT_SIZE*DEFAULT_SIZE]; game g; - int tab2[] = {0,1,2,8,9,10,11,12,13,16,32}; - for (int i = 0; i < 11; i ++){ + square list[] = {S_BLANK,S_LIGHTBULB,S_MARK,S_BLACK,S_BLACK0,S_BLACK,S_BLACK1,S_BLACK2,S_BLACK2,S_BLACK4,S_BLACKU,S_BLACKU,F_ERROR}; + for (uint i = 0; i < sizeof(list)/sizeof(list[0]) ; i ++){ g = NULL; - for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ - tab[j] = tab2[i]; + for (uint j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ + tab[j] = list[i]; } printf("%d\n",i); g = game_new(tab); @@ -70,11 +70,11 @@ bool test_game_new(void){ bool test_game_print(void){ game_print(NULL); square tab[DEFAULT_SIZE*DEFAULT_SIZE]; - int tab2[] = {0,1,2,8,9,10,11,12,13,16,32}; + square list[] = {S_BLANK,S_LIGHTBULB,S_MARK,S_BLACK,S_BLACK0,S_BLACK,S_BLACK1,S_BLACK2,S_BLACK2,S_BLACK4,S_BLACKU,S_BLACKU,F_ERROR}; game g; - for (int i = 0; i < 11; i ++){ - for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ - tab[j] = tab2[i]; + for (uint i = 0; i < sizeof(list)/sizeof(list[0]) ; i ++){ + for (uint j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ + tab[j] = list[i]; } printf("%d\n",i); g = game_new(tab); @@ -89,10 +89,10 @@ bool test_game_print(void){ bool test_game_get_square(void){ game g; square tab[DEFAULT_SIZE*DEFAULT_SIZE]; - int tab2[] = {0,1,2,8,9,10,11,12,13,16,32}; - for (int i = 0; i < 11; i ++){ - for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ - tab[j] = tab2[i]; + square list[] = {S_BLANK,S_LIGHTBULB,S_MARK,S_BLACK,S_BLACK0,S_BLACK,S_BLACK1,S_BLACK2,S_BLACK2,S_BLACK4,S_BLACKU,S_BLACKU,F_ERROR}; + for (uint i = 0; i < sizeof(list)/sizeof(list[0]) ; i ++){ + for (uint j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ + tab[j] = list[i]; g = game_new(tab); printf("[%d, %d] %d %d\n",j/(DEFAULT_SIZE),j-(j/(DEFAULT_SIZE))-(j/(DEFAULT_SIZE)*(DEFAULT_SIZE-1)),game_get_square(g,j/(DEFAULT_SIZE),j-(j/(DEFAULT_SIZE))-(j/(DEFAULT_SIZE)*(DEFAULT_SIZE-1))),tab[j]); assert(game_get_square(g,j/(DEFAULT_SIZE),j-(j/(DEFAULT_SIZE))-(j/(DEFAULT_SIZE)*(DEFAULT_SIZE-1))) == tab[j]); @@ -124,7 +124,6 @@ bool test_game_default(void){ bool test_game_default_solution(void){ game g = game_default_solution(); - //a verif aps sur assert(g); //default assert(game_get_square(g,0,2) == S_BLACK1); @@ -150,6 +149,57 @@ bool test_game_default_solution(void){ return EXIT_SUCCESS; } +/* **** game_update_flags **** */ + +bool test_game_update_flags(void){ + game g = game_new_empty(); + game_update_flags(g); + for (int i = 0; i < DEFAULT_SIZE; i++){ + + } + return EXIT_SUCCESS; +} + +bool check_update(game g){ + game tab_bulb[DEFAULT_SIZE*DEFAULT_SIZE]; + for (uint i = 0; i < DEFAULT_SIZE; i++){ + for (uint j = 0; j< DEFAULT_SIZE; j++){ + square state = game_get_state(g,i,j); + if (/*test if the current case is a lightbulb*/(state == S_LIGHTBULB) || (state == (S_LIGHTBULB|F_ERROR)) | (state == (S_LIGHTBULB|F_LIGHTED)) | (state == (S_LIGHTBULB|F_ERROR|F_LIGHTED))){ + bool wall = false; + //loop checking every case before i + for (int k = i-1; k > 0; k--){ + square state2 = game_get_state(g,k,j); + if (/*test if current case is a wall*/state2 == S_BLACK0 || state2 == (S_BLACK0|F_ERROR) || state2 == S_BLACK1 || state2 == (S_BLACK1|F_ERROR) || state2 == S_BLACK2 || state2 == (S_BLACK2|F_ERROR) || state2 == S_BLACK3 || state2 == (S_BLACK3|F_ERROR) || state2 == S_BLACK4 || state2 == (S_BLACK4|F_ERROR) || state2 == S_BLACKU || state2 == (S_BLACKU|F_ERROR)){ + wall = true; + } + //if no wall(s) before test if the light of the lightbulb has been well updated + else if (!wall){ + //test if the current case is a lightbulb and if it has been well updated if true we can break the loop because every others cases wont be lighted by the bulb we are testing + if (state2 == (S_LIGHTBULB|F_ERROR|F_LIGHTED)){ + break; + } + if ((state2 == S_LIGHTBULB) || (state2 == (S_LIGHTBULB|F_ERROR)) | (state2 == (S_LIGHTBULB|F_LIGHTED))){ + return false; + } + //test if the current case isn't lighted or ... if not the lightbulb isn't well updated + if (/*test if current case isn't lighted*/!(state2 == F_LIGHTED || /*or isn't a mark*/!((state2 == S_MARK) || (state2 == (S_MARK|F_ERROR)) | (state2 == (S_MARK|F_LIGHTED))))){ + + return false; + } + } + else{ + + if (/*test if the current case is lighted*/state2 == F_LIGHTED || state2 == (F_LIGHTED|S_MARK) || (state2 == (S_LIGHTBULB|F_ERROR)) | state2 == (S_LIGHTBULB|F_LIGHTED) | state2 == (S_LIGHTBULB|F_ERROR|F_LIGHTED)){ + return false; + } + } + } + } + } + } +} + /* ********** USAGE ********** */ int usage(int argc, char *argv[]) @@ -182,6 +232,8 @@ int main(int argc, char * argv[]){ ok = test_game_get_square(); else if (strcmp("game_is_over", argv[1]) == 0) ok = test_game_is_over(); + else if (strcmp("game_update_flags", argv[1]) == 0) + ok = test_game_update_flags(); else { fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); exit(EXIT_FAILURE);