From 255f0e2fafcc5a93f45ad39f1645aac71731bdff Mon Sep 17 00:00:00 2001 From: Aurelien Esnard Date: Wed, 13 Oct 2021 00:12:56 +0200 Subject: [PATCH 001/281] Initial commit --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b853a8e --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# lightup-a42e + From 2bd4cee4abe0241f9e31853fade6bc8bb74bc30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 14 Oct 2021 10:26:47 +0200 Subject: [PATCH 002/281] initial commit --- Makefile | 25 +++++ game.h | 314 ++++++++++++++++++++++++++++++++++++++++++++++++++++ game.o | Bin 0 -> 29736 bytes game_aux.c | 96 ++++++++++++++++ game_aux.h | 38 +++++++ game_text.c | 103 +++++++++++++++++ 6 files changed, 576 insertions(+) create mode 100644 Makefile create mode 100644 game.h create mode 100644 game.o create mode 100644 game_aux.c create mode 100644 game_aux.h create mode 100644 game_text.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b909c8c --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +CC=gcc # compilateur +CFLAGS=-Wall -std=c99 # options de compilation +LDFLAGS=-L. # options de link +LDLIBS=-lgame # bibliothèques +CPPFLAGS= # options de preprocessing +AR= ar + +all: game_text + +libgame.a: game_aux.o game.o + $(AR) rcs $@ $^ + +game_text: game_text.o libgame.a + $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) + +.PHONY: clean dep + +include dep + +# génération des dépendances +dep: + $(CC) -MM *.c > dep + +clean: + rm -f dep game_aux.o *~ game_text game_text.o libgame.a \ No newline at end of file diff --git a/game.h b/game.h new file mode 100644 index 0000000..309b6fe --- /dev/null +++ b/game.h @@ -0,0 +1,314 @@ +/** + * @file game.h + * @brief Basic Game Functions. + * @details See @ref index for further details. + * @copyright University of Bordeaux. All rights reserved, 2021. + **/ + +#ifndef __GAME_H__ +#define __GAME_H__ +#include + +/** + * @brief Standard unsigned integer type. + **/ +typedef unsigned int uint; + +/** + * @brief Size of the default game grid. + **/ +#define DEFAULT_SIZE 7 + +/** + * @brief Different squares used in the game. + * @details The value of a square is an integer represented on one byte, with a + * low-order half-byte that codes for the square state (blank, black wall, light + * bulb or mark) and a high-order half-byte that codes for the additionnal + * square flags (lighted or error). While each square has a single state, it can + * have zero, one or several flags (combined with bitwise operations). For + * instance, a light bulb can have both the lighted and error flags. In this + * case, the raw square value is S_LIGHTBULB | F_LIGHTED | F_ERROR, using the + * bitwise OR operator (|). For more details on bitwise operations, see + * https://en.wikipedia.org/wiki/Bitwise_operations_in_C. + **/ +typedef enum { + /* states */ + S_BLANK = 0, /**< a blank square */ + S_LIGHTBULB = 1, /**< a light bulb */ + S_MARK = 2, /**< a marked square (as not-a-light) */ + S_BLACK = 8, /**< black wall base code */ + S_BLACK0 = S_BLACK, /**< a numbered black wall (with 0 adjacent lights) */ + S_BLACK1, /**< a numbered black wall (with 1 adjacent light) */ + S_BLACK2, /**< a numbered black wall (with 2 adjacent lights) */ + S_BLACK3, /**< a numbered black wall (with 3 adjacent lights) */ + S_BLACK4, /**< a numbered black wall (with 4 adjacent lights) */ + S_BLACKU, /**< an unnumbered black wall (any number of adjacent lights) */ + /* flags */ + F_LIGHTED = 16, /**< lighted flag */ + F_ERROR = 32 /**< error flag */ +} square; + +/** state mask used in square enum */ +#define S_MASK 0x0F + +/** flag mask used in square enum */ +#define F_MASK 0xF0 + +/** square mask used in square enum */ +#define A_MASK 0xFF + +/** + * @brief The structure pointer that stores the game state. + **/ +typedef struct game_s *game; + +/** + * @brief The structure constant pointer that stores the game state. + * @details That means that it is not possible to modify the game using this + * pointer. + **/ +typedef const struct game_s *cgame; + +/** + * @brief Creates a new game with default size and initializes it. + * @param squares an array describing the initial square values (row-major + * storage) + * @pre @p squares must be an initialized array of default size squared. + * @return the created game + **/ +game game_new(square *squares); + +/** + * @brief Creates a new empty game with defaut size. + * @details All squares are initialized with blank squares. + * @return the created game + **/ +game game_new_empty(void); + +/** + * @brief Duplicates a game. + * @param g the game to copy + * @return the copy of the game + * @pre @p g must be a valid pointer toward a game structure. + **/ +game game_copy(cgame g); + +/** + * @brief Tests if two games are equal (same states and same flags). + * @param g1 the first game + * @param g2 the second game + * @return true if the two games are equal, false otherwise + * @pre @p g1 must be a valid pointer toward a game structure. + * @pre @p g2 must be a valid pointer toward a game structure. + **/ +bool game_equal(cgame g1, cgame g2); + +/** + * @brief Deletes the game and frees the allocated memory. + * @param g the game to delete + * @pre @p g must be a valid pointer toward a game structure. + **/ +void game_delete(game g); + +/** + * @brief Sets the value of a given square. + * @details This function is useful for initializing the squares of an empty + * game. + * @param g the game + * @param i row index + * @param j column index + * @param s the square value + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @pre @p s must be a valid square value. + **/ +void game_set_square(game g, uint i, uint j, square s); + +/** + * @brief Gets the raw value of a given square. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return the square value + **/ +square game_get_square(cgame g, uint i, uint j); + +/** + * @brief Gets the state of a given square. + * @details See description of enum square. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return the square state + **/ +square game_get_state(cgame g, uint i, uint j); + +/** + * @brief Gets the flags of a given square. + * @details See description of enum square. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return the square flags + **/ +square game_get_flags(cgame g, uint i, uint j); + +/** + * @brief Test if a given square is blank. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return true if the square is blank + **/ +bool game_is_blank(cgame g, uint i, uint j); + +/** + * @brief Test if a given square is a lightbulb. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return true if the square is a lightbulb + **/ +bool game_is_lightbulb(cgame g, uint i, uint j); + +/** + * @brief Test if a given square is black (whether or not it is numbered). + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return true if the square is black + **/ +bool game_is_black(cgame g, uint i, uint j); + +/** + * @brief Get the number of lightbulbs expected against a black wall. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return the back wall number, or -1 if it is unumbered + **/ +int game_get_black_number(cgame g, uint i, uint j); + +/** + * @brief Test if a given square is marked (as not-a-light). + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return true if the square is marked + **/ +bool game_is_marked(cgame g, uint i, uint j); + +/** + * @brief Test if a given square is lighted. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return true if the square is lighted + **/ +bool game_is_lighted(cgame g, uint i, uint j); + +/** + * @brief Test if a given square has an error flag + * @details An error can only occur on an numbered black wall or on a light + * bulb. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return true if the square has an error flag + **/ +bool game_has_error(cgame g, uint i, uint j); + + +/** + * @brief Checks if a given move is legal. + * @details This function checks that it is possible to play a move at a given + * position in the grid. More precisely, a move is said to be legal: 1) if the + * coordinates (i,j) are inside the grid, 2) if @p s is either a blank, light + * bulb or mark square, and 3) if the current square at (i,j) is not a black + * square. + * @param g the game + * @param i row index + * @param j column index + * @param s the square value + * @pre @p g must be a valid pointer toward a game structure. + * @return false if the move is not legal. + **/ +bool game_check_move(cgame g, uint i, uint j, square s); + +/** + * @brief Plays a move in a given square. + * @details The grid flags are updated consequently after each move. + * @param g the game + * @param i row index + * @param j column index + * @param s the square value + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @pre @p s must be either BLANK, LIGHTBULB or MARK. + * @pre The game square at position (i,j) must not be a black square. + **/ +void game_play_move(game g, uint i, uint j, square s); + +/** + * @brief Update all grid flags. + * @details This is a low-level function, which is not intended to be used + * directly by end-user during the game. + * @param g the game + * @pre @p g must be a valid pointer toward a game structure. + **/ +void game_update_flags(game g); + +/** + * @brief Checks if the game is won. + * @param g the game + * @details This function checks that all the game rules (decribed on @ref + * index) are satisfied, ie. that all the blank squares are ligthed, without any + * errors. + * @return true if the game ended successfully, false otherwise + * @pre @p g must be a valid pointer toward a game structure. + **/ +bool game_is_over(cgame g); + +/** + * @brief Restarts a game. + * @details All the game is reset to its initial state. In particular, all the + * squares except black walls are reset to blank, and all flags are cleared. + * @param g the game + * @pre @p g must be a valid pointer toward a game structure. + **/ +void game_restart(game g); + +#endif // __GAME_H__ diff --git a/game.o b/game.o new file mode 100644 index 0000000000000000000000000000000000000000..413f9e04cc563de9be3d61b6b49bf985cbc1531e GIT binary patch literal 29736 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 literal 0 HcmV?d00001 diff --git a/game_aux.c b/game_aux.c new file mode 100644 index 0000000..37d2375 --- /dev/null +++ b/game_aux.c @@ -0,0 +1,96 @@ +#ifndef __GAME_AUX_H__ +#define __GAME_AUX_H__ +#include +#include +#include "game.h" + +int charPrintCell(square sqState){ + if (sqState == S_BLANK){ + return ' '; + } + if ((sqState == S_LIGHTBULB) || (sqState == (S_LIGHTBULB|F_ERROR)) | (sqState == (S_LIGHTBULB|F_LIGHTED)) | (sqState == (S_LIGHTBULB|F_ERROR|F_LIGHTED))){ + return '*'; + } + if ((sqState == S_MARK) || (sqState == (S_MARK|F_ERROR)) | (sqState == (S_MARK|F_LIGHTED))){ + return '-'; + } + if (sqState == S_BLACK0 || sqState == (S_BLACK0|F_ERROR)){ + return '0'; + } + if (sqState == S_BLACK1 || sqState == (S_BLACK1|F_ERROR)){ + return '1'; + } + if (sqState == S_BLACK2 || sqState == (S_BLACK2|F_ERROR)){ + return '2'; + } + if (sqState == S_BLACK3 || sqState == (S_BLACK3|F_ERROR)){ + return '3'; + } + if (sqState == S_BLACK4 || sqState == (S_BLACK4|F_ERROR)){ + return '4'; + } + if (sqState == S_BLACKU || sqState == (S_BLACKU|F_ERROR)){ + return 'w'; + } + if (sqState == F_LIGHTED){ + return '.'; + } + return -1; +} + +void game_print(cgame g){ + if (g != NULL){ + uint i; + printf(" 0"); + for (i = 1; i < DEFAULT_SIZE; i++){ + printf("%u",i); + } + printf("\n -"); + for (i = 1; i < DEFAULT_SIZE; i++){ + printf("-"); + } + printf("\n"); + for (i = 0; i < DEFAULT_SIZE; i++){ + printf("%u |",i); + for (uint j = 0; j < DEFAULT_SIZE; j++){ + printf("%c",charPrintCell(game_get_square(g,i,j))); + } + printf("|\n"); + } + printf(" -"); + for (i = 1; i < DEFAULT_SIZE; i++){ + printf("-"); + } + printf("\n"); + } +} +game game_default(void){ + game g = game_new_empty(); + game_set_square(g,0,2,S_BLACK1); + game_set_square(g,1,2,S_BLACK2); + game_set_square(g,2,5,S_BLACKU); + game_set_square(g,2,6,S_BLACK2); + game_set_square(g,4,0,S_BLACK1); + game_set_square(g,4,1,S_BLACKU); + game_set_square(g,5,4,S_BLACK2); + game_set_square(g,6,4,S_BLACKU); + return g; +} + +game game_default_solution(void){ + game g = game_default(); + game_set_square(g,0,0,S_LIGHTBULB); + game_set_square(g,1,1,S_LIGHTBULB); + game_set_square(g,0,3,S_LIGHTBULB); + game_set_square(g,1,6,S_LIGHTBULB); + game_set_square(g,2,2,S_LIGHTBULB); + game_set_square(g,3,6,S_LIGHTBULB); + game_set_square(g,4,4,S_LIGHTBULB); + game_set_square(g,5,0,S_LIGHTBULB); + game_set_square(g,5,5,S_LIGHTBULB); + game_set_square(g,6,1,S_LIGHTBULB); + game_update_flags(g); + return g; +} + +#endif \ No newline at end of file diff --git a/game_aux.h b/game_aux.h new file mode 100644 index 0000000..294f997 --- /dev/null +++ b/game_aux.h @@ -0,0 +1,38 @@ +/** + * @file game_aux.h + * @brief Auxiliarry Game Functions. + * @details See @ref index for further details. + * @copyright University of Bordeaux. All rights reserved, 2021. + **/ + +#ifndef __GAME_AUX_H__ +#define __GAME_AUX_H__ +#include +#include "game.h" + +/** + * @brief Prints a game as text on the standard output stream. + * @details The different squares are respectively displayed as text, based on a + * square-character mapping table, as described in @ref index. + * @param g the game + * @pre @p g must be a valid pointer toward a game structure. + **/ +void game_print(cgame g); + +/** + * @brief Creates the default game. + * @details See the description of the default game in @ref index. + * @details https://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/lightup.html#7x7:b1f2iB2g1Bi2fBb + * @return the created game + **/ +game game_default(void); + +/** + * @brief Creates the default game solution. + * @details See the description of the default game in @ref index. + * @details https://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/lightup.html#7x7:b1f2iB2g1Bi2fBb + * @return the created game + **/ +game game_default_solution(void); + +#endif // __GAME_AUX_H__ diff --git a/game_text.c b/game_text.c new file mode 100644 index 0000000..f4c555a --- /dev/null +++ b/game_text.c @@ -0,0 +1,103 @@ +#include +#include +#include +#include "game.h" +#include "game_aux.h" + +bool checkerr(game g, char taberr[]){ + if (taberr == NULL || g == NULL){ + return -1; + } + uint err = 0; + taberr[0] = '\0'; + for (int i=0; i < DEFAULT_SIZE; i++){ + for (int j=0;j < DEFAULT_SIZE; j++){ + //check each case + if (game_has_error(g,i,j)){ + // if error append taberr with coo+, + taberr[err] = i+48; + err++; + taberr[err] = ':'; + err++; + taberr[err] = j+48; + err++; + taberr[err] = ' '; + err++; + } + } + } + // if taberr changes print + if (taberr[0] != '\0'){ + taberr[err] = '\0'; + return true; + } + return false; +} + +void printhelp(void){ + printf("Liste des différentes commandes :\n"); + printf("h : Affiche cette aide.\n"); + printf("r : Réinitialise la partie.\n"); + printf("q : Quitter la partie (abandon).\n"); + printf("l : Place une ampoule (*light bulb*) dans la case (,).\n"); + printf("m : Place une marque (*mark*) dans la case (,).\n"); + printf("b : Place placer une case vide (*blank*) à la position (,).\n"); +} + +int main(void) { + // Create new game + game g = game_default(); + // test if game is over + uint i; + uint j; + char taberr[DEFAULT_SIZE*DEFAULT_SIZE*4]; + char c; + // print game + game_print(g); + while (!game_is_over(g)){ + // print errors + if (checkerr(g,taberr)){ + printf("Il y a un problème case: %s\n",taberr); + } + printf("Entrez une commande (h pour afficher l'aide): "); + if (scanf(" %c",&c)){ + if (c == 'h'){ + printhelp(); + }else if (c == 'r'){ + game_restart(g); + printf("Partie réinitialisé avec success !\n"); + game_update_flags(g); + game_print(g); + }else if (c == 'q'){ + printf("shame\n"); + return EXIT_SUCCESS; + }else if (c == 'l' || c == 'm' || c == 'b'){ + if (scanf(" %u %u",&i,&j) == 2){ + if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && !game_is_black(g,i,j)){ + if (c == 'l'){ + game_set_square(g,i,j,S_LIGHTBULB); + game_update_flags(g); + game_print(g); + }else if (c == 'm'){ + game_set_square(g,i,j,S_MARK); + game_update_flags(g); + game_print(g); + }else if (c == 'b') { + game_set_square(g,i,j,S_BLANK); + game_update_flags(g); + game_print(g); + } + }else { + printf("Erreur: (,) invalide.\n"); + } + }else { + printf("Commande inconnue.\n"); + } + }else{ + printf("Commande inconnue.\n"); + } + } + } + printf("congratulation\n"); + return EXIT_SUCCESS; +} \ No newline at end of file From 7f8ec43912d063041df35bd923be2531966a085e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 14 Oct 2021 10:54:32 +0200 Subject: [PATCH 003/281] remove game.* --- game.h | 314 --------------------------------------------------------- game.o | Bin 29736 -> 0 bytes 2 files changed, 314 deletions(-) delete mode 100644 game.h delete mode 100644 game.o diff --git a/game.h b/game.h deleted file mode 100644 index 309b6fe..0000000 --- a/game.h +++ /dev/null @@ -1,314 +0,0 @@ -/** - * @file game.h - * @brief Basic Game Functions. - * @details See @ref index for further details. - * @copyright University of Bordeaux. All rights reserved, 2021. - **/ - -#ifndef __GAME_H__ -#define __GAME_H__ -#include - -/** - * @brief Standard unsigned integer type. - **/ -typedef unsigned int uint; - -/** - * @brief Size of the default game grid. - **/ -#define DEFAULT_SIZE 7 - -/** - * @brief Different squares used in the game. - * @details The value of a square is an integer represented on one byte, with a - * low-order half-byte that codes for the square state (blank, black wall, light - * bulb or mark) and a high-order half-byte that codes for the additionnal - * square flags (lighted or error). While each square has a single state, it can - * have zero, one or several flags (combined with bitwise operations). For - * instance, a light bulb can have both the lighted and error flags. In this - * case, the raw square value is S_LIGHTBULB | F_LIGHTED | F_ERROR, using the - * bitwise OR operator (|). For more details on bitwise operations, see - * https://en.wikipedia.org/wiki/Bitwise_operations_in_C. - **/ -typedef enum { - /* states */ - S_BLANK = 0, /**< a blank square */ - S_LIGHTBULB = 1, /**< a light bulb */ - S_MARK = 2, /**< a marked square (as not-a-light) */ - S_BLACK = 8, /**< black wall base code */ - S_BLACK0 = S_BLACK, /**< a numbered black wall (with 0 adjacent lights) */ - S_BLACK1, /**< a numbered black wall (with 1 adjacent light) */ - S_BLACK2, /**< a numbered black wall (with 2 adjacent lights) */ - S_BLACK3, /**< a numbered black wall (with 3 adjacent lights) */ - S_BLACK4, /**< a numbered black wall (with 4 adjacent lights) */ - S_BLACKU, /**< an unnumbered black wall (any number of adjacent lights) */ - /* flags */ - F_LIGHTED = 16, /**< lighted flag */ - F_ERROR = 32 /**< error flag */ -} square; - -/** state mask used in square enum */ -#define S_MASK 0x0F - -/** flag mask used in square enum */ -#define F_MASK 0xF0 - -/** square mask used in square enum */ -#define A_MASK 0xFF - -/** - * @brief The structure pointer that stores the game state. - **/ -typedef struct game_s *game; - -/** - * @brief The structure constant pointer that stores the game state. - * @details That means that it is not possible to modify the game using this - * pointer. - **/ -typedef const struct game_s *cgame; - -/** - * @brief Creates a new game with default size and initializes it. - * @param squares an array describing the initial square values (row-major - * storage) - * @pre @p squares must be an initialized array of default size squared. - * @return the created game - **/ -game game_new(square *squares); - -/** - * @brief Creates a new empty game with defaut size. - * @details All squares are initialized with blank squares. - * @return the created game - **/ -game game_new_empty(void); - -/** - * @brief Duplicates a game. - * @param g the game to copy - * @return the copy of the game - * @pre @p g must be a valid pointer toward a game structure. - **/ -game game_copy(cgame g); - -/** - * @brief Tests if two games are equal (same states and same flags). - * @param g1 the first game - * @param g2 the second game - * @return true if the two games are equal, false otherwise - * @pre @p g1 must be a valid pointer toward a game structure. - * @pre @p g2 must be a valid pointer toward a game structure. - **/ -bool game_equal(cgame g1, cgame g2); - -/** - * @brief Deletes the game and frees the allocated memory. - * @param g the game to delete - * @pre @p g must be a valid pointer toward a game structure. - **/ -void game_delete(game g); - -/** - * @brief Sets the value of a given square. - * @details This function is useful for initializing the squares of an empty - * game. - * @param g the game - * @param i row index - * @param j column index - * @param s the square value - * @pre @p g must be a valid pointer toward a game structure. - * @pre @p i < game height - * @pre @p j < game width - * @pre @p s must be a valid square value. - **/ -void game_set_square(game g, uint i, uint j, square s); - -/** - * @brief Gets the raw value of a given square. - * @param g the game - * @param i row index - * @param j column index - * @pre @p g must be a valid pointer toward a game structure. - * @pre @p i < game height - * @pre @p j < game width - * @return the square value - **/ -square game_get_square(cgame g, uint i, uint j); - -/** - * @brief Gets the state of a given square. - * @details See description of enum square. - * @param g the game - * @param i row index - * @param j column index - * @pre @p g must be a valid pointer toward a game structure. - * @pre @p i < game height - * @pre @p j < game width - * @return the square state - **/ -square game_get_state(cgame g, uint i, uint j); - -/** - * @brief Gets the flags of a given square. - * @details See description of enum square. - * @param g the game - * @param i row index - * @param j column index - * @pre @p g must be a valid pointer toward a game structure. - * @pre @p i < game height - * @pre @p j < game width - * @return the square flags - **/ -square game_get_flags(cgame g, uint i, uint j); - -/** - * @brief Test if a given square is blank. - * @param g the game - * @param i row index - * @param j column index - * @pre @p g must be a valid pointer toward a game structure. - * @pre @p i < game height - * @pre @p j < game width - * @return true if the square is blank - **/ -bool game_is_blank(cgame g, uint i, uint j); - -/** - * @brief Test if a given square is a lightbulb. - * @param g the game - * @param i row index - * @param j column index - * @pre @p g must be a valid pointer toward a game structure. - * @pre @p i < game height - * @pre @p j < game width - * @return true if the square is a lightbulb - **/ -bool game_is_lightbulb(cgame g, uint i, uint j); - -/** - * @brief Test if a given square is black (whether or not it is numbered). - * @param g the game - * @param i row index - * @param j column index - * @pre @p g must be a valid pointer toward a game structure. - * @pre @p i < game height - * @pre @p j < game width - * @return true if the square is black - **/ -bool game_is_black(cgame g, uint i, uint j); - -/** - * @brief Get the number of lightbulbs expected against a black wall. - * @param g the game - * @param i row index - * @param j column index - * @pre @p g must be a valid pointer toward a game structure. - * @pre @p i < game height - * @pre @p j < game width - * @return the back wall number, or -1 if it is unumbered - **/ -int game_get_black_number(cgame g, uint i, uint j); - -/** - * @brief Test if a given square is marked (as not-a-light). - * @param g the game - * @param i row index - * @param j column index - * @pre @p g must be a valid pointer toward a game structure. - * @pre @p i < game height - * @pre @p j < game width - * @return true if the square is marked - **/ -bool game_is_marked(cgame g, uint i, uint j); - -/** - * @brief Test if a given square is lighted. - * @param g the game - * @param i row index - * @param j column index - * @pre @p g must be a valid pointer toward a game structure. - * @pre @p i < game height - * @pre @p j < game width - * @return true if the square is lighted - **/ -bool game_is_lighted(cgame g, uint i, uint j); - -/** - * @brief Test if a given square has an error flag - * @details An error can only occur on an numbered black wall or on a light - * bulb. - * @param g the game - * @param i row index - * @param j column index - * @pre @p g must be a valid pointer toward a game structure. - * @pre @p i < game height - * @pre @p j < game width - * @return true if the square has an error flag - **/ -bool game_has_error(cgame g, uint i, uint j); - - -/** - * @brief Checks if a given move is legal. - * @details This function checks that it is possible to play a move at a given - * position in the grid. More precisely, a move is said to be legal: 1) if the - * coordinates (i,j) are inside the grid, 2) if @p s is either a blank, light - * bulb or mark square, and 3) if the current square at (i,j) is not a black - * square. - * @param g the game - * @param i row index - * @param j column index - * @param s the square value - * @pre @p g must be a valid pointer toward a game structure. - * @return false if the move is not legal. - **/ -bool game_check_move(cgame g, uint i, uint j, square s); - -/** - * @brief Plays a move in a given square. - * @details The grid flags are updated consequently after each move. - * @param g the game - * @param i row index - * @param j column index - * @param s the square value - * @pre @p g must be a valid pointer toward a game structure. - * @pre @p i < game height - * @pre @p j < game width - * @pre @p s must be either BLANK, LIGHTBULB or MARK. - * @pre The game square at position (i,j) must not be a black square. - **/ -void game_play_move(game g, uint i, uint j, square s); - -/** - * @brief Update all grid flags. - * @details This is a low-level function, which is not intended to be used - * directly by end-user during the game. - * @param g the game - * @pre @p g must be a valid pointer toward a game structure. - **/ -void game_update_flags(game g); - -/** - * @brief Checks if the game is won. - * @param g the game - * @details This function checks that all the game rules (decribed on @ref - * index) are satisfied, ie. that all the blank squares are ligthed, without any - * errors. - * @return true if the game ended successfully, false otherwise - * @pre @p g must be a valid pointer toward a game structure. - **/ -bool game_is_over(cgame g); - -/** - * @brief Restarts a game. - * @details All the game is reset to its initial state. In particular, all the - * squares except black walls are reset to blank, and all flags are cleared. - * @param g the game - * @pre @p g must be a valid pointer toward a game structure. - **/ -void game_restart(game g); - -#endif // __GAME_H__ diff --git a/game.o b/game.o deleted file mode 100644 index 413f9e04cc563de9be3d61b6b49bf985cbc1531e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 29736 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 From 1f741db26624b83bdd56c90331c2ab40d7f7da2d Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Thu, 14 Oct 2021 11:13:16 +0200 Subject: [PATCH 004/281] Voici le game.o --- game.o | Bin 0 -> 29736 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 game.o diff --git a/game.o b/game.o new file mode 100644 index 0000000000000000000000000000000000000000..413f9e04cc563de9be3d61b6b49bf985cbc1531e GIT binary patch literal 29736 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 literal 0 HcmV?d00001 From f26021d80ab8865d0a1e023f94a964c689d36048 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sat, 16 Oct 2021 16:21:12 +0200 Subject: [PATCH 005/281] ajout de game.h --- game.h | 314 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 314 insertions(+) create mode 100644 game.h diff --git a/game.h b/game.h new file mode 100644 index 0000000..bf1f72e --- /dev/null +++ b/game.h @@ -0,0 +1,314 @@ +/** + * @file game.h + * @brief Basic Game Functions. + * @details See @ref index for further details. + * @copyright University of Bordeaux. All rights reserved, 2021. + **/ + +#ifndef __GAME_H__ +#define __GAME_H__ +#include + +/** + * @brief Standard unsigned integer type. + **/ +typedef unsigned int uint; + +/** + * @brief Size of the default game grid. + **/ +#define DEFAULT_SIZE 7 + +/** + * @brief Different squares used in the game. + * @details The value of a square is an integer represented on one byte, with a + * low-order half-byte that codes for the square state (blank, black wall, light + * bulb or mark) and a high-order half-byte that codes for the additionnal + * square flags (lighted or error). While each square has a single state, it can + * have zero, one or several flags (combined with bitwise operations). For + * instance, a light bulb can have both the lighted and error flags. In this + * case, the raw square value is S_LIGHTBULB | F_LIGHTED | F_ERROR, using the + * bitwise OR operator (|). For more details on bitwise operations, see + * https://en.wikipedia.org/wiki/Bitwise_operations_in_C. + **/ +typedef enum { + /* states */ + S_BLANK = 0, /**< a blank square */ + S_LIGHTBULB = 1, /**< a light bulb */ + S_MARK = 2, /**< a marked square (as not-a-light) */ + S_BLACK = 8, /**< black wall base code */ + S_BLACK0 = S_BLACK, /**< a numbered black wall (with 0 adjacent lights) */ + S_BLACK1, /**< a numbered black wall (with 1 adjacent light) */ + S_BLACK2, /**< a numbered black wall (with 2 adjacent lights) */ + S_BLACK3, /**< a numbered black wall (with 3 adjacent lights) */ + S_BLACK4, /**< a numbered black wall (with 4 adjacent lights) */ + S_BLACKU, /**< an unnumbered black wall (any number of adjacent lights) */ + /* flags */ + F_LIGHTED = 16, /**< lighted flag */ + F_ERROR = 32 /**< error flag */ +} square; + +/** state mask used in square enum */ +#define S_MASK 0x0F + +/** flag mask used in square enum */ +#define F_MASK 0xF0 + +/** square mask used in square enum */ +#define A_MASK 0xFF + +/** + * @brief The structure pointer that stores the game state. + **/ +typedef struct game_s *game; + +/** + * @brief The structure constant pointer that stores the game state. + * @details That means that it is not possible to modify the game using this + * pointer. + **/ +typedef const struct game_s *cgame; + +/** + * @brief Creates a new game with default size and initializes it. + * @param squares an array describing the initial square values (row-major + * storage) + * @pre @p squares must be an initialized array of default size squared. + * @return the created game + **/ +game game_new(square *squares); + +/** + * @brief Creates a new empty game with defaut size. + * @details All squares are initialized with blank squares. + * @return the created game + **/ +game game_new_empty(void); + +/** + * @brief Duplicates a game. + * @param g the game to copy + * @return the copy of the game + * @pre @p g must be a valid pointer toward a game structure. + **/ +game game_copy(cgame g); + +/** + * @brief Tests if two games are equal (same states and same flags). + * @param g1 the first game + * @param g2 the second game + * @return true if the two games are equal, false otherwise + * @pre @p g1 must be a valid pointer toward a game structure. + * @pre @p g2 must be a valid pointer toward a game structure. + **/ +bool game_equal(cgame g1, cgame g2); + +/** + * @brief Deletes the game and frees the allocated memory. + * @param g the game to delete + * @pre @p g must be a valid pointer toward a game structure. + **/ +void game_delete(game g); + +/** + * @brief Sets the value of a given square. + * @details This function is useful for initializing the squares of an empty + * game. + * @param g the game + * @param i row index + * @param j column index + * @param s the square value + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @pre @p s must be a valid square value. + **/ +void game_set_square(game g, uint i, uint j, square s); + +/** + * @brief Gets the raw value of a given square. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return the square value + **/ +square game_get_square(cgame g, uint i, uint j); + +/** + * @brief Gets the state of a given square. + * @details See description of enum square. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return the square state + **/ +square game_get_state(cgame g, uint i, uint j); + +/** + * @brief Gets the flags of a given square. + * @details See description of enum square. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return the square flags + **/ +square game_get_flags(cgame g, uint i, uint j); + +/** + * @brief Test if a given square is blank. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return true if the square is blank + **/ +bool game_is_blank(cgame g, uint i, uint j); + +/** + * @brief Test if a given square is a lightbulb. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return true if the square is a lightbulb + **/ +bool game_is_lightbulb(cgame g, uint i, uint j); + +/** + * @brief Test if a given square is black (whether or not it is numbered). + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return true if the square is black + **/ +bool game_is_black(cgame g, uint i, uint j); + +/** + * @brief Get the number of lightbulbs expected against a black wall. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return the back wall number, or -1 if it is unumbered + **/ +int game_get_black_number(cgame g, uint i, uint j); + +/** + * @brief Test if a given square is marked (as not-a-light). + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return true if the square is marked + **/ +bool game_is_marked(cgame g, uint i, uint j); + +/** + * @brief Test if a given square is lighted. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return true if the square is lighted + **/ +bool game_is_lighted(cgame g, uint i, uint j); + +/** + * @brief Test if a given square has an error flag + * @details An error can only occur on an numbered black wall or on a light + * bulb. + * @param g the game + * @param i row index + * @param j column index + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @return true if the square has an error flag + **/ +bool game_has_error(cgame g, uint i, uint j); + + +/** + * @brief Checks if a given move is legal. + * @details This function checks that it is possible to play a move at a given + * position in the grid. More precisely, a move is said to be legal: 1) if the + * coordinates (i,j) are inside the grid, 2) if @p s is either a blank, light + * bulb or mark square, and 3) if the current square at (i,j) is not a black + * square. + * @param g the game + * @param i row index + * @param j column index + * @param s the square value + * @pre @p g must be a valid pointer toward a game structure. + * @return false if the move is not legal. + **/ +bool game_check_move(cgame g, uint i, uint j, square s); + +/** + * @brief Plays a move in a given square. + * @details The grid flags are updated consequently after each move. + * @param g the game + * @param i row index + * @param j column index + * @param s the square value + * @pre @p g must be a valid pointer toward a game structure. + * @pre @p i < game height + * @pre @p j < game width + * @pre @p s must be either BLANK, LIGHTBULB or MARK. + * @pre The game square at position (i,j) must not be a black square. + **/ +void game_play_move(game g, uint i, uint j, square s); + +/** + * @brief Update all grid flags. + * @details This is a low-level function, which is not intended to be used + * directly by end-user during the game. + * @param g the game + * @pre @p g must be a valid pointer toward a game structure. + **/ +void game_update_flags(game g); + +/** + * @brief Checks if the game is won. + * @param g the game + * @details This function checks that all the game rules (decribed on @ref + * index) are satisfied, ie. that all the blank squares are ligthed, without any + * errors. + * @return true if the game ended successfully, false otherwise + * @pre @p g must be a valid pointer toward a game structure. + **/ +bool game_is_over(cgame g); + +/** + * @brief Restarts a game. + * @details All the game is reset to its initial state. In particular, all the + * squares except black walls are reset to blank, and all flags are cleared. + * @param g the game + * @pre @p g must be a valid pointer toward a game structure. + **/ +void game_restart(game g); + +#endif // __GAME_H__ \ No newline at end of file From fc274612d457ed0f2daa03533df06c4f6e985fb5 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sat, 16 Oct 2021 16:38:56 +0200 Subject: [PATCH 006/281] ajout game.h v2 --- game.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/game.h b/game.h index bf1f72e..3a2af8a 100644 --- a/game.h +++ b/game.h @@ -12,6 +12,7 @@ /** * @brief Standard unsigned integer type. **/ + typedef unsigned int uint; /** @@ -311,4 +312,4 @@ bool game_is_over(cgame g); **/ void game_restart(game g); -#endif // __GAME_H__ \ No newline at end of file +#endif // __GAME_H__ From 30de2d2d8a09fe45e57fc844d059315ddcbf392e Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 21 Oct 2021 18:36:22 +0200 Subject: [PATCH 007/281] =?UTF-8?q?m=C3=A0j=20game.o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.o | Bin 29736 -> 30040 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/game.o b/game.o index 413f9e04cc563de9be3d61b6b49bf985cbc1531e..681775ccc88102a9c998710733ce79d2f608a818 100644 GIT binary patch literal 30040 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 DZM`67 literal 29736 zcmcIs3wTu3wLW<$0l`G8)(6#5Q654Bu@4kscnnO1Sc?WfTQGz$BtQaTlHs9=r3}^_ zN7Po^-nQ0@4=TOI(yHZZOC?fjqM{9!&&FPC=VH7LO+K5}RHrzayVl-oo!MvQoJs2a z?)g6Eoc*u0|Gn1QYwxqqJ|}!Fv~XU2UY^BAo;AbDmKe3HUG>@Ppt=lNr&^<|_lnOy zQ69G64##^+!gg~yoCu|7J%b9*;!oH<@Z2ys@5i6i!>3u+i@)J2O5vBNWvJYLx@9eO zRDd-AtSMkk74Hq6R=gJ*z{`^2z3q4zPF!Dv=R|#>I$5*qwB45aJhT+HL&}_Niw>O~ zONQgkDXVc9oRU`Tg7EfHXviL#=*10i8EEvejO##Cp!{o!<1aa5~_cn zs|oDuv>ofS%X{sz9_X61(KSJA&a-RM5ROn^)ak@oIW#dwy;;@S-l~aE4;VP%EX&%~ znoW*5-pV=#Dh<=RzxuFKd$XN-0QvIWzN&C)UxlOB`ZpsSU64alIJ(eZl@ij&_Kt){ z8hF}$gMSmk?i+Jx3cJhwRR^^@o-B5ymw(8Y__rcVUz$Txn0|}D>Y%1y(hHSc#!rT^ z(FvK-X$*;ocMEMHH8#6fw}pB@!|MJrq-ZC#*{M@Bg(=#TO;J7XfRdVb93_}{dW?A| zeyrFoi35a$INybOqL0QyDP4w9n2ILaLTJ0yeM?)YPhErtw%&`a_nEC*&{^?xUhIrS zd0(Qe7pvH>;#_iUv}MIX*J-gYx+e~UOO>I;-spE}o;^MW<}8|Oj~BvqqCAr*gXxK> z(3)+njWrUV6@Vss^FUOF%I-jUPtYPzX{ypwp0vx3LdKS|a?B|=B+P%rS?p+3C#h0<6hlp(#d!)l0^r^9-Tx13^G?j*#O zKuYA^54~OERn}%+Wi4~YT}snKJsRH^`HLty=X+_u%s}FCVzKprYq3?lbyI(T|G=e_ zmp4!6_NJ1(340l&XRGlLPBC5v%vNpaJWQajCE{+E)zJqu53J&#`X@igYE;XcaF%GS2v=(jSXz{*wZ^|b-iASyp?Ou5LsNJ)++X!y z^D2sIbgRw zSBNp;WtV+Gd24HL)yB*n#)idJ-p#99VCv~lV{mZ|HXGJsw2fodo{_8ehHUKs)eeNs z+ClHysB46ib_^5do*!euLSrM4K-|FcL{BqN-ZXSSy4>Vz5Uio}+Gl#c+VEKnMmpI2 zSPd4lFbLA{G>MO=F?>8tIh`P{6R-|;uWxrjpLORAzQV1_X`)(=eGgP%Pl`=c7(Q=j zP0S3*M7ab%$-_kTBp9|2hi&lwMA&`_8tH&I;5LN$P`Jh0?ENLc={GXAde?!#!Qh2f z63~jB7q-7#q;gcnSnVy=z;>cLl4z#f8M(`k9v<&u@Vo~*d*F=#FpC6$ zgeW)Dnm5DU)8V&$>0uDIrEWc2Z26RcV{%G;Fb9Wgr}fY0;P8fF4a@;xHa9XK@+L9D z3UeGx$gn4)9^HEQPN@7jO|5P8{je0%=2is{dnSN|Iw%yu{eLnRmO)`S6sBO|1}Kbx z!WCGU2Zd9hFck~apfC~&S7Koz6mUhf5epYU0oR2Suy8sQaA`3K3nx7@6HeJtZ>L*A znJvwk04RU}41vOAC=_8~85E{KVK^3UfWj3}7=eX(P?!n@c+3Gqpl~G=Mq*(i6gENu zo@c=jC`^C?L=Fsr!Xzlbbb*GzU83JG#5Z)Kcn9Qsd?LXekW2~gfMf#vc&RrnvRpU7 z8;i5?QP}hGB<0)YmJi}4rNW&lo_DZ4ZB=DCp#QMV>D`f5j2Lm zIB-*w+&S?PXp9AoA{U3D(TN)JaTXJ1TsC1~18=SkQ=WUiE`YrCSdzk4+{ouf;$lj~HaZzfmf0}uUVqCA->Qz@wv;aCP%X=<;QlB!f$q_?e8 z@Fp%1>MGvTft!Z7h*a;?+7s5rq0VWcqs0%j4w8Kkt<+q*tP68G7DzOw5@kJ@i!qgp z@NN;O(|a)qYE&|I<;5<>WUTLZbg>UfaV09w)Qb6}nCGQ<4Jw|c6$@fxF*P?qYNlY3 z=rr99!xL`8ZK)DeKCW`GtB{l-OTCrff-E_{Pb;4kn?TIkVpT<(>yST%`gd#nlO1w@ z{WxY}1%zvuV>T+2J%W5ODqjK0MJ{G<KR;v$bKo`7+b^#ZrF2exx^R{dqIPWQj119kEJK2iU> zOLxjZUA!ZcZi7qLqqlK!$8RH`m*xA2&v|zsZJy%f5mS?g>OkzhZU0n$7vhenA;u0v zal~7U9faa}-eP_x8*7NS;7g7sqX`T?a^xFIh8Tm5;;i*lsFfjH%n3aw;0b z;f9=w#z2^0C~j#!0z=?2Ximr1G{P7H9}MUSQ_)ENS92;FnZGlqqLKDZrlLnT(OW9$ z8S`~-jd#yLH+152v3L`-%3m8-XvPbz)j2eA0cX6>TH~)udoK945jJxCUN2=}xof=d zs{7=8xQgv`zpp-muVFjP_th_zz-!phk$7vK9qQ?Bc2&W(0_-`#TA{iUu3EPp-`Jksajy5>&%)y$TX$Ok$jKVVmYzd%kDX^{A!?s>u+m;Tn%|myf zZJ^|7TU~Enyt&sZwl}j;9V%dbY?RtwGCNkjx`!9Bv4}P*x2|8O^~p|iUio7$^G~O$9$;Ku8X}g?M$C9}=5NeApV;p4O?UN8n;60O z`fH0<8~5eV6kEsN^j3vsv+DES?rP}A6pbsrpw`LdUQp|>UOPlx^=Suv7jQ2wbM*%t z@J$^oNT(gxc()n~U1})wd05crv82})%o$*Tx2|cyD72ui54y0=+I+uiI;osbbJHqM z%uf(pc|tk0KsP<8uGuthc{?v(F}2g+eS%EDw9a(n!~^jkKoVYa#@hTHXm{YtYPFrFzmgF5pQpT22W;@V|2*xlE$%kp%@4gB$!XX}-gT5Uuwo1A_afn} zkuV%^ZidG%Ju1Qp3*I#}76S$%upQrGs23+t#B0=sOZZL|ZcJ(?igb!lkO-D+zaDo| zQc%fb>h^GR1guFtawMmlBfaZDyRgO0Zi1D{Cw2h(BZvz{>=5>#G3$=@RC!@~qyrK= zMOShnFsP&MeW7!F4aSg}FL%!M*CbPDve~FD0&gJC;U$W43QG6|F@yncqK();=r*S$ zxDCqA_r*|jJA|*~u;-Y}>EdkUdOdR2?dy1d4}`B1{53hl$l2SpMc|w1Ef#~Yl`q|O z_woRLdH#n~bvvw+T6eWGcHIs`YXe>!O!IXE-Yu56;^kF6n6vsFt+2H=D93z%4$2y5 zP7dc*_4+1RB~x}{`cf_i9Yd$J>j%*l%>~q4=+38`d?|D~!wNqD>Cvn50MB{|;D~^s zPsxs}@YowFi?X>4^=a1A(;5wwq0L*7!Oi--V-{}VtGNcOf-#CyR9pXRO6+SbzJN}- z=d8i4)d@zPKMLEKK;lHf?U+`z@s+FI?GNieF|goiK-9un)2iECU0D|?t+J}81TMWa zP<@3}ZLJDS4^&T@v37Yyblt`VYqe9XT36d(RaDhPs@7CAtdCVjBjXyzD;ldIaLqM= z8!BcmoORuTKvPqI%4M?_nZ<=)oFBe%cKO2D)`iP!E34K(wM%uaISb%=22$K`xoSCs^r2k4s=B6ed8~FhRx%F7hyJMkt5_SW zTdo>XIMl1FjIN2S$W~xn@qs{Z^)|RkuPXX3JIUVr!Kj3PhaxlKdagr!<=U!p);iMSEjqEoGTSSq_2XhUl!bU%9Vy zRgDH!Ryj*@a9@duryj~WrL|lqJyN}Hs$8)$hW5{&Gv}(n zxbo!?s90diNk=6byxjYoca$ABHu@Hd_V8BUog^%-%*m|yRxi&o+HnYT#W&?e}QUV_1|b3 zB_L(r zGv%RpLH-e?qWVZpW+3hFRV1IC&3!W`NFL54ujO5Q@zB=+>IP=UwlKaggT_neK ziBms+xzi7Y_|6HAckqY#^Z(??$B-P~{b%J#M?RP2e)I4OlH*(DZ2go|e;dj1!zxF< zL5a2hB%f=_jXXU_@;XzVzrx|~BDq@QIR344I`X+B zzs!{D@GARPkool2Eb9JPgWStUixK#qyB7~dsWT=wv_Nv z90PEudp4Z0Pf`DW2v_%Nz?ukun8vrdM+251{1yt4x;F#%L&EPK1s8Crdm5bgz(3?y zpWeZ>x);J3`4DfTzEk&bz+NHzVYQ87S!&Dyc9igi7;re$JsZwAW{~Gn3WmDZ0rpSA zGXlqt@lpTWQ$PU@=D~X$;wi$}{)-7;a;nx>_hPu5M)=}ljkA6jaB5Nu=ojZtFWh;s za4u+puO1w#*41y;0{!S#QBm2@5Q#Qctie!V zimpdGg}5HF7|~C~s^tHW$I9v%j|)BzSW3*#f2^w?{#0qeqa5qdgIpavbF8bfs`SaS zUZS|;Fu;G)A^v!9elQN-si@;kEmpcH;~C%>;W!L1RayT-;zNA6fseq-a7=)ICO*ao zznXB#6CoT=_-`S#w_f0E&nAIWx?0VIOZ)L1Bp!Ief6V^_fiwRj0_R+QoN&qiOQFyF zF9@9ZUlI5PXdE1``S8CZ^qK!XfiwRJftPA}tKWzJI+_nrjQ^HU{J$b_=C2eu$A2Z^ zGCrGxKJ#xAIP)h2&hfv`hyPKb&-{A?&is1?&hh`15C6&N5F8wzT8hu<0%!hn1kUj} zpKv^x<7=|eXMSE2bGytxN9c2W!an?875dCyEpX;vD{ziagAf1nLcfXP^NPTk|A@dj zK5zK&cME;y|3Ki(|FOV1J_R(=9x(A4a6}9jQ@pjZg)4?^S;1Y|0993J^8e5k?}l8IP>o# z{tkgN{~rX-{6~HG-xd1Ie?s8QpNBUmIM^P}hm#4H_Map4ng0@jGyg<^b3RP*;lEbs zGyh_NGyhV7&(-c&%YFDa7`WN*3Bkkdeple!?n44^q;?-Q_%StDKcCjC7*Fg&##a)~ z@jpcQ5EVGDr(@Sokb(T2spUi9%}atfpfd(37p#v5H8!jLg+L941qI$NZ>qPuJz$xD)gCu zmB5+5Uf?`lVm|zxLO(5@3DZ@UG~@#*#9&!^`&jz9CCDskdJQ{Wt*a|xI6pCt5| zf11RJKPYgHPsoRVx6mJnj=-V*>I=?}U&Oy(=yQAy`tZLl^qK#dz`1{q3!LNgt`C16 z8NhZj|0sbo{}}@3_?$zyjDM5RpGfg(5jgYTD{v}W5733=|B=vV{wD>_{Lc!Uuf<@wt+4Y5zQ-&-{x7&ipqEoXoav@!?-D^qId|;LN{G;2a;@hyU!;-SKIn z_>2)a^Is-#j?ZMmWqdXWedgaPaOSrKey29iy2poq*r&7twtFu8W1e#e=W%g2`E`lF zS%0Fy*{>-EzqxMQY~be^?f#qK;dUPrIJf%~fj^?%v3_Roo9(_X^qK#dz?uKJz@H%g zcYXNJP%j~~_kHFM2%P!H3Y_=FClW66VW-f4jQZv00%!hb1kU~PYajlP4IG#1%rip0 zJk|3vaxfkyobv>~+Q#EXfwTTs1py(> z+l4;!9}zh7|Chko{-h6ozk%Z;Ec1+o{|5#Sr(ejgsS>C4^Hl<8zh)9H`)iHR$B(M< z*eGze=XQZJf82-v9>OO8r|H+v1P`~nPvG3{Zv_6TveL5J3739t#20^XaNI_dUvYsm z|6Ky-ad$7_l7A0Q$_D=!;{TPvng4*mnZJ#2$$v!XGk;Rx%>RzSlgc{yX2^&Cf%CNj z#|OW{#$$)Tng4Ntv;DgXm-as^^qK#+0%!h10#7PyEbFij|E&S7!1iBB_J2d*%)edW zZ2z|im-fGMp__j$@xLK(=1&To`QIj7@>gH%=3hem4FYHWTLsSiUn5-de_QA?|HA@j z{#^p+_p49%@b4G;%>S~$ng2C`^Sbm8KKy?X`po~nz?uIef%CdFe~gZ^jL%hsbN(>@ zJb^QRnZWVCox@`h;e~K*-jBwQRbprUX)4g=&kCIRrwg3>cNXE2|0bc&{8a*H{?!8K z{$1z8|8=3y{M!Z2{0|76`}cc3{JVud^FJeS=HD-H?%#tx{O^o+$Nxc!|9b*w{u2V{ z`1cbo<9{aJ(BRV=`bWvHcLmP;{}4F)b;5_gaFULX?60#3=eTjZ7YUr(9WQY9tJL5({c02X zJ>=K#1MSA%Qdh?*%@Y?C0VE_*5z{6Zm2(ZxQ%TD(?_De@ELYaQvEduB7ad!xuzsGGA_-m(WJCXu_hxW($52{d%E`E;oLj!c5Vf2*KCGg>6HQp}pw(%NI2|P;c<0ASVjN|+!;o}5;kk*S~fj>d(ry7BOkJb|{ z0>6vy$GZgnBH`@>IN1K|JusLi&x=OHrR7PF%!1TtH z51Jre&(XlHvHE-poUkr^PG`}uvo0l^hP_sX-+|{&{WA}?pU<;F$k(P`HPtsUyq3C)0K=4&_SaDT0LaXP zzlG{=p?qh3Ss$~|tN(W)F&sQEVgKWLhU;_xd$o=Aie}<3>}!)@BjFnR nSk^~Q+4lfhyJq39Wi1u~6GaPen_l%N*Q@GQqdqymvi|=9`khO^ From 6f6a87aa341b9e0cc5b7eadd9f6e35cd61a4af67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 21 Oct 2021 18:39:56 +0200 Subject: [PATCH 008/281] Nvx cmake --- CMakeLists.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e69de29 From 7dbb3977df1ccd8733d6cc01eb0f8274f9cd4df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 21 Oct 2021 18:42:17 +0200 Subject: [PATCH 009/281] minimal version CMAKE --- CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e69de29..e3b10a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -0,0 +1,12 @@ +#version minimale de cmake nécessaire +cmake_minimum_required(VERSION 2.6) +#nom du projet +project () +#positionne la variable +set(CMAKE_C_FLAGS "-std=c99 -g -Wall") +#définit le nom du programme ainsi que +#ses sources +add_executable() +#les dépendances sont calculées automatiquement +target_link_libraries() +add_library () From 370e01bd6758ad3e4e474493e56b64b8939c5a03 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 21 Oct 2021 19:17:39 +0200 Subject: [PATCH 010/281] CMakeLists.txt + rm Makefile --- CMakeLists.txt | 12 ++++++++---- Makefile | 25 ------------------------- 2 files changed, 8 insertions(+), 29 deletions(-) delete mode 100644 Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt index e3b10a6..7b0d8a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,16 @@ #version minimale de cmake nécessaire cmake_minimum_required(VERSION 2.6) + #nom du projet -project () +project (game_text) + #positionne la variable set(CMAKE_C_FLAGS "-std=c99 -g -Wall") + #définit le nom du programme ainsi que #ses sources -add_executable() +add_executable(game_text game_text.c) + #les dépendances sont calculées automatiquement -target_link_libraries() -add_library () +target_link_libraries(game_text libgame) +add_library (libgame game.o game_aux.c) diff --git a/Makefile b/Makefile deleted file mode 100644 index b909c8c..0000000 --- a/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -CC=gcc # compilateur -CFLAGS=-Wall -std=c99 # options de compilation -LDFLAGS=-L. # options de link -LDLIBS=-lgame # bibliothèques -CPPFLAGS= # options de preprocessing -AR= ar - -all: game_text - -libgame.a: game_aux.o game.o - $(AR) rcs $@ $^ - -game_text: game_text.o libgame.a - $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) - -.PHONY: clean dep - -include dep - -# génération des dépendances -dep: - $(CC) -MM *.c > dep - -clean: - rm -f dep game_aux.o *~ game_text game_text.o libgame.a \ No newline at end of file From c6e5d257ae30792fd668e90fb448101c5cf2637c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 21 Oct 2021 19:23:24 +0200 Subject: [PATCH 011/281] libgame.a (hein tibault) --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b0d8a7..4b5f403 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,5 +12,5 @@ set(CMAKE_C_FLAGS "-std=c99 -g -Wall") add_executable(game_text game_text.c) #les dépendances sont calculées automatiquement -target_link_libraries(game_text libgame) -add_library (libgame game.o game_aux.c) +target_link_libraries(game_text libgame.a) +add_library (libgame.a game.o game_aux.c) From 1316111b6c37239aa9c45889a61870cc33534338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 21 Oct 2021 19:42:50 +0200 Subject: [PATCH 012/281] CMAKE qui marche --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b5f403..03d461d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,5 +12,5 @@ set(CMAKE_C_FLAGS "-std=c99 -g -Wall") add_executable(game_text game_text.c) #les dépendances sont calculées automatiquement -target_link_libraries(game_text libgame.a) -add_library (libgame.a game.o game_aux.c) +target_link_libraries(game_text game) +add_library (game game.o game_aux.c) From d75957501b062a0349b77de526a459b36939c617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 28 Oct 2021 10:32:17 +0200 Subject: [PATCH 013/281] gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d163863 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file From dc00f9c1239466557f2950062fd67a7507635a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 28 Oct 2021 10:37:12 +0200 Subject: [PATCH 014/281] remove .vscode --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d163863..01f9cb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -build/ \ No newline at end of file +build/ +.vscode/ \ No newline at end of file From a01ec8acf0c96f663f54f370909d814b4de1a7b2 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Thu, 28 Oct 2021 10:56:38 +0200 Subject: [PATCH 015/281] add test thperrier --- game_test_thperrier.c | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 game_test_thperrier.c diff --git a/game_test_thperrier.c b/game_test_thperrier.c new file mode 100644 index 0000000..2565b30 --- /dev/null +++ b/game_test_thperrier.c @@ -0,0 +1,7 @@ +void test_game_text(){ + +} + +int main (int argc, char *argv[]){ + +} \ No newline at end of file From f1b68044ef5db7ff8558b9c4eb49e5fc374c388f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 28 Oct 2021 10:56:45 +0200 Subject: [PATCH 016/281] game_test --- game_test_thoguet.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 game_test_thoguet.c diff --git a/game_test_thoguet.c b/game_test_thoguet.c new file mode 100644 index 0000000..fe1470f --- /dev/null +++ b/game_test_thoguet.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +/* ********** DUMMY ********** */ + +bool test_dummy(void){ + return EXIT_SUCCESS; +} + +/* ********** USAGE ********** */ + +int usage(int argc, char *argv[]) +{ + fprintf(stderr, "Usage: %s [<...>]\n", argv[0]); + exit(EXIT_FAILURE); +} + +/* ********** MAIN ********** */ + +int main(int argc, char * argv[]){ + if (argc == 1){ + usage(argc, argv); + } + fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); + bool ok = false; + if (strcmp("dummy", argv[1]) == 0) + ok = test_dummy(); + else { + fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); + exit(EXIT_FAILURE); + } + // print test result + if (!ok){ + fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); + return EXIT_SUCCESS; + } + else { + fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]); + return EXIT_FAILURE; + } +} \ No newline at end of file From 573bf9a4ac2b8373727412bfa527ad53adeca16e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 28 Oct 2021 10:57:32 +0200 Subject: [PATCH 017/281] TD5 --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03d461d..718aa4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ #version minimale de cmake nécessaire cmake_minimum_required(VERSION 2.6) +enable_testing() + #nom du projet project (game_text) @@ -10,7 +12,9 @@ set(CMAKE_C_FLAGS "-std=c99 -g -Wall") #définit le nom du programme ainsi que #ses sources add_executable(game_text game_text.c) +add_executable(game_test_thoguet game_test_thoguet.c) #les dépendances sont calculées automatiquement target_link_libraries(game_text game) add_library (game game.o game_aux.c) +add_test(game_test_dummy ./game_test_thoguet dummy) \ No newline at end of file From 0f54536f453ef5e10098d72918799c209abb1720 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Thu, 28 Oct 2021 14:25:59 +0200 Subject: [PATCH 018/281] Update CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 718aa4c..f98a2b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,4 +17,4 @@ add_executable(game_test_thoguet game_test_thoguet.c) #les dépendances sont calculées automatiquement target_link_libraries(game_text game) add_library (game game.o game_aux.c) -add_test(game_test_dummy ./game_test_thoguet dummy) \ No newline at end of file +add_test(test_thoguet_dummy ./game_test_thoguet dummy) From bbdd857adcf0cc68b6c88a74992bd637d3218ab5 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Fri, 5 Nov 2021 18:25:12 +0100 Subject: [PATCH 019/281] base struct --- game_test_thperrier.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 2565b30..2207238 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -1,7 +1,11 @@ -void test_game_text(){ +#include +#include +#include +void test_game_text(){ + return EXIT_SUCCESS; } int main (int argc, char *argv[]){ - + return EXIT_SUCCESS; } \ No newline at end of file From 0a415928d052b1f96b734f842dcac66214e1a18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Mon, 8 Nov 2021 13:44:54 +0100 Subject: [PATCH 020/281] change cmake minimum required --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f98a2b7..6351697 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ #version minimale de cmake nécessaire -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 2.6...3.13) enable_testing() From bbb6649d56f372c959dda770476cdd0e61a9e655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Mon, 8 Nov 2021 13:52:00 +0100 Subject: [PATCH 021/281] change ok condition --- game_test_thoguet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index fe1470f..96c0d11 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -24,7 +24,7 @@ int main(int argc, char * argv[]){ usage(argc, argv); } fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); - bool ok = false; + bool ok = true; if (strcmp("dummy", argv[1]) == 0) ok = test_dummy(); else { From 52d6c1b81bad0f83384cc3b05be0bf99df19e73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Mon, 8 Nov 2021 14:27:17 +0100 Subject: [PATCH 022/281] undo last commit --- game_test_thoguet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 96c0d11..fe1470f 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -24,7 +24,7 @@ int main(int argc, char * argv[]){ usage(argc, argv); } fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); - bool ok = true; + bool ok = false; if (strcmp("dummy", argv[1]) == 0) ok = test_dummy(); else { From d56c4722ceb740112eebcc65233a7effd082ee2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Mon, 8 Nov 2021 15:33:50 +0100 Subject: [PATCH 023/281] Logical change --- game_aux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_aux.c b/game_aux.c index 37d2375..c4a14d8 100644 --- a/game_aux.c +++ b/game_aux.c @@ -4,7 +4,7 @@ #include #include "game.h" -int charPrintCell(square sqState){ +char charPrintCell(square sqState){ if (sqState == S_BLANK){ return ' '; } From 1e6908b3c0e6671e21ee3bdd63dab32d087779ba Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Mon, 8 Nov 2021 17:59:35 +0100 Subject: [PATCH 024/281] started ex3 TD5 --- CMakeLists.txt | 6 +++ game_test_thoguet.c | 109 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6351697..851db44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,5 +16,11 @@ add_executable(game_test_thoguet game_test_thoguet.c) #les dépendances sont calculées automatiquement target_link_libraries(game_text game) +target_link_libraries(game_test_thoguet game) add_library (game game.o game_aux.c) add_test(test_thoguet_dummy ./game_test_thoguet dummy) +add_test(test_thoguet_new ./game_test_thoguet game_new) +add_test(test_thoguet_game_print ./game_test_thoguet game_print) +add_test(test_thoguet_get_square ./game_test_thoguet game_get_square) +add_test(test_thoguet_default ./game_test_thoguet game_default) +add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_solution) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index fe1470f..b9f68c5 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -2,6 +2,9 @@ #include #include #include +#include +#include "game.h" +#include "game_aux.h" /* ********** DUMMY ********** */ @@ -9,6 +12,102 @@ bool test_dummy(void){ return EXIT_SUCCESS; } +/* ********* game_new ********* */ + +bool test_game_new(void){ + square tab[DEFAULT_SIZE*DEFAULT_SIZE]; + game g; + for (int i = 0; i <= 128; i ++){ + g = NULL; + for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ + tab[j] = i; + } + printf("%d\n",i); + g = game_new(tab); + assert(g); + } + return EXIT_SUCCESS; +} + +/* ******** game_print ******** */ + +// est ce qu'il faut faire avec un tab invalide ? + +bool test_game_print(void){ + game_print(NULL); + square tab[DEFAULT_SIZE*DEFAULT_SIZE]; + for (int i = 0; i <= 128; i ++){ + for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ + tab[j] = i; + } + printf("%d\n",i); + game_print(game_new(tab)); + } + return EXIT_SUCCESS; +} + +/* ******* game_get_square ******* */ + +bool test_game_get_square(void){ + game g = game_new_empty(); + square tab[DEFAULT_SIZE*DEFAULT_SIZE]; + for (int i = 0; i <= 128; i ++){ + for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ + tab[j] = 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]); + } + } + return EXIT_SUCCESS; +} + +/* ******* game_default ******* */ + +bool test_game_default(void){ + game g = game_default(); + //a verif aps sur + assert(g); + assert(game_get_square(g,0,2) == S_BLACK1); + assert(game_get_square(g,1,2) == S_BLACK2); + assert(game_get_square(g,2,5) == S_BLACKU); + assert(game_get_square(g,2,6) == S_BLACK2); + assert(game_get_square(g,4,0) == S_BLACK1); + assert(game_get_square(g,4,1) == S_BLACKU); + assert(game_get_square(g,5,4) == S_BLACK2); + assert(game_get_square(g,6,4) == S_BLACKU); + return EXIT_SUCCESS; +} + +/* *** game_default_solution *** */ + +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); + assert(game_get_square(g,1,2) == S_BLACK2); + assert(game_get_square(g,2,5) == S_BLACKU); + assert(game_get_square(g,2,6) == S_BLACK2); + assert(game_get_square(g,4,0) == S_BLACK1); + assert(game_get_square(g,4,1) == S_BLACKU); + assert(game_get_square(g,5,4) == S_BLACK2); + assert(game_get_square(g,6,4) == S_BLACKU); + //solution + assert(game_get_square(g,0,0) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,1,1) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,0,3) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,1,6) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,2,2) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,3,6) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,4,4) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,5,0) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,5,5) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,6,1) == (S_LIGHTBULB|F_LIGHTED)); + return EXIT_SUCCESS; +} + /* ********** USAGE ********** */ int usage(int argc, char *argv[]) @@ -27,6 +126,16 @@ int main(int argc, char * argv[]){ bool ok = false; if (strcmp("dummy", argv[1]) == 0) ok = test_dummy(); + else if (strcmp("game_print", argv[1]) == 0) + ok = test_game_print(); + else if (strcmp("game_default", argv[1]) == 0) + ok = test_game_default(); + else if (strcmp("game_default_solution", argv[1]) == 0) + ok = test_game_default_solution(); + else if (strcmp("game_new", argv[1]) == 0) + ok = test_game_new(); + else if (strcmp("game_get_square", argv[1]) == 0) + ok = test_game_get_square(); else { fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); exit(EXIT_FAILURE); From 608c85f546dbd4bcfa326b2c581361f4c7d5f313 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Tue, 9 Nov 2021 15:07:49 +0100 Subject: [PATCH 025/281] voici mon game_test --- game_test_nnunes.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 game_test_nnunes.c diff --git a/game_test_nnunes.c b/game_test_nnunes.c new file mode 100644 index 0000000..9c121fa --- /dev/null +++ b/game_test_nnunes.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include + +bool test_dummy(void){ + return EXIT_SUCCESS; +} + +int usage(int argc, char *argv[]) +{ + fprintf(stderr, "Usage: %s [<...>]\n", argv[0]); + exit(EXIT_FAILURE); +} + +int main(int argc, char * argv[]){ + if (argc == 1){ + usage(argc, argv); + } + fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); + bool ok = false; + if (strcmp("dummy", argv[1]) == 0) + ok = test_dummy(); + else { + fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); + exit(EXIT_FAILURE); + } + if (!ok){ + fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); + return EXIT_SUCCESS; + } + else { + fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]); + return EXIT_FAILURE; + } +} \ No newline at end of file From 4ba5fccda888694e09b3caa03fb3f76a1dee2680 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 9 Nov 2021 18:00:15 +0100 Subject: [PATCH 026/281] =?UTF-8?q?compl=C3=A9tion=20de=20main=20+=20usage?= =?UTF-8?q?=20+=20test=5Fdummy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game_test_thperrier.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 2207238..8f9c9e8 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -1,11 +1,40 @@ #include #include #include +#include + +bool test_dummy(){ + return EXIT_SUCCESS; +} void test_game_text(){ return EXIT_SUCCESS; } +void usage(int argc, char *argv[]){ + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(EXIT_FAILURE); +} + int main (int argc, char *argv[]){ + bool success = false; + if (argc != 2){ + usage(argc, argv); + } + else if (strcmp("dummy", argv[1]) == 0){ + success = test_dummy(); + } + else{ + fprintf ("\"%s\" is not a valid test name.\n", argv[1]); + return EXIT_FAILURE; + } + if (success){ + fprintf (stderr, "test \"%s\" finished successfully", argv[1]); + return EXIT_SUCCESS; + } + else { + fprintf (stderr, "test \"%s\" error ", argv[1]); + return EXIT_FAILURE; + } return EXIT_SUCCESS; } \ No newline at end of file From a15d7de0647ff9bca043a25af816e704f174be0c Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 9 Nov 2021 19:05:13 +0100 Subject: [PATCH 027/281] correction de bug --- game_test_thperrier.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 8f9c9e8..4ec7732 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -4,12 +4,9 @@ #include bool test_dummy(){ - return EXIT_SUCCESS; + return true; } -void test_game_text(){ - return EXIT_SUCCESS; -} void usage(int argc, char *argv[]){ fprintf(stderr, "Usage: %s \n", argv[0]); @@ -25,15 +22,15 @@ int main (int argc, char *argv[]){ success = test_dummy(); } else{ - fprintf ("\"%s\" is not a valid test name.\n", argv[1]); + fprintf (stderr, "test \"%s\" is not a valid test name.\n", argv[1]); return EXIT_FAILURE; } if (success){ - fprintf (stderr, "test \"%s\" finished successfully", argv[1]); + fprintf (stderr, "test \"%s\" finished successfully\n", argv[1]); return EXIT_SUCCESS; } else { - fprintf (stderr, "test \"%s\" error ", argv[1]); + fprintf (stderr, "test \"%s\" error\n", argv[1]); return EXIT_FAILURE; } return EXIT_SUCCESS; From 5f9afa21ae2afb4e5adb87583ecdc54e0ae7c696 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 9 Nov 2021 19:08:39 +0100 Subject: [PATCH 028/281] =?UTF-8?q?m=C3=A0j=20CMake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 851db44..38c786f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ set(CMAKE_C_FLAGS "-std=c99 -g -Wall") #ses sources add_executable(game_text game_text.c) add_executable(game_test_thoguet game_test_thoguet.c) +add_executable(game_test_thperrier game_test_thperrier.c) #les dépendances sont calculées automatiquement target_link_libraries(game_text game) @@ -24,3 +25,5 @@ add_test(test_thoguet_game_print ./game_test_thoguet game_print) add_test(test_thoguet_get_square ./game_test_thoguet game_get_square) add_test(test_thoguet_default ./game_test_thoguet game_default) add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_solution) + +add_test(test_thperrier_dummy ./game_test_thperrier dummy) \ No newline at end of file From 9090ca6b75b433e4190f7e4457ea6841b47ae8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Wed, 10 Nov 2021 17:15:17 +0100 Subject: [PATCH 029/281] Update README --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/README.md b/README.md index b853a8e..02c8f77 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,49 @@ # lightup-a42e +### game game_new(square *squares) -> + +### game game_new_empty(void) -> + +### game game_copy(cgame g); + +### bool game_equal(cgame g1, cgame g2); + +### void game_delete(game g); + +### void game_set_square(game g, uint i, uint j, square s); + +### square game_get_square(cgame g, uint i, uint j); + +### square game_get_state(cgame g, uint i, uint j); + +### square game_get_flags(cgame g, uint i, uint j); + +### bool game_is_blank(cgame g, uint i, uint j); + +### bool game_is_lightbulb(cgame g, uint i, uint j); + +### bool game_is_black(cgame g, uint i, uint j); + +### int game_get_black_number(cgame g, uint i, uint j); + +### bool game_is_marked(cgame g, uint i, uint j); + +### bool game_is_lighted(cgame g, uint i, uint j); + +### bool game_has_error(cgame g, uint i, uint j); + +### bool game_check_move(cgame g, uint i, uint j, square s); + +### void game_play_move(game g, uint i, uint j, square s); + +### void game_update_flags(game g); + +### bool game_is_over(cgame g); + +### void game_restart(game g); + +### void game_print(cgame g); + +### game game_default(void); + +### game game_default_solution(void); From ee8a68e524cfcdbb1b5a5eea19bb7d255a4739c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Wed, 10 Nov 2021 17:23:08 +0100 Subject: [PATCH 030/281] update readme --- README.md | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 02c8f77..07ea5fa 100644 --- a/README.md +++ b/README.md @@ -1,49 +1,49 @@ # lightup-a42e -### game game_new(square *squares) -> +### game game_new(square *squares) -> thoguet -> fait ### game game_new_empty(void) -> -### game game_copy(cgame g); +### game game_copy(cgame g) -> -### bool game_equal(cgame g1, cgame g2); +### bool game_equal(cgame g1, cgame g2) -> -### void game_delete(game g); +### void game_delete(game g) -> -### void game_set_square(game g, uint i, uint j, square s); +### void game_set_square(game g, uint i, uint j, square s) -> -### square game_get_square(cgame g, uint i, uint j); +### square game_get_square(cgame g, uint i, uint j) -> thoguet -> fini -### square game_get_state(cgame g, uint i, uint j); +### square game_get_state(cgame g, uint i, uint j) -> -### square game_get_flags(cgame g, uint i, uint j); +### square game_get_flags(cgame g, uint i, uint j) -> -### bool game_is_blank(cgame g, uint i, uint j); +### bool game_is_blank(cgame g, uint i, uint j) -> -### bool game_is_lightbulb(cgame g, uint i, uint j); +### bool game_is_lightbulb(cgame g, uint i, uint j) -> -### bool game_is_black(cgame g, uint i, uint j); +### bool game_is_black(cgame g, uint i, uint j) -> -### int game_get_black_number(cgame g, uint i, uint j); +### int game_get_black_number(cgame g, uint i, uint j) -> -### bool game_is_marked(cgame g, uint i, uint j); +### bool game_is_marked(cgame g, uint i, uint j) -> -### bool game_is_lighted(cgame g, uint i, uint j); +### bool game_is_lighted(cgame g, uint i, uint j) -> -### bool game_has_error(cgame g, uint i, uint j); +### bool game_has_error(cgame g, uint i, uint j) -> -### bool game_check_move(cgame g, uint i, uint j, square s); +### bool game_check_move(cgame g, uint i, uint j, square s) -> -### void game_play_move(game g, uint i, uint j, square s); +### void game_play_move(game g, uint i, uint j, square s) -> -### void game_update_flags(game g); +### void game_update_flags(game g) -> -### bool game_is_over(cgame g); +### bool game_is_over(cgame g) -> -### void game_restart(game g); +### void game_restart(game g) -> -### void game_print(cgame g); +### void game_print(cgame g) -> thoguet -> fini -### game game_default(void); +### game game_default(void) -> thoguet -> fini -### game game_default_solution(void); +### game game_default_solution(void) -> thoguet -> fini From ae699d7d05c26ed53033b9f86578d3b6d3453d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Wed, 10 Nov 2021 17:25:23 +0100 Subject: [PATCH 031/281] update readme selected --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 07ea5fa..ee94d24 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,11 @@ ### void game_play_move(game g, uint i, uint j, square s) -> -### void game_update_flags(game g) -> +### void game_update_flags(game g) -> thoguet -> pas fait -### bool game_is_over(cgame g) -> +### bool game_is_over(cgame g) -> thoguet -> pas fait -### void game_restart(game g) -> +### void game_restart(game g) -> thoguet -> pas fait ### void game_print(cgame g) -> thoguet -> fini From f9e59ebf0e3c5b240437865408bee31ddc944f27 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Wed, 10 Nov 2021 17:29:48 +0100 Subject: [PATCH 032/281] ajout liste test thperrier --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 07ea5fa..dc9aa6b 100644 --- a/README.md +++ b/README.md @@ -2,29 +2,29 @@ ### game game_new(square *squares) -> thoguet -> fait -### game game_new_empty(void) -> +### game game_new_empty(void) -> thperrier -> à faire -### game game_copy(cgame g) -> +### game game_copy(cgame g) -> thperrier -> à faire -### bool game_equal(cgame g1, cgame g2) -> +### bool game_equal(cgame g1, cgame g2) -> thperrier -> à faire -### void game_delete(game g) -> +### void game_delete(game g) -> thperrier -> à faire ### void game_set_square(game g, uint i, uint j, square s) -> ### square game_get_square(cgame g, uint i, uint j) -> thoguet -> fini -### square game_get_state(cgame g, uint i, uint j) -> +### square game_get_state(cgame g, uint i, uint j) -> ### square game_get_flags(cgame g, uint i, uint j) -> -### bool game_is_blank(cgame g, uint i, uint j) -> +### bool game_is_blank(cgame g, uint i, uint j) -> thperrier -> à faire -### bool game_is_lightbulb(cgame g, uint i, uint j) -> +### bool game_is_lightbulb(cgame g, uint i, uint j) -> thperrier -> à faire -### bool game_is_black(cgame g, uint i, uint j) -> +### bool game_is_black(cgame g, uint i, uint j) -> thperrier -> à faire -### int game_get_black_number(cgame g, uint i, uint j) -> +### int game_get_black_number(cgame g, uint i, uint j) -> thperrier -> à faire ### bool game_is_marked(cgame g, uint i, uint j) -> From 88273a1c332134a74e4588171bfe07552023c527 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Wed, 10 Nov 2021 17:33:06 +0100 Subject: [PATCH 033/281] ajout liste test nnunes --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7aa3396..b637aa9 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,13 @@ ### void game_delete(game g) -> thperrier -> à faire -### void game_set_square(game g, uint i, uint j, square s) -> +### void game_set_square(game g, uint i, uint j, square s) -> nnunes -> à faire ### square game_get_square(cgame g, uint i, uint j) -> thoguet -> fini -### square game_get_state(cgame g, uint i, uint j) -> +### square game_get_state(cgame g, uint i, uint j) -> nnunes -> à faire -### square game_get_flags(cgame g, uint i, uint j) -> +### square game_get_flags(cgame g, uint i, uint j) -> nnunes -> à faire ### bool game_is_blank(cgame g, uint i, uint j) -> thperrier -> à faire @@ -26,15 +26,15 @@ ### int game_get_black_number(cgame g, uint i, uint j) -> thperrier -> à faire -### bool game_is_marked(cgame g, uint i, uint j) -> +### bool game_is_marked(cgame g, uint i, uint j) -> nnunes -> à faire -### bool game_is_lighted(cgame g, uint i, uint j) -> +### bool game_is_lighted(cgame g, uint i, uint j) -> nnunes -> à faire -### bool game_has_error(cgame g, uint i, uint j) -> +### bool game_has_error(cgame g, uint i, uint j) -> nnunes -> à faire -### bool game_check_move(cgame g, uint i, uint j, square s) -> +### bool game_check_move(cgame g, uint i, uint j, square s) -> nnunes -> à faire -### void game_play_move(game g, uint i, uint j, square s) -> +### void game_play_move(game g, uint i, uint j, square s) -> nnunes -> à faire ### void game_update_flags(game g) -> thoguet -> pas fait From 9e0192960b4a1a36d332b6300405a4b2da69dde5 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Wed, 10 Nov 2021 18:12:26 +0100 Subject: [PATCH 034/281] ajout test_game_new_empty + modification CMakeList --- CMakeLists.txt | 3 ++- game_test_thperrier.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38c786f..964b1b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,4 +26,5 @@ add_test(test_thoguet_get_square ./game_test_thoguet game_get_square) add_test(test_thoguet_default ./game_test_thoguet game_default) add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_solution) -add_test(test_thperrier_dummy ./game_test_thperrier dummy) \ No newline at end of file +add_test(test_thperrier_dummy ./game_test_thperrier dummy) +add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty) \ No newline at end of file diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 4ec7732..3430f31 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -2,11 +2,30 @@ #include #include #include +#include "game.h" +#include "game_aux.c" + +/* ********** DUMMY ********** */ bool test_dummy(){ return true; } +/* ********** game_new_empty ********** */ +bool test_game_new_empty(){ + game g = game_new_empty(); + assert(g); + for (int i = 0; i < DEFAULT_SIZE; i++){ + for (int j = 0; j < DEFAULT_SIZE; j++){ + if (game_get_flags(g, i, j) != S_BLANK){ + game_delete(g); + return false; + } + } + } + game_delete(g); + return true; +} void usage(int argc, char *argv[]){ fprintf(stderr, "Usage: %s \n", argv[0]); @@ -21,6 +40,9 @@ int main (int argc, char *argv[]){ else if (strcmp("dummy", argv[1]) == 0){ success = test_dummy(); } + else if (strcmp("game_new_empty", argv[1]) == 0){ + success = test_game_new_empty(); + } else{ fprintf (stderr, "test \"%s\" is not a valid test name.\n", argv[1]); return EXIT_FAILURE; From b64bf4ee3fb1b3ac8f2343bddf9c67651e1b8faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Wed, 10 Nov 2021 18:13:18 +0100 Subject: [PATCH 035/281] test_game_restart --- CMakeLists.txt | 2 ++ game_test_thoguet.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38c786f..107a6b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ enable_testing() #nom du projet project (game_text) +include(CTest) #positionne la variable set(CMAKE_C_FLAGS "-std=c99 -g -Wall") @@ -25,5 +26,6 @@ add_test(test_thoguet_game_print ./game_test_thoguet game_print) add_test(test_thoguet_get_square ./game_test_thoguet game_get_square) add_test(test_thoguet_default ./game_test_thoguet game_default) add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_solution) +add_test(test_game_restart ./game_test_thoguet game_restart) add_test(test_thperrier_dummy ./game_test_thperrier dummy) \ No newline at end of file diff --git a/game_test_thoguet.c b/game_test_thoguet.c index b9f68c5..561ca5c 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -12,15 +12,28 @@ bool test_dummy(void){ return EXIT_SUCCESS; } +/* ******* game_restart ******* */ + +bool test_game_restart(void){ + game g = game_default_solution(); + game g1 = game_default_solution(); + game_restart(g); + assert(game_equal(g,g1)); + return true; + game_delete(g); + game_delete(g1); +} + /* ********* game_new ********* */ bool test_game_new(void){ square tab[DEFAULT_SIZE*DEFAULT_SIZE]; game g; - for (int i = 0; i <= 128; i ++){ + int tab2[] = {0,1,2,8,9,10,11,12,13,16,32}; + for (int i = 0; i < 11; i ++){ g = NULL; for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ - tab[j] = i; + tab[j] = tab2[i]; } printf("%d\n",i); g = game_new(tab); @@ -36,9 +49,10 @@ bool test_game_new(void){ bool test_game_print(void){ game_print(NULL); square tab[DEFAULT_SIZE*DEFAULT_SIZE]; - for (int i = 0; i <= 128; i ++){ + 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] = i; + tab[j] = tab2[i]; } printf("%d\n",i); game_print(game_new(tab)); @@ -51,15 +65,17 @@ bool test_game_print(void){ bool test_game_get_square(void){ game g = game_new_empty(); square tab[DEFAULT_SIZE*DEFAULT_SIZE]; - for (int i = 0; i <= 128; i ++){ + 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] = i; + tab[j] = tab2[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]); } } return EXIT_SUCCESS; + game_delete(g); } /* ******* game_default ******* */ @@ -77,6 +93,7 @@ bool test_game_default(void){ assert(game_get_square(g,5,4) == S_BLACK2); assert(game_get_square(g,6,4) == S_BLACKU); return EXIT_SUCCESS; + game_delete(g); } /* *** game_default_solution *** */ @@ -106,6 +123,7 @@ bool test_game_default_solution(void){ assert(game_get_square(g,5,5) == (S_LIGHTBULB|F_LIGHTED)); assert(game_get_square(g,6,1) == (S_LIGHTBULB|F_LIGHTED)); return EXIT_SUCCESS; + game_delete(g); } /* ********** USAGE ********** */ @@ -134,6 +152,8 @@ int main(int argc, char * argv[]){ ok = test_game_default_solution(); else if (strcmp("game_new", argv[1]) == 0) ok = test_game_new(); + else if (strcmp("game_restart", argv[1]) == 0) + ok = test_game_restart(); else if (strcmp("game_get_square", argv[1]) == 0) ok = test_game_get_square(); else { From a3445bba9ddf2c96a4981290fcb4aaf8d5aa7df7 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Wed, 10 Nov 2021 18:13:29 +0100 Subject: [PATCH 036/281] test_game_new_empty fait --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b637aa9..b6b4320 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ### game game_new(square *squares) -> thoguet -> fait -### game game_new_empty(void) -> thperrier -> à faire +### game game_new_empty(void) -> thperrier -> fait ### game game_copy(cgame g) -> thperrier -> à faire From ca50774cfe180f22c4b3a2ff08d9c9f01bb2f1cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Wed, 10 Nov 2021 18:14:45 +0100 Subject: [PATCH 037/281] update readme game_restart --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b637aa9..75dd92b 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ ### bool game_is_over(cgame g) -> thoguet -> pas fait -### void game_restart(game g) -> thoguet -> pas fait +### void game_restart(game g) -> thoguet -> fait ### void game_print(cgame g) -> thoguet -> fini From 50366c557ea1c7ea6211d8ce03faa75deb62a8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Wed, 10 Nov 2021 18:27:10 +0100 Subject: [PATCH 038/281] update game restart --- game_test_thoguet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 561ca5c..0cc41d4 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -19,9 +19,9 @@ bool test_game_restart(void){ game g1 = game_default_solution(); game_restart(g); assert(game_equal(g,g1)); - return true; game_delete(g); game_delete(g1); + return EXIT_SUCCESS; } /* ********* game_new ********* */ From ec3a92b3a130152af6c1dd009aa345d8ea43f455 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Wed, 10 Nov 2021 18:38:59 +0100 Subject: [PATCH 039/281] ajout test_game_copy + modif readme + modif CMake --- CMakeLists.txt | 4 +++- README.md | 2 +- game_test_thperrier.c | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b925a0b..dcbe254 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ add_executable(game_test_thperrier game_test_thperrier.c) #les dépendances sont calculées automatiquement target_link_libraries(game_text game) target_link_libraries(game_test_thoguet game) +target_link_libraries(game_test_thperrier game) add_library (game game.o game_aux.c) add_test(test_thoguet_dummy ./game_test_thoguet dummy) add_test(test_thoguet_new ./game_test_thoguet game_new) @@ -29,4 +30,5 @@ add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_sol add_test(test_game_restart ./game_test_thoguet game_restart) add_test(test_thperrier_dummy ./game_test_thperrier dummy) -add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty) \ No newline at end of file +add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty) +add_test(test_thperrier_game_copy ./game_test_thperrier game_copy) \ No newline at end of file diff --git a/README.md b/README.md index fcee062..44a3ed9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ### game game_new_empty(void) -> thperrier -> fait -### game game_copy(cgame g) -> thperrier -> à faire +### game game_copy(cgame g) -> thperrier -> fait ### bool game_equal(cgame g1, cgame g2) -> thperrier -> à faire diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 3430f31..81699fc 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -2,8 +2,9 @@ #include #include #include +#include #include "game.h" -#include "game_aux.c" +#include "game_aux.h" /* ********** DUMMY ********** */ @@ -27,6 +28,21 @@ bool test_game_new_empty(){ return true; } +/* ********** game_copy ********** */ +bool test_game_copy(){ + game g1 = game_new_empty(); + game g2 = game_copy(g1); + assert(g2); + if (game_equal(g1, g2) == true){ + game_delete(g1); + game_delete(g2); + return true; + } + game_delete(g1); + game_delete(g2); + return true; +} + void usage(int argc, char *argv[]){ fprintf(stderr, "Usage: %s \n", argv[0]); exit(EXIT_FAILURE); @@ -43,6 +59,9 @@ int main (int argc, char *argv[]){ else if (strcmp("game_new_empty", argv[1]) == 0){ success = test_game_new_empty(); } + else if (strcmp("game_copy", argv[1]) == 0){ + success = test_game_copy(); + } else{ fprintf (stderr, "test \"%s\" is not a valid test name.\n", argv[1]); return EXIT_FAILURE; From 9aebca97242588a2fc5f16f7cb554ede3537f858 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Wed, 10 Nov 2021 20:38:29 +0100 Subject: [PATCH 040/281] bug fix --- game_test_thoguet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 0cc41d4..d4a19fd 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -16,7 +16,7 @@ bool test_dummy(void){ bool test_game_restart(void){ game g = game_default_solution(); - game g1 = game_default_solution(); + game g1 = game_default(); game_restart(g); assert(game_equal(g,g1)); game_delete(g); @@ -141,7 +141,7 @@ int main(int argc, char * argv[]){ usage(argc, argv); } fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); - bool ok = false; + bool ok = true; if (strcmp("dummy", argv[1]) == 0) ok = test_dummy(); else if (strcmp("game_print", argv[1]) == 0) From 43ebf0e4cef9cb555756de3a659ba1db46ef1b98 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Wed, 10 Nov 2021 21:41:22 +0100 Subject: [PATCH 041/281] print soluce on abandon game_text --- game_text.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/game_text.c b/game_text.c index f4c555a..cd42911 100644 --- a/game_text.c +++ b/game_text.c @@ -69,6 +69,8 @@ int main(void) { game_update_flags(g); game_print(g); }else if (c == 'q'){ + printf("Solution: \n"); + game_print(game_default_solution()); printf("shame\n"); return EXIT_SUCCESS; }else if (c == 'l' || c == 'm' || c == 'b'){ From 05c9cdc127e09c958d84aa9a7320be1629b9956c Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Wed, 10 Nov 2021 22:49:28 +0100 Subject: [PATCH 042/281] test gameisover --- CMakeLists.txt | 1 + game_test_thoguet.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index dcbe254..a8860bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ add_test(test_thoguet_get_square ./game_test_thoguet game_get_square) add_test(test_thoguet_default ./game_test_thoguet game_default) add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_solution) add_test(test_game_restart ./game_test_thoguet game_restart) +add_test(test_game_is_over ./game_test_thoguet game_is_over) add_test(test_thperrier_dummy ./game_test_thperrier dummy) add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index d4a19fd..d3aad84 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -12,6 +12,24 @@ bool test_dummy(void){ return EXIT_SUCCESS; } +/* ******* game_is_over ******* */ +bool test_game_is_over(void){ + square tab[49] = + { + S_LIGHTBULB,S_BLANK ,S_BLACK1 ,S_LIGHTBULB,S_BLANK ,S_BLANK ,S_BLANK , + S_BLANK ,S_LIGHTBULB,S_BLACK2 ,S_BLANK ,S_BLANK ,S_BLANK ,S_LIGHTBULB, + S_BLANK ,S_BLANK ,S_LIGHTBULB,S_BLANK ,S_BLANK ,S_BLACKU ,S_BLACK2 , + S_BLANK ,S_BLANK ,S_BLANK ,S_BLANK ,S_BLANK ,S_BLANK ,S_LIGHTBULB, + S_BLACK1 ,S_BLACKU ,S_BLANK ,S_BLANK ,S_LIGHTBULB,S_BLANK ,S_BLANK , + S_LIGHTBULB,S_BLANK ,S_BLANK ,S_BLANK ,S_BLACK2 ,S_LIGHTBULB,S_BLANK , + S_BLANK ,S_LIGHTBULB,S_BLANK ,S_BLANK ,S_BLACKU ,S_BLANK ,S_BLANK + }; + game g = game_new(tab); + game_update_flags(g); + assert(game_is_over(g)); + return EXIT_SUCCESS; +} + /* ******* game_restart ******* */ bool test_game_restart(void){ @@ -156,6 +174,8 @@ int main(int argc, char * argv[]){ ok = test_game_restart(); else if (strcmp("game_get_square", argv[1]) == 0) ok = test_game_get_square(); + else if (strcmp("game_is_over", argv[1]) == 0) + ok = test_game_is_over(); else { fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); exit(EXIT_FAILURE); From fffe5fede30370d230fd36bef0c04e6245927106 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Wed, 10 Nov 2021 23:06:45 +0100 Subject: [PATCH 043/281] resolve mem leak --- game_test_thoguet.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index d3aad84..f3d84a7 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -27,6 +27,7 @@ bool test_game_is_over(void){ game g = game_new(tab); game_update_flags(g); assert(game_is_over(g)); + game_delete(g); return EXIT_SUCCESS; } @@ -56,6 +57,7 @@ bool test_game_new(void){ printf("%d\n",i); g = game_new(tab); assert(g); + game_delete(g); } return EXIT_SUCCESS; } @@ -68,12 +70,15 @@ 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}; + game g; for (int i = 0; i < 11; i ++){ for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ tab[j] = tab2[i]; } printf("%d\n",i); - game_print(game_new(tab)); + g = game_new(tab); + game_print(g); + game_delete(g); } return EXIT_SUCCESS; } @@ -81,7 +86,7 @@ bool test_game_print(void){ /* ******* game_get_square ******* */ bool test_game_get_square(void){ - game g = game_new_empty(); + 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 ++){ @@ -90,10 +95,10 @@ bool test_game_get_square(void){ 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]); + game_delete(g); } } return EXIT_SUCCESS; - game_delete(g); } /* ******* game_default ******* */ @@ -110,8 +115,8 @@ bool test_game_default(void){ assert(game_get_square(g,4,1) == S_BLACKU); assert(game_get_square(g,5,4) == S_BLACK2); assert(game_get_square(g,6,4) == S_BLACKU); - return EXIT_SUCCESS; game_delete(g); + return EXIT_SUCCESS; } /* *** game_default_solution *** */ @@ -140,8 +145,8 @@ bool test_game_default_solution(void){ assert(game_get_square(g,5,0) == (S_LIGHTBULB|F_LIGHTED)); assert(game_get_square(g,5,5) == (S_LIGHTBULB|F_LIGHTED)); assert(game_get_square(g,6,1) == (S_LIGHTBULB|F_LIGHTED)); - return EXIT_SUCCESS; game_delete(g); + return EXIT_SUCCESS; } /* ********** USAGE ********** */ From 8bde30b52c13360967737e559b6281616fefa06f Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Thu, 11 Nov 2021 18:57:10 +0100 Subject: [PATCH 044/281] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 44a3ed9..d9690bb 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ ### void game_update_flags(game g) -> thoguet -> pas fait -### bool game_is_over(cgame g) -> thoguet -> pas fait +### bool game_is_over(cgame g) -> thoguet -> fait ### void game_restart(game g) -> thoguet -> fait From 6957bdf75511c75e53eba33fafa0d19b21ddec3c Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Thu, 11 Nov 2021 19:13:13 +0100 Subject: [PATCH 045/281] edit readme beautiful --- README.md | 74 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index d9690bb..0412d1c 100644 --- a/README.md +++ b/README.md @@ -1,49 +1,75 @@ # lightup-a42e -### game game_new(square *squares) -> thoguet -> fait +Projet Techno +## Tests + - [X] game game_new(square *squares) + - @thoguet -### game game_new_empty(void) -> thperrier -> fait + - [X] game game_new_empty(void) + - @thperrier -### game game_copy(cgame g) -> thperrier -> fait + - [X] game game_copy(cgame g) + - @thperrier -### bool game_equal(cgame g1, cgame g2) -> thperrier -> à faire + - [] bool game_equal(cgame g1, cgame g2) + - @thperrier -### void game_delete(game g) -> thperrier -> à faire + - [] void game_delete(game g) + - @thperrier -### void game_set_square(game g, uint i, uint j, square s) -> nnunes -> à faire + - [] void game_set_square(game g, uint i, uint j, square s) + - @nnunes -### square game_get_square(cgame g, uint i, uint j) -> thoguet -> fini + - [X] square game_get_square(cgame g, uint i, uint j) + - @thoguet -### square game_get_state(cgame g, uint i, uint j) -> nnunes -> à faire + - [] square game_get_state(cgame g, uint i, uint j) + - @nnunes -### square game_get_flags(cgame g, uint i, uint j) -> nnunes -> à faire + - [] square game_get_flags(cgame g, uint i, uint j) + - @nnunes -### bool game_is_blank(cgame g, uint i, uint j) -> thperrier -> à faire + - [] bool game_is_blank(cgame g, uint i, uint j) + - @thperrier -### bool game_is_lightbulb(cgame g, uint i, uint j) -> thperrier -> à faire + - [] bool game_is_lightbulb(cgame g, uint i, uint j) + - @thperrier -### bool game_is_black(cgame g, uint i, uint j) -> thperrier -> à faire + - [] bool game_is_black(cgame g, uint i, uint j) + - @thperrier -### int game_get_black_number(cgame g, uint i, uint j) -> thperrier -> à faire + - [] int game_get_black_number(cgame g, uint i, uint j) + - @thperrier -### bool game_is_marked(cgame g, uint i, uint j) -> nnunes -> à faire + - [] bool game_is_marked(cgame g, uint i, uint j) + - @nnunes -### bool game_is_lighted(cgame g, uint i, uint j) -> nnunes -> à faire + - [] bool game_is_lighted(cgame g, uint i, uint j) + - @nnunes -### bool game_has_error(cgame g, uint i, uint j) -> nnunes -> à faire + - [] bool game_has_error(cgame g, uint i, uint j) + - @nnunes -### bool game_check_move(cgame g, uint i, uint j, square s) -> nnunes -> à faire + - [] bool game_check_move(cgame g, uint i, uint j, square s) + - @nnunes -### void game_play_move(game g, uint i, uint j, square s) -> nnunes -> à faire + - [] void game_play_move(game g, uint i, uint j, square s) + - @nnunes -### void game_update_flags(game g) -> thoguet -> pas fait + - [] void game_update_flags(game g) + - @thoguet -> pas fait -### bool game_is_over(cgame g) -> thoguet -> fait + - [] bool game_is_over(cgame g) + - @thoguet -### void game_restart(game g) -> thoguet -> fait + - [X] void game_restart(game g) + - @thoguet -### void game_print(cgame g) -> thoguet -> fini + - [X] void game_print(cgame g) + - @thoguet -### game game_default(void) -> thoguet -> fini + - [X] game game_default(void) + - @thoguet -### game game_default_solution(void) -> thoguet -> fini + - [X] game game_default_solution(void) + - @thoguet From 5918c5592027c504a0324706504b69c8c6a54738 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Thu, 11 Nov 2021 19:13:56 +0100 Subject: [PATCH 046/281] reupdate --- README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0412d1c..dbf72d3 100644 --- a/README.md +++ b/README.md @@ -11,55 +11,55 @@ Projet Techno - [X] game game_copy(cgame g) - @thperrier - - [] bool game_equal(cgame g1, cgame g2) + - [ ] bool game_equal(cgame g1, cgame g2) - @thperrier - - [] void game_delete(game g) + - [ ] void game_delete(game g) - @thperrier - - [] void game_set_square(game g, uint i, uint j, square s) + - [ ] void game_set_square(game g, uint i, uint j, square s) - @nnunes - [X] square game_get_square(cgame g, uint i, uint j) - @thoguet - - [] square game_get_state(cgame g, uint i, uint j) + - [ ] square game_get_state(cgame g, uint i, uint j) - @nnunes - - [] square game_get_flags(cgame g, uint i, uint j) + - [ ] square game_get_flags(cgame g, uint i, uint j) - @nnunes - - [] bool game_is_blank(cgame g, uint i, uint j) + - [ ] bool game_is_blank(cgame g, uint i, uint j) - @thperrier - - [] bool game_is_lightbulb(cgame g, uint i, uint j) + - [ ] bool game_is_lightbulb(cgame g, uint i, uint j) - @thperrier - - [] bool game_is_black(cgame g, uint i, uint j) + - [ ] bool game_is_black(cgame g, uint i, uint j) - @thperrier - - [] int game_get_black_number(cgame g, uint i, uint j) + - [ ] int game_get_black_number(cgame g, uint i, uint j) - @thperrier - - [] bool game_is_marked(cgame g, uint i, uint j) + - [ ] bool game_is_marked(cgame g, uint i, uint j) - @nnunes - - [] bool game_is_lighted(cgame g, uint i, uint j) + - [ ] bool game_is_lighted(cgame g, uint i, uint j) - @nnunes - - [] bool game_has_error(cgame g, uint i, uint j) + - [ ] bool game_has_error(cgame g, uint i, uint j) - @nnunes - - [] bool game_check_move(cgame g, uint i, uint j, square s) + - [ ] bool game_check_move(cgame g, uint i, uint j, square s) - @nnunes - - [] void game_play_move(game g, uint i, uint j, square s) + - [ ] void game_play_move(game g, uint i, uint j, square s) - @nnunes - - [] void game_update_flags(game g) + - [ ] void game_update_flags(game g) - @thoguet -> pas fait - - [] bool game_is_over(cgame g) + - [ ] bool game_is_over(cgame g) - @thoguet - [X] void game_restart(game g) From 485c77eb197c983f30349c168f34fb6d2d0fe78c Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Thu, 11 Nov 2021 20:35:05 +0100 Subject: [PATCH 047/281] updated --- README.md | 96 +++++++++++++++---------------------------------------- 1 file changed, 26 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index dbf72d3..4f44164 100644 --- a/README.md +++ b/README.md @@ -2,74 +2,30 @@ Projet Techno ## Tests - - [X] game game_new(square *squares) - - @thoguet - - [X] game game_new_empty(void) - - @thperrier - - - [X] game game_copy(cgame g) - - @thperrier - - - [ ] bool game_equal(cgame g1, cgame g2) - - @thperrier - - - [ ] void game_delete(game g) - - @thperrier - - - [ ] void game_set_square(game g, uint i, uint j, square s) - - @nnunes - - - [X] square game_get_square(cgame g, uint i, uint j) - - @thoguet - - - [ ] square game_get_state(cgame g, uint i, uint j) - - @nnunes - - - [ ] square game_get_flags(cgame g, uint i, uint j) - - @nnunes - - - [ ] bool game_is_blank(cgame g, uint i, uint j) - - @thperrier - - - [ ] bool game_is_lightbulb(cgame g, uint i, uint j) - - @thperrier - - - [ ] bool game_is_black(cgame g, uint i, uint j) - - @thperrier - - - [ ] int game_get_black_number(cgame g, uint i, uint j) - - @thperrier - - - [ ] bool game_is_marked(cgame g, uint i, uint j) - - @nnunes - - - [ ] bool game_is_lighted(cgame g, uint i, uint j) - - @nnunes - - - [ ] bool game_has_error(cgame g, uint i, uint j) - - @nnunes - - - [ ] bool game_check_move(cgame g, uint i, uint j, square s) - - @nnunes - - - [ ] void game_play_move(game g, uint i, uint j, square s) - - @nnunes - - - [ ] void game_update_flags(game g) - - @thoguet -> pas fait - - - [ ] bool game_is_over(cgame g) - - @thoguet - - - [X] void game_restart(game g) - - @thoguet - - - [X] void game_print(cgame g) - - @thoguet - - - [X] game game_default(void) - - @thoguet - - - [X] game game_default_solution(void) - - @thoguet +| Test | Assigned to | Finished | +|----------------|---------------|:-----------:| +| game_new | @thoguet |
  • [x]
| +| game_new_empty | @thoguet |
  • [x]
| +| game_copy | @thperrier |
  • [x]
| +| game_equal | @thoguet |
  • [ ]
| +| game_delete | @thperrier |
  • [ ]
| +| game_set_square | @nnunes |
  • [ ]
| +| game_get_square | @thoguet |
  • [x]
| +| game_get_state | @nnunes |
  • [ ]
| +| game_get_flags | @nnunes |
  • [ ]
| +| game_is_blank | @thperrier |
  • [ ]
| +| game_is_lightbulb | @thperrier |
  • [ ]
| +| game_is_black | @thperrier |
  • [ ]
| +| game_get_black_number | @thperrier |
  • [ ]
| +| game_is_marked | @nnunes |
  • [ ]
| +| game_is_lighted | @nnunes |
  • [ ]
| +| game_has_error | @nnunes |
  • [ ]
| +| game_check_move | @nnunes |
  • [ ]
| +| game_play_move | @nnunes |
  • [ ]
| +| game_update_flags | @thoguet |
  • [ ]
| +| game_is_over | @thoguet |
  • [ ]
| +| game_restart | @thoguet |
  • [X]
| +| game_print | @thoguet |
  • [X]
| +| game_default | @thoguet |
  • [X]
| +| game_default_solution | @thoguet |
  • [X]
| \ No newline at end of file From c997a2ee911094ac69ea8bebc20046981f0ba36c Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Thu, 11 Nov 2021 20:51:16 +0100 Subject: [PATCH 048/281] finished readme --- README.md | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 4f44164..b43237a 100644 --- a/README.md +++ b/README.md @@ -5,27 +5,27 @@ Projet Techno | Test | Assigned to | Finished | |----------------|---------------|:-----------:| -| game_new | @thoguet |
  • [x]
| -| game_new_empty | @thoguet |
  • [x]
| -| game_copy | @thperrier |
  • [x]
| -| game_equal | @thoguet |
  • [ ]
| -| game_delete | @thperrier |
  • [ ]
| -| game_set_square | @nnunes |
  • [ ]
| -| game_get_square | @thoguet |
  • [x]
| -| game_get_state | @nnunes |
  • [ ]
| -| game_get_flags | @nnunes |
  • [ ]
| -| game_is_blank | @thperrier |
  • [ ]
| -| game_is_lightbulb | @thperrier |
  • [ ]
| -| game_is_black | @thperrier |
  • [ ]
| -| game_get_black_number | @thperrier |
  • [ ]
| -| game_is_marked | @nnunes |
  • [ ]
| -| game_is_lighted | @nnunes |
  • [ ]
| -| game_has_error | @nnunes |
  • [ ]
| -| game_check_move | @nnunes |
  • [ ]
| -| game_play_move | @nnunes |
  • [ ]
| -| game_update_flags | @thoguet |
  • [ ]
| -| game_is_over | @thoguet |
  • [ ]
| -| game_restart | @thoguet |
  • [X]
| -| game_print | @thoguet |
  • [X]
| -| game_default | @thoguet |
  • [X]
| -| game_default_solution | @thoguet |
  • [X]
| \ No newline at end of file +| [game_new](./game_test_thoguet.c#L55) | @thoguet |
  • [x]
| +| [game_new_empty](./game_test_thperrier.c#L16) | @thperrier |
  • [X]
| +| [game_copy](./game_test_thperrier.c#L32) | @thperrier |
  • [X]
| +| [game_equal](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| +| [game_delete](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| +| [game_set_square](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_get_square](./game_test_thoguet.c#L95) | @thoguet |
  • [x]
| +| [game_get_state](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_get_flags](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_is_blank](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| +| [game_is_lightbulb](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| +| [game_is_black](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| +| [game_get_black_number](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| +| [game_is_marked](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_is_lighted](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_has_error](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_check_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_play_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_update_flags](./game_test_thoguet.c#L?) | @thoguet |
  • [ ]
| +| [game_is_over](./game_test_thoguet.c#L?) | @thoguet |
  • [ ]
| +| [game_restart](./game_test_thoguet.c#L43) | @thoguet |
  • [X]
| +| [game_print](./game_test_thoguet.c#L76) | @thoguet |
  • [X]
| +| [game_default](./game_test_thoguet.c#L113) | @thoguet |
  • [X]
| +| [game_default_solution](./game_test_thoguet.c#L131) | @thoguet |
  • [X]
| \ No newline at end of file From 1c7695a3a6be3f7c0df8cbe100933951140f6da5 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Thu, 11 Nov 2021 21:04:22 +0100 Subject: [PATCH 049/281] readme checkbox --- README.md | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index b43237a..fa2c3ca 100644 --- a/README.md +++ b/README.md @@ -5,27 +5,27 @@ Projet Techno | Test | Assigned to | Finished | |----------------|---------------|:-----------:| -| [game_new](./game_test_thoguet.c#L55) | @thoguet |
  • [x]
| -| [game_new_empty](./game_test_thperrier.c#L16) | @thperrier |
  • [X]
| -| [game_copy](./game_test_thperrier.c#L32) | @thperrier |
  • [X]
| -| [game_equal](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_delete](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_set_square](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_get_square](./game_test_thoguet.c#L95) | @thoguet |
  • [x]
| -| [game_get_state](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_get_flags](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_is_blank](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_is_lightbulb](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_is_black](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_get_black_number](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_is_marked](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_is_lighted](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_has_error](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_check_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_play_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_update_flags](./game_test_thoguet.c#L?) | @thoguet |
  • [ ]
| -| [game_is_over](./game_test_thoguet.c#L?) | @thoguet |
  • [ ]
| -| [game_restart](./game_test_thoguet.c#L43) | @thoguet |
  • [X]
| -| [game_print](./game_test_thoguet.c#L76) | @thoguet |
  • [X]
| -| [game_default](./game_test_thoguet.c#L113) | @thoguet |
  • [X]
| -| [game_default_solution](./game_test_thoguet.c#L131) | @thoguet |
  • [X]
| \ No newline at end of file +| [game_new](./game_test_thoguet.c#L55) | @thoguet || +| [game_new_empty](./game_test_thperrier.c#L16) | @thperrier || +| [game_copy](./game_test_thperrier.c#L32) | @thperrier || +| [game_equal](./game_test_thperrier.c#L?) | @thperrier || +| [game_delete](./game_test_thperrier.c#L?) | @thperrier || +| [game_set_square](./game_test_nnunes.c#L?) | @nnunes || +| [game_get_square](./game_test_thoguet.c#L95) | @thoguet || +| [game_get_state](./game_test_nnunes.c#L?) | @nnunes || +| [game_get_flags](./game_test_nnunes.c#L?) | @nnunes || +| [game_is_blank](./game_test_thperrier.c#L?) | @thperrier || +| [game_is_lightbulb](./game_test_thperrier.c#L?) | @thperrier || +| [game_is_black](./game_test_thperrier.c#L?) | @thperrier || +| [game_get_black_number](./game_test_thperrier.c#L?) | @thperrier || +| [game_is_marked](./game_test_nnunes.c#L?) | @nnunes || +| [game_is_lighted](./game_test_nnunes.c#L?) | @nnunes || +| [game_has_error](./game_test_nnunes.c#L?) | @nnunes || +| [game_check_move](./game_test_nnunes.c#L?) | @nnunes || +| [game_play_move](./game_test_nnunes.c#L?) | @nnunes || +| [game_update_flags](./game_test_thoguet.c#L?) | @thoguet || +| [game_is_over](./game_test_thoguet.c#L?) | @thoguet || +| [game_restart](./game_test_thoguet.c#L43) | @thoguet || +| [game_print](./game_test_thoguet.c#L76) | @thoguet || +| [game_default](./game_test_thoguet.c#L113) | @thoguet || +| [game_default_solution](./game_test_thoguet.c#L131) | @thoguet || \ No newline at end of file From 65f6de758c13bc30b227d4a47cb6711384bb24ad Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Thu, 11 Nov 2021 21:11:08 +0100 Subject: [PATCH 050/281] Revert "readme checkbox" This reverts commit 1c7695a3a6be3f7c0df8cbe100933951140f6da5 --- README.md | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index fa2c3ca..b43237a 100644 --- a/README.md +++ b/README.md @@ -5,27 +5,27 @@ Projet Techno | Test | Assigned to | Finished | |----------------|---------------|:-----------:| -| [game_new](./game_test_thoguet.c#L55) | @thoguet || -| [game_new_empty](./game_test_thperrier.c#L16) | @thperrier || -| [game_copy](./game_test_thperrier.c#L32) | @thperrier || -| [game_equal](./game_test_thperrier.c#L?) | @thperrier || -| [game_delete](./game_test_thperrier.c#L?) | @thperrier || -| [game_set_square](./game_test_nnunes.c#L?) | @nnunes || -| [game_get_square](./game_test_thoguet.c#L95) | @thoguet || -| [game_get_state](./game_test_nnunes.c#L?) | @nnunes || -| [game_get_flags](./game_test_nnunes.c#L?) | @nnunes || -| [game_is_blank](./game_test_thperrier.c#L?) | @thperrier || -| [game_is_lightbulb](./game_test_thperrier.c#L?) | @thperrier || -| [game_is_black](./game_test_thperrier.c#L?) | @thperrier || -| [game_get_black_number](./game_test_thperrier.c#L?) | @thperrier || -| [game_is_marked](./game_test_nnunes.c#L?) | @nnunes || -| [game_is_lighted](./game_test_nnunes.c#L?) | @nnunes || -| [game_has_error](./game_test_nnunes.c#L?) | @nnunes || -| [game_check_move](./game_test_nnunes.c#L?) | @nnunes || -| [game_play_move](./game_test_nnunes.c#L?) | @nnunes || -| [game_update_flags](./game_test_thoguet.c#L?) | @thoguet || -| [game_is_over](./game_test_thoguet.c#L?) | @thoguet || -| [game_restart](./game_test_thoguet.c#L43) | @thoguet || -| [game_print](./game_test_thoguet.c#L76) | @thoguet || -| [game_default](./game_test_thoguet.c#L113) | @thoguet || -| [game_default_solution](./game_test_thoguet.c#L131) | @thoguet || \ No newline at end of file +| [game_new](./game_test_thoguet.c#L55) | @thoguet |
  • [x]
| +| [game_new_empty](./game_test_thperrier.c#L16) | @thperrier |
  • [X]
| +| [game_copy](./game_test_thperrier.c#L32) | @thperrier |
  • [X]
| +| [game_equal](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| +| [game_delete](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| +| [game_set_square](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_get_square](./game_test_thoguet.c#L95) | @thoguet |
  • [x]
| +| [game_get_state](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_get_flags](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_is_blank](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| +| [game_is_lightbulb](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| +| [game_is_black](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| +| [game_get_black_number](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| +| [game_is_marked](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_is_lighted](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_has_error](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_check_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_play_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| +| [game_update_flags](./game_test_thoguet.c#L?) | @thoguet |
  • [ ]
| +| [game_is_over](./game_test_thoguet.c#L?) | @thoguet |
  • [ ]
| +| [game_restart](./game_test_thoguet.c#L43) | @thoguet |
  • [X]
| +| [game_print](./game_test_thoguet.c#L76) | @thoguet |
  • [X]
| +| [game_default](./game_test_thoguet.c#L113) | @thoguet |
  • [X]
| +| [game_default_solution](./game_test_thoguet.c#L131) | @thoguet |
  • [X]
| \ No newline at end of file From dd2294b68de3130078306c862c0a62dde72727c4 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Thu, 11 Nov 2021 21:37:01 +0100 Subject: [PATCH 051/281] update readme line --- README.md | 12 ++++++------ game_test_thoguet.c | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b43237a..09210b0 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,13 @@ Projet Techno | Test | Assigned to | Finished | |----------------|---------------|:-----------:| -| [game_new](./game_test_thoguet.c#L55) | @thoguet |
  • [x]
| +| [game_new](./game_test_thoguet.c#L49) | @thoguet |
  • [x]
| | [game_new_empty](./game_test_thperrier.c#L16) | @thperrier |
  • [X]
| | [game_copy](./game_test_thperrier.c#L32) | @thperrier |
  • [X]
| | [game_equal](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| | [game_delete](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| | [game_set_square](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_get_square](./game_test_thoguet.c#L95) | @thoguet |
  • [x]
| +| [game_get_square](./game_test_thoguet.c#L89) | @thoguet |
  • [x]
| | [game_get_state](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| | [game_get_flags](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| | [game_is_blank](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| @@ -25,7 +25,7 @@ Projet Techno | [game_play_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| | [game_update_flags](./game_test_thoguet.c#L?) | @thoguet |
  • [ ]
| | [game_is_over](./game_test_thoguet.c#L?) | @thoguet |
  • [ ]
| -| [game_restart](./game_test_thoguet.c#L43) | @thoguet |
  • [X]
| -| [game_print](./game_test_thoguet.c#L76) | @thoguet |
  • [X]
| -| [game_default](./game_test_thoguet.c#L113) | @thoguet |
  • [X]
| -| [game_default_solution](./game_test_thoguet.c#L131) | @thoguet |
  • [X]
| \ No newline at end of file +| [game_restart](./game_test_thoguet.c#L37) | @thoguet |
  • [X]
| +| [game_print](./game_test_thoguet.c#L70) | @thoguet |
  • [X]
| +| [game_default](./game_test_thoguet.c#L107) | @thoguet |
  • [X]
| +| [game_default_solution](./game_test_thoguet.c#L125) | @thoguet |
  • [X]
| \ No newline at end of file diff --git a/game_test_thoguet.c b/game_test_thoguet.c index f3d84a7..281d009 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -13,6 +13,7 @@ bool test_dummy(void){ } /* ******* game_is_over ******* */ + bool test_game_is_over(void){ square tab[49] = { From 16b4fce11202d53813461e07ff9ee842c59c83af Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Thu, 11 Nov 2021 21:43:09 +0100 Subject: [PATCH 052/281] gameisover update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 09210b0..d5a5e40 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Projet Techno | [game_check_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| | [game_play_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| | [game_update_flags](./game_test_thoguet.c#L?) | @thoguet |
  • [ ]
| -| [game_is_over](./game_test_thoguet.c#L?) | @thoguet |
  • [ ]
| +| [game_is_over](./game_test_thoguet.c#L17) | @thoguet |
  • [X]
| | [game_restart](./game_test_thoguet.c#L37) | @thoguet |
  • [X]
| | [game_print](./game_test_thoguet.c#L70) | @thoguet |
  • [X]
| | [game_default](./game_test_thoguet.c#L107) | @thoguet |
  • [X]
| From 3579fb84fddd8476ed416fc4c22cb12aebe291c9 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Fri, 12 Nov 2021 02:07:27 +0100 Subject: [PATCH 053/281] update readme ajout refs --- README.md | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index d5a5e40..c0de0f6 100644 --- a/README.md +++ b/README.md @@ -3,29 +3,29 @@ Projet Techno ## Tests -| Test | Assigned to | Finished | -|----------------|---------------|:-----------:| -| [game_new](./game_test_thoguet.c#L49) | @thoguet |
  • [x]
| -| [game_new_empty](./game_test_thperrier.c#L16) | @thperrier |
  • [X]
| -| [game_copy](./game_test_thperrier.c#L32) | @thperrier |
  • [X]
| -| [game_equal](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_delete](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_set_square](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_get_square](./game_test_thoguet.c#L89) | @thoguet |
  • [x]
| -| [game_get_state](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_get_flags](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_is_blank](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_is_lightbulb](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_is_black](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_get_black_number](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_is_marked](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_is_lighted](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_has_error](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_check_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_play_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_update_flags](./game_test_thoguet.c#L?) | @thoguet |
  • [ ]
| -| [game_is_over](./game_test_thoguet.c#L17) | @thoguet |
  • [X]
| -| [game_restart](./game_test_thoguet.c#L37) | @thoguet |
  • [X]
| -| [game_print](./game_test_thoguet.c#L70) | @thoguet |
  • [X]
| -| [game_default](./game_test_thoguet.c#L107) | @thoguet |
  • [X]
| -| [game_default_solution](./game_test_thoguet.c#L125) | @thoguet |
  • [X]
| \ No newline at end of file +| Test | REF | Assigned to | Finished | +| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | :--------------------: | +| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet |
  • [x]
| +| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier |
  • [X]
| +| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier |
  • [X]
| +| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier |
  • [ ]
| +| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier |
  • [ ]
| +| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes |
  • [ ]
| +| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet |
  • [x]
| +| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes |
  • [ ]
| +| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes |
  • [ ]
| +| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier |
  • [ ]
| +| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier |
  • [ ]
| +| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier |
  • [ ]
| +| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier |
  • [ ]
| +| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes |
  • [ ]
| +| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes |
  • [ ]
| +| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes |
  • [ ]
| +| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes |
  • [ ]
| +| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes |
  • [ ]
| +| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L286-293) | @thoguet |
  • [ ]
| +| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet |
  • [X]
| +| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet |
  • [X]
| +| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet |
  • [X]
| +| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet |
  • [X]
| +| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet |
  • [X]
| \ No newline at end of file From 13c75854a84945037d6f2f0d7b1a2061074c44c6 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Fri, 12 Nov 2021 02:20:15 +0100 Subject: [PATCH 054/281] update readme add notes section --- README.md | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index c0de0f6..b86f110 100644 --- a/README.md +++ b/README.md @@ -3,29 +3,29 @@ Projet Techno ## Tests -| Test | REF | Assigned to | Finished | -| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | :--------------------: | -| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet |
  • [x]
| -| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier |
  • [X]
| -| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier |
  • [X]
| -| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier |
  • [ ]
| -| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier |
  • [ ]
| -| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes |
  • [ ]
| -| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet |
  • [x]
| -| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes |
  • [ ]
| -| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes |
  • [ ]
| -| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier |
  • [ ]
| -| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier |
  • [ ]
| -| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier |
  • [ ]
| -| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier |
  • [ ]
| -| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes |
  • [ ]
| -| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes |
  • [ ]
| -| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes |
  • [ ]
| -| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes |
  • [ ]
| -| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes |
  • [ ]
| -| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L286-293) | @thoguet |
  • [ ]
| -| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet |
  • [X]
| -| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet |
  • [X]
| -| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet |
  • [X]
| -| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet |
  • [X]
| -| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet |
  • [X]
| \ No newline at end of file +| Test | REF | Assigned to | Notes | Finished | +| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | -------------------------------------------------------- | :--------------------: | +| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| +| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| +| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| +| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| +| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| +| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| +| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| +| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| +| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| +| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| +| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| +| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| +| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| +| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| +| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| +| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| +| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| +| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| +| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L286-293) | @thoguet | finir checks walls / faire les autres directions / debug |
  • [ ]
| +| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| +| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| +| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| +| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| +| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| \ No newline at end of file From 2a4d904c509759efacfe0ba7b06a7d8388160b3a Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Fri, 12 Nov 2021 02:21:01 +0100 Subject: [PATCH 055/281] 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); From ec6fd26f8763608b9d0716a0968868a518cc9cfd Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Fri, 12 Nov 2021 02:23:44 +0100 Subject: [PATCH 056/281] updated readme --- README.md | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index d5a5e40..b86f110 100644 --- a/README.md +++ b/README.md @@ -3,29 +3,29 @@ Projet Techno ## Tests -| Test | Assigned to | Finished | -|----------------|---------------|:-----------:| -| [game_new](./game_test_thoguet.c#L49) | @thoguet |
  • [x]
| -| [game_new_empty](./game_test_thperrier.c#L16) | @thperrier |
  • [X]
| -| [game_copy](./game_test_thperrier.c#L32) | @thperrier |
  • [X]
| -| [game_equal](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_delete](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_set_square](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_get_square](./game_test_thoguet.c#L89) | @thoguet |
  • [x]
| -| [game_get_state](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_get_flags](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_is_blank](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_is_lightbulb](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_is_black](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_get_black_number](./game_test_thperrier.c#L?) | @thperrier |
  • [ ]
| -| [game_is_marked](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_is_lighted](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_has_error](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_check_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_play_move](./game_test_nnunes.c#L?) | @nnunes |
  • [ ]
| -| [game_update_flags](./game_test_thoguet.c#L?) | @thoguet |
  • [ ]
| -| [game_is_over](./game_test_thoguet.c#L17) | @thoguet |
  • [X]
| -| [game_restart](./game_test_thoguet.c#L37) | @thoguet |
  • [X]
| -| [game_print](./game_test_thoguet.c#L70) | @thoguet |
  • [X]
| -| [game_default](./game_test_thoguet.c#L107) | @thoguet |
  • [X]
| -| [game_default_solution](./game_test_thoguet.c#L125) | @thoguet |
  • [X]
| \ No newline at end of file +| Test | REF | Assigned to | Notes | Finished | +| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | -------------------------------------------------------- | :--------------------: | +| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| +| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| +| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| +| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| +| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| +| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| +| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| +| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| +| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| +| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| +| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| +| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| +| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| +| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| +| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| +| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| +| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| +| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| +| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L286-293) | @thoguet | finir checks walls / faire les autres directions / debug |
  • [ ]
| +| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| +| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| +| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| +| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| +| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| \ No newline at end of file From 95aabe4960022dda6c9f5827d1d31c0b2eb9c191 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sat, 13 Nov 2021 00:04:10 +0100 Subject: [PATCH 057/281] a debug --- game_test_thoguet.c | 63 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index f9f59eb..9e4a0d5 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -162,6 +162,11 @@ bool test_game_update_flags(void){ bool check_update(game g){ game tab_bulb[DEFAULT_SIZE*DEFAULT_SIZE]; + uint size; + square choice[4]; + uint lb; + uint notempty; + bool res; for (uint i = 0; i < DEFAULT_SIZE; i++){ for (uint j = 0; j< DEFAULT_SIZE; j++){ square state = game_get_state(g,i,j); @@ -172,6 +177,63 @@ bool check_update(game g){ 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 (state2 != S_BLACKU && state2 != (S_BLACKU|F_ERROR)){ + //lookup for lightbulb and emptycells + size = 0; + lb = 0; + notempty = 0; + res = true; + if (k > 0){ + choice[size] = game_get_state(g,k-1,j); + size++; + } + else{ + notempty++; + } + if (k < DEFAULT_SIZE-1){ + choice[size] = game_get_state(g,k+1,j); + size++; + } + else{ + notempty++; + } + if (j > 0){ + choice[size] = game_get_state(g,k,j-1); + size++; + } + else{ + notempty++; + } + if (j < DEFAULT_SIZE-1){ + choice[size] = game_get_state(g,k,j+1); + size++; + } + else{ + notempty++; + } + for (int l = 0 ; l < size ; l++){ + if (choice[l] == S_LIGHTBULB || choice[l] == (S_LIGHTBULB|F_ERROR) || choice[l] == (S_LIGHTBULB|F_LIGHTED) || choice[l] == (S_LIGHTBULB|F_ERROR|F_LIGHTED)){ + lb++; + } + else if (choice[l] != S_BLANK){ + notempty++; + } + } + if (lb+8 > state2){ + res = false; + } + //look if there is enough empty cell around the wall + else if (notempty > abs(state2-S_BLACK4)){ + res = false; + } + + if (!(state2 == S_BLACK0 || state2 == S_BLACK1 || state2 == S_BLACK2 || state2 == S_BLACK3 || state2 == S_BLACK4)){ + res = !res; + } + if (!res){ + return res; + } + } } //if no wall(s) before test if the light of the lightbulb has been well updated else if (!wall){ @@ -189,7 +251,6 @@ bool check_update(game g){ } } 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; } From 32aa67b92b9e11bc90f22027f05dc32316079207 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sat, 13 Nov 2021 00:05:04 +0100 Subject: [PATCH 058/281] a debug --- README.md | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index b86f110..ab5d2fa 100644 --- a/README.md +++ b/README.md @@ -3,29 +3,29 @@ Projet Techno ## Tests -| Test | REF | Assigned to | Notes | Finished | -| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | -------------------------------------------------------- | :--------------------: | -| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| -| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| -| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| -| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| -| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| -| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| -| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| -| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| -| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| -| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| -| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| -| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| -| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| -| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| -| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| -| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| -| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| -| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| -| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L286-293) | @thoguet | finir checks walls / faire les autres directions / debug |
  • [ ]
| -| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| -| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| -| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| -| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| -| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| \ No newline at end of file +| Test | REF | Assigned to | Notes | Finished | +| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | ------- | :--------------------: | +| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| +| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| +| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| +| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| +| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| +| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| +| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| +| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| +| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| +| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| +| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| +| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| +| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| +| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| +| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| +| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| +| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| +| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| +| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L286-293) | @thoguet | a debug |
  • [ ]
| +| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| +| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| +| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| +| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| +| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| \ No newline at end of file From 05f8007b3235046cce7b2e26629ced0df56d5880 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 03:38:46 +0100 Subject: [PATCH 059/281] update cmake + presque fini le test --- CMakeLists.txt | 1 + game_test_thoguet.c | 257 +++++++++++++++++++++++++++++--------------- 2 files changed, 173 insertions(+), 85 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a8860bf..92eed56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ add_test(test_thoguet_default ./game_test_thoguet game_default) add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_solution) add_test(test_game_restart ./game_test_thoguet game_restart) add_test(test_game_is_over ./game_test_thoguet game_is_over) +add_test(test_game_update_flags ./game_test_thoguet game_update_flags) add_test(test_thperrier_dummy ./game_test_thperrier dummy) add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 9e4a0d5..e841943 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -49,7 +49,7 @@ bool test_game_restart(void){ bool test_game_new(void){ square tab[DEFAULT_SIZE*DEFAULT_SIZE]; game g; - 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}; + square list[] = {S_BLANK,S_LIGHTBULB,S_MARK,S_BLACK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,S_BLACKU,F_ERROR}; for (uint i = 0; i < sizeof(list)/sizeof(list[0]) ; i ++){ g = NULL; for (uint j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ @@ -70,7 +70,7 @@ bool test_game_new(void){ bool test_game_print(void){ game_print(NULL); square tab[DEFAULT_SIZE*DEFAULT_SIZE]; - 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}; + square list[] = {S_BLANK,S_LIGHTBULB,S_MARK,S_BLACK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,S_BLACKU,F_ERROR}; game g; for (uint i = 0; i < sizeof(list)/sizeof(list[0]) ; i ++){ for (uint j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ @@ -89,7 +89,7 @@ bool test_game_print(void){ bool test_game_get_square(void){ game g; square tab[DEFAULT_SIZE*DEFAULT_SIZE]; - 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}; + square list[] = {S_BLANK,S_LIGHTBULB,S_MARK,S_BLACK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,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]; @@ -151,116 +151,203 @@ bool test_game_default_solution(void){ /* **** 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++){ +int checklightbulb(game g, uint i, uint j, bool wall){ + square flags = game_get_flags(g,i,j); + //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 (game_is_lightbulb(g,i,j)){ + if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR){ + return 0; + } + return -1; + } + //if no wall(s) before test if the light of the lightbulb has been well updated + if (!wall){ + + //test if the current case is not lighted + if (flags != F_LIGHTED){ + return 0; + } } - return EXIT_SUCCESS; + else{ + if (/*test if the current case is lighted*/ flags == F_LIGHTED){ + return 0; + } + } + return 1; } bool check_update(game g){ - game tab_bulb[DEFAULT_SIZE*DEFAULT_SIZE]; uint size; square choice[4]; uint lb; uint notempty; bool res; + bool wall; 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; + if (game_is_lightbulb(g,i,j)){ + square flags = game_get_flags(g,i,j); + if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR){ + return false; + } //loop checking every case before i + wall = false; 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)){ + if (/*test if current case is a wall*/ game_is_black(g,k,j)){ wall = true; - if (state2 != S_BLACKU && state2 != (S_BLACKU|F_ERROR)){ - //lookup for lightbulb and emptycells - size = 0; - lb = 0; - notempty = 0; - res = true; - if (k > 0){ - choice[size] = game_get_state(g,k-1,j); - size++; - } - else{ - notempty++; - } - if (k < DEFAULT_SIZE-1){ - choice[size] = game_get_state(g,k+1,j); - size++; - } - else{ - notempty++; - } - if (j > 0){ - choice[size] = game_get_state(g,k,j-1); - size++; - } - else{ - notempty++; - } - if (j < DEFAULT_SIZE-1){ - choice[size] = game_get_state(g,k,j+1); - size++; - } - else{ - notempty++; - } - for (int l = 0 ; l < size ; l++){ - if (choice[l] == S_LIGHTBULB || choice[l] == (S_LIGHTBULB|F_ERROR) || choice[l] == (S_LIGHTBULB|F_LIGHTED) || choice[l] == (S_LIGHTBULB|F_ERROR|F_LIGHTED)){ - lb++; - } - else if (choice[l] != S_BLANK){ - notempty++; - } - } - if (lb+8 > state2){ - res = false; - } - //look if there is enough empty cell around the wall - else if (notempty > abs(state2-S_BLACK4)){ - res = false; - } - - if (!(state2 == S_BLACK0 || state2 == S_BLACK1 || state2 == S_BLACK2 || state2 == S_BLACK3 || state2 == S_BLACK4)){ - res = !res; - } - if (!res){ - return res; - } - } } - //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)){ + else { + int tmp = checklightbulb(g,k,j,wall); + if (tmp == -1){ 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; + if (!tmp){ + return tmp; } } - 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; + } + wall = false; + for (int k = i+1; k < DEFAULT_SIZE; k++){ + if (/*test if current case is a wall*/ game_is_black(g,k,j)){ + wall = true; + } + else { + int tmp = checklightbulb(g,k,j,wall); + if (tmp == -1){ + break; } + if (!tmp){ + return tmp; + } + } + } + wall = false; + for (int k = j-1; k > 0; k--){ + if (/*test if current case is a wall*/ game_is_black(g,i,k)){ + wall = true; + } + else { + int tmp = checklightbulb(g,i,k,wall); + if (tmp == -1){ + break; + } + if (!tmp){ + return tmp; + } + } + } + wall = false; + for (int k = j+1; k < DEFAULT_SIZE; k++){ + if (/*test if current case is a wall*/ game_is_black(g,i,k)){ + wall = true; + } + else { + int tmp = checklightbulb(g,i,k,wall); + if (tmp == -1){ + break; + } + if (!tmp){ + return tmp; + } + } + } + } + if (/*test if current case is a wall*/game_is_black(g,i,j)){ + if (game_get_black_number(g,i,j) != -1){ + //lookup for lightbulb and emptycells + size = 0; + lb = 0; + notempty = 0; + res = true; + if (i > 0){ + choice[size] = game_get_square(g,i-1,j); + size++; + } + else{ + notempty++; + } + if (i < DEFAULT_SIZE-1){ + choice[size] = game_get_square(g,i+1,j); + size++; + } + else{ + notempty++; + } + if (j > 0){ + choice[size] = game_get_square(g,i,j-1); + size++; + } + else{ + notempty++; + } + if (j < DEFAULT_SIZE-1){ + choice[size] = game_get_square(g,i,j+1); + size++; + } + else{ + notempty++; + } + for (int l = 0 ; l < size ; l++){ + if (choice[l] == S_LIGHTBULB || choice[l] == (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ + lb++; + } + else if (choice[l] != S_BLANK){ + notempty++; + } + } + if (lb > game_get_black_number(g,i,j)){ + res = false; + } + //look if there is enough empty cell around the wall + else if (notempty > abs(game_get_black_number(g,i,j)-4)){ + res = false; + } + if (game_get_flags(g,i,j) == F_ERROR){ + res = !res; + } + if (!res){ + return res; } } } } } + return true; } +// a > 2 = temps d'exec > 3 min et expo +bool brutforce(game g,int a){ + square list[] = {S_LIGHTBULB,S_MARK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,S_BLACKU,S_BLANK}; + for (uint i = 0; i < DEFAULT_SIZE; i++){ + for (uint j = 0 ;j < DEFAULT_SIZE; j++){ + if (game_get_state(g,i,j) == S_BLANK){ + for (uint k = 0 ; k < sizeof(list)/sizeof(list[0]); k++){ + game_set_square(g,i,j,list[k]); + game_update_flags(g); + if (!check_update(g)){ + game_print(g); + return false; + } + if (a > 0){ + return brutforce(g,a-1); + } + } + } + } + } + return true; +} + +bool test_game_update_flags(void){ + game g = game_new_empty(); + if (!brutforce(g,DEFAULT_SIZE*DEFAULT_SIZE)){ + return EXIT_FAILURE; + }; + return EXIT_SUCCESS; +} + + /* ********** USAGE ********** */ int usage(int argc, char *argv[]) From 53bcea30f7720778670784f8f76590f8e9edeef7 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 03:39:20 +0100 Subject: [PATCH 060/281] update readme --- README.md | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index ab5d2fa..cce2acc 100644 --- a/README.md +++ b/README.md @@ -3,29 +3,29 @@ Projet Techno ## Tests -| Test | REF | Assigned to | Notes | Finished | -| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | ------- | :--------------------: | -| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| -| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| -| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| -| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| -| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| -| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| -| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| -| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| -| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| -| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| -| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| -| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| -| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| -| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| -| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| -| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| -| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| -| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| -| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L286-293) | @thoguet | a debug |
  • [ ]
| -| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| -| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| -| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| -| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| -| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| \ No newline at end of file +| Test | REF | Assigned to | Notes | Finished | +| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | -------------------- | :--------------------: | +| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| +| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| +| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| +| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| +| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| +| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| +| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| +| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| +| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| +| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| +| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| +| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| +| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| +| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| +| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| +| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| +| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| +| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| +| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L286-293) | @thoguet | pb avec le brutforce |
  • [ ]
| +| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| +| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| +| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| +| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| +| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| \ No newline at end of file From c7dc6a4556ebbc466288fbdef8e1f8340854292a Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 03:59:52 +0100 Subject: [PATCH 061/281] preshoot commit qui compile pas --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b86f110..b597ea9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # lightup-a42e Projet Techno + +LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE ## Tests | Test | REF | Assigned to | Notes | Finished | From 5133b97c9a7dfb7b52f5b7632868946f9cdd6fed Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 04:00:37 +0100 Subject: [PATCH 062/281] update du preshoot --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b597ea9..07eb639 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Projet Techno -LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE +**LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE** ## Tests | Test | REF | Assigned to | Notes | Finished | From 3c3ec09fc2328f9bb7f34b50d185b3ab735db7bc Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 04:03:13 +0100 Subject: [PATCH 063/281] ptit warning --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 07eb639..86240e5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Projet Techno -**LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE** +:warning: ** LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE ** :warning: ## Tests | Test | REF | Assigned to | Notes | Finished | From 96b45136b4bd2e0fa7e0182e6ab3da871eddb0b6 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 04:03:37 +0100 Subject: [PATCH 064/281] warning qui marche ? --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86240e5..2acc00f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Projet Techno -:warning: ** LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE ** :warning: +** :warning: LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE :warning: ** ## Tests | Test | REF | Assigned to | Notes | Finished | From 38409f1d3f88344b13502466416021288901909d Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 04:04:11 +0100 Subject: [PATCH 065/281] warning qui marche vrm ? --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2acc00f..1ab1786 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Projet Techno -** :warning: LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE :warning: ** +:warning: LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE :warning: ## Tests | Test | REF | Assigned to | Notes | Finished | From f2eab85bae19d0829e58e8b0915c051499fd1833 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 20:59:48 +0100 Subject: [PATCH 066/281] finished but not sure if it enough efficient --- game_test_thoguet.c | 106 +++++++++++++++++++++++++++++++++----------- 1 file changed, 81 insertions(+), 25 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index e841943..960677b 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -15,19 +15,12 @@ bool test_dummy(void){ /* ******* game_is_over ******* */ bool test_game_is_over(void){ - square tab[49] = - { - S_LIGHTBULB,S_BLANK ,S_BLACK1 ,S_LIGHTBULB,S_BLANK ,S_BLANK ,S_BLANK , - S_BLANK ,S_LIGHTBULB,S_BLACK2 ,S_BLANK ,S_BLANK ,S_BLANK ,S_LIGHTBULB, - S_BLANK ,S_BLANK ,S_LIGHTBULB,S_BLANK ,S_BLANK ,S_BLACKU ,S_BLACK2 , - S_BLANK ,S_BLANK ,S_BLANK ,S_BLANK ,S_BLANK ,S_BLANK ,S_LIGHTBULB, - S_BLACK1 ,S_BLACKU ,S_BLANK ,S_BLANK ,S_LIGHTBULB,S_BLANK ,S_BLANK , - S_LIGHTBULB,S_BLANK ,S_BLANK ,S_BLANK ,S_BLACK2 ,S_LIGHTBULB,S_BLANK , - S_BLANK ,S_LIGHTBULB,S_BLANK ,S_BLANK ,S_BLACKU ,S_BLANK ,S_BLANK - }; - game g = game_new(tab); + game g = game_default_solution(); game_update_flags(g); assert(game_is_over(g)); + g = game_default(); + game_update_flags(g); + assert(!game_is_over(g)); game_delete(g); return EXIT_SUCCESS; } @@ -153,9 +146,11 @@ bool test_game_default_solution(void){ int checklightbulb(game g, uint i, uint j, bool wall){ square flags = game_get_flags(g,i,j); + square state = game_get_state(g,i,j); //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 (game_is_lightbulb(g,i,j)){ if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR){ + //printf("156\n"); return 0; } return -1; @@ -165,12 +160,56 @@ int checklightbulb(game g, uint i, uint j, bool wall){ //test if the current case is not lighted if (flags != F_LIGHTED){ + //printf("170\n"); return 0; } } else{ if (/*test if the current case is lighted*/ flags == F_LIGHTED){ + //printf("i:%d j:%d\n",i,j); + for (int i2 = i-1 ; i2 >= 0; i2--){ + flags = game_get_flags(g,i2,j); + state = game_get_state(g,i2,j); + //printf("i2:%d i2state:%d i2flags:%d\n",i2,state,flags); + if (state == S_LIGHTBULB){ + return -1; + } + if (flags != F_LIGHTED){ + break; + } + } + for (int i2 = i+1 ; i2 < DEFAULT_SIZE; i2++){ + flags = game_get_flags(g,i2,j); + state = game_get_state(g,i2,j); + if (state == S_LIGHTBULB){ + return -1; + } + if (flags != F_LIGHTED){ + break; + } + } + for (int j2 = j-1 ; j2 >= 0; j2--){ + flags = game_get_flags(g,i,j2); + state = game_get_state(g,i,j2); + if (state == S_LIGHTBULB){ + return -1; + } + if (flags != F_LIGHTED){ + break; + } + } + for (int j2 = j+1 ; j2 < DEFAULT_SIZE; j2++){ + flags = game_get_flags(g,i,j2); + state = game_get_state(g,i,j2); + if (state == S_LIGHTBULB){ + return -1; + } + if (flags != F_LIGHTED){ + break; + } + } + //printf("220\n"); return 0; } } @@ -189,6 +228,7 @@ bool check_update(game g){ if (game_is_lightbulb(g,i,j)){ square flags = game_get_flags(g,i,j); if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR){ + //printf("196\n"); return false; } //loop checking every case before i @@ -253,7 +293,7 @@ bool check_update(game g){ } } } - if (/*test if current case is a wall*/game_is_black(g,i,j)){ + else if (/*test if current case is a wall*/game_is_black(g,i,j)){ if (game_get_black_number(g,i,j) != -1){ //lookup for lightbulb and emptycells size = 0; @@ -289,7 +329,7 @@ bool check_update(game g){ notempty++; } for (int l = 0 ; l < size ; l++){ - if (choice[l] == S_LIGHTBULB || choice[l] == (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ + if (choice[l] == (S_LIGHTBULB|F_LIGHTED) || choice[l] == (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ lb++; } else if (choice[l] != S_BLANK){ @@ -307,6 +347,8 @@ bool check_update(game g){ res = !res; } if (!res){ + //printf("386\n"); + //printf("lb:%d notempty:%d i:%d j:%d state : %d, flags: %d\n",lb,notempty,i,j,game_get_state(g,i,j),game_get_flags(g,i,j)); return res; } } @@ -319,31 +361,45 @@ bool check_update(game g){ // a > 2 = temps d'exec > 3 min et expo bool brutforce(game g,int a){ square list[] = {S_LIGHTBULB,S_MARK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,S_BLACKU,S_BLANK}; + uint * deldup = (uint *) calloc(DEFAULT_SIZE*DEFAULT_SIZE,sizeof(uint)); for (uint i = 0; i < DEFAULT_SIZE; i++){ for (uint j = 0 ;j < DEFAULT_SIZE; j++){ - if (game_get_state(g,i,j) == S_BLANK){ - for (uint k = 0 ; k < sizeof(list)/sizeof(list[0]); k++){ - game_set_square(g,i,j,list[k]); - game_update_flags(g); - if (!check_update(g)){ - game_print(g); - return false; - } - if (a > 0){ - return brutforce(g,a-1); + if (!deldup[i+j]){ + if (game_get_state(g,i,j) == S_BLANK){ + for (uint k = 0 ; k < sizeof(list)/sizeof(list[0]); k++){ + game_set_square(g,i,j,list[k]); + deldup[i+j] = 1; + game_update_flags(g); + // game_print(g); + if (!check_update(g)){ + game_print(g); + //printf("i:%d j:%d state : %d, flags: %d\n",i,j,game_get_state(g,i,j),game_get_flags(g,i,j)); + free(deldup); + return false; + } + if (a > 0){ + if (!brutforce(g,a-1)){ + //printf("341\n"); + free(deldup); + return false; + } + } } } } } } + free(deldup); return true; } bool test_game_update_flags(void){ game g = game_new_empty(); - if (!brutforce(g,DEFAULT_SIZE*DEFAULT_SIZE)){ + if (!brutforce(g,2)){ + game_delete(g); return EXIT_FAILURE; - }; + } + game_delete(g); return EXIT_SUCCESS; } From 73ac0bbb4a6124a10b1711d2ccac15eccdbf76b6 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 21:03:59 +0100 Subject: [PATCH 067/281] update readme --- README.md | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 485276c..8207e0a 100644 --- a/README.md +++ b/README.md @@ -5,29 +5,29 @@ Projet Techno :warning: LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE :warning: ## Tests -| Test | REF | Assigned to | Notes | Finished | -| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | ------------------------ | :--------------------: | -| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| -| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| -| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| -| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| -| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| -| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| -| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| -| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| -| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| -| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| -| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| -| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| -| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| -| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| -| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| -| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| -| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| -| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| -| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | not sure if it efficient |
  • [X]
| -| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| -| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| -| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| -| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| -| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| +| Test | REF | Assigned to | Notes | Finished | +| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | -------------------------- | :--------------------: | +| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| +| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| +| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| +| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| +| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| +| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| +| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| +| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| +| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| +| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| +| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| +| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| +| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| +| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| +| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| +| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| +| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| +| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| +| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | not sure if it's efficient |
  • [X]
| +| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| +| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| +| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| +| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| +| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| From 5ac78463cf79ffda7f32f49bc411cd9428883bd3 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 21:10:26 +0100 Subject: [PATCH 068/281] changes for moodle --- CMakeLists.txt | 12 ++++++------ README.md | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92eed56..5bb0acd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,14 +22,14 @@ target_link_libraries(game_test_thoguet game) target_link_libraries(game_test_thperrier game) add_library (game game.o game_aux.c) add_test(test_thoguet_dummy ./game_test_thoguet dummy) -add_test(test_thoguet_new ./game_test_thoguet game_new) +add_test(test_thoguet_game_new ./game_test_thoguet game_new) add_test(test_thoguet_game_print ./game_test_thoguet game_print) -add_test(test_thoguet_get_square ./game_test_thoguet game_get_square) -add_test(test_thoguet_default ./game_test_thoguet game_default) +add_test(test_thoguet_game_get_square ./game_test_thoguet game_get_square) +add_test(test_thoguet_game_default ./game_test_thoguet game_default) add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_solution) -add_test(test_game_restart ./game_test_thoguet game_restart) -add_test(test_game_is_over ./game_test_thoguet game_is_over) -add_test(test_game_update_flags ./game_test_thoguet game_update_flags) +add_test(test_thoguet_game_restart ./game_test_thoguet game_restart) +add_test(test_thoguet_game_is_over ./game_test_thoguet game_is_over) +add_test(test_thoguet_game_update_flags ./game_test_thoguet game_update_flags) add_test(test_thperrier_dummy ./game_test_thperrier dummy) add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty) diff --git a/README.md b/README.md index 8207e0a..160eab3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Projet Techno :warning: LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE :warning: -## Tests +## Test | Test | REF | Assigned to | Notes | Finished | | --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | -------------------------- | :--------------------: | From e21080ad4fec2ecbb8f24e3f709bdd679ead6a61 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 21:14:18 +0100 Subject: [PATCH 069/281] debug vpl --- game_test_thoguet.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 960677b..5fbde92 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -61,9 +61,8 @@ bool test_game_new(void){ // est ce qu'il faut faire avec un tab invalide ? bool test_game_print(void){ - game_print(NULL); square tab[DEFAULT_SIZE*DEFAULT_SIZE]; - square list[] = {S_BLANK,S_LIGHTBULB,S_MARK,S_BLACK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,S_BLACKU,F_ERROR}; + square list[] = {S_BLANK,S_LIGHTBULB,S_MARK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,S_BLACKU}; game g; for (uint i = 0; i < sizeof(list)/sizeof(list[0]) ; i ++){ for (uint j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ @@ -395,7 +394,7 @@ bool brutforce(game g,int a){ bool test_game_update_flags(void){ game g = game_new_empty(); - if (!brutforce(g,2)){ + if (!brutforce(g,3)){ game_delete(g); return EXIT_FAILURE; } From f58325658f53f2a2a603beaa75c462174e34e467 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 21:15:54 +0100 Subject: [PATCH 070/281] debug moodle --- game_test_thoguet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 5fbde92..c119f8d 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -394,7 +394,7 @@ bool brutforce(game g,int a){ bool test_game_update_flags(void){ game g = game_new_empty(); - if (!brutforce(g,3)){ + if (!brutforce(g,1)){ game_delete(g); return EXIT_FAILURE; } From 5e98e7b8597917efbcd05ed12d6783cd705f8c38 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 22:40:31 +0100 Subject: [PATCH 071/281] tried to clean up but i failed --- game_test_thoguet.c | 73 +++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 960677b..efe44be 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -146,7 +146,7 @@ bool test_game_default_solution(void){ int checklightbulb(game g, uint i, uint j, bool wall){ square flags = game_get_flags(g,i,j); - square state = game_get_state(g,i,j); + //square state = game_get_state(g,i,j); //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 (game_is_lightbulb(g,i,j)){ if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR){ @@ -169,43 +169,39 @@ int checklightbulb(game g, uint i, uint j, bool wall){ if (/*test if the current case is lighted*/ flags == F_LIGHTED){ //printf("i:%d j:%d\n",i,j); for (int i2 = i-1 ; i2 >= 0; i2--){ - flags = game_get_flags(g,i2,j); - state = game_get_state(g,i2,j); + flags = game_get_square(g,i2,j); //printf("i2:%d i2state:%d i2flags:%d\n",i2,state,flags); - if (state == S_LIGHTBULB){ + if (flags == (S_LIGHTBULB|F_LIGHTED) || flags == (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ return -1; } - if (flags != F_LIGHTED){ + if (flags != F_LIGHTED && flags != (F_LIGHTED|S_MARK)){ break; } } for (int i2 = i+1 ; i2 < DEFAULT_SIZE; i2++){ - flags = game_get_flags(g,i2,j); - state = game_get_state(g,i2,j); - if (state == S_LIGHTBULB){ + flags = game_get_square(g,i2,j); + if (flags == (S_LIGHTBULB|F_LIGHTED) || flags == (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ return -1; } - if (flags != F_LIGHTED){ + if (flags != F_LIGHTED && flags != (F_LIGHTED|S_MARK)){ break; } } for (int j2 = j-1 ; j2 >= 0; j2--){ - flags = game_get_flags(g,i,j2); - state = game_get_state(g,i,j2); - if (state == S_LIGHTBULB){ + flags = game_get_square(g,i,j2); + if (flags == (S_LIGHTBULB|F_LIGHTED) || flags == (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ return -1; } - if (flags != F_LIGHTED){ + if (flags != F_LIGHTED && flags != (F_LIGHTED|S_MARK)){ break; } } for (int j2 = j+1 ; j2 < DEFAULT_SIZE; j2++){ - flags = game_get_flags(g,i,j2); - state = game_get_state(g,i,j2); - if (state == S_LIGHTBULB){ + flags = game_get_square(g,i,j2); + if (flags == (S_LIGHTBULB|F_LIGHTED) || flags == (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ return -1; } - if (flags != F_LIGHTED){ + if (flags != F_LIGHTED && flags != (F_LIGHTED|S_MARK)){ break; } } @@ -359,43 +355,54 @@ bool check_update(game g){ } // a > 2 = temps d'exec > 3 min et expo -bool brutforce(game g,int a){ +bool brutforce(game g,int a, bool * deldup){ + // char c; + bool * delDupNext; + if (a > 0) + delDupNext = (bool *) calloc(DEFAULT_SIZE*DEFAULT_SIZE,sizeof(bool)); square list[] = {S_LIGHTBULB,S_MARK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,S_BLACKU,S_BLANK}; - uint * deldup = (uint *) calloc(DEFAULT_SIZE*DEFAULT_SIZE,sizeof(uint)); for (uint i = 0; i < DEFAULT_SIZE; i++){ for (uint j = 0 ;j < DEFAULT_SIZE; j++){ - if (!deldup[i+j]){ + // printf("state: %d i:%d j:%d\n",game_get_state(g,i,j),i,j); + if (deldup == NULL || !(deldup[i*DEFAULT_SIZE+j])){ if (game_get_state(g,i,j) == S_BLANK){ - for (uint k = 0 ; k < sizeof(list)/sizeof(list[0]); k++){ + if (delDupNext != NULL && a > 0) + delDupNext[i*DEFAULT_SIZE+j] = true; + for (uint k = 0 ; k < 9; k++){ game_set_square(g,i,j,list[k]); - deldup[i+j] = 1; + // if (k == 0){ + // game_print(g); + // scanf("%c",&c); + // } + if (a > 0){ + if (!brutforce(g,a-1,delDupNext)){ + //printf("341\n"); + if (delDupNext != NULL) + free(delDupNext); + return false; + } + } game_update_flags(g); - // game_print(g); if (!check_update(g)){ game_print(g); //printf("i:%d j:%d state : %d, flags: %d\n",i,j,game_get_state(g,i,j),game_get_flags(g,i,j)); - free(deldup); + if (delDupNext != NULL && a > 0) + free(delDupNext); return false; } - if (a > 0){ - if (!brutforce(g,a-1)){ - //printf("341\n"); - free(deldup); - return false; - } - } } } } } } - free(deldup); + if (delDupNext != NULL && a > 0) + free(delDupNext); return true; } bool test_game_update_flags(void){ game g = game_new_empty(); - if (!brutforce(g,2)){ + if (!brutforce(g,2,NULL)){ game_delete(g); return EXIT_FAILURE; } From f980c2e0f9211bd09e4ad74a2cadf9fad648d15e Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 22:49:23 +0100 Subject: [PATCH 072/281] more efficient on large scale but not on little --- game_test_thoguet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index efe44be..a139703 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -402,7 +402,7 @@ bool brutforce(game g,int a, bool * deldup){ bool test_game_update_flags(void){ game g = game_new_empty(); - if (!brutforce(g,2,NULL)){ + if (!brutforce(g,1,NULL)){ game_delete(g); return EXIT_FAILURE; } From 74216f3323afd9940348094ac994e02f6ca2b564 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 22:52:45 +0100 Subject: [PATCH 073/281] test game default --- game_test_thoguet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 9932aa1..81534c8 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -400,7 +400,7 @@ bool brutforce(game g,int a, bool * deldup){ } bool test_game_update_flags(void){ - game g = game_new_empty(); + game g = game_default(); if (!brutforce(g,1,NULL)){ game_delete(g); return EXIT_FAILURE; From 681d52d8f4da9856e2afc64f1bd08856f1536f2f Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 22:53:50 +0100 Subject: [PATCH 074/281] updated --- README.md | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 160eab3..bde8f81 100644 --- a/README.md +++ b/README.md @@ -5,29 +5,29 @@ Projet Techno :warning: LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE :warning: ## Test -| Test | REF | Assigned to | Notes | Finished | -| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | -------------------------- | :--------------------: | -| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| -| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| -| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| -| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| -| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| -| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| -| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| -| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| -| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| -| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| -| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| -| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| -| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| -| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| -| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| -| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| -| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| -| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| -| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | not sure if it's efficient |
  • [X]
| -| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| -| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| -| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| -| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| -| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| +| Test | REF | Assigned to | Notes | Finished | +| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | --------------------------------------- | :--------------------: | +| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| +| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| +| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| +| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| +| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| +| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| +| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| +| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| +| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| +| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| +| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| +| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| +| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| +| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| +| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| +| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| +| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| +| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| +| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every case |
  • [X]
| +| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| +| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| +| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| +| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| +| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| From 6beb0be763a4443956c3f7c8de130cdec52ac8ca Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Sun, 14 Nov 2021 22:54:46 +0100 Subject: [PATCH 075/281] updated --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bde8f81..28a9030 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Projet Techno | [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| | [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| | [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| -| [game_update_flags](./game_test_thoguet.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every case |
  • [X]
| +| [game_update_flags](./game_test_thoguet.c#L144-410) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every case |
  • [X]
| | [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| | [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| | [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| From 1c8977c0525de4ce75d04c645230217c9ed5a6c4 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Mon, 15 Nov 2021 19:00:46 +0100 Subject: [PATCH 076/281] ajout test_game_equal + modif Cmake et README --- CMakeLists.txt | 3 ++- README.md | 2 +- game_test_thperrier.c | 22 +++++++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bb0acd..6493f02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,5 +32,6 @@ add_test(test_thoguet_game_is_over ./game_test_thoguet game_is_over) add_test(test_thoguet_game_update_flags ./game_test_thoguet game_update_flags) add_test(test_thperrier_dummy ./game_test_thperrier dummy) +add_test(test_thperrier_game_copy ./game_test_thperrier game_copy) add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty) -add_test(test_thperrier_game_copy ./game_test_thperrier game_copy) \ No newline at end of file +add_test(test_thperrier_game_equal ./game_test_thperrier game_equal) \ No newline at end of file diff --git a/README.md b/README.md index 28a9030..4fe4b56 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Projet Techno | [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| | [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| | [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| -| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| +| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [X]
| | [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| | [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| | [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 81699fc..3ce74b5 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -12,13 +12,30 @@ bool test_dummy(){ return true; } +/* ********** game_equal ********** */ +bool test_game_equal(){ + bool equal = true; + game g1 = game_new_empty(); + game g2 = game_new_empty(); + for (int i = 0; i < DEFAULT_SIZE; i++){ + for (int j = 0; j < DEFAULT_SIZE; j++){ + if (game_get_square(g1, i, j) != game_get_square(g2, i, j)){ + game_delete(g1); + game_delete(g2); + equal = false; + } + } + } + return (equal == game_equal(g1, g2)); +} + /* ********** game_new_empty ********** */ bool test_game_new_empty(){ game g = game_new_empty(); assert(g); for (int i = 0; i < DEFAULT_SIZE; i++){ for (int j = 0; j < DEFAULT_SIZE; j++){ - if (game_get_flags(g, i, j) != S_BLANK){ + if (game_get_square(g, i, j) != S_BLANK){ game_delete(g); return false; } @@ -62,6 +79,9 @@ int main (int argc, char *argv[]){ else if (strcmp("game_copy", argv[1]) == 0){ success = test_game_copy(); } + else if (strcmp("game_equal", argv[1]) == 0){ + success = test_game_equal(); + } else{ fprintf (stderr, "test \"%s\" is not a valid test name.\n", argv[1]); return EXIT_FAILURE; From 0cc0bfa4c225d4696f54d7fa9c83a1cc03696585 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Mon, 15 Nov 2021 20:42:52 +0100 Subject: [PATCH 077/281] ajout test_game_delete + modif CMake & README --- CMakeLists.txt | 3 ++- README.md | 2 +- game_test_thperrier.c | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6493f02..dbb5ac0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,4 +34,5 @@ add_test(test_thoguet_game_update_flags ./game_test_thoguet game_update_flags) add_test(test_thperrier_dummy ./game_test_thperrier dummy) add_test(test_thperrier_game_copy ./game_test_thperrier game_copy) add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty) -add_test(test_thperrier_game_equal ./game_test_thperrier game_equal) \ No newline at end of file +add_test(test_thperrier_game_equal ./game_test_thperrier game_equal) +add_test(test_thperrier_game_delete ./game_test_thperrier game_delete) \ No newline at end of file diff --git a/README.md b/README.md index 4fe4b56..ddcfd47 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Projet Techno | [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| | [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| | [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [X]
| -| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| +| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| | [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| | [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| | [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 3ce74b5..36f5660 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -12,6 +12,17 @@ bool test_dummy(){ return true; } +/* ********** game_delete ********** */ +bool test_game_delete(){ + game g1 = game_new_empty(); + game g2 = game_new_empty(); + game_delete(g1); + if (game_equal(g1, g2)){ + return false; + } + return true; +} + /* ********** game_equal ********** */ bool test_game_equal(){ bool equal = true; @@ -82,6 +93,9 @@ int main (int argc, char *argv[]){ else if (strcmp("game_equal", argv[1]) == 0){ success = test_game_equal(); } + else if (strcmp("game_delete", argv[1]) == 0){ + success = test_game_delete(); + } else{ fprintf (stderr, "test \"%s\" is not a valid test name.\n", argv[1]); return EXIT_FAILURE; From 6632eb4b2ddf670011528c3f840eee04d39b6279 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Mon, 15 Nov 2021 21:16:25 +0100 Subject: [PATCH 078/281] ajout game_is_blank + modif CMake & README --- CMakeLists.txt | 3 ++- README.md | 2 +- game_test_thperrier.c | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbb5ac0..549981f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,4 +35,5 @@ add_test(test_thperrier_dummy ./game_test_thperrier dummy) add_test(test_thperrier_game_copy ./game_test_thperrier game_copy) add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty) add_test(test_thperrier_game_equal ./game_test_thperrier game_equal) -add_test(test_thperrier_game_delete ./game_test_thperrier game_delete) \ No newline at end of file +add_test(test_thperrier_game_delete ./game_test_thperrier game_delete) +add_test(test_thperrier_game_is_blank ./game_test_thperrier game_is_blank) \ No newline at end of file diff --git a/README.md b/README.md index ddcfd47..62807fd 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Projet Techno | [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| | [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| | [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| -| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| +| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [x]
| | [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| | [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| | [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 36f5660..f5d5c53 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -12,6 +12,17 @@ bool test_dummy(){ return true; } +/* ********** game_is_blank ********** */ +bool test_game_is_blank(){ + game g = game_new_empty(); + if (game_is_blank(g, 0, 0)){ + game_delete(g); + return true; + } + game_delete(g); + return false; +} + /* ********** game_delete ********** */ bool test_game_delete(){ game g1 = game_new_empty(); @@ -96,6 +107,9 @@ int main (int argc, char *argv[]){ else if (strcmp("game_delete", argv[1]) == 0){ success = test_game_delete(); } + else if (strcmp("game_is_blank", argv[1]) == 0){ + success = test_game_is_blank(); + } else{ fprintf (stderr, "test \"%s\" is not a valid test name.\n", argv[1]); return EXIT_FAILURE; From 5f3664fc56b57a3fe7aea679816da5e36ff2afdc Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Mon, 15 Nov 2021 21:40:55 +0100 Subject: [PATCH 079/281] ajout game_is_lightbulb + modif CMake & README --- CMakeLists.txt | 3 ++- README.md | 2 +- game_test_thperrier.c | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 549981f..6e391f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,4 +36,5 @@ add_test(test_thperrier_game_copy ./game_test_thperrier game_copy) add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty) add_test(test_thperrier_game_equal ./game_test_thperrier game_equal) add_test(test_thperrier_game_delete ./game_test_thperrier game_delete) -add_test(test_thperrier_game_is_blank ./game_test_thperrier game_is_blank) \ No newline at end of file +add_test(test_thperrier_game_is_blank ./game_test_thperrier game_is_blank) +add_test(test_thperrier_game_is_lightbulb ./game_test_thperrier game_is_lightbulb) \ No newline at end of file diff --git a/README.md b/README.md index 62807fd..7edaf71 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Projet Techno | [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| | [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| | [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [x]
| -| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| +| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| | [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| | [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| | [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| diff --git a/game_test_thperrier.c b/game_test_thperrier.c index f5d5c53..d2b35cf 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -12,6 +12,18 @@ bool test_dummy(){ return true; } +/* ********** game_is_blank ********** */ +bool test_game_is_lightbulb(){ + game g = game_new_empty(); + game_set_square(g, 0, 0, S_LIGHTBULB); + if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_lightbulb(g, 0, 0)){ + game_delete(g); + return true; + } + game_delete(g); + return false; +} + /* ********** game_is_blank ********** */ bool test_game_is_blank(){ game g = game_new_empty(); @@ -110,6 +122,9 @@ int main (int argc, char *argv[]){ else if (strcmp("game_is_blank", argv[1]) == 0){ success = test_game_is_blank(); } + else if (strcmp("game_is_lightbulb", argv[1]) == 0){ + success = test_game_is_lightbulb(); + } else{ fprintf (stderr, "test \"%s\" is not a valid test name.\n", argv[1]); return EXIT_FAILURE; From ce7b4b024fcc4b1de75c9313551fba6999ffb9eb Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Tue, 16 Nov 2021 12:02:30 +0100 Subject: [PATCH 080/281] =?UTF-8?q?voil=C3=A0=20les=205=20premi=C3=A8res?= =?UTF-8?q?=20fonctions=20=C3=A0=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 11 ++- README.md | 10 +- game_test_nnunes.c | 223 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 218 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e391f4..0421e75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,11 +15,13 @@ set(CMAKE_C_FLAGS "-std=c99 -g -Wall") add_executable(game_text game_text.c) add_executable(game_test_thoguet game_test_thoguet.c) add_executable(game_test_thperrier game_test_thperrier.c) +add_executable(game_test_nnunes game_test_nnunes.c) #les dépendances sont calculées automatiquement target_link_libraries(game_text game) target_link_libraries(game_test_thoguet game) target_link_libraries(game_test_thperrier game) +target_link_libraries(game_test_nnunes game) add_library (game game.o game_aux.c) add_test(test_thoguet_dummy ./game_test_thoguet dummy) add_test(test_thoguet_game_new ./game_test_thoguet game_new) @@ -37,4 +39,11 @@ add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty) add_test(test_thperrier_game_equal ./game_test_thperrier game_equal) add_test(test_thperrier_game_delete ./game_test_thperrier game_delete) add_test(test_thperrier_game_is_blank ./game_test_thperrier game_is_blank) -add_test(test_thperrier_game_is_lightbulb ./game_test_thperrier game_is_lightbulb) \ No newline at end of file +add_test(test_thperrier_game_is_lightbulb ./game_test_thperrier game_is_lightbulb) + +add_test(test_nnunes_dummy ./game_test_thperrier dummy) +add_test(test_nnunes_game_get_square ./game_test_nnunes game_get_square) +add_test(test_nnunes_game_get_state ./game_test_nnunes game_get_state) +add_test(test_nnunes_game_get_flags ./game_test_nnunes game_get_flags) +add_test(test_nnunes_game_is_marked ./game_test_nnunes game_is_marked) +add_test(test_nnunes_game_is_lighted ./game_test_nnunes game_is_lighted) diff --git a/README.md b/README.md index 7edaf71..8eda52f 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,16 @@ Projet Techno | [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| | [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [X]
| | [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| -| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| +| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [X]
| | [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| -| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| -| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| +| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [X]
| +| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [X]
| | [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [x]
| | [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| | [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| | [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| -| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| -| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| +| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [X]
| +| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [X]
| | [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| | [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| | [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 9c121fa..4e0e2c9 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -2,35 +2,218 @@ #include #include #include +#include +#include "game.h" +#include "game_aux.h" bool test_dummy(void){ return EXIT_SUCCESS; } -int usage(int argc, char *argv[]) +void usage(int argc, char *argv[]) { fprintf(stderr, "Usage: %s [<...>]\n", argv[0]); exit(EXIT_FAILURE); } +/* ************** game_get_square ************** */ +bool test_game_set_square(void){ + game g = game_new_empty(); + game_set_square(g, 0, 0, S_LIGHTBULB); + if (game_get_square(g, 0, 0) != S_LIGHTBULB){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLANK); + if (game_get_square(g, 0, 0) != S_BLANK){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK); + if (game_get_square(g, 0, 0) != S_MARK){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK); + if (game_get_square(g, 0, 0) != S_BLACK){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK0); + if (game_get_square(g, 0, 0) != S_BLACK0){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK1); + if (game_get_square(g, 0, 0) != S_BLACK1){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK2); + if (game_get_square(g, 0, 0) != S_BLACK2){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK3); + if (game_get_square(g, 0, 0) != S_BLACK3){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK4); + if (game_get_square(g, 0, 0) != S_BLACK4){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACKU); + if (game_get_square(g, 0, 0) != S_BLACKU){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_F_LIGHTED); + if (game_get_square(g, 0, 0) != F_LIGHTED){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, F_ERROR); + if (game_get_square(g, 0, 0) != F_ERROR){ + game_delete(g); + return false; + } + game_delete(g); + return true; +} + +/* ************** game_get_state ************** */ +bool test_game_get_state(void){ + game g = game_new_empty(); + game_set_square(g, 0, 0, S_LIGHTBULB); + if (game_get_state(g, 0, 0) != S_LIGHTBULB){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLANK); + if (game_get_state(g, 0, 0) != S_BLANK){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK); + if (game_get_state(g, 0, 0) != S_MARK){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK); + if (game_get_state(g, 0, 0) != S_BLACK){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK0); + if (game_get_state(g, 0, 0) != S_BLACK0){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK1); + if (game_get_state(g, 0, 0) != S_BLACK1){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK2); + if (game_get_state(g, 0, 0) != S_BLACK2){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK3); + if (game_get_state(g, 0, 0) != S_BLACK3){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK4); + if (game_get_state(g, 0, 0) != S_BLACK4){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACKU); + if (game_get_state(g, 0, 0) != S_BLACKU){ + game_delete(g); + return false; + } + game_delete(g); + return true; +} + +/* ************** game_get_flags ************** */ +bool test_game_get_flags(void){ + game g = game_new_empty(); + game_set_square(g, 0, 0, S_F_LIGHTED); + if (game_get_flags(g, 0, 0) != F_LIGHTED){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, F_ERROR); + if (game_get_flags(g, 0, 0) != F_ERROR){ + game_delete(g); + return false; + } + game_delete(g); + return true; +} + +/* ************** game_is_marked ************** */ +bool test_game_is_marked(void){ + game g = game_new_empty(); + game_set_square(g, 0, 0, S_MARK); + if ((game_get_square(g, 0, 0) == S_MARK) && game_is_marked(g, 0, 0)){ + game_delete(g); + return true; + } + game_delete(g); + return false; +} + +/* ************** game_is_lighted ************** */ +bool test_game_is_marked(void){ + game g = game_new_empty(); + game_set_square(g, 0, 0, F_LIGHTED); + if ((game_get_square(g, 0, 0) == F_LIGHTED) && game_is_lighted(g, 0, 0)){ + game_delete(g); + return true; + } + game_delete(g); + return false; +} + int main(int argc, char * argv[]){ - if (argc == 1){ - usage(argc, argv); - } - fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); - bool ok = false; - if (strcmp("dummy", argv[1]) == 0) - ok = test_dummy(); - else { - fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); - exit(EXIT_FAILURE); - } - if (!ok){ - fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); - return EXIT_SUCCESS; - } - else { - fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]); - return EXIT_FAILURE; - } + if (argc != 2){ + usage(argc, argv); + } + fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); + bool ok = false; + if (strcmp("dummy", argv[1]) == 0) + ok = test_dummy(); + else if (strcmp("game_get_square", argv[1]) == 0){ + success = test_game_get_square(); + } + else if (strcmp("game_get_state", argv[1]) == 0){ + success = test_game_get_state(); + } + else if (strcmp("game_get_falgs", argv[1]) == 0){ + success = test_game_get_flags(); + } + else if (strcmp("game_is_marked", argv[1]) == 0){ + success = test_game_is_marked(); + } + else if (strcmp("game_is_lighted", argv[1]) == 0){ + success = test_game_is_lighted(); + } + else { + fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); + exit(EXIT_FAILURE); + } + if (!ok){ + fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); + return EXIT_SUCCESS; + } + else { + fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]); + return EXIT_FAILURE; + } } \ No newline at end of file From 0ffa1058adb6b8d7060352f98cbea1682046f074 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Tue, 16 Nov 2021 15:46:05 +0100 Subject: [PATCH 081/281] finished checkmove playmove update readme --- CMakeLists.txt | 3 +++ README.md | 6 ++--- game_test_thoguet.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e391f4..066d79d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ target_link_libraries(game_text game) target_link_libraries(game_test_thoguet game) target_link_libraries(game_test_thperrier game) add_library (game game.o game_aux.c) + add_test(test_thoguet_dummy ./game_test_thoguet dummy) add_test(test_thoguet_game_new ./game_test_thoguet game_new) add_test(test_thoguet_game_print ./game_test_thoguet game_print) @@ -30,6 +31,8 @@ add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_sol add_test(test_thoguet_game_restart ./game_test_thoguet game_restart) add_test(test_thoguet_game_is_over ./game_test_thoguet game_is_over) add_test(test_thoguet_game_update_flags ./game_test_thoguet game_update_flags) +add_test(test_game_play_move ./game_test_thoguet game_play_move) +add_test(test_game_check_move ./game_test_thoguet game_check_move) add_test(test_thperrier_dummy ./game_test_thperrier dummy) add_test(test_thperrier_game_copy ./game_test_thperrier game_copy) diff --git a/README.md b/README.md index 7edaf71..2767328 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,9 @@ Projet Techno | [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| | [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| | [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| -| [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| -| [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| -| [game_update_flags](./game_test_thoguet.c#L144-410) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every case |
  • [X]
| +| [game_check_move](./game_test_thoguet.c#L439-463) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [X]
| +| [game_play_move](./game_test_thoguet.c#L412-436) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [X]
| +| [game_update_flags](./game_test_thoguet.c#L144-410) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every possibilites |
  • [X]
| | [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| | [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| | [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 81534c8..9a59484 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -409,6 +409,58 @@ bool test_game_update_flags(void){ return EXIT_SUCCESS; } +/* ****** game_play_move ****** */ + +bool test_game_play_move(void){ + game g = game_new_empty(); + game g1 = game_new_empty(); + game_play_move(g,0,0,S_LIGHTBULB); + assert(!game_equal(g,g1)); + game_set_square(g1,0,0,S_LIGHTBULB); + assert(!game_equal(g,g1)); + game_update_flags(g1); + assert(game_equal(g,g1)); + game_play_move(g,3,0,S_MARK); + assert(!game_equal(g,g1)); + game_set_square(g1,3,0,S_MARK); + assert(!game_equal(g,g1)); + game_update_flags(g1); + assert(game_equal(g,g1)); + game_play_move(g,0,3,S_BLANK); + assert(game_equal(g,g1)); + game_set_square(g1,0,3,S_BLANK); + assert(!game_equal(g,g1)); + game_update_flags(g1); + assert(game_equal(g,g1)); + return EXIT_SUCCESS; +} + + +/* ***** game_check_move ***** */ + +bool test_game_check_move(void){ + game g = game_new_empty(); + assert(!game_check_move(g,10,10,S_BLANK)); + assert(!game_check_move(g,10,10,S_BLACK0)); + assert(!game_check_move(g,0,0,S_BLACK0)); + assert(!game_check_move(g,0,0,S_BLACK1)); + assert(!game_check_move(g,0,0,S_BLACK2)); + assert(!game_check_move(g,0,0,S_BLACK3)); + assert(!game_check_move(g,0,0,S_BLACK4)); + assert(!game_check_move(g,0,0,S_BLACKU)); + assert(!game_check_move(g,0,0,F_LIGHTED)); + assert(!game_check_move(g,0,0,F_ERROR)); + for (uint i = 0 ; i < S_BLACKU-S_BLACK0 ; i ++){ + game_set_square(g,0,0,S_BLACK0+i); + assert(!game_check_move(g,0,0,S_BLANK)); + assert(!game_check_move(g,0,0,S_MARK)); + assert(!game_check_move(g,0,0,S_LIGHTBULB)); + } + assert(game_check_move(g,1,0,S_BLANK)); + assert(game_check_move(g,1,0,S_MARK)); + assert(game_check_move(g,1,0,S_LIGHTBULB)); + return EXIT_SUCCESS; +} /* ********** USAGE ********** */ @@ -444,6 +496,10 @@ int main(int argc, char * argv[]){ ok = test_game_is_over(); else if (strcmp("game_update_flags", argv[1]) == 0) ok = test_game_update_flags(); + else if (strcmp("game_play_move", argv[1]) == 0) + ok = test_game_play_move(); + else if (strcmp("game_check_move", argv[1]) == 0) + ok = test_game_check_move(); else { fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); exit(EXIT_FAILURE); From 60c3363fa13e84d1eec23d7651afa239170dfba2 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Tue, 16 Nov 2021 16:30:36 +0100 Subject: [PATCH 082/281] =?UTF-8?q?deuxi=C3=A8me=20=C3=A9bauche?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + README.md | 2 +- game_test_nnunes.c | 125 ++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 114 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0421e75..53cabad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,3 +47,4 @@ add_test(test_nnunes_game_get_state ./game_test_nnunes game_get_state) add_test(test_nnunes_game_get_flags ./game_test_nnunes game_get_flags) add_test(test_nnunes_game_is_marked ./game_test_nnunes game_is_marked) add_test(test_nnunes_game_is_lighted ./game_test_nnunes game_is_lighted) +add_test(test_nnunes_game_has_error ./gametest_nnunes game_has_error) diff --git a/README.md b/README.md index 8eda52f..58638d7 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Projet Techno | [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| | [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [X]
| | [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [X]
| -| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| +| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [X]
| | [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | |
  • [ ]
| | [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | |
  • [ ]
| | [game_update_flags](./game_test_thoguet.c#L144-410) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every case |
  • [X]
| diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 4e0e2c9..b836233 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -69,16 +69,96 @@ bool test_game_set_square(void){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_F_LIGHTED); - if (game_get_square(g, 0, 0) != F_LIGHTED){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, F_ERROR); - if (game_get_square(g, 0, 0) != F_ERROR){ + game_set_square(g, 0, 0, S_LIGHTBULB|F_ERROR); + if (game_get_square(g, 0, 0) != S_LIGHTBULB|F_ERROR){ game_delete(g); return false; } + game_set_square(g, 0, 0, S_BLANK|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLANK|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK|F_ERROR); + if (game_get_square(g, 0, 0) != S_MARK|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACK|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK0|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACK0|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK1|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACK1|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK2|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACK2|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK3|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACK3|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK4|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACK4|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACKU|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACKU|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_LIGHTBULB|F_LIGHTED); + if (game_get_square(g, 0, 0) != S_LIGHTBULB|F_LIGHTED){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLANK|F_LIGHTED); + if (game_get_square(g, 0, 0) != S_BLANK|F_LIGHTED){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK|F_LIGHTED); + if (game_get_square(g, 0, 0) != S_MARK|F_LIGHTED){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACKU|F_LIGHTED); + if (game_get_square(g, 0, 0) != S_BLACKU|F_LIGHTED){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_LIGHTBULB|F_LIGHTED|F_ERROR); + if (game_get_square(g, 0, 0) != S_LIGHTBULB|F_LIGHTED|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLANK|F_LIGHTED|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLANK|F_LIGHTED|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK|F_LIGHTED|F_ERROR); + if (game_get_square(g, 0, 0) != S_MARK|F_LIGHTED|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACKU|F_LIGHTED|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACKU|F_LIGHTED|F_ERROR){ + game_delete(g); + return false; + } game_delete(g); return true; } @@ -143,16 +223,21 @@ bool test_game_get_state(void){ /* ************** game_get_flags ************** */ bool test_game_get_flags(void){ game g = game_new_empty(); - game_set_square(g, 0, 0, S_F_LIGHTED); + game_set_square(g, 0, 0, S_BLANK|F_LIGHTED); if (game_get_flags(g, 0, 0) != F_LIGHTED){ game_delete(g); return false; } - game_set_square(g, 0, 0, F_ERROR); + game_set_square(g, 0, 0, S_BLANK|F_ERROR); if (game_get_flags(g, 0, 0) != F_ERROR){ game_delete(g); return false; } + game_set_square(g, 0, 0, S_BLANK|F_ERROR|F_LIGHTED); + if (game_get_flags(g, 0, 0) != (F_ERROR|F_LIGHTED)){ + game_delete(g); + return false; + } game_delete(g); return true; } @@ -172,7 +257,7 @@ bool test_game_is_marked(void){ /* ************** game_is_lighted ************** */ bool test_game_is_marked(void){ game g = game_new_empty(); - game_set_square(g, 0, 0, F_LIGHTED); + game_set_square(g, 0, 0, S_BLANK|F_LIGHTED); if ((game_get_square(g, 0, 0) == F_LIGHTED) && game_is_lighted(g, 0, 0)){ game_delete(g); return true; @@ -181,14 +266,28 @@ bool test_game_is_marked(void){ return false; } +/* ************** game_has_error ************** */ +bool test_game_has_error(void){ + for(int i=0; i < DEFAULT_SIZE; i++){ + for(int j=0; j < DEFAULT_SIZE; j++){ + if((game_get_flags(g, i, j) == F_ERROR)||(game_get_flags(g, i, j) == F_ERROR|F_LIGHTED) && (game_has_error(g, i, j) == false)){ + game_delete(g); + return false; + } + } + } + game_delete(g); + return true; +} + int main(int argc, char * argv[]){ if (argc != 2){ usage(argc, argv); } fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); - bool ok = false; + bool success = false; if (strcmp("dummy", argv[1]) == 0) - ok = test_dummy(); + success = test_dummy(); else if (strcmp("game_get_square", argv[1]) == 0){ success = test_game_get_square(); } @@ -208,7 +307,7 @@ int main(int argc, char * argv[]){ fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); exit(EXIT_FAILURE); } - if (!ok){ + if (!success){ fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); return EXIT_SUCCESS; } From 63910636e37a8a809ed6b727b306564a166bfee0 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Tue, 16 Nov 2021 17:04:29 +0100 Subject: [PATCH 083/281] repared --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 8b13789..acd681f 100644 --- a/README.md +++ b/README.md @@ -1 +1,33 @@ +# lightup-a42e +Projet Techno + +:warning: LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE :warning: +## Test + +| Test | REF | Assigned to | Notes | Finished | +| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | --------------------------------------- | :--------------------: | +| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| +| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| +| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| +| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [X]
| +| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| +| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [X]
| +| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| +| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [X]
| +| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [X]
| +| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [x]
| +| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| +| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| +| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| +| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [X]
| +| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [X]
| +| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| +| [game_check_move](./game_test_thoguet.c#L439-463) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [X]
| +| [game_play_move](./game_test_thoguet.c#L412-436) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [X]
| +| [game_update_flags](./game_test_thoguet.c#L144-410) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every possibilites |
  • [X]
| +| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| +| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| +| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| +| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| +| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| From 05e9afc5cf97cc302990b11ebe49b31f79ccbf04 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 16 Nov 2021 17:28:19 +0100 Subject: [PATCH 084/281] ajout test_game_is_black + modif CMake & README --- CMakeLists.txt | 1 + README.md | 2 +- game_test_thperrier.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 240c095..dbf8e81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ add_test(test_thperrier_game_equal ./game_test_thperrier game_equal) add_test(test_thperrier_game_delete ./game_test_thperrier game_delete) add_test(test_thperrier_game_is_blank ./game_test_thperrier game_is_blank) add_test(test_thperrier_game_is_lightbulb ./game_test_thperrier game_is_lightbulb) +add_test(test_thperrier_game_is_black ./game_test_thperrier game_is_black) add_test(test_nnunes_dummy ./game_test_thperrier dummy) add_test(test_nnunes_game_get_square ./game_test_nnunes game_get_square) diff --git a/README.md b/README.md index acd681f..0bf3e60 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Projet Techno | [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [X]
| | [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [x]
| | [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| -| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [ ]
| +| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [x]
| | [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| | [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [X]
| | [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [X]
| diff --git a/game_test_thperrier.c b/game_test_thperrier.c index d2b35cf..7000739 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -12,6 +12,43 @@ bool test_dummy(){ return true; } +/* ********** game_is_black ********** */ +bool test_game_is_black(){ + game g = game_new_empty(); + game_set_square(g, 0, 0, S_BLACKU); + if (!(game_get_square(g, 0, 0) == S_BLACKU) && game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK0); + if (!(game_get_square(g, 0, 0) == S_BLACK0) && game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK1); + if (!(game_get_square(g, 0, 0) == S_BLACK1) && game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK2); + if (!(game_get_square(g, 0, 0) == S_BLACK2) && game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK3); + if (!(game_get_square(g, 0, 0) == S_BLACK3) && game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK4); + if (!(game_get_square(g, 0, 0) == S_BLACK4) && game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } + game_delete(g); + return true; +} + /* ********** game_is_blank ********** */ bool test_game_is_lightbulb(){ game g = game_new_empty(); @@ -43,6 +80,7 @@ bool test_game_delete(){ if (game_equal(g1, g2)){ return false; } + g1 = NULL; return true; } From 9e2755a8d12f6a899134f8d6dc385bcf7944d8c7 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Tue, 16 Nov 2021 17:33:56 +0100 Subject: [PATCH 085/281] forme finale --- game_test_nnunes.c | 81 +++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index b836233..f8b2719 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -17,7 +17,7 @@ void usage(int argc, char *argv[]) } /* ************** game_get_square ************** */ -bool test_game_set_square(void){ +bool test_game_get_square(void){ game g = game_new_empty(); game_set_square(g, 0, 0, S_LIGHTBULB); if (game_get_square(g, 0, 0) != S_LIGHTBULB){ @@ -69,93 +69,93 @@ bool test_game_set_square(void){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_LIGHTBULB|F_ERROR); - if (game_get_square(g, 0, 0) != S_LIGHTBULB|F_ERROR){ + game_set_square(g, 0, 0, (S_LIGHTBULB|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_LIGHTBULB|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_BLANK|F_ERROR); - if (game_get_square(g, 0, 0) != S_BLANK|F_ERROR){ + game_set_square(g, 0, 0, (S_BLANK|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLANK|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_MARK|F_ERROR); - if (game_get_square(g, 0, 0) != S_MARK|F_ERROR){ + game_set_square(g, 0, 0, (S_MARK|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_MARK|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_BLACK|F_ERROR); - if (game_get_square(g, 0, 0) != S_BLACK|F_ERROR){ + game_set_square(g, 0, 0, (S_BLACK|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACK|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_BLACK0|F_ERROR); - if (game_get_square(g, 0, 0) != S_BLACK0|F_ERROR){ + game_set_square(g, 0, 0, (S_BLACK0|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACK0|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_BLACK1|F_ERROR); - if (game_get_square(g, 0, 0) != S_BLACK1|F_ERROR){ + game_set_square(g, 0, 0, (S_BLACK1|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACK1|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_BLACK2|F_ERROR); - if (game_get_square(g, 0, 0) != S_BLACK2|F_ERROR){ + game_set_square(g, 0, 0, (S_BLACK2|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACK2|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_BLACK3|F_ERROR); - if (game_get_square(g, 0, 0) != S_BLACK3|F_ERROR){ + game_set_square(g, 0, 0, (S_BLACK3|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACK3|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_BLACK4|F_ERROR); - if (game_get_square(g, 0, 0) != S_BLACK4|F_ERROR){ + game_set_square(g, 0, 0, (S_BLACK4|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACK4|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_BLACKU|F_ERROR); - if (game_get_square(g, 0, 0) != S_BLACKU|F_ERROR){ + game_set_square(g, 0, 0, (S_BLACKU|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACKU|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_LIGHTBULB|F_LIGHTED); - if (game_get_square(g, 0, 0) != S_LIGHTBULB|F_LIGHTED){ + game_set_square(g, 0, 0, (S_LIGHTBULB|F_LIGHTED)); + if (game_get_square(g, 0, 0) != (S_LIGHTBULB|F_LIGHTED)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_BLANK|F_LIGHTED); - if (game_get_square(g, 0, 0) != S_BLANK|F_LIGHTED){ + game_set_square(g, 0, 0, (S_BLANK|F_LIGHTED)); + if (game_get_square(g, 0, 0) != (S_BLANK|F_LIGHTED)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_MARK|F_LIGHTED); - if (game_get_square(g, 0, 0) != S_MARK|F_LIGHTED){ + game_set_square(g, 0, 0, (S_MARK|F_LIGHTED)); + if (game_get_square(g, 0, 0) != (S_MARK|F_LIGHTED)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_BLACKU|F_LIGHTED); - if (game_get_square(g, 0, 0) != S_BLACKU|F_LIGHTED){ + game_set_square(g, 0, 0, (S_BLACKU|F_LIGHTED)); + if (game_get_square(g, 0, 0) != (S_BLACKU|F_LIGHTED)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_LIGHTBULB|F_LIGHTED|F_ERROR); - if (game_get_square(g, 0, 0) != S_LIGHTBULB|F_LIGHTED|F_ERROR){ + game_set_square(g, 0, 0, (S_LIGHTBULB|F_LIGHTED|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_BLANK|F_LIGHTED|F_ERROR); - if (game_get_square(g, 0, 0) != S_BLANK|F_LIGHTED|F_ERROR){ + game_set_square(g, 0, 0, (S_BLANK|F_LIGHTED|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLANK|F_LIGHTED|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_MARK|F_LIGHTED|F_ERROR); - if (game_get_square(g, 0, 0) != S_MARK|F_LIGHTED|F_ERROR){ + game_set_square(g, 0, 0, (S_MARK|F_LIGHTED|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_MARK|F_LIGHTED|F_ERROR)){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_BLACKU|F_LIGHTED|F_ERROR); - if (game_get_square(g, 0, 0) != S_BLACKU|F_LIGHTED|F_ERROR){ + game_set_square(g, 0, 0, (S_BLACKU|F_LIGHTED|F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACKU|F_LIGHTED|F_ERROR)){ game_delete(g); return false; } @@ -255,7 +255,7 @@ bool test_game_is_marked(void){ } /* ************** game_is_lighted ************** */ -bool test_game_is_marked(void){ +bool test_game_is_lighted(void){ game g = game_new_empty(); game_set_square(g, 0, 0, S_BLANK|F_LIGHTED); if ((game_get_square(g, 0, 0) == F_LIGHTED) && game_is_lighted(g, 0, 0)){ @@ -268,9 +268,10 @@ bool test_game_is_marked(void){ /* ************** game_has_error ************** */ bool test_game_has_error(void){ + game g = game_new_empty(); for(int i=0; i < DEFAULT_SIZE; i++){ for(int j=0; j < DEFAULT_SIZE; j++){ - if((game_get_flags(g, i, j) == F_ERROR)||(game_get_flags(g, i, j) == F_ERROR|F_LIGHTED) && (game_has_error(g, i, j) == false)){ + if(((game_get_flags(g, i, j) == F_ERROR)||(game_get_flags(g, i, j) == (F_ERROR|F_LIGHTED))) && (game_has_error(g, i, j) == false)){ game_delete(g); return false; } @@ -294,7 +295,7 @@ int main(int argc, char * argv[]){ else if (strcmp("game_get_state", argv[1]) == 0){ success = test_game_get_state(); } - else if (strcmp("game_get_falgs", argv[1]) == 0){ + else if (strcmp("game_get_flags", argv[1]) == 0){ success = test_game_get_flags(); } else if (strcmp("game_is_marked", argv[1]) == 0){ From cbc149b4798bac212b70d4393c53a6b861d969a1 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Tue, 16 Nov 2021 17:38:36 +0100 Subject: [PATCH 086/281] this is the end --- CMakeLists.txt | 2 +- game_test_nnunes.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbf8e81..8b261db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,4 +51,4 @@ add_test(test_nnunes_game_get_state ./game_test_nnunes game_get_state) add_test(test_nnunes_game_get_flags ./game_test_nnunes game_get_flags) add_test(test_nnunes_game_is_marked ./game_test_nnunes game_is_marked) add_test(test_nnunes_game_is_lighted ./game_test_nnunes game_is_lighted) -add_test(test_nnunes_game_has_error ./gametest_nnunes game_has_error) +add_test(test_nnunes_game_has_error ./game_test_nnunes game_has_error) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index f8b2719..af9cfe2 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -303,12 +303,15 @@ int main(int argc, char * argv[]){ } else if (strcmp("game_is_lighted", argv[1]) == 0){ success = test_game_is_lighted(); - } + } + else if (strcmp("game_has_error", argv[1]) == 0){ + success = test_game_has_error(); + } else { fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); exit(EXIT_FAILURE); } - if (!success){ + if (success){ fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); return EXIT_SUCCESS; } From 77c93f881b1d482d42d79a54ea4a05a205ee69a1 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 16 Nov 2021 18:03:03 +0100 Subject: [PATCH 087/281] modif test_game_is_black --- game_test_thperrier.c | 55 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 7000739..b038b32 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -15,33 +15,71 @@ bool test_dummy(){ /* ********** game_is_black ********** */ bool test_game_is_black(){ game g = game_new_empty(); + if (game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } game_set_square(g, 0, 0, S_BLACKU); - if (!(game_get_square(g, 0, 0) == S_BLACKU) && game_is_black(g, 0, 0)){ + if (!game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } + if (!((game_get_square(g, 0, 0) == S_BLACKU) && game_is_black(g, 0, 0))){ game_delete(g); return false; } game_set_square(g, 0, 0, S_BLACK0); - if (!(game_get_square(g, 0, 0) == S_BLACK0) && game_is_black(g, 0, 0)){ + if (!((game_get_square(g, 0, 0) == S_BLACK0) && game_is_black(g, 0, 0))){ game_delete(g); return false; } game_set_square(g, 0, 0, S_BLACK1); - if (!(game_get_square(g, 0, 0) == S_BLACK1) && game_is_black(g, 0, 0)){ + if (!((game_get_square(g, 0, 0) == S_BLACK1) && game_is_black(g, 0, 0))){ game_delete(g); return false; } game_set_square(g, 0, 0, S_BLACK2); - if (!(game_get_square(g, 0, 0) == S_BLACK2) && game_is_black(g, 0, 0)){ + if (!((game_get_square(g, 0, 0) == S_BLACK2) && game_is_black(g, 0, 0))){ game_delete(g); return false; } game_set_square(g, 0, 0, S_BLACK3); - if (!(game_get_square(g, 0, 0) == S_BLACK3) && game_is_black(g, 0, 0)){ + if (!((game_get_square(g, 0, 0) == S_BLACK3) && game_is_black(g, 0, 0))){ game_delete(g); return false; } game_set_square(g, 0, 0, S_BLACK4); - if (!(game_get_square(g, 0, 0) == S_BLACK4) && game_is_black(g, 0, 0)){ + if (!((game_get_square(g, 0, 0) == S_BLACK4) && game_is_black(g, 0, 0))){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK); + if ((game_get_square(g, 0, 0) == S_MARK) && game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK); + if ((game_get_square(g, 0, 0) == S_MARK) && game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_LIGHTBULB); + if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_LIGHTBULB); + if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, F_ERROR); + if ((game_get_square(g, 0, 0) == F_ERROR) && game_is_black(g, 0, 0)){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, F_LIGHTED); + if ((game_get_square(g, 0, 0) == F_LIGHTED) && game_is_black(g, 0, 0)){ game_delete(g); return false; } @@ -49,7 +87,7 @@ bool test_game_is_black(){ return true; } -/* ********** game_is_blank ********** */ +/* ********** game_is_lightbulb ********** */ bool test_game_is_lightbulb(){ game g = game_new_empty(); game_set_square(g, 0, 0, S_LIGHTBULB); @@ -163,6 +201,9 @@ int main (int argc, char *argv[]){ else if (strcmp("game_is_lightbulb", argv[1]) == 0){ success = test_game_is_lightbulb(); } + else if (strcmp("game_is_black", argv[1]) == 0){ + success = test_game_is_black(); + } else{ fprintf (stderr, "test \"%s\" is not a valid test name.\n", argv[1]); return EXIT_FAILURE; From 988eb1e9c55575af0e5ef9ccaa89ef30fcdf71e2 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 16 Nov 2021 18:40:45 +0100 Subject: [PATCH 088/281] ajout test_game_get_black_number + CMake & README --- CMakeLists.txt | 1 + README.md | 2 +- game_test_thperrier.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b261db..56db5ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ add_test(test_thperrier_game_delete ./game_test_thperrier game_delete) add_test(test_thperrier_game_is_blank ./game_test_thperrier game_is_blank) add_test(test_thperrier_game_is_lightbulb ./game_test_thperrier game_is_lightbulb) add_test(test_thperrier_game_is_black ./game_test_thperrier game_is_black) +add_test(test_thperrier_game_get_black_number ./game_test_thperrier game_get_black_number) add_test(test_nnunes_dummy ./game_test_thperrier dummy) add_test(test_nnunes_game_get_square ./game_test_nnunes game_get_square) diff --git a/README.md b/README.md index 0bf3e60..92cd721 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Projet Techno | [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [x]
| | [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| | [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [x]
| -| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [ ]
| +| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [x]
| | [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [X]
| | [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [X]
| | [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| diff --git a/game_test_thperrier.c b/game_test_thperrier.c index b038b32..4f18412 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -12,6 +12,38 @@ bool test_dummy(){ return true; } +/* ********** game_get_black_number ********** */ +bool test_game_get_black_number(){ + game g = game_new_empty(); + game_set_square(g, 0, 0, S_BLACK0); + if (game_get_black_number(g, 0, 0) != 0){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK1); + if (game_get_black_number(g, 0, 0) != 1){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK2); + if (game_get_black_number(g, 0, 0) != 2){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK3); + if (game_get_black_number(g, 0, 0) != 3){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK4); + if (game_get_black_number(g, 0, 0) != 4){ + game_delete(g); + return false; + } + game_delete(g); + return true; +} + /* ********** game_is_black ********** */ bool test_game_is_black(){ game g = game_new_empty(); @@ -204,6 +236,9 @@ int main (int argc, char *argv[]){ else if (strcmp("game_is_black", argv[1]) == 0){ success = test_game_is_black(); } + else if (strcmp("game_get_black_number", argv[1]) == 0){ + success = test_game_get_black_number(); + } else{ fprintf (stderr, "test \"%s\" is not a valid test name.\n", argv[1]); return EXIT_FAILURE; From b47e6bad7b3041f6fc736542798d7dab1ce91ca4 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Tue, 16 Nov 2021 19:41:19 +0100 Subject: [PATCH 089/281] finished --- CMakeLists.txt | 4 ++-- game_test_thoguet.c | 54 ++++++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b261db..9878364 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,8 +33,8 @@ add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_sol add_test(test_thoguet_game_restart ./game_test_thoguet game_restart) add_test(test_thoguet_game_is_over ./game_test_thoguet game_is_over) add_test(test_thoguet_game_update_flags ./game_test_thoguet game_update_flags) -add_test(test_game_play_move ./game_test_thoguet game_play_move) -add_test(test_game_check_move ./game_test_thoguet game_check_move) +add_test(test_thoguet_game_play_move ./game_test_thoguet game_play_move) +add_test(test_thoguet_game_check_move ./game_test_thoguet game_check_move) add_test(test_thperrier_dummy ./game_test_thperrier dummy) add_test(test_thperrier_game_copy ./game_test_thperrier game_copy) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 9a59484..47ee316 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -100,15 +100,21 @@ bool test_game_default(void){ game g = game_default(); //a verif aps sur assert(g); - assert(game_get_square(g,0,2) == S_BLACK1); - assert(game_get_square(g,1,2) == S_BLACK2); - assert(game_get_square(g,2,5) == S_BLACKU); - assert(game_get_square(g,2,6) == S_BLACK2); - assert(game_get_square(g,4,0) == S_BLACK1); - assert(game_get_square(g,4,1) == S_BLACKU); - assert(game_get_square(g,5,4) == S_BLACK2); - assert(game_get_square(g,6,4) == S_BLACKU); + square tab[49] = + { + /*X0 X1 X2 X3 X4 X5 X6*/ + /*Y 0*/ S_BLANK, S_BLANK, S_BLACK1, S_BLANK, S_BLANK, S_BLANK, S_BLANK, + /*Y 1*/ S_BLANK, S_BLANK, S_BLACK2, S_BLANK, S_BLANK, S_BLANK, S_BLANK, + /*Y 2*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLACK2, + /*Y 3*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, + /*Y 4*/ S_BLACK1, S_BLACKU, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, + /*Y 5*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACK2, S_BLANK, S_BLANK, + /*Y 6*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLANK + }; + game g1 = game_new(tab); + assert(game_equal(g,g1)); game_delete(g); + game_delete(g1); return EXIT_SUCCESS; } @@ -116,27 +122,21 @@ bool test_game_default(void){ bool test_game_default_solution(void){ game g = game_default_solution(); + game g1 = game_default(); assert(g); - //default - assert(game_get_square(g,0,2) == S_BLACK1); - assert(game_get_square(g,1,2) == S_BLACK2); - assert(game_get_square(g,2,5) == S_BLACKU); - assert(game_get_square(g,2,6) == S_BLACK2); - assert(game_get_square(g,4,0) == S_BLACK1); - assert(game_get_square(g,4,1) == S_BLACKU); - assert(game_get_square(g,5,4) == S_BLACK2); - assert(game_get_square(g,6,4) == S_BLACKU); //solution - assert(game_get_square(g,0,0) == (S_LIGHTBULB|F_LIGHTED)); - assert(game_get_square(g,1,1) == (S_LIGHTBULB|F_LIGHTED)); - assert(game_get_square(g,0,3) == (S_LIGHTBULB|F_LIGHTED)); - assert(game_get_square(g,1,6) == (S_LIGHTBULB|F_LIGHTED)); - assert(game_get_square(g,2,2) == (S_LIGHTBULB|F_LIGHTED)); - assert(game_get_square(g,3,6) == (S_LIGHTBULB|F_LIGHTED)); - assert(game_get_square(g,4,4) == (S_LIGHTBULB|F_LIGHTED)); - assert(game_get_square(g,5,0) == (S_LIGHTBULB|F_LIGHTED)); - assert(game_get_square(g,5,5) == (S_LIGHTBULB|F_LIGHTED)); - assert(game_get_square(g,6,1) == (S_LIGHTBULB|F_LIGHTED)); + game_set_square(g1,0,0,S_LIGHTBULB); + game_set_square(g1,1,1,S_LIGHTBULB); + game_set_square(g1,0,3,S_LIGHTBULB); + game_set_square(g1,1,6,S_LIGHTBULB); + game_set_square(g1,2,2,S_LIGHTBULB); + game_set_square(g1,3,6,S_LIGHTBULB); + game_set_square(g1,4,4,S_LIGHTBULB); + game_set_square(g1,5,0,S_LIGHTBULB); + game_set_square(g1,5,5,S_LIGHTBULB); + game_set_square(g1,6,1,S_LIGHTBULB); + game_update_flags(g1); + assert(game_equal(g,g1)); game_delete(g); return EXIT_SUCCESS; } From edb972d99f89c77f87789ab969345828a301850c Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 16 Nov 2021 21:02:52 +0100 Subject: [PATCH 090/281] modif test_game_delete --- game_test_thperrier.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 4f18412..7b32d11 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -150,7 +150,6 @@ bool test_game_delete(){ if (game_equal(g1, g2)){ return false; } - g1 = NULL; return true; } @@ -201,12 +200,12 @@ bool test_game_copy(){ game_delete(g2); return true; } - +/* ********** usage ********** */ void usage(int argc, char *argv[]){ fprintf(stderr, "Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } - +/* ********** main ********** */ int main (int argc, char *argv[]){ bool success = false; if (argc != 2){ From 8dbb7e620cfdc6442bbf79924a3270e94fabcd7f Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Tue, 16 Nov 2021 23:11:24 +0100 Subject: [PATCH 091/281] mem leak patched --- game_test_thoguet.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 47ee316..7718ba8 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -18,6 +18,7 @@ bool test_game_is_over(void){ game g = game_default_solution(); game_update_flags(g); assert(game_is_over(g)); + game_delete(g); g = game_default(); game_update_flags(g); assert(!game_is_over(g)); @@ -138,6 +139,7 @@ bool test_game_default_solution(void){ game_update_flags(g1); assert(game_equal(g,g1)); game_delete(g); + game_delete(g1); return EXIT_SUCCESS; } @@ -356,9 +358,7 @@ bool check_update(game g){ // a > 2 = temps d'exec > 3 min et expo bool brutforce(game g,int a, bool * deldup){ // char c; - bool * delDupNext; - if (a > 0) - delDupNext = (bool *) calloc(DEFAULT_SIZE*DEFAULT_SIZE,sizeof(bool)); + bool * delDupNext = (bool *) calloc(DEFAULT_SIZE*DEFAULT_SIZE,sizeof(bool)); square list[] = {S_LIGHTBULB,S_MARK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,S_BLACKU,S_BLANK}; for (uint i = 0; i < DEFAULT_SIZE; i++){ for (uint j = 0 ;j < DEFAULT_SIZE; j++){ @@ -376,8 +376,7 @@ bool brutforce(game g,int a, bool * deldup){ if (a > 0){ if (!brutforce(g,a-1,delDupNext)){ //printf("341\n"); - if (delDupNext != NULL) - free(delDupNext); + free(delDupNext); return false; } } @@ -385,8 +384,7 @@ bool brutforce(game g,int a, bool * deldup){ if (!check_update(g)){ game_print(g); //printf("i:%d j:%d state : %d, flags: %d\n",i,j,game_get_state(g,i,j),game_get_flags(g,i,j)); - if (delDupNext != NULL && a > 0) - free(delDupNext); + free(delDupNext); return false; } } @@ -394,8 +392,7 @@ bool brutforce(game g,int a, bool * deldup){ } } } - if (delDupNext != NULL && a > 0) - free(delDupNext); + free(delDupNext); return true; } @@ -432,6 +429,8 @@ bool test_game_play_move(void){ assert(!game_equal(g,g1)); game_update_flags(g1); assert(game_equal(g,g1)); + game_delete(g); + game_delete(g1); return EXIT_SUCCESS; } @@ -459,6 +458,7 @@ bool test_game_check_move(void){ assert(game_check_move(g,1,0,S_BLANK)); assert(game_check_move(g,1,0,S_MARK)); assert(game_check_move(g,1,0,S_LIGHTBULB)); + game_delete(g); return EXIT_SUCCESS; } From 844a9bce0f5c809ebb81bb0492ab7ff3a83c2766 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 16 Nov 2021 23:24:06 +0100 Subject: [PATCH 092/281] modif test_game_delete & test_game_equal --- game_test_thperrier.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 7b32d11..7ebdb3f 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -145,11 +145,7 @@ bool test_game_is_blank(){ /* ********** game_delete ********** */ bool test_game_delete(){ game g1 = game_new_empty(); - game g2 = game_new_empty(); game_delete(g1); - if (game_equal(g1, g2)){ - return false; - } return true; } @@ -161,13 +157,14 @@ bool test_game_equal(){ for (int i = 0; i < DEFAULT_SIZE; i++){ for (int j = 0; j < DEFAULT_SIZE; j++){ if (game_get_square(g1, i, j) != game_get_square(g2, i, j)){ - game_delete(g1); - game_delete(g2); equal = false; } } } - return (equal == game_equal(g1, g2)); + equal = (equal == game_equal(g1, g2)); + game_delete(g1); + game_delete(g2); + return equal; } /* ********** game_new_empty ********** */ From 754a33b6a07f6e3ac7b2f9d09816e02d4138c8cc Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Sat, 20 Nov 2021 18:49:58 +0100 Subject: [PATCH 093/281] changement de game_has_bug --- CMakeLists.txt | 2 +- game_test_nnunes.c | 35 ++++++++++++++++------------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef0d11b..1a63228 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ add_test(test_thperrier_game_is_lightbulb ./game_test_thperrier game_is_lightbul add_test(test_thperrier_game_is_black ./game_test_thperrier game_is_black) add_test(test_thperrier_game_get_black_number ./game_test_thperrier game_get_black_number) -add_test(test_nnunes_dummy ./game_test_thperrier dummy) +add_test(test_nnunes_dummy ./game_test_nnunes dummy) add_test(test_nnunes_game_get_square ./game_test_nnunes game_get_square) add_test(test_nnunes_game_get_state ./game_test_nnunes game_get_state) add_test(test_nnunes_game_get_flags ./game_test_nnunes game_get_flags) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index af9cfe2..fc44991 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -134,11 +134,6 @@ bool test_game_get_square(void){ game_delete(g); return false; } - game_set_square(g, 0, 0, (S_BLACKU|F_LIGHTED)); - if (game_get_square(g, 0, 0) != (S_BLACKU|F_LIGHTED)){ - game_delete(g); - return false; - } game_set_square(g, 0, 0, (S_LIGHTBULB|F_LIGHTED|F_ERROR)); if (game_get_square(g, 0, 0) != (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ game_delete(g); @@ -153,12 +148,7 @@ bool test_game_get_square(void){ if (game_get_square(g, 0, 0) != (S_MARK|F_LIGHTED|F_ERROR)){ game_delete(g); return false; - } - game_set_square(g, 0, 0, (S_BLACKU|F_LIGHTED|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACKU|F_LIGHTED|F_ERROR)){ - game_delete(g); - return false; - } + } game_delete(g); return true; } @@ -262,6 +252,11 @@ bool test_game_is_lighted(void){ game_delete(g); return true; } + game_set_square(g, 0, 0, S_BLANK|F_LIGHTED|F_ERROR); + if((game_get_flags(g, 0, 0) == (F_LIGHTED|F_ERROR)) && game_is_lighted(g, 0, 0)){ + game_delete(g); + return true; + } game_delete(g); return false; } @@ -269,16 +264,18 @@ bool test_game_is_lighted(void){ /* ************** game_has_error ************** */ bool test_game_has_error(void){ game g = game_new_empty(); - for(int i=0; i < DEFAULT_SIZE; i++){ - for(int j=0; j < DEFAULT_SIZE; j++){ - if(((game_get_flags(g, i, j) == F_ERROR)||(game_get_flags(g, i, j) == (F_ERROR|F_LIGHTED))) && (game_has_error(g, i, j) == false)){ - game_delete(g); - return false; - } + game_set_square(g, 0, 0, S_BLANK|F_ERROR); + if((game_get_flags(g, 0, 0) == F_ERROR) && game_has_error(g, 0, 0)){ + game_delete(g); + return true; } - } + game_set_square(g, 0, 0, S_BLANK|F_LIGHTED|F_ERROR); + if((game_get_flags(g, 0, 0) == (F_LIGHTED|F_ERROR)) && game_has_error(g, 0, 0)){ + game_delete(g); + return true; + } game_delete(g); - return true; + return false; } int main(int argc, char * argv[]){ From 86417a212e4e84c0f86883e51544e1ee4afd1d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 21 Nov 2021 00:09:53 +0100 Subject: [PATCH 094/281] update flags on game restart --- game_test_thoguet.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 7718ba8..925f78e 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -30,8 +30,11 @@ bool test_game_is_over(void){ bool test_game_restart(void){ game g = game_default_solution(); + game_update_flags(g); game g1 = game_default(); + game_update_flags(g1); game_restart(g); + game_update_flags(g); assert(game_equal(g,g1)); game_delete(g); game_delete(g1); From ac615873cccccd3836b1e4be8b71c83743f1b64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 21 Nov 2021 00:26:51 +0100 Subject: [PATCH 095/281] maybe --- game_test_thoguet.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 925f78e..5b54dbc 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -29,12 +29,19 @@ bool test_game_is_over(void){ /* ******* game_restart ******* */ bool test_game_restart(void){ - game g = game_default_solution(); - game_update_flags(g); - game g1 = game_default(); - game_update_flags(g1); + game g = game_default(); + game g1 = game_default_solution(); + game_set_square(g,1,5,S_BLACK4); + game_set_square(g1,1,5,S_BLACK4); + game_set_square(g,3,2,S_BLACK3); + game_set_square(g1,3,2,S_BLACK3); + game_set_square(g,0,1,S_LIGHTBULB); + game_set_square(g1,0,1,S_LIGHTBULB); + game_play_move(g,2,0,S_MARK); + game_play_move(g1,2,0,S_MARK); + assert(!game_equal(g,g1)); + game_restart(g1); game_restart(g); - game_update_flags(g); assert(game_equal(g,g1)); game_delete(g); game_delete(g1); From 96f2d7fe62d196b0bff8cbab81638716741f296f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 21 Nov 2021 00:51:58 +0100 Subject: [PATCH 096/281] Je suis turbo con --- game_test_thoguet.c | 1 - 1 file changed, 1 deletion(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 7718ba8..05bdf84 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -18,7 +18,6 @@ bool test_game_is_over(void){ game g = game_default_solution(); game_update_flags(g); assert(game_is_over(g)); - game_delete(g); g = game_default(); game_update_flags(g); assert(!game_is_over(g)); From ef9a75ff0e7149865dcfe5d784ac12785412e85b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 21 Nov 2021 01:10:12 +0100 Subject: [PATCH 097/281] en fait non j'etais pas turbo con --- game_test_thoguet.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 05bdf84..33408dd 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -18,6 +18,12 @@ bool test_game_is_over(void){ game g = game_default_solution(); game_update_flags(g); assert(game_is_over(g)); + game_set_square(g,0,0,(S_LIGHTBULB|F_LIGHTED|F_ERROR)); + assert(!game_is_over(g)); + game_update_flags(g); + game_set_square(g,0,1,S_BLANK); + assert(!game_is_over(g)); + game_delete(g); g = game_default(); game_update_flags(g); assert(!game_is_over(g)); From ed402b23c2983cd93945b34909ae9005df2f81c6 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Sun, 21 Nov 2021 01:38:59 +0100 Subject: [PATCH 098/281] fix dummy --- game_test_nnunes.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index fc44991..0e372e1 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -7,11 +7,10 @@ #include "game_aux.h" bool test_dummy(void){ - return EXIT_SUCCESS; + return true; } -void usage(int argc, char *argv[]) -{ +void usage(int argc, char *argv[]){ fprintf(stderr, "Usage: %s [<...>]\n", argv[0]); exit(EXIT_FAILURE); } From 53b298037c0585be3ada7baef6c5211578723d3e Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Sun, 21 Nov 2021 01:46:42 +0100 Subject: [PATCH 099/281] update game_get_state --- game_test_nnunes.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 0e372e1..4cfb420 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -205,6 +205,86 @@ bool test_game_get_state(void){ game_delete(g); return false; } + game_set_square(g, 0, 0, (S_LIGHTBULB|F_ERROR)); + if (game_get_state(g, 0, 0) != S_LIGHTBULB){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLANK|F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLANK){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_MARK|F_ERROR)); + if (game_get_state(g, 0, 0) != S_MARK){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK|F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACK){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK0|F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACK0){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK1|F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACK1){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK2|F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACK2){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK3|F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACK3){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK4|F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACK4){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACKU|F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACKU){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_LIGHTBULB|F_LIGHTED)); + if (game_get_state(g, 0, 0) != S_LIGHTBULB){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLANK|F_LIGHTED)); + if (game_get_state(g, 0, 0) != S_BLANK){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_MARK|F_LIGHTED)); + if (game_get_state(g, 0, 0) != S_MARK){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_LIGHTBULB|F_LIGHTED|F_ERROR)); + if (game_get_state(g, 0, 0) != S_LIGHTBULB){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLANK|F_LIGHTED|F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLANK){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_MARK|F_LIGHTED|F_ERROR)); + if (game_get_state(g, 0, 0) != S_MARK){ + game_delete(g); + return false; + } game_delete(g); return true; } From b9834a69fd1dbe57a9e456e85ab78afafd9a49bb Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Mon, 22 Nov 2021 19:27:11 +0100 Subject: [PATCH 100/281] modification test_game_copy --- README.md | 2 +- game_test_thperrier.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 92cd721..96f7acb 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Projet Techno | [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [x]
| | [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [X]
| | [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [X]
| -| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| +| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [x]
| | [game_check_move](./game_test_thoguet.c#L439-463) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [X]
| | [game_play_move](./game_test_thoguet.c#L412-436) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [X]
| | [game_update_flags](./game_test_thoguet.c#L144-410) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every possibilites |
  • [X]
| diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 7ebdb3f..c64e5a4 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -186,16 +186,27 @@ bool test_game_new_empty(){ /* ********** game_copy ********** */ bool test_game_copy(){ game g1 = game_new_empty(); + game_set_square(g1, 0, 0, S_LIGHTBULB); + game_set_square(g1, 0, 1, S_MARK); + game_set_square(g1, 0, 2, S_BLACK); + game_set_square(g1, 0, 3, S_BLACK0); + game_set_square(g1, 0, 4, S_BLACK1); + game_set_square(g1, 0, 5, S_BLACK2); + game_set_square(g1, 0, 6, S_BLACK3); + game_set_square(g1, 1, 0, S_BLACK4); + game_set_square(g1, 1, 1, S_BLACKU); + game_set_square(g1, 1, 2, F_LIGHTED); + game_set_square(g1, 1, 3, F_ERROR); game g2 = game_copy(g1); assert(g2); - if (game_equal(g1, g2) == true){ + if (game_equal(g1, g2)){ game_delete(g1); game_delete(g2); return true; } game_delete(g1); game_delete(g2); - return true; + return false; } /* ********** usage ********** */ void usage(int argc, char *argv[]){ From e33ce9e2993249189dcf0588580f8374cce125eb Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Mon, 22 Nov 2021 23:22:57 +0100 Subject: [PATCH 101/281] modif test_game_copy --- game_test_thperrier.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index c64e5a4..b397d03 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -186,27 +186,37 @@ bool test_game_new_empty(){ /* ********** game_copy ********** */ bool test_game_copy(){ game g1 = game_new_empty(); - game_set_square(g1, 0, 0, S_LIGHTBULB); - game_set_square(g1, 0, 1, S_MARK); - game_set_square(g1, 0, 2, S_BLACK); - game_set_square(g1, 0, 3, S_BLACK0); - game_set_square(g1, 0, 4, S_BLACK1); - game_set_square(g1, 0, 5, S_BLACK2); - game_set_square(g1, 0, 6, S_BLACK3); - game_set_square(g1, 1, 0, S_BLACK4); - game_set_square(g1, 1, 1, S_BLACKU); - game_set_square(g1, 1, 2, F_LIGHTED); - game_set_square(g1, 1, 3, F_ERROR); + for (int i = 0; i < DEFAULT_SIZE; i++){ + game_set_square(g1, i, 0, S_LIGHTBULB); + game_set_square(g1, i, 1, S_MARK); + game_set_square(g1, i, 2, S_BLACKU); + game_set_square(g1, i, 3, S_BLACK0); + game_set_square(g1, i, 4, S_BLACK1); + game_set_square(g1, 1, 2, F_LIGHTED); + game_set_square(g1, 1, 3, F_ERROR); + } game g2 = game_copy(g1); assert(g2); - if (game_equal(g1, g2)){ + if (!game_equal(g1, g2)){ game_delete(g1); game_delete(g2); - return true; + return false; + } + for (int i = 0; i < DEFAULT_SIZE; i++){ + for (int j = 0; j < DEFAULT_SIZE; j++){ + game_set_square(g2, i, j, S_BLACK3); + } + } + g2 = game_copy(g1); + assert(g2); + if (!game_equal(g1, g2)){ + game_delete(g1); + game_delete(g2); + return false; } game_delete(g1); game_delete(g2); - return false; + return true; } /* ********** usage ********** */ void usage(int argc, char *argv[]){ From aff9199b4fc5d54e6f32d94537d016e30291f927 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Thu, 25 Nov 2021 09:51:26 +0100 Subject: [PATCH 102/281] suppression game.o --- game.o | Bin 30040 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 game.o diff --git a/game.o b/game.o deleted file mode 100644 index 681775ccc88102a9c998710733ce79d2f608a818..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 30040 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 DZM`67 From 4448ffb3a1b9f52c4e08de86d5f76288bd4f0095 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Thu, 25 Nov 2021 10:11:39 +0100 Subject: [PATCH 103/281] adding game.c + edit CMake --- CMakeLists.txt | 2 +- game.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 game.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a63228..2bd4afd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ target_link_libraries(game_text game) target_link_libraries(game_test_thoguet game) target_link_libraries(game_test_thperrier game) target_link_libraries(game_test_nnunes game) -add_library (game game.o game_aux.c) +add_library (game game.c game_aux.c) add_test(test_thoguet_dummy ./game_test_thoguet dummy) add_test(test_thoguet_game_new ./game_test_thoguet game_new) diff --git a/game.c b/game.c new file mode 100644 index 0000000..096bfdc --- /dev/null +++ b/game.c @@ -0,0 +1,123 @@ +#include "game.h" + +game game_new(square *squares){ + return; +} + + +game game_new_empty(void){ + return; +} + + +game game_copy(cgame g){ + return; +} + + +bool game_equal(cgame g1, cgame g2){ + return; +} + + +void game_delete(game g){ + return; +} + + + +void game_set_square(game g, uint i, uint j, square s){ + return; +} + + + +square game_get_square(cgame g, uint i, uint j){ + return; +} + + + +square game_get_state(cgame g, uint i, uint j){ + return; +} + + + +square game_get_flags(cgame g, uint i, uint j){ + return; +} + + + +bool game_is_blank(cgame g, uint i, uint j){ + return; +} + + + +bool game_is_lightbulb(cgame g, uint i, uint j){ + return; +} + + + +bool game_is_black(cgame g, uint i, uint j){ + return; +} + + + +int game_get_black_number(cgame g, uint i, uint j){ + return; +} + + + +bool game_is_marked(cgame g, uint i, uint j){ + return; +} + + + +bool game_is_lighted(cgame g, uint i, uint j){ + return; +} + + + +bool game_has_error(cgame g, uint i, uint j){ + return; +} + + + + +bool game_check_move(cgame g, uint i, uint j, square s){ + return; +} + + + +void game_play_move(game g, uint i, uint j, square s){ + return; +} + + + +void game_update_flags(game g){ + return; +} + + + +bool game_is_over(cgame g){ + return; +} + + + +void game_restart(game g){ + return; +} + From b5d64e7792ca623fc4c2c2fa893c411af1c49f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 25 Nov 2021 10:13:22 +0100 Subject: [PATCH 104/281] edit gameaux.c --- game_aux.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/game_aux.c b/game_aux.c index c4a14d8..4c69b60 100644 --- a/game_aux.c +++ b/game_aux.c @@ -1,5 +1,3 @@ -#ifndef __GAME_AUX_H__ -#define __GAME_AUX_H__ #include #include #include "game.h" @@ -91,6 +89,4 @@ game game_default_solution(void){ game_set_square(g,6,1,S_LIGHTBULB); game_update_flags(g); return g; -} - -#endif \ No newline at end of file +} \ No newline at end of file From 7b26e255fb113e9925cc8d841a65537fe52f51b0 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Thu, 25 Nov 2021 10:26:42 +0100 Subject: [PATCH 105/281] adding struct game_s --- game.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/game.c b/game.c index 096bfdc..d180090 100644 --- a/game.c +++ b/game.c @@ -1,5 +1,9 @@ #include "game.h" +struct game_s{ + square ** tab_cell; +}; + game game_new(square *squares){ return; } From a33083a61ea3ff6b6f1d8064fae0ed972f787ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 25 Nov 2021 10:41:03 +0100 Subject: [PATCH 106/281] updated readme --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 96f7acb..791c136 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,33 @@ Projet Techno :warning: LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE :warning: + +## game.c + +| Fonction | REF | Assigned to | Notes | Finished | +| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | --------------------------------------- | :--------------------: | +| [game_new](./game.c#L?) | [game game_new(square *squares)](./game.h#L73-81) | @thperrier | |
  • [x]
| +| [game_new_empty](./game.c#L?) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| +| [game_copy](./game.c#L?) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| +| [game_equal](./game.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [X]
| +| [game_delete](./game.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| +| [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [X]
| +| [game_get_square](./game.c#L?) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| +| [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [X]
| +| [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [X]
| +| [game_is_blank](./game.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [x]
| +| [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| +| [game_is_black](./game.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [x]
| +| [game_get_black_number](./game.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thoguet | |
  • [x]
| +| [game_is_marked](./game.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [X]
| +| [game_is_lighted](./game.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [X]
| +| [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [x]
| +| [game_check_move](./game.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [X]
| +| [game_play_move](./game.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [X]
| +| [game_update_flags](./game.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every possibilites |
  • [X]
| +| [game_is_over](./game.c#L?) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| +| [game_restart](./game.c#L?) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| + ## Test | Test | REF | Assigned to | Notes | Finished | From d466599752e5b23453f570e0d70b86264dc949f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 25 Nov 2021 10:44:36 +0100 Subject: [PATCH 107/281] update checkbox --- README.md | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 791c136..2f6a5a0 100644 --- a/README.md +++ b/README.md @@ -8,27 +8,27 @@ Projet Techno | Fonction | REF | Assigned to | Notes | Finished | | --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | --------------------------------------- | :--------------------: | -| [game_new](./game.c#L?) | [game game_new(square *squares)](./game.h#L73-81) | @thperrier | |
  • [x]
| -| [game_new_empty](./game.c#L?) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| -| [game_copy](./game.c#L?) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| -| [game_equal](./game.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [X]
| -| [game_delete](./game.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| -| [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [X]
| -| [game_get_square](./game.c#L?) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| -| [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [X]
| -| [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [X]
| -| [game_is_blank](./game.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [x]
| -| [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| -| [game_is_black](./game.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [x]
| -| [game_get_black_number](./game.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thoguet | |
  • [x]
| -| [game_is_marked](./game.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [X]
| -| [game_is_lighted](./game.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [X]
| -| [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [x]
| -| [game_check_move](./game.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [X]
| -| [game_play_move](./game.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [X]
| -| [game_update_flags](./game.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every possibilites |
  • [X]
| -| [game_is_over](./game.c#L?) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| -| [game_restart](./game.c#L?) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| +| [game_new](./game.c#L?) | [game game_new(square *squares)](./game.h#L73-81) | @thperrier | |
  • [ ]
| +| [game_new_empty](./game.c#L?) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [ ]
| +| [game_copy](./game.c#L?) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [ ]
| +| [game_equal](./game.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| +| [game_delete](./game.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| +| [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| +| [game_get_square](./game.c#L?) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [ ]
| +| [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| +| [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| +| [game_is_blank](./game.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| +| [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| +| [game_is_black](./game.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [ ]
| +| [game_get_black_number](./game.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thoguet | |
  • [ ]
| +| [game_is_marked](./game.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| +| [game_is_lighted](./game.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| +| [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| +| [game_check_move](./game.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [ ]
| +| [game_play_move](./game.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [ ]
| +| [game_update_flags](./game.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every possibilites |
  • [ ]
| +| [game_is_over](./game.c#L?) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [ ]
| +| [game_restart](./game.c#L?) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [ ]
| ## Test From ccbf8460479279e9261b57e5e026ec4bee1a9345 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Thu, 25 Nov 2021 10:56:13 +0100 Subject: [PATCH 108/281] adding game_new --- game.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/game.c b/game.c index d180090..c771ce4 100644 --- a/game.c +++ b/game.c @@ -1,3 +1,5 @@ +#include +#include #include "game.h" struct game_s{ @@ -5,7 +7,24 @@ struct game_s{ }; game game_new(square *squares){ - return; + game g = (game)malloc(sizeof(game)); + if (g == NULL){ + fprintf(stderr, "not enough memory\n"); + exit (EXIT_FAILURE); + } + g->tab_cell = (square**)malloc(sizeof(square**)*DEFAULT_SIZE); + if (g->tab_cell == NULL){ + fprintf(stderr, "not enough memory\n"); + exit (EXIT_FAILURE); + } + for (int i = 0; i < DEFAULT_SIZE; i++){ + g->tab_cell[i] = (square*)malloc(sizeof(square*)*DEFAULT_SIZE); + if (g->tab_cell[i] == NULL){ + fprintf(stderr, "not enough memory\n"); + exit (EXIT_FAILURE); + } + } + return g; } From 60cc903de39fb71194a428627ddcf6133af50625 Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Thu, 25 Nov 2021 19:04:17 +0100 Subject: [PATCH 109/281] updated --- README.md | 96 +++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 2f6a5a0..90fc3fb 100644 --- a/README.md +++ b/README.md @@ -6,55 +6,55 @@ Projet Techno ## game.c -| Fonction | REF | Assigned to | Notes | Finished | -| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | --------------------------------------- | :--------------------: | -| [game_new](./game.c#L?) | [game game_new(square *squares)](./game.h#L73-81) | @thperrier | |
  • [ ]
| -| [game_new_empty](./game.c#L?) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [ ]
| -| [game_copy](./game.c#L?) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [ ]
| -| [game_equal](./game.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| -| [game_delete](./game.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| -| [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| -| [game_get_square](./game.c#L?) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [ ]
| -| [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| -| [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| -| [game_is_blank](./game.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| -| [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| -| [game_is_black](./game.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [ ]
| -| [game_get_black_number](./game.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thoguet | |
  • [ ]
| -| [game_is_marked](./game.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| -| [game_is_lighted](./game.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| -| [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| -| [game_check_move](./game.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [ ]
| -| [game_play_move](./game.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [ ]
| -| [game_update_flags](./game.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every possibilites |
  • [ ]
| -| [game_is_over](./game.c#L?) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [ ]
| -| [game_restart](./game.c#L?) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [ ]
| +| Fonction | REF | Assigned to | Notes | Finished | +| ------------------------------------ | ---------------------------------------------------------------------------- | ----------- | ----- | :--------------------: | +| [game_new](./game.c#L?) | [game game_new(square *squares)](./game.h#L73-81) | @thperrier | |
  • [ ]
| +| [game_new_empty](./game.c#L?) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [ ]
| +| [game_copy](./game.c#L?) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [ ]
| +| [game_equal](./game.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| +| [game_delete](./game.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| +| [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| +| [game_get_square](./game.c#L?) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [ ]
| +| [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| +| [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| +| [game_is_blank](./game.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| +| [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| +| [game_is_black](./game.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [ ]
| +| [game_get_black_number](./game.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thoguet | |
  • [ ]
| +| [game_is_marked](./game.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| +| [game_is_lighted](./game.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| +| [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| +| [game_check_move](./game.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [ ]
| +| [game_play_move](./game.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [ ]
| +| [game_update_flags](./game.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | |
  • [ ]
| +| [game_is_over](./game.c#L?) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [ ]
| +| [game_restart](./game.c#L?) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [ ]
| ## Test -| Test | REF | Assigned to | Notes | Finished | -| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | --------------------------------------- | :--------------------: | -| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| -| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| -| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| -| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [X]
| -| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| -| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [X]
| -| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| -| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [X]
| -| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [X]
| -| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [x]
| -| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| -| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [x]
| -| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [x]
| -| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [X]
| -| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [X]
| -| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [x]
| -| [game_check_move](./game_test_thoguet.c#L439-463) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [X]
| -| [game_play_move](./game_test_thoguet.c#L412-436) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [X]
| +| Test | REF | Assigned to | Notes | Finished | +| --------------------------------------------------- | ---------------------------------------------------------------------------- | ----------- | ----------------------------------------------- | :--------------------: | +| [game_new](./game_test_thoguet.c#L49) | [game game_new(square *squares)](./game.h#L73-81) | @thoguet | |
  • [x]
| +| [game_new_empty](./game_test_thperrier.c#L16) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [X]
| +| [game_copy](./game_test_thperrier.c#L32) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [X]
| +| [game_equal](./game_test_thperrier.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [X]
| +| [game_delete](./game_test_thperrier.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| +| [game_set_square](./game_test_nnunes.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [X]
| +| [game_get_square](./game_test_thoguet.c#L89) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [x]
| +| [game_get_state](./game_test_nnunes.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [X]
| +| [game_get_flags](./game_test_nnunes.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [X]
| +| [game_is_blank](./game_test_thperrier.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [x]
| +| [game_is_lightbulb](./game_test_thperrier.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| +| [game_is_black](./game_test_thperrier.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thperrier | |
  • [x]
| +| [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | |
  • [x]
| +| [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [X]
| +| [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [X]
| +| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [x]
| +| [game_check_move](./game_test_thoguet.c#L439-463) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [X]
| +| [game_play_move](./game_test_thoguet.c#L412-436) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [X]
| | [game_update_flags](./game_test_thoguet.c#L144-410) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every possibilites |
  • [X]
| -| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| -| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| -| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| -| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| -| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| +| [game_is_over](./game_test_thoguet.c#L17) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| +| [game_restart](./game_test_thoguet.c#L37) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| +| [game_print](./game_test_thoguet.c#L70) | [void game_print(cgame g)](./game_aux.h#L13-20) | @thoguet | |
  • [X]
| +| [game_default](./game_test_thoguet.c#L107) | [game game_default(void)](./game_aux.h#L22-28) | @thoguet | |
  • [X]
| +| [game_default_solution](./game_test_thoguet.c#L125) | [game game_default_solution(void)](./game_aux.h#L30-36) | @thoguet | |
  • [X]
| From bdcd253d7bff8c2198cfc0a598ec8a049fc92119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Fri, 26 Nov 2021 22:50:31 +0100 Subject: [PATCH 110/281] clangformat --- .clang-format | 148 +++++++++ game.c | 164 ++++------ game_aux.c | 92 +++--- game_test_nnunes.c | 733 +++++++++++++++++++++--------------------- game_test_thoguet.c | 497 ++++++++++++++-------------- game_test_thperrier.c | 465 +++++++++++++-------------- game_text.c | 73 +++-- 7 files changed, 1150 insertions(+), 1022 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..1c5cae1 --- /dev/null +++ b/.clang-format @@ -0,0 +1,148 @@ +--- +Language: Cpp +# BasedOnStyle: Chromium +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: true +BinPackParameters: false +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^' + Priority: 2 + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 +IncludeIsMainRegex: '([-_](test|unittest))?$' +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Left +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + CanonicalDelimiter: '' + BasedOnStyle: google +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +TabWidth: 4 +UseTab: ForIndentation +... + diff --git a/game.c b/game.c index c771ce4..9e8b10d 100644 --- a/game.c +++ b/game.c @@ -1,146 +1,108 @@ -#include -#include #include "game.h" +#include +#include -struct game_s{ - square ** tab_cell; +struct game_s { + square** tab_cell; }; -game game_new(square *squares){ - game g = (game)malloc(sizeof(game)); - if (g == NULL){ - fprintf(stderr, "not enough memory\n"); - exit (EXIT_FAILURE); - } - g->tab_cell = (square**)malloc(sizeof(square**)*DEFAULT_SIZE); - if (g->tab_cell == NULL){ - fprintf(stderr, "not enough memory\n"); - exit (EXIT_FAILURE); - } - for (int i = 0; i < DEFAULT_SIZE; i++){ - g->tab_cell[i] = (square*)malloc(sizeof(square*)*DEFAULT_SIZE); - if (g->tab_cell[i] == NULL){ - fprintf(stderr, "not enough memory\n"); - exit (EXIT_FAILURE); - } - } - return g; +game game_new(square* squares) { + game g = (game)malloc(sizeof(game)); + if (g == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + g->tab_cell = (square**)malloc(sizeof(square**) * DEFAULT_SIZE); + if (g->tab_cell == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + for (int i = 0; i < DEFAULT_SIZE; i++) { + g->tab_cell[i] = (square*)malloc(sizeof(square*) * DEFAULT_SIZE); + if (g->tab_cell[i] == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + } + return g; } - -game game_new_empty(void){ - return; +game game_new_empty(void) { + return; } - -game game_copy(cgame g){ - return; +game game_copy(cgame g) { + return; } - -bool game_equal(cgame g1, cgame g2){ - return; +bool game_equal(cgame g1, cgame g2) { + return; } - -void game_delete(game g){ - return; +void game_delete(game g) { + return; } - - -void game_set_square(game g, uint i, uint j, square s){ - return; +void game_set_square(game g, uint i, uint j, square s) { + return; } - - -square game_get_square(cgame g, uint i, uint j){ - return; +square game_get_square(cgame g, uint i, uint j) { + return; } - - -square game_get_state(cgame g, uint i, uint j){ - return; +square game_get_state(cgame g, uint i, uint j) { + return; } - - -square game_get_flags(cgame g, uint i, uint j){ - return; +square game_get_flags(cgame g, uint i, uint j) { + return; } - - -bool game_is_blank(cgame g, uint i, uint j){ - return; +bool game_is_blank(cgame g, uint i, uint j) { + return; } - - -bool game_is_lightbulb(cgame g, uint i, uint j){ - return; +bool game_is_lightbulb(cgame g, uint i, uint j) { + return; } - - -bool game_is_black(cgame g, uint i, uint j){ - return; +bool game_is_black(cgame g, uint i, uint j) { + return; } - - -int game_get_black_number(cgame g, uint i, uint j){ - return; +int game_get_black_number(cgame g, uint i, uint j) { + return; } - - -bool game_is_marked(cgame g, uint i, uint j){ - return; +bool game_is_marked(cgame g, uint i, uint j) { + return; } - - -bool game_is_lighted(cgame g, uint i, uint j){ - return; +bool game_is_lighted(cgame g, uint i, uint j) { + return; } - - -bool game_has_error(cgame g, uint i, uint j){ - return; +bool game_has_error(cgame g, uint i, uint j) { + return; } - - - -bool game_check_move(cgame g, uint i, uint j, square s){ - return; +bool game_check_move(cgame g, uint i, uint j, square s) { + return; } - - -void game_play_move(game g, uint i, uint j, square s){ - return; +void game_play_move(game g, uint i, uint j, square s) { + return; } - - -void game_update_flags(game g){ - return; +void game_update_flags(game g) { + return; } - - -bool game_is_over(cgame g){ - return; +bool game_is_over(cgame g) { + return; } - - -void game_restart(game g){ - return; +void game_restart(game g) { + return; } - diff --git a/game_aux.c b/game_aux.c index 4c69b60..9168c56 100644 --- a/game_aux.c +++ b/game_aux.c @@ -2,91 +2,95 @@ #include #include "game.h" -char charPrintCell(square sqState){ - if (sqState == S_BLANK){ +char charPrintCell(square sqState) { + if (sqState == S_BLANK) { return ' '; } - if ((sqState == S_LIGHTBULB) || (sqState == (S_LIGHTBULB|F_ERROR)) | (sqState == (S_LIGHTBULB|F_LIGHTED)) | (sqState == (S_LIGHTBULB|F_ERROR|F_LIGHTED))){ + if ((sqState == S_LIGHTBULB) || + (sqState == (S_LIGHTBULB | F_ERROR)) | + (sqState == (S_LIGHTBULB | F_LIGHTED)) | + (sqState == (S_LIGHTBULB | F_ERROR | F_LIGHTED))) { return '*'; } - if ((sqState == S_MARK) || (sqState == (S_MARK|F_ERROR)) | (sqState == (S_MARK|F_LIGHTED))){ + if ((sqState == S_MARK) || + (sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) { return '-'; } - if (sqState == S_BLACK0 || sqState == (S_BLACK0|F_ERROR)){ + if (sqState == S_BLACK0 || sqState == (S_BLACK0 | F_ERROR)) { return '0'; } - if (sqState == S_BLACK1 || sqState == (S_BLACK1|F_ERROR)){ + if (sqState == S_BLACK1 || sqState == (S_BLACK1 | F_ERROR)) { return '1'; } - if (sqState == S_BLACK2 || sqState == (S_BLACK2|F_ERROR)){ + if (sqState == S_BLACK2 || sqState == (S_BLACK2 | F_ERROR)) { return '2'; } - if (sqState == S_BLACK3 || sqState == (S_BLACK3|F_ERROR)){ + if (sqState == S_BLACK3 || sqState == (S_BLACK3 | F_ERROR)) { return '3'; } - if (sqState == S_BLACK4 || sqState == (S_BLACK4|F_ERROR)){ + if (sqState == S_BLACK4 || sqState == (S_BLACK4 | F_ERROR)) { return '4'; } - if (sqState == S_BLACKU || sqState == (S_BLACKU|F_ERROR)){ + if (sqState == S_BLACKU || sqState == (S_BLACKU | F_ERROR)) { return 'w'; } - if (sqState == F_LIGHTED){ + if (sqState == F_LIGHTED) { return '.'; } return -1; } -void game_print(cgame g){ - if (g != NULL){ +void game_print(cgame g) { + if (g != NULL) { uint i; printf(" 0"); - for (i = 1; i < DEFAULT_SIZE; i++){ - printf("%u",i); + for (i = 1; i < DEFAULT_SIZE; i++) { + printf("%u", i); } printf("\n -"); - for (i = 1; i < DEFAULT_SIZE; i++){ + for (i = 1; i < DEFAULT_SIZE; i++) { printf("-"); } printf("\n"); - for (i = 0; i < DEFAULT_SIZE; i++){ - printf("%u |",i); - for (uint j = 0; j < DEFAULT_SIZE; j++){ - printf("%c",charPrintCell(game_get_square(g,i,j))); + for (i = 0; i < DEFAULT_SIZE; i++) { + printf("%u |", i); + for (uint j = 0; j < DEFAULT_SIZE; j++) { + printf("%c", charPrintCell(game_get_square(g, i, j))); } printf("|\n"); } printf(" -"); - for (i = 1; i < DEFAULT_SIZE; i++){ + for (i = 1; i < DEFAULT_SIZE; i++) { printf("-"); } printf("\n"); } } -game game_default(void){ +game game_default(void) { game g = game_new_empty(); - game_set_square(g,0,2,S_BLACK1); - game_set_square(g,1,2,S_BLACK2); - game_set_square(g,2,5,S_BLACKU); - game_set_square(g,2,6,S_BLACK2); - game_set_square(g,4,0,S_BLACK1); - game_set_square(g,4,1,S_BLACKU); - game_set_square(g,5,4,S_BLACK2); - game_set_square(g,6,4,S_BLACKU); + game_set_square(g, 0, 2, S_BLACK1); + game_set_square(g, 1, 2, S_BLACK2); + game_set_square(g, 2, 5, S_BLACKU); + game_set_square(g, 2, 6, S_BLACK2); + game_set_square(g, 4, 0, S_BLACK1); + game_set_square(g, 4, 1, S_BLACKU); + game_set_square(g, 5, 4, S_BLACK2); + game_set_square(g, 6, 4, S_BLACKU); return g; } -game game_default_solution(void){ - game g = game_default(); - game_set_square(g,0,0,S_LIGHTBULB); - game_set_square(g,1,1,S_LIGHTBULB); - game_set_square(g,0,3,S_LIGHTBULB); - game_set_square(g,1,6,S_LIGHTBULB); - game_set_square(g,2,2,S_LIGHTBULB); - game_set_square(g,3,6,S_LIGHTBULB); - game_set_square(g,4,4,S_LIGHTBULB); - game_set_square(g,5,0,S_LIGHTBULB); - game_set_square(g,5,5,S_LIGHTBULB); - game_set_square(g,6,1,S_LIGHTBULB); - game_update_flags(g); - return g; +game game_default_solution(void) { + game g = game_default(); + game_set_square(g, 0, 0, S_LIGHTBULB); + game_set_square(g, 1, 1, S_LIGHTBULB); + game_set_square(g, 0, 3, S_LIGHTBULB); + game_set_square(g, 1, 6, S_LIGHTBULB); + game_set_square(g, 2, 2, S_LIGHTBULB); + game_set_square(g, 3, 6, S_LIGHTBULB); + game_set_square(g, 4, 4, S_LIGHTBULB); + game_set_square(g, 5, 0, S_LIGHTBULB); + game_set_square(g, 5, 5, S_LIGHTBULB); + game_set_square(g, 6, 1, S_LIGHTBULB); + game_update_flags(g); + return g; } \ No newline at end of file diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 4cfb420..7cbe96b 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -1,398 +1,393 @@ +#include +#include #include #include -#include #include -#include #include "game.h" #include "game_aux.h" -bool test_dummy(void){ - return true; +bool test_dummy(void) { + return true; } -void usage(int argc, char *argv[]){ - fprintf(stderr, "Usage: %s [<...>]\n", argv[0]); - exit(EXIT_FAILURE); +void usage(int argc, char* argv[]) { + fprintf(stderr, "Usage: %s [<...>]\n", argv[0]); + exit(EXIT_FAILURE); } /* ************** game_get_square ************** */ -bool test_game_get_square(void){ - game g = game_new_empty(); - game_set_square(g, 0, 0, S_LIGHTBULB); - if (game_get_square(g, 0, 0) != S_LIGHTBULB){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLANK); - if (game_get_square(g, 0, 0) != S_BLANK){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_MARK); - if (game_get_square(g, 0, 0) != S_MARK){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK); - if (game_get_square(g, 0, 0) != S_BLACK){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK0); - if (game_get_square(g, 0, 0) != S_BLACK0){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK1); - if (game_get_square(g, 0, 0) != S_BLACK1){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK2); - if (game_get_square(g, 0, 0) != S_BLACK2){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK3); - if (game_get_square(g, 0, 0) != S_BLACK3){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK4); - if (game_get_square(g, 0, 0) != S_BLACK4){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACKU); - if (game_get_square(g, 0, 0) != S_BLACKU){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_LIGHTBULB|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_LIGHTBULB|F_ERROR)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLANK|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLANK|F_ERROR)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_MARK|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_MARK|F_ERROR)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACK|F_ERROR)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK0|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACK0|F_ERROR)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK1|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACK1|F_ERROR)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK2|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACK2|F_ERROR)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK3|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACK3|F_ERROR)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK4|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACK4|F_ERROR)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACKU|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACKU|F_ERROR)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_LIGHTBULB|F_LIGHTED)); - if (game_get_square(g, 0, 0) != (S_LIGHTBULB|F_LIGHTED)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLANK|F_LIGHTED)); - if (game_get_square(g, 0, 0) != (S_BLANK|F_LIGHTED)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_MARK|F_LIGHTED)); - if (game_get_square(g, 0, 0) != (S_MARK|F_LIGHTED)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_LIGHTBULB|F_LIGHTED|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLANK|F_LIGHTED|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLANK|F_LIGHTED|F_ERROR)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_MARK|F_LIGHTED|F_ERROR)); - if (game_get_square(g, 0, 0) != (S_MARK|F_LIGHTED|F_ERROR)){ - game_delete(g); - return false; - } - game_delete(g); - return true; +bool test_game_get_square(void) { + game g = game_new_empty(); + game_set_square(g, 0, 0, S_LIGHTBULB); + if (game_get_square(g, 0, 0) != S_LIGHTBULB) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLANK); + if (game_get_square(g, 0, 0) != S_BLANK) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK); + if (game_get_square(g, 0, 0) != S_MARK) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK); + if (game_get_square(g, 0, 0) != S_BLACK) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK0); + if (game_get_square(g, 0, 0) != S_BLACK0) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK1); + if (game_get_square(g, 0, 0) != S_BLACK1) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK2); + if (game_get_square(g, 0, 0) != S_BLACK2) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK3); + if (game_get_square(g, 0, 0) != S_BLACK3) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK4); + if (game_get_square(g, 0, 0) != S_BLACK4) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACKU); + if (game_get_square(g, 0, 0) != S_BLACKU) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_LIGHTBULB | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_LIGHTBULB | F_ERROR)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLANK | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLANK | F_ERROR)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_MARK | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_MARK | F_ERROR)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACK | F_ERROR)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK0 | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACK0 | F_ERROR)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK1 | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACK1 | F_ERROR)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK2 | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACK2 | F_ERROR)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK3 | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACK3 | F_ERROR)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK4 | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACK4 | F_ERROR)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACKU | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLACKU | F_ERROR)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_LIGHTBULB | F_LIGHTED)); + if (game_get_square(g, 0, 0) != (S_LIGHTBULB | F_LIGHTED)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLANK | F_LIGHTED)); + if (game_get_square(g, 0, 0) != (S_BLANK | F_LIGHTED)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_MARK | F_LIGHTED)); + if (game_get_square(g, 0, 0) != (S_MARK | F_LIGHTED)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLANK | F_LIGHTED | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_BLANK | F_LIGHTED | F_ERROR)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_MARK | F_LIGHTED | F_ERROR)); + if (game_get_square(g, 0, 0) != (S_MARK | F_LIGHTED | F_ERROR)) { + game_delete(g); + return false; + } + game_delete(g); + return true; } /* ************** game_get_state ************** */ -bool test_game_get_state(void){ - game g = game_new_empty(); - game_set_square(g, 0, 0, S_LIGHTBULB); - if (game_get_state(g, 0, 0) != S_LIGHTBULB){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLANK); - if (game_get_state(g, 0, 0) != S_BLANK){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_MARK); - if (game_get_state(g, 0, 0) != S_MARK){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK); - if (game_get_state(g, 0, 0) != S_BLACK){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK0); - if (game_get_state(g, 0, 0) != S_BLACK0){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK1); - if (game_get_state(g, 0, 0) != S_BLACK1){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK2); - if (game_get_state(g, 0, 0) != S_BLACK2){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK3); - if (game_get_state(g, 0, 0) != S_BLACK3){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK4); - if (game_get_state(g, 0, 0) != S_BLACK4){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACKU); - if (game_get_state(g, 0, 0) != S_BLACKU){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_LIGHTBULB|F_ERROR)); - if (game_get_state(g, 0, 0) != S_LIGHTBULB){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLANK|F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLANK){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_MARK|F_ERROR)); - if (game_get_state(g, 0, 0) != S_MARK){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK|F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACK){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK0|F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACK0){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK1|F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACK1){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK2|F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACK2){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK3|F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACK3){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK4|F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACK4){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACKU|F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACKU){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_LIGHTBULB|F_LIGHTED)); - if (game_get_state(g, 0, 0) != S_LIGHTBULB){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLANK|F_LIGHTED)); - if (game_get_state(g, 0, 0) != S_BLANK){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_MARK|F_LIGHTED)); - if (game_get_state(g, 0, 0) != S_MARK){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_LIGHTBULB|F_LIGHTED|F_ERROR)); - if (game_get_state(g, 0, 0) != S_LIGHTBULB){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLANK|F_LIGHTED|F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLANK){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_MARK|F_LIGHTED|F_ERROR)); - if (game_get_state(g, 0, 0) != S_MARK){ - game_delete(g); - return false; - } - game_delete(g); - return true; +bool test_game_get_state(void) { + game g = game_new_empty(); + game_set_square(g, 0, 0, S_LIGHTBULB); + if (game_get_state(g, 0, 0) != S_LIGHTBULB) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLANK); + if (game_get_state(g, 0, 0) != S_BLANK) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK); + if (game_get_state(g, 0, 0) != S_MARK) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK); + if (game_get_state(g, 0, 0) != S_BLACK) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK0); + if (game_get_state(g, 0, 0) != S_BLACK0) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK1); + if (game_get_state(g, 0, 0) != S_BLACK1) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK2); + if (game_get_state(g, 0, 0) != S_BLACK2) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK3); + if (game_get_state(g, 0, 0) != S_BLACK3) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK4); + if (game_get_state(g, 0, 0) != S_BLACK4) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACKU); + if (game_get_state(g, 0, 0) != S_BLACKU) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_LIGHTBULB | F_ERROR)); + if (game_get_state(g, 0, 0) != S_LIGHTBULB) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLANK | F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLANK) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_MARK | F_ERROR)); + if (game_get_state(g, 0, 0) != S_MARK) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK | F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACK) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK0 | F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACK0) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK1 | F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACK1) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK2 | F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACK2) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK3 | F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACK3) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACK4 | F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACK4) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLACKU | F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLACKU) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_LIGHTBULB | F_LIGHTED)); + if (game_get_state(g, 0, 0) != S_LIGHTBULB) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLANK | F_LIGHTED)); + if (game_get_state(g, 0, 0) != S_BLANK) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_MARK | F_LIGHTED)); + if (game_get_state(g, 0, 0) != S_MARK) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + if (game_get_state(g, 0, 0) != S_LIGHTBULB) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_BLANK | F_LIGHTED | F_ERROR)); + if (game_get_state(g, 0, 0) != S_BLANK) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, (S_MARK | F_LIGHTED | F_ERROR)); + if (game_get_state(g, 0, 0) != S_MARK) { + game_delete(g); + return false; + } + game_delete(g); + return true; } /* ************** game_get_flags ************** */ -bool test_game_get_flags(void){ - game g = game_new_empty(); - game_set_square(g, 0, 0, S_BLANK|F_LIGHTED); - if (game_get_flags(g, 0, 0) != F_LIGHTED){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLANK|F_ERROR); - if (game_get_flags(g, 0, 0) != F_ERROR){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLANK|F_ERROR|F_LIGHTED); - if (game_get_flags(g, 0, 0) != (F_ERROR|F_LIGHTED)){ - game_delete(g); - return false; - } - game_delete(g); - return true; +bool test_game_get_flags(void) { + game g = game_new_empty(); + game_set_square(g, 0, 0, S_BLANK | F_LIGHTED); + if (game_get_flags(g, 0, 0) != F_LIGHTED) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLANK | F_ERROR); + if (game_get_flags(g, 0, 0) != F_ERROR) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLANK | F_ERROR | F_LIGHTED); + if (game_get_flags(g, 0, 0) != (F_ERROR | F_LIGHTED)) { + game_delete(g); + return false; + } + game_delete(g); + return true; } /* ************** game_is_marked ************** */ -bool test_game_is_marked(void){ - game g = game_new_empty(); - game_set_square(g, 0, 0, S_MARK); - if ((game_get_square(g, 0, 0) == S_MARK) && game_is_marked(g, 0, 0)){ - game_delete(g); - return true; - } - game_delete(g); - return false; +bool test_game_is_marked(void) { + game g = game_new_empty(); + game_set_square(g, 0, 0, S_MARK); + if ((game_get_square(g, 0, 0) == S_MARK) && game_is_marked(g, 0, 0)) { + game_delete(g); + return true; + } + game_delete(g); + return false; } /* ************** game_is_lighted ************** */ -bool test_game_is_lighted(void){ - game g = game_new_empty(); - game_set_square(g, 0, 0, S_BLANK|F_LIGHTED); - if ((game_get_square(g, 0, 0) == F_LIGHTED) && game_is_lighted(g, 0, 0)){ - game_delete(g); - return true; - } - game_set_square(g, 0, 0, S_BLANK|F_LIGHTED|F_ERROR); - if((game_get_flags(g, 0, 0) == (F_LIGHTED|F_ERROR)) && game_is_lighted(g, 0, 0)){ - game_delete(g); - return true; - } - game_delete(g); - return false; +bool test_game_is_lighted(void) { + game g = game_new_empty(); + game_set_square(g, 0, 0, S_BLANK | F_LIGHTED); + if ((game_get_square(g, 0, 0) == F_LIGHTED) && game_is_lighted(g, 0, 0)) { + game_delete(g); + return true; + } + game_set_square(g, 0, 0, S_BLANK | F_LIGHTED | F_ERROR); + if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && + game_is_lighted(g, 0, 0)) { + game_delete(g); + return true; + } + game_delete(g); + return false; } /* ************** game_has_error ************** */ -bool test_game_has_error(void){ - game g = game_new_empty(); - game_set_square(g, 0, 0, S_BLANK|F_ERROR); - if((game_get_flags(g, 0, 0) == F_ERROR) && game_has_error(g, 0, 0)){ - game_delete(g); - return true; - } - game_set_square(g, 0, 0, S_BLANK|F_LIGHTED|F_ERROR); - if((game_get_flags(g, 0, 0) == (F_LIGHTED|F_ERROR)) && game_has_error(g, 0, 0)){ - game_delete(g); - return true; - } - game_delete(g); - return false; +bool test_game_has_error(void) { + game g = game_new_empty(); + game_set_square(g, 0, 0, S_BLANK | F_ERROR); + if ((game_get_flags(g, 0, 0) == F_ERROR) && game_has_error(g, 0, 0)) { + game_delete(g); + return true; + } + game_set_square(g, 0, 0, S_BLANK | F_LIGHTED | F_ERROR); + if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && + game_has_error(g, 0, 0)) { + game_delete(g); + return true; + } + game_delete(g); + return false; } -int main(int argc, char * argv[]){ - if (argc != 2){ - usage(argc, argv); - } - fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); - bool success = false; - if (strcmp("dummy", argv[1]) == 0) - success = test_dummy(); - else if (strcmp("game_get_square", argv[1]) == 0){ - success = test_game_get_square(); - } - else if (strcmp("game_get_state", argv[1]) == 0){ - success = test_game_get_state(); - } - else if (strcmp("game_get_flags", argv[1]) == 0){ - success = test_game_get_flags(); - } - else if (strcmp("game_is_marked", argv[1]) == 0){ - success = test_game_is_marked(); - } - else if (strcmp("game_is_lighted", argv[1]) == 0){ - success = test_game_is_lighted(); - } - else if (strcmp("game_has_error", argv[1]) == 0){ - success = test_game_has_error(); - } - else { - fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); - exit(EXIT_FAILURE); - } - if (success){ - fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); - return EXIT_SUCCESS; - } - else { - fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]); - return EXIT_FAILURE; - } +int main(int argc, char* argv[]) { + if (argc != 2) { + usage(argc, argv); + } + fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); + bool success = false; + if (strcmp("dummy", argv[1]) == 0) + success = test_dummy(); + else if (strcmp("game_get_square", argv[1]) == 0) { + success = test_game_get_square(); + } else if (strcmp("game_get_state", argv[1]) == 0) { + success = test_game_get_state(); + } else if (strcmp("game_get_flags", argv[1]) == 0) { + success = test_game_get_flags(); + } else if (strcmp("game_is_marked", argv[1]) == 0) { + success = test_game_is_marked(); + } else if (strcmp("game_is_lighted", argv[1]) == 0) { + success = test_game_is_lighted(); + } else if (strcmp("game_has_error", argv[1]) == 0) { + success = test_game_has_error(); + } else { + fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); + exit(EXIT_FAILURE); + } + if (success) { + fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); + return EXIT_SUCCESS; + } else { + fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]); + return EXIT_FAILURE; + } } \ No newline at end of file diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 24bd142..90eb189 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -1,27 +1,27 @@ +#include +#include #include #include -#include #include -#include #include "game.h" #include "game_aux.h" typedef unsigned int uint; /* ********** DUMMY ********** */ -bool test_dummy(void){ +bool test_dummy(void) { return EXIT_SUCCESS; } /* ******* game_is_over ******* */ -bool test_game_is_over(void){ +bool test_game_is_over(void) { game g = game_default_solution(); game_update_flags(g); assert(game_is_over(g)); - game_set_square(g,0,0,(S_LIGHTBULB|F_LIGHTED|F_ERROR)); + game_set_square(g, 0, 0, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); assert(!game_is_over(g)); game_update_flags(g); - game_set_square(g,0,1,S_BLANK); + game_set_square(g, 0, 1, S_BLANK); assert(!game_is_over(g)); game_delete(g); g = game_default(); @@ -33,21 +33,21 @@ bool test_game_is_over(void){ /* ******* game_restart ******* */ -bool test_game_restart(void){ +bool test_game_restart(void) { game g = game_default(); game g1 = game_default_solution(); - game_set_square(g,1,5,S_BLACK4); - game_set_square(g1,1,5,S_BLACK4); - game_set_square(g,3,2,S_BLACK3); - game_set_square(g1,3,2,S_BLACK3); - game_set_square(g,0,1,S_LIGHTBULB); - game_set_square(g1,0,1,S_LIGHTBULB); - game_play_move(g,2,0,S_MARK); - game_play_move(g1,2,0,S_MARK); - assert(!game_equal(g,g1)); + game_set_square(g, 1, 5, S_BLACK4); + game_set_square(g1, 1, 5, S_BLACK4); + game_set_square(g, 3, 2, S_BLACK3); + game_set_square(g1, 3, 2, S_BLACK3); + game_set_square(g, 0, 1, S_LIGHTBULB); + game_set_square(g1, 0, 1, S_LIGHTBULB); + game_play_move(g, 2, 0, S_MARK); + game_play_move(g1, 2, 0, S_MARK); + assert(!game_equal(g, g1)); game_restart(g1); game_restart(g); - assert(game_equal(g,g1)); + assert(game_equal(g, g1)); game_delete(g); game_delete(g1); return EXIT_SUCCESS; @@ -55,16 +55,18 @@ bool test_game_restart(void){ /* ********* game_new ********* */ -bool test_game_new(void){ - square tab[DEFAULT_SIZE*DEFAULT_SIZE]; +bool test_game_new(void) { + square tab[DEFAULT_SIZE * DEFAULT_SIZE]; game g; - square list[] = {S_BLANK,S_LIGHTBULB,S_MARK,S_BLACK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,S_BLACKU,F_ERROR}; - for (uint i = 0; i < sizeof(list)/sizeof(list[0]) ; i ++){ + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, + S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, + S_BLACK4, S_BLACKU, F_ERROR}; + for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { g = NULL; - for (uint j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ + for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) { tab[j] = list[i]; } - printf("%d\n",i); + printf("%d\n", i); g = game_new(tab); assert(g); game_delete(g); @@ -76,15 +78,16 @@ bool test_game_new(void){ // est ce qu'il faut faire avec un tab invalide ? -bool test_game_print(void){ - square tab[DEFAULT_SIZE*DEFAULT_SIZE]; - square list[] = {S_BLANK,S_LIGHTBULB,S_MARK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,S_BLACKU}; +bool test_game_print(void) { + square tab[DEFAULT_SIZE * DEFAULT_SIZE]; + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, + S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g; - for (uint i = 0; i < sizeof(list)/sizeof(list[0]) ; i ++){ - for (uint j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ + 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); + printf("%d\n", i); g = game_new(tab); game_print(g); game_delete(g); @@ -94,16 +97,28 @@ bool test_game_print(void){ /* ******* game_get_square ******* */ -bool test_game_get_square(void){ +bool test_game_get_square(void) { game g; - square tab[DEFAULT_SIZE*DEFAULT_SIZE]; - square list[] = {S_BLANK,S_LIGHTBULB,S_MARK,S_BLACK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,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++){ + square tab[DEFAULT_SIZE * DEFAULT_SIZE]; + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, + S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, + S_BLACK4, 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]); + 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]); game_delete(g); } } @@ -112,23 +127,27 @@ bool test_game_get_square(void){ /* ******* game_default ******* */ -bool test_game_default(void){ +bool test_game_default(void) { game g = game_default(); - //a verif aps sur + // a verif aps sur assert(g); - square tab[49] = - { - /*X0 X1 X2 X3 X4 X5 X6*/ - /*Y 0*/ S_BLANK, S_BLANK, S_BLACK1, S_BLANK, S_BLANK, S_BLANK, S_BLANK, - /*Y 1*/ S_BLANK, S_BLANK, S_BLACK2, S_BLANK, S_BLANK, S_BLANK, S_BLANK, - /*Y 2*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLACK2, - /*Y 3*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, - /*Y 4*/ S_BLACK1, S_BLACKU, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, - /*Y 5*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACK2, S_BLANK, S_BLANK, - /*Y 6*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLANK - }; + square tab[49] = {/*X0 X1 X2 X3 X4 X5 X6*/ + /*Y 0*/ S_BLANK, S_BLANK, S_BLACK1, S_BLANK, + S_BLANK, S_BLANK, S_BLANK, + /*Y 1*/ S_BLANK, S_BLANK, S_BLACK2, S_BLANK, + S_BLANK, S_BLANK, S_BLANK, + /*Y 2*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, + S_BLANK, S_BLACKU, S_BLACK2, + /*Y 3*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, + S_BLANK, S_BLANK, S_BLANK, + /*Y 4*/ S_BLACK1, S_BLACKU, S_BLANK, S_BLANK, + S_BLANK, S_BLANK, S_BLANK, + /*Y 5*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, + S_BLACK2, S_BLANK, S_BLANK, + /*Y 6*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, + S_BLACKU, S_BLANK, S_BLANK}; game g1 = game_new(tab); - assert(game_equal(g,g1)); + assert(game_equal(g, g1)); game_delete(g); game_delete(g1); return EXIT_SUCCESS; @@ -136,23 +155,23 @@ bool test_game_default(void){ /* *** game_default_solution *** */ -bool test_game_default_solution(void){ +bool test_game_default_solution(void) { game g = game_default_solution(); game g1 = game_default(); assert(g); - //solution - game_set_square(g1,0,0,S_LIGHTBULB); - game_set_square(g1,1,1,S_LIGHTBULB); - game_set_square(g1,0,3,S_LIGHTBULB); - game_set_square(g1,1,6,S_LIGHTBULB); - game_set_square(g1,2,2,S_LIGHTBULB); - game_set_square(g1,3,6,S_LIGHTBULB); - game_set_square(g1,4,4,S_LIGHTBULB); - game_set_square(g1,5,0,S_LIGHTBULB); - game_set_square(g1,5,5,S_LIGHTBULB); - game_set_square(g1,6,1,S_LIGHTBULB); + // solution + game_set_square(g1, 0, 0, S_LIGHTBULB); + game_set_square(g1, 1, 1, S_LIGHTBULB); + game_set_square(g1, 0, 3, S_LIGHTBULB); + game_set_square(g1, 1, 6, S_LIGHTBULB); + game_set_square(g1, 2, 2, S_LIGHTBULB); + game_set_square(g1, 3, 6, S_LIGHTBULB); + game_set_square(g1, 4, 4, S_LIGHTBULB); + game_set_square(g1, 5, 0, S_LIGHTBULB); + game_set_square(g1, 5, 5, S_LIGHTBULB); + game_set_square(g1, 6, 1, S_LIGHTBULB); game_update_flags(g1); - assert(game_equal(g,g1)); + assert(game_equal(g, g1)); game_delete(g); game_delete(g1); return EXIT_SUCCESS; @@ -160,207 +179,214 @@ bool test_game_default_solution(void){ /* **** game_update_flags **** */ -int checklightbulb(game g, uint i, uint j, bool wall){ - square flags = game_get_flags(g,i,j); - //square state = game_get_state(g,i,j); - //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 (game_is_lightbulb(g,i,j)){ - if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR){ - //printf("156\n"); +int checklightbulb(game g, uint i, uint j, bool wall) { + square flags = game_get_flags(g, i, j); + // square state = game_get_state(g,i,j); + // 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 (game_is_lightbulb(g, i, j)) { + if (/*test if this lightbulb is well updated*/ flags == S_BLANK || + flags == F_ERROR) { + // printf("156\n"); return 0; } return -1; } - //if no wall(s) before test if the light of the lightbulb has been well updated - if (!wall){ - - //test if the current case is not lighted - if (flags != F_LIGHTED){ - //printf("170\n"); - return 0; + // if no wall(s) before test if the light of the lightbulb has been well + // updated + if (!wall) { + // test if the current case is not lighted + if (flags != F_LIGHTED) { + // printf("170\n"); + return 0; } - - } - else{ - if (/*test if the current case is lighted*/ flags == F_LIGHTED){ - //printf("i:%d j:%d\n",i,j); - for (int i2 = i-1 ; i2 >= 0; i2--){ - flags = game_get_square(g,i2,j); - //printf("i2:%d i2state:%d i2flags:%d\n",i2,state,flags); - if (flags == (S_LIGHTBULB|F_LIGHTED) || flags == (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ + + } else { + if (/*test if the current case is lighted*/ flags == F_LIGHTED) { + // printf("i:%d j:%d\n",i,j); + for (int i2 = i - 1; i2 >= 0; i2--) { + flags = game_get_square(g, i2, j); + // printf("i2:%d i2state:%d i2flags:%d\n",i2,state,flags); + if (flags == (S_LIGHTBULB | F_LIGHTED) || + flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } - if (flags != F_LIGHTED && flags != (F_LIGHTED|S_MARK)){ + if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { break; } } - for (int i2 = i+1 ; i2 < DEFAULT_SIZE; i2++){ - flags = game_get_square(g,i2,j); - if (flags == (S_LIGHTBULB|F_LIGHTED) || flags == (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ + for (int i2 = i + 1; i2 < DEFAULT_SIZE; i2++) { + flags = game_get_square(g, i2, j); + if (flags == (S_LIGHTBULB | F_LIGHTED) || + flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } - if (flags != F_LIGHTED && flags != (F_LIGHTED|S_MARK)){ + if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { break; } } - for (int j2 = j-1 ; j2 >= 0; j2--){ - flags = game_get_square(g,i,j2); - if (flags == (S_LIGHTBULB|F_LIGHTED) || flags == (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ + for (int j2 = j - 1; j2 >= 0; j2--) { + flags = game_get_square(g, i, j2); + if (flags == (S_LIGHTBULB | F_LIGHTED) || + flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } - if (flags != F_LIGHTED && flags != (F_LIGHTED|S_MARK)){ + if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { break; } } - for (int j2 = j+1 ; j2 < DEFAULT_SIZE; j2++){ - flags = game_get_square(g,i,j2); - if (flags == (S_LIGHTBULB|F_LIGHTED) || flags == (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ + for (int j2 = j + 1; j2 < DEFAULT_SIZE; j2++) { + flags = game_get_square(g, i, j2); + if (flags == (S_LIGHTBULB | F_LIGHTED) || + flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } - if (flags != F_LIGHTED && flags != (F_LIGHTED|S_MARK)){ + if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { break; } } - //printf("220\n"); + // printf("220\n"); return 0; } } return 1; } -bool check_update(game g){ +bool check_update(game g) { uint size; square choice[4]; uint lb; uint notempty; bool res; bool wall; - for (uint i = 0; i < DEFAULT_SIZE; i++){ - for (uint j = 0; j< DEFAULT_SIZE; j++){ - if (game_is_lightbulb(g,i,j)){ - square flags = game_get_flags(g,i,j); - if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR){ - //printf("196\n"); + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + if (game_is_lightbulb(g, i, j)) { + square flags = game_get_flags(g, i, j); + if (/*test if this lightbulb is well updated*/ flags == + S_BLANK || + flags == F_ERROR) { + // printf("196\n"); return false; } - //loop checking every case before i + // loop checking every case before i wall = false; - for (int k = i-1; k > 0; k--){ - if (/*test if current case is a wall*/ game_is_black(g,k,j)){ + for (int k = i - 1; k > 0; k--) { + if (/*test if current case is a wall*/ game_is_black(g, k, + j)) { wall = true; - } - else { - int tmp = checklightbulb(g,k,j,wall); - if (tmp == -1){ + } else { + int tmp = checklightbulb(g, k, j, wall); + if (tmp == -1) { break; } - if (!tmp){ + if (!tmp) { return tmp; } } } wall = false; - for (int k = i+1; k < DEFAULT_SIZE; k++){ - if (/*test if current case is a wall*/ game_is_black(g,k,j)){ + for (int k = i + 1; k < DEFAULT_SIZE; k++) { + if (/*test if current case is a wall*/ game_is_black(g, k, + j)) { wall = true; - } - else { - int tmp = checklightbulb(g,k,j,wall); - if (tmp == -1){ + } else { + int tmp = checklightbulb(g, k, j, wall); + if (tmp == -1) { break; } - if (!tmp){ + if (!tmp) { return tmp; } } } wall = false; - for (int k = j-1; k > 0; k--){ - if (/*test if current case is a wall*/ game_is_black(g,i,k)){ + for (int k = j - 1; k > 0; k--) { + if (/*test if current case is a wall*/ game_is_black(g, i, + k)) { wall = true; - } - else { - int tmp = checklightbulb(g,i,k,wall); - if (tmp == -1){ + } else { + int tmp = checklightbulb(g, i, k, wall); + if (tmp == -1) { break; } - if (!tmp){ + if (!tmp) { return tmp; } } } wall = false; - for (int k = j+1; k < DEFAULT_SIZE; k++){ - if (/*test if current case is a wall*/ game_is_black(g,i,k)){ + for (int k = j + 1; k < DEFAULT_SIZE; k++) { + if (/*test if current case is a wall*/ game_is_black(g, i, + k)) { wall = true; - } - else { - int tmp = checklightbulb(g,i,k,wall); - if (tmp == -1){ + } else { + int tmp = checklightbulb(g, i, k, wall); + if (tmp == -1) { break; } - if (!tmp){ + if (!tmp) { return tmp; } } } - } - else if (/*test if current case is a wall*/game_is_black(g,i,j)){ - if (game_get_black_number(g,i,j) != -1){ - //lookup for lightbulb and emptycells + } else if (/*test if current case is a wall*/ game_is_black(g, i, + j)) { + if (game_get_black_number(g, i, j) != -1) { + // lookup for lightbulb and emptycells size = 0; lb = 0; notempty = 0; res = true; - if (i > 0){ - choice[size] = game_get_square(g,i-1,j); + if (i > 0) { + choice[size] = game_get_square(g, i - 1, j); size++; - } - else{ + } else { notempty++; } - if (i < DEFAULT_SIZE-1){ - choice[size] = game_get_square(g,i+1,j); + if (i < DEFAULT_SIZE - 1) { + choice[size] = game_get_square(g, i + 1, j); size++; - } - else{ + } else { notempty++; } - if (j > 0){ - choice[size] = game_get_square(g,i,j-1); + if (j > 0) { + choice[size] = game_get_square(g, i, j - 1); size++; - } - else{ + } else { notempty++; } - if (j < DEFAULT_SIZE-1){ - choice[size] = game_get_square(g,i,j+1); + if (j < DEFAULT_SIZE - 1) { + choice[size] = game_get_square(g, i, j + 1); size++; - } - else{ + } else { notempty++; } - for (int l = 0 ; l < size ; l++){ - if (choice[l] == (S_LIGHTBULB|F_LIGHTED) || choice[l] == (S_LIGHTBULB|F_LIGHTED|F_ERROR)){ + for (int l = 0; l < size; l++) { + if (choice[l] == (S_LIGHTBULB | F_LIGHTED) || + choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { lb++; - } - else if (choice[l] != S_BLANK){ + } else if (choice[l] != S_BLANK) { notempty++; } } - if (lb > game_get_black_number(g,i,j)){ + if (lb > game_get_black_number(g, i, j)) { res = false; } - //look if there is enough empty cell around the wall - else if (notempty > abs(game_get_black_number(g,i,j)-4)){ + // look if there is enough empty cell around the wall + else if (notempty > + abs(game_get_black_number(g, i, j) - 4)) { res = false; } - if (game_get_flags(g,i,j) == F_ERROR){ + if (game_get_flags(g, i, j) == F_ERROR) { res = !res; } - if (!res){ - //printf("386\n"); - //printf("lb:%d notempty:%d i:%d j:%d state : %d, flags: %d\n",lb,notempty,i,j,game_get_state(g,i,j),game_get_flags(g,i,j)); + if (!res) { + // printf("386\n"); + // printf("lb:%d notempty:%d i:%d j:%d state : %d, + // flags: + // %d\n",lb,notempty,i,j,game_get_state(g,i,j),game_get_flags(g,i,j)); return res; } } @@ -371,34 +397,36 @@ bool check_update(game g){ } // a > 2 = temps d'exec > 3 min et expo -bool brutforce(game g,int a, bool * deldup){ +bool brutforce(game g, int a, bool* deldup) { // char c; - bool * delDupNext = (bool *) calloc(DEFAULT_SIZE*DEFAULT_SIZE,sizeof(bool)); - square list[] = {S_LIGHTBULB,S_MARK,S_BLACK0,S_BLACK1,S_BLACK2,S_BLACK3,S_BLACK4,S_BLACKU,S_BLANK}; - for (uint i = 0; i < DEFAULT_SIZE; i++){ - for (uint j = 0 ;j < DEFAULT_SIZE; j++){ - // printf("state: %d i:%d j:%d\n",game_get_state(g,i,j),i,j); - if (deldup == NULL || !(deldup[i*DEFAULT_SIZE+j])){ - if (game_get_state(g,i,j) == S_BLANK){ + bool* delDupNext = (bool*)calloc(DEFAULT_SIZE * DEFAULT_SIZE, sizeof(bool)); + square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, + S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK}; + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + // printf("state: %d i:%d j:%d\n",game_get_state(g,i,j),i,j); + if (deldup == NULL || !(deldup[i * DEFAULT_SIZE + j])) { + if (game_get_state(g, i, j) == S_BLANK) { if (delDupNext != NULL && a > 0) - delDupNext[i*DEFAULT_SIZE+j] = true; - for (uint k = 0 ; k < 9; k++){ - game_set_square(g,i,j,list[k]); + delDupNext[i * DEFAULT_SIZE + j] = true; + for (uint k = 0; k < 9; k++) { + game_set_square(g, i, j, list[k]); // if (k == 0){ // game_print(g); // scanf("%c",&c); // } - if (a > 0){ - if (!brutforce(g,a-1,delDupNext)){ - //printf("341\n"); + if (a > 0) { + if (!brutforce(g, a - 1, delDupNext)) { + // printf("341\n"); free(delDupNext); return false; } } game_update_flags(g); - if (!check_update(g)){ + if (!check_update(g)) { game_print(g); - //printf("i:%d j:%d state : %d, flags: %d\n",i,j,game_get_state(g,i,j),game_get_flags(g,i,j)); + // printf("i:%d j:%d state : %d, flags: + // %d\n",i,j,game_get_state(g,i,j),game_get_flags(g,i,j)); free(delDupNext); return false; } @@ -411,9 +439,9 @@ bool brutforce(game g,int a, bool * deldup){ return true; } -bool test_game_update_flags(void){ +bool test_game_update_flags(void) { game g = game_default(); - if (!brutforce(g,1,NULL)){ + if (!brutforce(g, 1, NULL)) { game_delete(g); return EXIT_FAILURE; } @@ -423,72 +451,70 @@ bool test_game_update_flags(void){ /* ****** game_play_move ****** */ -bool test_game_play_move(void){ +bool test_game_play_move(void) { game g = game_new_empty(); game g1 = game_new_empty(); - game_play_move(g,0,0,S_LIGHTBULB); - assert(!game_equal(g,g1)); - game_set_square(g1,0,0,S_LIGHTBULB); - assert(!game_equal(g,g1)); + game_play_move(g, 0, 0, S_LIGHTBULB); + assert(!game_equal(g, g1)); + game_set_square(g1, 0, 0, S_LIGHTBULB); + assert(!game_equal(g, g1)); game_update_flags(g1); - assert(game_equal(g,g1)); - game_play_move(g,3,0,S_MARK); - assert(!game_equal(g,g1)); - game_set_square(g1,3,0,S_MARK); - assert(!game_equal(g,g1)); + assert(game_equal(g, g1)); + game_play_move(g, 3, 0, S_MARK); + assert(!game_equal(g, g1)); + game_set_square(g1, 3, 0, S_MARK); + assert(!game_equal(g, g1)); game_update_flags(g1); - assert(game_equal(g,g1)); - game_play_move(g,0,3,S_BLANK); - assert(game_equal(g,g1)); - game_set_square(g1,0,3,S_BLANK); - assert(!game_equal(g,g1)); + assert(game_equal(g, g1)); + game_play_move(g, 0, 3, S_BLANK); + assert(game_equal(g, g1)); + game_set_square(g1, 0, 3, S_BLANK); + assert(!game_equal(g, g1)); game_update_flags(g1); - assert(game_equal(g,g1)); + assert(game_equal(g, g1)); game_delete(g); game_delete(g1); return EXIT_SUCCESS; } - /* ***** game_check_move ***** */ -bool test_game_check_move(void){ +bool test_game_check_move(void) { game g = game_new_empty(); - assert(!game_check_move(g,10,10,S_BLANK)); - assert(!game_check_move(g,10,10,S_BLACK0)); - assert(!game_check_move(g,0,0,S_BLACK0)); - assert(!game_check_move(g,0,0,S_BLACK1)); - assert(!game_check_move(g,0,0,S_BLACK2)); - assert(!game_check_move(g,0,0,S_BLACK3)); - assert(!game_check_move(g,0,0,S_BLACK4)); - assert(!game_check_move(g,0,0,S_BLACKU)); - assert(!game_check_move(g,0,0,F_LIGHTED)); - assert(!game_check_move(g,0,0,F_ERROR)); - for (uint i = 0 ; i < S_BLACKU-S_BLACK0 ; i ++){ - game_set_square(g,0,0,S_BLACK0+i); - assert(!game_check_move(g,0,0,S_BLANK)); - assert(!game_check_move(g,0,0,S_MARK)); - assert(!game_check_move(g,0,0,S_LIGHTBULB)); + assert(!game_check_move(g, 10, 10, S_BLANK)); + assert(!game_check_move(g, 10, 10, S_BLACK0)); + assert(!game_check_move(g, 0, 0, S_BLACK0)); + assert(!game_check_move(g, 0, 0, S_BLACK1)); + assert(!game_check_move(g, 0, 0, S_BLACK2)); + assert(!game_check_move(g, 0, 0, S_BLACK3)); + assert(!game_check_move(g, 0, 0, S_BLACK4)); + assert(!game_check_move(g, 0, 0, S_BLACKU)); + assert(!game_check_move(g, 0, 0, F_LIGHTED)); + assert(!game_check_move(g, 0, 0, F_ERROR)); + for (uint i = 0; i < S_BLACKU - S_BLACK0; i++) { + game_set_square(g, 0, 0, S_BLACK0 + i); + assert(!game_check_move(g, 0, 0, S_BLANK)); + assert(!game_check_move(g, 0, 0, S_MARK)); + assert(!game_check_move(g, 0, 0, S_LIGHTBULB)); } - assert(game_check_move(g,1,0,S_BLANK)); - assert(game_check_move(g,1,0,S_MARK)); - assert(game_check_move(g,1,0,S_LIGHTBULB)); + assert(game_check_move(g, 1, 0, S_BLANK)); + assert(game_check_move(g, 1, 0, S_MARK)); + assert(game_check_move(g, 1, 0, S_LIGHTBULB)); game_delete(g); return EXIT_SUCCESS; } /* ********** USAGE ********** */ -int usage(int argc, char *argv[]) -{ - fprintf(stderr, "Usage: %s [<...>]\n", argv[0]); - exit(EXIT_FAILURE); +int usage(int argc, char* argv[]) { + fprintf(stderr, "Usage: %s [<...>]\n", argv[0]); + exit(EXIT_FAILURE); } /* ********** MAIN ********** */ -int main(int argc, char * argv[]){ - if (argc == 1){ +int main(int argc, char* argv[]) { + if (argc == 1) { usage(argc, argv); } fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); @@ -516,16 +542,15 @@ int main(int argc, char * argv[]){ else if (strcmp("game_check_move", argv[1]) == 0) ok = test_game_check_move(); else { - fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); - exit(EXIT_FAILURE); + fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); + exit(EXIT_FAILURE); } // print test result - if (!ok){ - fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); - return EXIT_SUCCESS; - } - else { - fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]); - return EXIT_FAILURE; + if (!ok) { + fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); + return EXIT_SUCCESS; + } else { + fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]); + return EXIT_FAILURE; } } \ No newline at end of file diff --git a/game_test_thperrier.c b/game_test_thperrier.c index b397d03..86dbe81 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -1,272 +1,261 @@ -#include -#include -#include -#include #include +#include +#include +#include +#include #include "game.h" #include "game_aux.h" - /* ********** DUMMY ********** */ -bool test_dummy(){ - return true; +bool test_dummy() { + return true; } /* ********** game_get_black_number ********** */ -bool test_game_get_black_number(){ - game g = game_new_empty(); - game_set_square(g, 0, 0, S_BLACK0); - if (game_get_black_number(g, 0, 0) != 0){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK1); - if (game_get_black_number(g, 0, 0) != 1){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK2); - if (game_get_black_number(g, 0, 0) != 2){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK3); - if (game_get_black_number(g, 0, 0) != 3){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK4); - if (game_get_black_number(g, 0, 0) != 4){ - game_delete(g); - return false; - } - game_delete(g); - return true; +bool test_game_get_black_number() { + game g = game_new_empty(); + game_set_square(g, 0, 0, S_BLACK0); + if (game_get_black_number(g, 0, 0) != 0) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK1); + if (game_get_black_number(g, 0, 0) != 1) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK2); + if (game_get_black_number(g, 0, 0) != 2) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK3); + if (game_get_black_number(g, 0, 0) != 3) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK4); + if (game_get_black_number(g, 0, 0) != 4) { + game_delete(g); + return false; + } + game_delete(g); + return true; } /* ********** game_is_black ********** */ -bool test_game_is_black(){ - game g = game_new_empty(); - if (game_is_black(g, 0, 0)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACKU); - if (!game_is_black(g, 0, 0)){ - game_delete(g); - return false; - } - if (!((game_get_square(g, 0, 0) == S_BLACKU) && game_is_black(g, 0, 0))){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK0); - if (!((game_get_square(g, 0, 0) == S_BLACK0) && game_is_black(g, 0, 0))){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK1); - if (!((game_get_square(g, 0, 0) == S_BLACK1) && game_is_black(g, 0, 0))){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK2); - if (!((game_get_square(g, 0, 0) == S_BLACK2) && game_is_black(g, 0, 0))){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK3); - if (!((game_get_square(g, 0, 0) == S_BLACK3) && game_is_black(g, 0, 0))){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK4); - if (!((game_get_square(g, 0, 0) == S_BLACK4) && game_is_black(g, 0, 0))){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_MARK); - if ((game_get_square(g, 0, 0) == S_MARK) && game_is_black(g, 0, 0)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_MARK); - if ((game_get_square(g, 0, 0) == S_MARK) && game_is_black(g, 0, 0)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_LIGHTBULB); - if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_black(g, 0, 0)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_LIGHTBULB); - if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_black(g, 0, 0)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, F_ERROR); - if ((game_get_square(g, 0, 0) == F_ERROR) && game_is_black(g, 0, 0)){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, F_LIGHTED); - if ((game_get_square(g, 0, 0) == F_LIGHTED) && game_is_black(g, 0, 0)){ - game_delete(g); - return false; - } - game_delete(g); - return true; +bool test_game_is_black() { + game g = game_new_empty(); + if (game_is_black(g, 0, 0)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACKU); + if (!game_is_black(g, 0, 0)) { + game_delete(g); + return false; + } + if (!((game_get_square(g, 0, 0) == S_BLACKU) && game_is_black(g, 0, 0))) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK0); + if (!((game_get_square(g, 0, 0) == S_BLACK0) && game_is_black(g, 0, 0))) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK1); + if (!((game_get_square(g, 0, 0) == S_BLACK1) && game_is_black(g, 0, 0))) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK2); + if (!((game_get_square(g, 0, 0) == S_BLACK2) && game_is_black(g, 0, 0))) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK3); + if (!((game_get_square(g, 0, 0) == S_BLACK3) && game_is_black(g, 0, 0))) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK4); + if (!((game_get_square(g, 0, 0) == S_BLACK4) && game_is_black(g, 0, 0))) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK); + if ((game_get_square(g, 0, 0) == S_MARK) && game_is_black(g, 0, 0)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK); + if ((game_get_square(g, 0, 0) == S_MARK) && game_is_black(g, 0, 0)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_LIGHTBULB); + if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_black(g, 0, 0)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_LIGHTBULB); + if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_black(g, 0, 0)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, F_ERROR); + if ((game_get_square(g, 0, 0) == F_ERROR) && game_is_black(g, 0, 0)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, F_LIGHTED); + if ((game_get_square(g, 0, 0) == F_LIGHTED) && game_is_black(g, 0, 0)) { + game_delete(g); + return false; + } + game_delete(g); + return true; } /* ********** game_is_lightbulb ********** */ -bool test_game_is_lightbulb(){ - game g = game_new_empty(); - game_set_square(g, 0, 0, S_LIGHTBULB); - if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_lightbulb(g, 0, 0)){ - game_delete(g); - return true; - } - game_delete(g); - return false; +bool test_game_is_lightbulb() { + game g = game_new_empty(); + game_set_square(g, 0, 0, S_LIGHTBULB); + if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && + game_is_lightbulb(g, 0, 0)) { + game_delete(g); + return true; + } + game_delete(g); + return false; } /* ********** game_is_blank ********** */ -bool test_game_is_blank(){ - game g = game_new_empty(); - if (game_is_blank(g, 0, 0)){ - game_delete(g); - return true; - } - game_delete(g); - return false; +bool test_game_is_blank() { + game g = game_new_empty(); + if (game_is_blank(g, 0, 0)) { + game_delete(g); + return true; + } + game_delete(g); + return false; } /* ********** game_delete ********** */ -bool test_game_delete(){ - game g1 = game_new_empty(); - game_delete(g1); - return true; +bool test_game_delete() { + game g1 = game_new_empty(); + game_delete(g1); + return true; } /* ********** game_equal ********** */ -bool test_game_equal(){ - bool equal = true; - game g1 = game_new_empty(); - game g2 = game_new_empty(); - for (int i = 0; i < DEFAULT_SIZE; i++){ - for (int j = 0; j < DEFAULT_SIZE; j++){ - if (game_get_square(g1, i, j) != game_get_square(g2, i, j)){ - equal = false; - } - } - } - equal = (equal == game_equal(g1, g2)); - game_delete(g1); - game_delete(g2); - return equal; +bool test_game_equal() { + bool equal = true; + game g1 = game_new_empty(); + game g2 = game_new_empty(); + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + if (game_get_square(g1, i, j) != game_get_square(g2, i, j)) { + equal = false; + } + } + } + equal = (equal == game_equal(g1, g2)); + game_delete(g1); + game_delete(g2); + return equal; } /* ********** game_new_empty ********** */ -bool test_game_new_empty(){ - game g = game_new_empty(); - assert(g); - for (int i = 0; i < DEFAULT_SIZE; i++){ - for (int j = 0; j < DEFAULT_SIZE; j++){ - if (game_get_square(g, i, j) != S_BLANK){ - game_delete(g); - return false; - } - } - } - game_delete(g); - return true; +bool test_game_new_empty() { + game g = game_new_empty(); + assert(g); + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + if (game_get_square(g, i, j) != S_BLANK) { + game_delete(g); + return false; + } + } + } + game_delete(g); + return true; } /* ********** game_copy ********** */ -bool test_game_copy(){ - game g1 = game_new_empty(); - for (int i = 0; i < DEFAULT_SIZE; i++){ - game_set_square(g1, i, 0, S_LIGHTBULB); - game_set_square(g1, i, 1, S_MARK); - game_set_square(g1, i, 2, S_BLACKU); - game_set_square(g1, i, 3, S_BLACK0); - game_set_square(g1, i, 4, S_BLACK1); - game_set_square(g1, 1, 2, F_LIGHTED); - game_set_square(g1, 1, 3, F_ERROR); - } - game g2 = game_copy(g1); - assert(g2); - if (!game_equal(g1, g2)){ - game_delete(g1); - game_delete(g2); - return false; - } - for (int i = 0; i < DEFAULT_SIZE; i++){ - for (int j = 0; j < DEFAULT_SIZE; j++){ - game_set_square(g2, i, j, S_BLACK3); - } - } - g2 = game_copy(g1); - assert(g2); - if (!game_equal(g1, g2)){ - game_delete(g1); - game_delete(g2); - return false; - } - game_delete(g1); - game_delete(g2); - return true; +bool test_game_copy() { + game g1 = game_new_empty(); + for (int i = 0; i < DEFAULT_SIZE; i++) { + game_set_square(g1, i, 0, S_LIGHTBULB); + game_set_square(g1, i, 1, S_MARK); + game_set_square(g1, i, 2, S_BLACKU); + game_set_square(g1, i, 3, S_BLACK0); + game_set_square(g1, i, 4, S_BLACK1); + game_set_square(g1, 1, 2, F_LIGHTED); + game_set_square(g1, 1, 3, F_ERROR); + } + game g2 = game_copy(g1); + assert(g2); + if (!game_equal(g1, g2)) { + game_delete(g1); + game_delete(g2); + return false; + } + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + game_set_square(g2, i, j, S_BLACK3); + } + } + g2 = game_copy(g1); + assert(g2); + if (!game_equal(g1, g2)) { + game_delete(g1); + game_delete(g2); + return false; + } + game_delete(g1); + game_delete(g2); + return true; } /* ********** usage ********** */ -void usage(int argc, char *argv[]){ - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(EXIT_FAILURE); +void usage(int argc, char* argv[]) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(EXIT_FAILURE); } /* ********** main ********** */ -int main (int argc, char *argv[]){ - bool success = false; - if (argc != 2){ - usage(argc, argv); - } - else if (strcmp("dummy", argv[1]) == 0){ - success = test_dummy(); - } - else if (strcmp("game_new_empty", argv[1]) == 0){ - success = test_game_new_empty(); - } - else if (strcmp("game_copy", argv[1]) == 0){ - success = test_game_copy(); - } - else if (strcmp("game_equal", argv[1]) == 0){ - success = test_game_equal(); - } - else if (strcmp("game_delete", argv[1]) == 0){ - success = test_game_delete(); - } - else if (strcmp("game_is_blank", argv[1]) == 0){ - success = test_game_is_blank(); - } - else if (strcmp("game_is_lightbulb", argv[1]) == 0){ - success = test_game_is_lightbulb(); - } - else if (strcmp("game_is_black", argv[1]) == 0){ - success = test_game_is_black(); - } - else if (strcmp("game_get_black_number", argv[1]) == 0){ - success = test_game_get_black_number(); - } - else{ - fprintf (stderr, "test \"%s\" is not a valid test name.\n", argv[1]); - return EXIT_FAILURE; - } - if (success){ - fprintf (stderr, "test \"%s\" finished successfully\n", argv[1]); - return EXIT_SUCCESS; - } - else { - fprintf (stderr, "test \"%s\" error\n", argv[1]); - return EXIT_FAILURE; - } - return EXIT_SUCCESS; +int main(int argc, char* argv[]) { + bool success = false; + if (argc != 2) { + usage(argc, argv); + } else if (strcmp("dummy", argv[1]) == 0) { + success = test_dummy(); + } else if (strcmp("game_new_empty", argv[1]) == 0) { + success = test_game_new_empty(); + } else if (strcmp("game_copy", argv[1]) == 0) { + success = test_game_copy(); + } else if (strcmp("game_equal", argv[1]) == 0) { + success = test_game_equal(); + } else if (strcmp("game_delete", argv[1]) == 0) { + success = test_game_delete(); + } else if (strcmp("game_is_blank", argv[1]) == 0) { + success = test_game_is_blank(); + } else if (strcmp("game_is_lightbulb", argv[1]) == 0) { + success = test_game_is_lightbulb(); + } else if (strcmp("game_is_black", argv[1]) == 0) { + success = test_game_is_black(); + } else if (strcmp("game_get_black_number", argv[1]) == 0) { + success = test_game_get_black_number(); + } else { + fprintf(stderr, "test \"%s\" is not a valid test name.\n", argv[1]); + return EXIT_FAILURE; + } + if (success) { + fprintf(stderr, "test \"%s\" finished successfully\n", argv[1]); + return EXIT_SUCCESS; + } else { + fprintf(stderr, "test \"%s\" error\n", argv[1]); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/game_text.c b/game_text.c index cd42911..46b9d55 100644 --- a/game_text.c +++ b/game_text.c @@ -1,47 +1,51 @@ +#include #include #include -#include #include "game.h" #include "game_aux.h" -bool checkerr(game g, char taberr[]){ - if (taberr == NULL || g == NULL){ +bool checkerr(game g, char taberr[]) { + if (taberr == NULL || g == NULL) { return -1; } uint err = 0; taberr[0] = '\0'; - for (int i=0; i < DEFAULT_SIZE; i++){ - for (int j=0;j < DEFAULT_SIZE; j++){ - //check each case - if (game_has_error(g,i,j)){ + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + // check each case + if (game_has_error(g, i, j)) { // if error append taberr with coo+, - taberr[err] = i+48; + taberr[err] = i + 48; err++; taberr[err] = ':'; err++; - taberr[err] = j+48; + taberr[err] = j + 48; err++; taberr[err] = ' '; err++; } } } - // if taberr changes print - if (taberr[0] != '\0'){ + // if taberr changes print + if (taberr[0] != '\0') { taberr[err] = '\0'; return true; } return false; } -void printhelp(void){ +void printhelp(void) { printf("Liste des différentes commandes :\n"); printf("h : Affiche cette aide.\n"); printf("r : Réinitialise la partie.\n"); printf("q : Quitter la partie (abandon).\n"); - printf("l : Place une ampoule (*light bulb*) dans la case (,).\n"); + printf( + "l : Place une ampoule (*light bulb*) dans la case " + "(,).\n"); printf("m : Place une marque (*mark*) dans la case (,).\n"); - printf("b : Place placer une case vide (*blank*) à la position (,).\n"); + printf( + "b : Place placer une case vide (*blank*) à la position " + "(,).\n"); } int main(void) { @@ -50,52 +54,53 @@ int main(void) { // test if game is over uint i; uint j; - char taberr[DEFAULT_SIZE*DEFAULT_SIZE*4]; + char taberr[DEFAULT_SIZE * DEFAULT_SIZE * 4]; char c; // print game game_print(g); - while (!game_is_over(g)){ + while (!game_is_over(g)) { // print errors - if (checkerr(g,taberr)){ - printf("Il y a un problème case: %s\n",taberr); + if (checkerr(g, taberr)) { + printf("Il y a un problème case: %s\n", taberr); } printf("Entrez une commande (h pour afficher l'aide): "); - if (scanf(" %c",&c)){ - if (c == 'h'){ + if (scanf(" %c", &c)) { + if (c == 'h') { printhelp(); - }else if (c == 'r'){ + } else if (c == 'r') { game_restart(g); printf("Partie réinitialisé avec success !\n"); game_update_flags(g); game_print(g); - }else if (c == 'q'){ + } else if (c == 'q') { printf("Solution: \n"); game_print(game_default_solution()); printf("shame\n"); return EXIT_SUCCESS; - }else if (c == 'l' || c == 'm' || c == 'b'){ - if (scanf(" %u %u",&i,&j) == 2){ - if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && !game_is_black(g,i,j)){ - if (c == 'l'){ - game_set_square(g,i,j,S_LIGHTBULB); + } else if (c == 'l' || c == 'm' || c == 'b') { + if (scanf(" %u %u", &i, &j) == 2) { + if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && + !game_is_black(g, i, j)) { + if (c == 'l') { + game_set_square(g, i, j, S_LIGHTBULB); game_update_flags(g); game_print(g); - }else if (c == 'm'){ - game_set_square(g,i,j,S_MARK); + } else if (c == 'm') { + game_set_square(g, i, j, S_MARK); game_update_flags(g); game_print(g); - }else if (c == 'b') { - game_set_square(g,i,j,S_BLANK); + } else if (c == 'b') { + game_set_square(g, i, j, S_BLANK); game_update_flags(g); game_print(g); } - }else { + } else { printf("Erreur: (,) invalide.\n"); } - }else { + } else { printf("Commande inconnue.\n"); } - }else{ + } else { printf("Commande inconnue.\n"); } } From bf2bc092c571b427c2824305b0133b2290e458f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Fri, 26 Nov 2021 22:53:39 +0100 Subject: [PATCH 111/281] clang format off l134 --- game_test_thoguet.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 90eb189..b07a24f 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -131,21 +131,19 @@ bool test_game_default(void) { game g = game_default(); // a verif aps sur assert(g); - square tab[49] = {/*X0 X1 X2 X3 X4 X5 X6*/ - /*Y 0*/ S_BLANK, S_BLANK, S_BLACK1, S_BLANK, - S_BLANK, S_BLANK, S_BLANK, - /*Y 1*/ S_BLANK, S_BLANK, S_BLACK2, S_BLANK, - S_BLANK, S_BLANK, S_BLANK, - /*Y 2*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, - S_BLANK, S_BLACKU, S_BLACK2, - /*Y 3*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, - S_BLANK, S_BLANK, S_BLANK, - /*Y 4*/ S_BLACK1, S_BLACKU, S_BLANK, S_BLANK, - S_BLANK, S_BLANK, S_BLANK, - /*Y 5*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, - S_BLACK2, S_BLANK, S_BLANK, - /*Y 6*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, - S_BLACKU, S_BLANK, S_BLANK}; + // clang-format off + square tab[49] = + { + /*X0 X1 X2 X3 X4 X5 X6*/ + /*Y 0*/ S_BLANK, S_BLANK, S_BLACK1, S_BLANK, S_BLANK, S_BLANK, S_BLANK, + /*Y 1*/ S_BLANK, S_BLANK, S_BLACK2, S_BLANK, S_BLANK, S_BLANK, S_BLANK, + /*Y 2*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLACK2, + /*Y 3*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, + /*Y 4*/ S_BLACK1, S_BLACKU, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, + /*Y 5*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACK2, S_BLANK, S_BLANK, + /*Y 6*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLANK + }; + // clang-format on game g1 = game_new(tab); assert(game_equal(g, g1)); game_delete(g); From 777b419b5c3b47214bba35b48441f48580259e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Fri, 26 Nov 2021 22:54:35 +0100 Subject: [PATCH 112/281] edited tabs --- game_test_thoguet.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index b07a24f..8bf7afe 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -134,14 +134,14 @@ bool test_game_default(void) { // clang-format off square tab[49] = { - /*X0 X1 X2 X3 X4 X5 X6*/ - /*Y 0*/ S_BLANK, S_BLANK, S_BLACK1, S_BLANK, S_BLANK, S_BLANK, S_BLANK, - /*Y 1*/ S_BLANK, S_BLANK, S_BLACK2, S_BLANK, S_BLANK, S_BLANK, S_BLANK, - /*Y 2*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLACK2, - /*Y 3*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, - /*Y 4*/ S_BLACK1, S_BLACKU, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, - /*Y 5*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACK2, S_BLANK, S_BLANK, - /*Y 6*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLANK + /*X0 X1 X2 X3 X4 X5 X6*/ + /*Y 0*/ S_BLANK, S_BLANK, S_BLACK1, S_BLANK, S_BLANK, S_BLANK, S_BLANK, + /*Y 1*/ S_BLANK, S_BLANK, S_BLACK2, S_BLANK, S_BLANK, S_BLANK, S_BLANK, + /*Y 2*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLACK2, + /*Y 3*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, + /*Y 4*/ S_BLACK1, S_BLACKU, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, + /*Y 5*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACK2, S_BLANK, S_BLANK, + /*Y 6*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLANK }; // clang-format on game g1 = game_new(tab); From a2d0b0e4a3ae5a89c5ede5bff2689e55b72650b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Fri, 26 Nov 2021 23:17:29 +0100 Subject: [PATCH 113/281] coquille vide + update test --- game.c | 49 ++++++++++++++----------------------------- game_test_thoguet.c | 6 ++++++ game_test_thperrier.c | 5 +++-- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/game.c b/game.c index 9e8b10d..28dac3a 100644 --- a/game.c +++ b/game.c @@ -7,36 +7,19 @@ struct game_s { }; game game_new(square* squares) { - game g = (game)malloc(sizeof(game)); - if (g == NULL) { - fprintf(stderr, "not enough memory\n"); - exit(EXIT_FAILURE); - } - g->tab_cell = (square**)malloc(sizeof(square**) * DEFAULT_SIZE); - if (g->tab_cell == NULL) { - fprintf(stderr, "not enough memory\n"); - exit(EXIT_FAILURE); - } - for (int i = 0; i < DEFAULT_SIZE; i++) { - g->tab_cell[i] = (square*)malloc(sizeof(square*) * DEFAULT_SIZE); - if (g->tab_cell[i] == NULL) { - fprintf(stderr, "not enough memory\n"); - exit(EXIT_FAILURE); - } - } - return g; + return NULL; } game game_new_empty(void) { - return; + return NULL; } game game_copy(cgame g) { - return; + return NULL; } bool game_equal(cgame g1, cgame g2) { - return; + return false; } void game_delete(game g) { @@ -48,47 +31,47 @@ void game_set_square(game g, uint i, uint j, square s) { } square game_get_square(cgame g, uint i, uint j) { - return; + return 0; } square game_get_state(cgame g, uint i, uint j) { - return; + return 0; } square game_get_flags(cgame g, uint i, uint j) { - return; + return 0; } bool game_is_blank(cgame g, uint i, uint j) { - return; + return false; } bool game_is_lightbulb(cgame g, uint i, uint j) { - return; + return false; } bool game_is_black(cgame g, uint i, uint j) { - return; + return false; } int game_get_black_number(cgame g, uint i, uint j) { - return; + return -1; } bool game_is_marked(cgame g, uint i, uint j) { - return; + return false; } bool game_is_lighted(cgame g, uint i, uint j) { - return; + return false; } bool game_has_error(cgame g, uint i, uint j) { - return; + return false; } bool game_check_move(cgame g, uint i, uint j, square s) { - return; + return false; } void game_play_move(game g, uint i, uint j, square s) { @@ -100,7 +83,7 @@ void game_update_flags(game g) { } bool game_is_over(cgame g) { - return; + return false; } void game_restart(game g) { diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 8bf7afe..5c3eb1c 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -89,6 +89,7 @@ bool test_game_print(void) { } printf("%d\n", i); g = game_new(tab); + assert(g); game_print(g); game_delete(g); } @@ -398,6 +399,10 @@ bool check_update(game g) { bool brutforce(game g, int a, bool* deldup) { // char c; bool* delDupNext = (bool*)calloc(DEFAULT_SIZE * DEFAULT_SIZE, sizeof(bool)); + if (delDupNext == NULL) { + fprintf(stderr, "Not enought memory\n"); + exit(EXIT_FAILURE); + } square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK}; for (uint i = 0; i < DEFAULT_SIZE; i++) { @@ -439,6 +444,7 @@ bool brutforce(game g, int a, bool* deldup) { bool test_game_update_flags(void) { game g = game_default(); + assert(g); if (!brutforce(g, 1, NULL)) { game_delete(g); return EXIT_FAILURE; diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 86dbe81..d2832a5 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -144,8 +144,9 @@ bool test_game_is_blank() { /* ********** game_delete ********** */ bool test_game_delete() { - game g1 = game_new_empty(); - game_delete(g1); + game g = game_new_empty(); + assert(g); + game_delete(g); return true; } From 756f73d8406362328322035f430e7e5d119ce760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 26 Nov 2021 23:20:11 +0100 Subject: [PATCH 114/281] wrong email commit --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bd4afd..cab00ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,4 +52,4 @@ add_test(test_nnunes_game_get_state ./game_test_nnunes game_get_state) add_test(test_nnunes_game_get_flags ./game_test_nnunes game_get_flags) add_test(test_nnunes_game_is_marked ./game_test_nnunes game_is_marked) add_test(test_nnunes_game_is_lighted ./game_test_nnunes game_is_lighted) -add_test(test_nnunes_game_has_error ./game_test_nnunes game_has_error) +add_test(test_nnunes_game_has_error ./game_test_nnunes game_has_error) \ No newline at end of file From a88c5d786740fa3baf214d3577284e537dddf1b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 26 Nov 2021 23:22:02 +0100 Subject: [PATCH 115/281] game_new --- game.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/game.c b/game.c index 28dac3a..be163cd 100644 --- a/game.c +++ b/game.c @@ -7,7 +7,24 @@ struct game_s { }; game game_new(square* squares) { - return NULL; + game g = (game)malloc(sizeof(game)); + if (g == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + g->tab_cell = (square**)malloc(sizeof(square**) * DEFAULT_SIZE); + if (g->tab_cell == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + for (int i = 0; i < DEFAULT_SIZE; i++) { + g->tab_cell[i] = (square*)malloc(sizeof(square*) * DEFAULT_SIZE); + if (g->tab_cell[i] == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + } + return g; } game game_new_empty(void) { From 7f6c2bd7cdf9f93b8321e0e8bb188065a3a990e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 28 Nov 2021 20:43:14 +0100 Subject: [PATCH 116/281] update test_game_new --- game_test_thoguet.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 5c3eb1c..15fa42c 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -89,6 +89,11 @@ bool test_game_print(void) { } printf("%d\n", i); g = game_new(tab); + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + assert(list[i] == game_get_square(g, i, j)); + } + } assert(g); game_print(g); game_delete(g); From 33812900ec8a3f8d3d7d4a5619b6a0aef6101444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 28 Nov 2021 20:49:31 +0100 Subject: [PATCH 117/281] undo last commit --- game_test_thoguet.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 5c3eb1c..15fa42c 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -89,6 +89,11 @@ bool test_game_print(void) { } printf("%d\n", i); g = game_new(tab); + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + assert(list[i] == game_get_square(g, i, j)); + } + } assert(g); game_print(g); game_delete(g); From fddc2872c507637f33dc36ed5bc6acee9eb9485a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 28 Nov 2021 20:50:36 +0100 Subject: [PATCH 118/281] undo last commit --- game_test_thoguet.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 15fa42c..5c3eb1c 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -89,11 +89,6 @@ bool test_game_print(void) { } printf("%d\n", i); g = game_new(tab); - for (uint i = 0; i < DEFAULT_SIZE; i++) { - for (uint j = 0; j < DEFAULT_SIZE; j++) { - assert(list[i] == game_get_square(g, i, j)); - } - } assert(g); game_print(g); game_delete(g); From d9477ef979faa4b31d6f612e153854c179e99800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 28 Nov 2021 20:52:08 +0100 Subject: [PATCH 119/281] update test_game_new --- game_test_thoguet.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 5c3eb1c..2953743 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -68,6 +68,11 @@ bool test_game_new(void) { } printf("%d\n", i); g = game_new(tab); + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + assert(list[i] == game_get_square(g, i, j)); + } + } assert(g); game_delete(g); } From 24e484af8087b5b22a6f5fafb952819caecd77a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 28 Nov 2021 21:08:26 +0100 Subject: [PATCH 120/281] gamenew debugged --- game_test_thoguet.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 2953743..f9fcded 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -68,9 +68,11 @@ bool test_game_new(void) { } printf("%d\n", i); g = game_new(tab); - for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint i2 = 0; i2 < DEFAULT_SIZE; i2++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { - assert(list[i] == game_get_square(g, i, j)); + printf("list :%d, get square :%d", list[i], + game_get_square(g, i2, j)); + assert(list[i] == game_get_square(g, i2, j)); } } assert(g); From 9e16c4d4ddaef3515ab9189af191860cca064d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 28 Nov 2021 21:11:57 +0100 Subject: [PATCH 121/281] miss \n --- game_test_thoguet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index f9fcded..26cd304 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -70,7 +70,7 @@ bool test_game_new(void) { g = game_new(tab); for (uint i2 = 0; i2 < DEFAULT_SIZE; i2++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { - printf("list :%d, get square :%d", list[i], + printf("list :%d, get square :%d\n", list[i], game_get_square(g, i2, j)); assert(list[i] == game_get_square(g, i2, j)); } From 307be81bb9dbf4f54eba61b5802c963a4a471f09 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Sun, 28 Nov 2021 21:38:12 +0100 Subject: [PATCH 122/281] edit game_new & game_new_empty + edit README --- README.md | 4 ++-- game.c | 39 ++++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 90fc3fb..db8374b 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ Projet Techno | Fonction | REF | Assigned to | Notes | Finished | | ------------------------------------ | ---------------------------------------------------------------------------- | ----------- | ----- | :--------------------: | -| [game_new](./game.c#L?) | [game game_new(square *squares)](./game.h#L73-81) | @thperrier | |
  • [ ]
| -| [game_new_empty](./game.c#L?) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [ ]
| +| [game_new](./game.c#L9-17) | [game game_new(square *squares)](./game.h#L73-81) | @thperrier | |
  • [x]
| +| [game_new_empty](./game.c#L?) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [x]
| | [game_copy](./game.c#L?) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [ ]
| | [game_equal](./game.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| | [game_delete](./game.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| diff --git a/game.c b/game.c index be163cd..6774455 100644 --- a/game.c +++ b/game.c @@ -7,28 +7,37 @@ struct game_s { }; game game_new(square* squares) { - game g = (game)malloc(sizeof(game)); - if (g == NULL) { - fprintf(stderr, "not enough memory\n"); - exit(EXIT_FAILURE); - } - g->tab_cell = (square**)malloc(sizeof(square**) * DEFAULT_SIZE); - if (g->tab_cell == NULL) { - fprintf(stderr, "not enough memory\n"); - exit(EXIT_FAILURE); - } + game g = game_new_empty(); for (int i = 0; i < DEFAULT_SIZE; i++) { - g->tab_cell[i] = (square*)malloc(sizeof(square*) * DEFAULT_SIZE); - if (g->tab_cell[i] == NULL) { - fprintf(stderr, "not enough memory\n"); - exit(EXIT_FAILURE); + for (int j = 0; j < DEFAULT_SIZE; j++) { + g->tab_cell[i][j] = squares[DEFAULT_SIZE * i + j]; } } return g; } game game_new_empty(void) { - return NULL; + game g = (game)malloc(sizeof(game)); + if (g == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + g->tab_cell = (square**)malloc(sizeof(square*) * DEFAULT_SIZE); + if (g->tab_cell == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + for (int i = 0; i < DEFAULT_SIZE; i++) { + g->tab_cell[i] = (square*)malloc(sizeof(square) * DEFAULT_SIZE); + if (g->tab_cell[i] == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + for (int j = 0; j < DEFAULT_SIZE; j++) { + g->tab_cell[i][j] = S_BLANK; + } + } + return g; } game game_copy(cgame g) { From 4b21f2c17b43a5c469b5cf466dbd4cd14a6a305d Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Sun, 28 Nov 2021 21:39:12 +0100 Subject: [PATCH 123/281] adding code lines --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db8374b..90f08ce 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Projet Techno | Fonction | REF | Assigned to | Notes | Finished | | ------------------------------------ | ---------------------------------------------------------------------------- | ----------- | ----- | :--------------------: | | [game_new](./game.c#L9-17) | [game game_new(square *squares)](./game.h#L73-81) | @thperrier | |
  • [x]
| -| [game_new_empty](./game.c#L?) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [x]
| +| [game_new_empty](./game.c#L19-41) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [x]
| | [game_copy](./game.c#L?) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [ ]
| | [game_equal](./game.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| | [game_delete](./game.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| From 3d9f9edb3ef355355833b13b18d314d4776ca673 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Sun, 28 Nov 2021 23:03:01 +0100 Subject: [PATCH 124/281] game_copy + edit README --- README.md | 2 +- game.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 90f08ce..570c8f2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Projet Techno | ------------------------------------ | ---------------------------------------------------------------------------- | ----------- | ----- | :--------------------: | | [game_new](./game.c#L9-17) | [game game_new(square *squares)](./game.h#L73-81) | @thperrier | |
  • [x]
| | [game_new_empty](./game.c#L19-41) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [x]
| -| [game_copy](./game.c#L?) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [ ]
| +| [game_copy](./game.c#L43-51) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [x]
| | [game_equal](./game.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| | [game_delete](./game.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| | [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| diff --git a/game.c b/game.c index 6774455..cf3bb29 100644 --- a/game.c +++ b/game.c @@ -40,8 +40,14 @@ game game_new_empty(void) { return g; } -game game_copy(cgame g) { - return NULL; +game game_copy(cgame g1) { + game g2 = game_new_empty(); + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + g2->tab_cell[i][j] = g1->tab_cell[i][j]; + } + } + return g2; } bool game_equal(cgame g1, cgame g2) { From 097e4da7c64b7660caa8ac8465efa0ccd0acca2f Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Sun, 28 Nov 2021 23:10:52 +0100 Subject: [PATCH 125/281] game_equal + edit README --- README.md | 2 +- game.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 570c8f2..4dd94d8 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Projet Techno | [game_new](./game.c#L9-17) | [game game_new(square *squares)](./game.h#L73-81) | @thperrier | |
  • [x]
| | [game_new_empty](./game.c#L19-41) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [x]
| | [game_copy](./game.c#L43-51) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [x]
| -| [game_equal](./game.c#L?) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [ ]
| +| [game_equal](./game.c#L53-62) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [x]
| | [game_delete](./game.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| | [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| | [game_get_square](./game.c#L?) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [ ]
| diff --git a/game.c b/game.c index cf3bb29..50980a0 100644 --- a/game.c +++ b/game.c @@ -51,7 +51,14 @@ game game_copy(cgame g1) { } bool game_equal(cgame g1, cgame g2) { - return false; + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + if (g1->tab_cell[i][j] != g2->tab_cell[i][j]) { + return false; + } + } + } + return true; } void game_delete(game g) { From 640ad33df63338d2ceacd4488aaa0cedd495c29f Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Sun, 28 Nov 2021 23:21:17 +0100 Subject: [PATCH 126/281] game_delete + edit README --- README.md | 2 +- game.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4dd94d8..1e2e619 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Projet Techno | [game_new_empty](./game.c#L19-41) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [x]
| | [game_copy](./game.c#L43-51) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [x]
| | [game_equal](./game.c#L53-62) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [x]
| -| [game_delete](./game.c#L?) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [ ]
| +| [game_delete](./game.c#L64-72) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| | [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| | [game_get_square](./game.c#L?) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [ ]
| | [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| diff --git a/game.c b/game.c index 50980a0..9bc7f88 100644 --- a/game.c +++ b/game.c @@ -62,6 +62,12 @@ bool game_equal(cgame g1, cgame g2) { } void game_delete(game g) { + for (int i = 0; i < DEFAULT_SIZE; i++) { + free(g->tab_cell[i]); + g->tab_cell[i] = NULL; + } + free(g); + g = NULL; return; } From b40712b6d87cd928d33e602dd114970fd8ed80b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Mon, 29 Nov 2021 19:17:47 +0100 Subject: [PATCH 127/281] all my functions except updateflags --- game.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/game.c b/game.c index 9bc7f88..79eec8d 100644 --- a/game.c +++ b/game.c @@ -76,7 +76,7 @@ void game_set_square(game g, uint i, uint j, square s) { } square game_get_square(cgame g, uint i, uint j) { - return 0; + return g->tab_cell[i][j]; } square game_get_state(cgame g, uint i, uint j) { @@ -96,11 +96,15 @@ bool game_is_lightbulb(cgame g, uint i, uint j) { } bool game_is_black(cgame g, uint i, uint j) { + if (game_get_state(g, i, j) >= 8 && game_get_state(g, i, j) <= 13) + return true; return false; } int game_get_black_number(cgame g, uint i, uint j) { - return -1; + if (game_get_state(g, i, j) == S_BLACKU) + return -1; + return game_get_state(g, i, j) - 8; } bool game_is_marked(cgame g, uint i, uint j) { @@ -116,11 +120,16 @@ bool game_has_error(cgame g, uint i, uint j) { } bool game_check_move(cgame g, uint i, uint j, square s) { - return false; + if (i >= DEFAULT_SIZE || j >= DEFAULT_SIZE || + (s != S_BLANK && s != S_MARK && s != S_LIGHTBULB) || + game_is_black(g, i, j)) + return false; + return true; } void game_play_move(game g, uint i, uint j, square s) { - return; + game_set_square(g, i, j, s); + game_update_flags(g); } void game_update_flags(game g) { @@ -128,9 +137,24 @@ void game_update_flags(game g) { } bool game_is_over(cgame g) { - return false; + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + if ((game_get_state(g, i, j) == S_BLANK && + game_get_flags(g, i, j) == S_BLANK) || + game_get_flags(g, i, j) == F_ERROR || + game_get_flags(g, i, j) == (F_LIGHTED | F_ERROR)) + return false; + } + } + return true; } void game_restart(game g) { - return; + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + if (game_get_state(g, i, j) == S_MARK || + game_get_state(g, i, j) == S_LIGHTBULB) + game_set_square(g, i, j, S_BLANK); + } + } } From f98641b3ffa278cc13cdf538b467dc47dbb2d6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Mon, 29 Nov 2021 19:24:44 +0100 Subject: [PATCH 128/281] update README --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1e2e619..47e6b7c 100644 --- a/README.md +++ b/README.md @@ -14,21 +14,21 @@ Projet Techno | [game_equal](./game.c#L53-62) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [x]
| | [game_delete](./game.c#L64-72) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| | [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| -| [game_get_square](./game.c#L?) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [ ]
| +| [game_get_square](./game.c#L78-80) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [X]
| | [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| | [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| | [game_is_blank](./game.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| | [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| -| [game_is_black](./game.c#L?) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [ ]
| -| [game_get_black_number](./game.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thoguet | |
  • [ ]
| +| [game_is_black](./game.c#L98-102) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [X]
| +| [game_get_black_number](./game.c#L104-108) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thoguet | |
  • [X]
| | [game_is_marked](./game.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| | [game_is_lighted](./game.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| | [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| -| [game_check_move](./game.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [ ]
| -| [game_play_move](./game.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [ ]
| +| [game_check_move](./game.c#L122-128) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [X]
| +| [game_play_move](./game.c#L130-133) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [X]
| | [game_update_flags](./game.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | |
  • [ ]
| -| [game_is_over](./game.c#L?) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [ ]
| -| [game_restart](./game.c#L?) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [ ]
| +| [game_is_over](./game.c#L139-150) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| +| [game_restart](./game.c#L152-160) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| ## Test From ae53f99df91d76d615d9c433c08434d730be1c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Mon, 29 Nov 2021 20:36:20 +0100 Subject: [PATCH 129/281] update flags finished not sure if it works well --- README.md | 2 +- game.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 47e6b7c..ac50da3 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Projet Techno | [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| | [game_check_move](./game.c#L122-128) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [X]
| | [game_play_move](./game.c#L130-133) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [X]
| -| [game_update_flags](./game.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | |
  • [ ]
| +| [game_update_flags](./game.c#L?135-234) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | |
  • [X]
| | [game_is_over](./game.c#L139-150) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| | [game_restart](./game.c#L152-160) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| diff --git a/game.c b/game.c index 79eec8d..110b407 100644 --- a/game.c +++ b/game.c @@ -133,7 +133,104 @@ void game_play_move(game g, uint i, uint j, square s) { } void game_update_flags(game g) { - return; + // delete prev flags + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + game_set_square(g, i, j, game_get_state(g, i, j)); + } + } + // update flags + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + if (game_get_state(g, i, j) == S_LIGHTBULB) { + game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED)); + for (uint i2 = i + 1; + i2 < DEFAULT_SIZE && !game_is_black(g, i2, j); i2++) { + if (game_get_state(g, i2, j) == S_LIGHTBULB) + // update initial lightbulb on F_ERROR + game_set_square(g, i, j, + (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + // update cases on FLIGHTED + game_set_square(g, i2, j, + (game_get_state(g, i2, j) | F_LIGHTED)); + } + for (uint i2 = i - 1; i2 >= 0 && !game_is_black(g, i2, j); + i2--) { + if (game_get_state(g, i2, j) == S_LIGHTBULB) + // update initial lightbulb on F_ERROR + game_set_square(g, i, j, + (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + game_set_square(g, i2, j, + (game_get_state(g, i2, j) | F_LIGHTED)); + } + for (uint j2 = j - 1; j2 >= 0 && !game_is_black(g, i, j2); + j2--) { + if (game_get_state(g, i, j2) == S_LIGHTBULB) + // update initial lightbulb on F_ERROR + game_set_square(g, i, j, + (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + game_set_square(g, i, j2, + (game_get_state(g, i, j2) | F_LIGHTED)); + } + for (uint j2 = j + 1; + j2 < DEFAULT_SIZE && !game_is_black(g, i, j2); j2++) { + if (game_get_state(g, i, j2) == S_LIGHTBULB) + // update initial lightbulb on F_ERROR + game_set_square(g, i, j, + (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + game_set_square(g, i, j2, + (game_get_state(g, i, j2) | F_LIGHTED)); + } + } else if (game_is_black(g, i, j)) { + square choice[4]; + int size = 0; + int lb = 0; + int notempty = 0; + if (i > 0) { + choice[size] = game_get_square(g, i - 1, j); + size++; + } else { + notempty++; + } + if (i < DEFAULT_SIZE - 1) { + choice[size] = game_get_square(g, i + 1, j); + size++; + } else { + notempty++; + } + if (j > 0) { + choice[size] = game_get_square(g, i, j - 1); + size++; + } else { + notempty++; + } + if (j < DEFAULT_SIZE - 1) { + choice[size] = game_get_square(g, i, j + 1); + size++; + } else { + notempty++; + } + for (int l = 0; l < size; l++) { + if (choice[l] == S_LIGHTBULB || + choice[l] == (S_LIGHTBULB | F_LIGHTED) || + choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + lb++; + } else if (choice[l] != S_BLANK) { + notempty++; + } + } + if (lb > game_get_black_number(g, i, j)) { + game_set_square(g, i, j, + (game_get_state(g, i, j) | F_ERROR)); + } + // look if there is enough empty cell around the wall + else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { + game_set_square(g, i, j, + (game_get_state(g, i, j) | F_ERROR)); + } + } + } + } } bool game_is_over(cgame g) { From bca7d0af548e5b3ea0926ad43066310446d4a926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Mon, 29 Nov 2021 20:59:13 +0100 Subject: [PATCH 130/281] readme misstake --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ac50da3..2c11688 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Projet Techno | [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| | [game_check_move](./game.c#L122-128) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [X]
| | [game_play_move](./game.c#L130-133) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [X]
| -| [game_update_flags](./game.c#L?135-234) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | |
  • [X]
| +| [game_update_flags](./game.c#L135-234) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | |
  • [X]
| | [game_is_over](./game.c#L139-150) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | |
  • [X]
| | [game_restart](./game.c#L152-160) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | |
  • [X]
| From 5bf2f11d0f241623d5e34e4aa202aa453609cc76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 30 Nov 2021 11:14:03 +0100 Subject: [PATCH 131/281] update game_is_black --- game.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/game.c b/game.c index 110b407..524782d 100644 --- a/game.c +++ b/game.c @@ -96,9 +96,7 @@ bool game_is_lightbulb(cgame g, uint i, uint j) { } bool game_is_black(cgame g, uint i, uint j) { - if (game_get_state(g, i, j) >= 8 && game_get_state(g, i, j) <= 13) - return true; - return false; + return game_get_state(g, i, j) >= 8 && game_get_state(g, i, j) <= 13; } int game_get_black_number(cgame g, uint i, uint j) { From 1e1c68402708605e444d7fb9dd462ae5acc89627 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Tue, 30 Nov 2021 14:42:31 +0100 Subject: [PATCH 132/281] first game_set_square --- CMakeLists.txt | 1 + game.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cab00ab..56170d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ add_test(test_thperrier_game_is_black ./game_test_thperrier game_is_black) add_test(test_thperrier_game_get_black_number ./game_test_thperrier game_get_black_number) add_test(test_nnunes_dummy ./game_test_nnunes dummy) +add_test(test_nnunes_game_set_square ./game_test_nnunes game_set_square) add_test(test_nnunes_game_get_square ./game_test_nnunes game_get_square) add_test(test_nnunes_game_get_state ./game_test_nnunes game_get_state) add_test(test_nnunes_game_get_flags ./game_test_nnunes game_get_flags) diff --git a/game.c b/game.c index 524782d..46ba5dc 100644 --- a/game.c +++ b/game.c @@ -72,6 +72,113 @@ void game_delete(game g) { } void game_set_square(game g, uint i, uint j, square s) { + if (s == S_BLANK) { + g->tab_cell[i][j] = S_BLANK; + return; + } + if (s == S_LIGHTBULB) { + g->tab_cell[i][j] = S_LIGHTBULB; + return; + } + if (s == S_MARK) { + g->tab_cell[i][j] = S_MARK; + return; + } + if (s == S_BLACK) { + g->tab_cell[i][j] = S_BLACK; + return; + } + if (s == S_BLACK0) { + g->tab_cell[i][j] = S_BLACK0; + return; + } + if (s == S_BLACK1) { + g->tab_cell[i][j] = S_BLACK1; + return; + } + if (s == S_BLACK2) { + g->tab_cell[i][j] = S_BLACK2; + return; + } + if (s == S_BLACK3) { + g->tab_cell[i][j] = S_BLACK3; + return; + } + if (s == S_BLACK4) { + g->tab_cell[i][j] = S_BLACK4; + return; + } + if (s == S_BLACKU) { + g->tab_cell[i][j] = S_BLACKU; + return; + } + // Avec F_LIGHTED // + if (s == (S_BLANK|F_LIGHTED)) { + g->tab_cell[i][j] = (S_BLANK|F_LIGHTED); + return; + } + if (s == (S_LIGHTBULB|F_LIGHTED)) { + g->tab_cell[i][j] = (S_LIGHTBULB|F_LIGHTED); + return; + } + if (s == (S_MARK|F_LIGHTED)) { + g->tab_cell[i][j] = (S_MARK|F_LIGHTED); + return; + } + // Avec F_ERROR // + if (s == (S_BLANK|F_ERROR)) { + g->tab_cell[i][j] = (S_BLANK|F_ERROR); + return; + } + if (s == (S_LIGHTBULB|F_ERROR)) { + g->tab_cell[i][j] = (S_LIGHTBULB|F_ERROR); + return; + } + if (s == (S_MARK|F_ERROR)) { + g->tab_cell[i][j] = (S_MARK|F_ERROR); + return; + } + if (s == (S_BLACK|F_ERROR)) { + g->tab_cell[i][j] = (S_BLACK|F_ERROR); + return; + } + if (s == (S_BLACK0|F_ERROR)) { + g->tab_cell[i][j] = (S_BLACK0|F_ERROR); + return; + } + if (s == (S_BLACK1|F_ERROR)) { + g->tab_cell[i][j] = (S_BLACK1|F_ERROR); + return; + } + if (s == (S_BLACK2|F_ERROR)) { + g->tab_cell[i][j] = (S_BLACK2|F_ERROR); + return; + } + if (s == (S_BLACK3|F_ERROR)) { + g->tab_cell[i][j] = (S_BLACK3|F_ERROR); + return; + } + if (s == (S_BLACK4|F_ERROR)) { + g->tab_cell[i][j] = (S_BLACK4|F_ERROR); + return; + } + if (s == (S_BLACKU|F_ERROR)) { + g->tab_cell[i][j] = (S_BLACKU|F_ERROR); + return; + } + // Avec les 2 flags // + if (s == (S_BLANK|F_LIGHTED|F_ERROR)) { + g->tab_cell[i][j] = (S_BLANK|F_LIGHTED|F_ERROR); + return; + } + if (s == (S_LIGHTBULB|F_LIGHTED|F_ERROR)) { + g->tab_cell[i][j] = (S_LIGHTBULB|F_LIGHTED|F_ERROR); + return; + } + if (s == (S_MARK|F_LIGHTED|F_ERROR)) { + g->tab_cell[i][j] = (S_MARK|F_LIGHTED|F_ERROR); + return; + } return; } From a93b12699cc3ff61a6778baa0b6376c8a7a3254a Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Tue, 30 Nov 2021 14:50:40 +0100 Subject: [PATCH 133/281] petit oopsi --- CMakeLists.txt | 1 - game_test_nnunes.c | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 56170d3..d9796b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,6 @@ add_test(test_thperrier_game_get_black_number ./game_test_thperrier game_get_bla add_test(test_nnunes_dummy ./game_test_nnunes dummy) add_test(test_nnunes_game_set_square ./game_test_nnunes game_set_square) -add_test(test_nnunes_game_get_square ./game_test_nnunes game_get_square) add_test(test_nnunes_game_get_state ./game_test_nnunes game_get_state) add_test(test_nnunes_game_get_flags ./game_test_nnunes game_get_flags) add_test(test_nnunes_game_is_marked ./game_test_nnunes game_is_marked) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 7cbe96b..935aba8 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -15,8 +15,8 @@ void usage(int argc, char* argv[]) { exit(EXIT_FAILURE); } -/* ************** game_get_square ************** */ -bool test_game_get_square(void) { +/* ************** game_set_square ************** */ +bool test_game_set_square(void) { game g = game_new_empty(); game_set_square(g, 0, 0, S_LIGHTBULB); if (game_get_square(g, 0, 0) != S_LIGHTBULB) { @@ -367,8 +367,8 @@ int main(int argc, char* argv[]) { bool success = false; if (strcmp("dummy", argv[1]) == 0) success = test_dummy(); - else if (strcmp("game_get_square", argv[1]) == 0) { - success = test_game_get_square(); + else if (strcmp("game_set_square", argv[1]) == 0) { + success = test_game_set_square(); } else if (strcmp("game_get_state", argv[1]) == 0) { success = test_game_get_state(); } else if (strcmp("game_get_flags", argv[1]) == 0) { From 763e12528307f8f179ae240322bfcb1454785385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 30 Nov 2021 14:55:33 +0100 Subject: [PATCH 134/281] update malloc new empty sizeof --- game.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/game.c b/game.c index 524782d..90b0aee 100644 --- a/game.c +++ b/game.c @@ -4,6 +4,7 @@ struct game_s { square** tab_cell; + int menfou; }; game game_new(square* squares) { @@ -17,7 +18,7 @@ game game_new(square* squares) { } game game_new_empty(void) { - game g = (game)malloc(sizeof(game)); + game g = (game)malloc(sizeof(struct game_s)); if (g == NULL) { fprintf(stderr, "not enough memory\n"); exit(EXIT_FAILURE); @@ -114,7 +115,7 @@ bool game_is_lighted(cgame g, uint i, uint j) { } bool game_has_error(cgame g, uint i, uint j) { - return false; + return false ; } bool game_check_move(cgame g, uint i, uint j, square s) { From b41f444653334d5663c03e21d3ab42c0e3ea4385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 30 Nov 2021 14:59:20 +0100 Subject: [PATCH 135/281] clang-format --- game.c | 78 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/game.c b/game.c index 08908b0..406d041 100644 --- a/game.c +++ b/game.c @@ -80,7 +80,7 @@ void game_set_square(game g, uint i, uint j, square s) { if (s == S_LIGHTBULB) { g->tab_cell[i][j] = S_LIGHTBULB; return; - } + } if (s == S_MARK) { g->tab_cell[i][j] = S_MARK; return; @@ -114,72 +114,72 @@ void game_set_square(game g, uint i, uint j, square s) { return; } // Avec F_LIGHTED // - if (s == (S_BLANK|F_LIGHTED)) { - g->tab_cell[i][j] = (S_BLANK|F_LIGHTED); + if (s == (S_BLANK | F_LIGHTED)) { + g->tab_cell[i][j] = (S_BLANK | F_LIGHTED); return; } - if (s == (S_LIGHTBULB|F_LIGHTED)) { - g->tab_cell[i][j] = (S_LIGHTBULB|F_LIGHTED); + if (s == (S_LIGHTBULB | F_LIGHTED)) { + g->tab_cell[i][j] = (S_LIGHTBULB | F_LIGHTED); return; - } - if (s == (S_MARK|F_LIGHTED)) { - g->tab_cell[i][j] = (S_MARK|F_LIGHTED); + } + if (s == (S_MARK | F_LIGHTED)) { + g->tab_cell[i][j] = (S_MARK | F_LIGHTED); return; } // Avec F_ERROR // - if (s == (S_BLANK|F_ERROR)) { - g->tab_cell[i][j] = (S_BLANK|F_ERROR); + if (s == (S_BLANK | F_ERROR)) { + g->tab_cell[i][j] = (S_BLANK | F_ERROR); return; } - if (s == (S_LIGHTBULB|F_ERROR)) { - g->tab_cell[i][j] = (S_LIGHTBULB|F_ERROR); - return; - } - if (s == (S_MARK|F_ERROR)) { - g->tab_cell[i][j] = (S_MARK|F_ERROR); + if (s == (S_LIGHTBULB | F_ERROR)) { + g->tab_cell[i][j] = (S_LIGHTBULB | F_ERROR); return; } - if (s == (S_BLACK|F_ERROR)) { - g->tab_cell[i][j] = (S_BLACK|F_ERROR); + if (s == (S_MARK | F_ERROR)) { + g->tab_cell[i][j] = (S_MARK | F_ERROR); return; } - if (s == (S_BLACK0|F_ERROR)) { - g->tab_cell[i][j] = (S_BLACK0|F_ERROR); + if (s == (S_BLACK | F_ERROR)) { + g->tab_cell[i][j] = (S_BLACK | F_ERROR); return; } - if (s == (S_BLACK1|F_ERROR)) { - g->tab_cell[i][j] = (S_BLACK1|F_ERROR); + if (s == (S_BLACK0 | F_ERROR)) { + g->tab_cell[i][j] = (S_BLACK0 | F_ERROR); return; } - if (s == (S_BLACK2|F_ERROR)) { - g->tab_cell[i][j] = (S_BLACK2|F_ERROR); + if (s == (S_BLACK1 | F_ERROR)) { + g->tab_cell[i][j] = (S_BLACK1 | F_ERROR); return; } - if (s == (S_BLACK3|F_ERROR)) { - g->tab_cell[i][j] = (S_BLACK3|F_ERROR); + if (s == (S_BLACK2 | F_ERROR)) { + g->tab_cell[i][j] = (S_BLACK2 | F_ERROR); return; } - if (s == (S_BLACK4|F_ERROR)) { - g->tab_cell[i][j] = (S_BLACK4|F_ERROR); + if (s == (S_BLACK3 | F_ERROR)) { + g->tab_cell[i][j] = (S_BLACK3 | F_ERROR); return; } - if (s == (S_BLACKU|F_ERROR)) { - g->tab_cell[i][j] = (S_BLACKU|F_ERROR); + if (s == (S_BLACK4 | F_ERROR)) { + g->tab_cell[i][j] = (S_BLACK4 | F_ERROR); + return; + } + if (s == (S_BLACKU | F_ERROR)) { + g->tab_cell[i][j] = (S_BLACKU | F_ERROR); return; } // Avec les 2 flags // - if (s == (S_BLANK|F_LIGHTED|F_ERROR)) { - g->tab_cell[i][j] = (S_BLANK|F_LIGHTED|F_ERROR); + if (s == (S_BLANK | F_LIGHTED | F_ERROR)) { + g->tab_cell[i][j] = (S_BLANK | F_LIGHTED | F_ERROR); return; } - if (s == (S_LIGHTBULB|F_LIGHTED|F_ERROR)) { - g->tab_cell[i][j] = (S_LIGHTBULB|F_LIGHTED|F_ERROR); + if (s == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + g->tab_cell[i][j] = (S_LIGHTBULB | F_LIGHTED | F_ERROR); return; - } - if (s == (S_MARK|F_LIGHTED|F_ERROR)) { - g->tab_cell[i][j] = (S_MARK|F_LIGHTED|F_ERROR); + } + if (s == (S_MARK | F_LIGHTED | F_ERROR)) { + g->tab_cell[i][j] = (S_MARK | F_LIGHTED | F_ERROR); return; - } + } return; } @@ -222,7 +222,7 @@ bool game_is_lighted(cgame g, uint i, uint j) { } bool game_has_error(cgame g, uint i, uint j) { - return false ; + return false; } bool game_check_move(cgame g, uint i, uint j, square s) { From 264ccf4d3a898d7483c5cf121154e71291de7d96 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 30 Nov 2021 18:56:17 +0100 Subject: [PATCH 136/281] edit game_is_blank + README --- README.md | 2 +- game.c | 215 ++---------------------------------------------------- 2 files changed, 7 insertions(+), 210 deletions(-) diff --git a/README.md b/README.md index 2c11688..01e2562 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Projet Techno | [game_get_square](./game.c#L78-80) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [X]
| | [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| | [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| -| [game_is_blank](./game.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [ ]
| +| [game_is_blank](./game.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [X]
| | [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| | [game_is_black](./game.c#L98-102) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [X]
| | [game_get_black_number](./game.c#L104-108) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thoguet | |
  • [X]
| diff --git a/game.c b/game.c index 406d041..2191972 100644 --- a/game.c +++ b/game.c @@ -4,7 +4,6 @@ struct game_s { square** tab_cell; - int menfou; }; game game_new(square* squares) { @@ -18,7 +17,7 @@ game game_new(square* squares) { } game game_new_empty(void) { - game g = (game)malloc(sizeof(struct game_s)); + game g = (game)malloc(sizeof(game)); if (g == NULL) { fprintf(stderr, "not enough memory\n"); exit(EXIT_FAILURE); @@ -73,113 +72,6 @@ void game_delete(game g) { } void game_set_square(game g, uint i, uint j, square s) { - if (s == S_BLANK) { - g->tab_cell[i][j] = S_BLANK; - return; - } - if (s == S_LIGHTBULB) { - g->tab_cell[i][j] = S_LIGHTBULB; - return; - } - if (s == S_MARK) { - g->tab_cell[i][j] = S_MARK; - return; - } - if (s == S_BLACK) { - g->tab_cell[i][j] = S_BLACK; - return; - } - if (s == S_BLACK0) { - g->tab_cell[i][j] = S_BLACK0; - return; - } - if (s == S_BLACK1) { - g->tab_cell[i][j] = S_BLACK1; - return; - } - if (s == S_BLACK2) { - g->tab_cell[i][j] = S_BLACK2; - return; - } - if (s == S_BLACK3) { - g->tab_cell[i][j] = S_BLACK3; - return; - } - if (s == S_BLACK4) { - g->tab_cell[i][j] = S_BLACK4; - return; - } - if (s == S_BLACKU) { - g->tab_cell[i][j] = S_BLACKU; - return; - } - // Avec F_LIGHTED // - if (s == (S_BLANK | F_LIGHTED)) { - g->tab_cell[i][j] = (S_BLANK | F_LIGHTED); - return; - } - if (s == (S_LIGHTBULB | F_LIGHTED)) { - g->tab_cell[i][j] = (S_LIGHTBULB | F_LIGHTED); - return; - } - if (s == (S_MARK | F_LIGHTED)) { - g->tab_cell[i][j] = (S_MARK | F_LIGHTED); - return; - } - // Avec F_ERROR // - if (s == (S_BLANK | F_ERROR)) { - g->tab_cell[i][j] = (S_BLANK | F_ERROR); - return; - } - if (s == (S_LIGHTBULB | F_ERROR)) { - g->tab_cell[i][j] = (S_LIGHTBULB | F_ERROR); - return; - } - if (s == (S_MARK | F_ERROR)) { - g->tab_cell[i][j] = (S_MARK | F_ERROR); - return; - } - if (s == (S_BLACK | F_ERROR)) { - g->tab_cell[i][j] = (S_BLACK | F_ERROR); - return; - } - if (s == (S_BLACK0 | F_ERROR)) { - g->tab_cell[i][j] = (S_BLACK0 | F_ERROR); - return; - } - if (s == (S_BLACK1 | F_ERROR)) { - g->tab_cell[i][j] = (S_BLACK1 | F_ERROR); - return; - } - if (s == (S_BLACK2 | F_ERROR)) { - g->tab_cell[i][j] = (S_BLACK2 | F_ERROR); - return; - } - if (s == (S_BLACK3 | F_ERROR)) { - g->tab_cell[i][j] = (S_BLACK3 | F_ERROR); - return; - } - if (s == (S_BLACK4 | F_ERROR)) { - g->tab_cell[i][j] = (S_BLACK4 | F_ERROR); - return; - } - if (s == (S_BLACKU | F_ERROR)) { - g->tab_cell[i][j] = (S_BLACKU | F_ERROR); - return; - } - // Avec les 2 flags // - if (s == (S_BLANK | F_LIGHTED | F_ERROR)) { - g->tab_cell[i][j] = (S_BLANK | F_LIGHTED | F_ERROR); - return; - } - if (s == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { - g->tab_cell[i][j] = (S_LIGHTBULB | F_LIGHTED | F_ERROR); - return; - } - if (s == (S_MARK | F_LIGHTED | F_ERROR)) { - g->tab_cell[i][j] = (S_MARK | F_LIGHTED | F_ERROR); - return; - } return; } @@ -196,7 +88,7 @@ square game_get_flags(cgame g, uint i, uint j) { } bool game_is_blank(cgame g, uint i, uint j) { - return false; + return (g->tab_cell[i][j] == S_BLANK); } bool game_is_lightbulb(cgame g, uint i, uint j) { @@ -204,7 +96,9 @@ bool game_is_lightbulb(cgame g, uint i, uint j) { } bool game_is_black(cgame g, uint i, uint j) { - return game_get_state(g, i, j) >= 8 && game_get_state(g, i, j) <= 13; + if (game_get_state(g, i, j) >= 8 && game_get_state(g, i, j) <= 13) + return true; + return false; } int game_get_black_number(cgame g, uint i, uint j) { @@ -239,104 +133,7 @@ void game_play_move(game g, uint i, uint j, square s) { } void game_update_flags(game g) { - // delete prev flags - for (uint i = 0; i < DEFAULT_SIZE; i++) { - for (uint j = 0; j < DEFAULT_SIZE; j++) { - game_set_square(g, i, j, game_get_state(g, i, j)); - } - } - // update flags - for (uint i = 0; i < DEFAULT_SIZE; i++) { - for (uint j = 0; j < DEFAULT_SIZE; j++) { - if (game_get_state(g, i, j) == S_LIGHTBULB) { - game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED)); - for (uint i2 = i + 1; - i2 < DEFAULT_SIZE && !game_is_black(g, i2, j); i2++) { - if (game_get_state(g, i2, j) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - // update cases on FLIGHTED - game_set_square(g, i2, j, - (game_get_state(g, i2, j) | F_LIGHTED)); - } - for (uint i2 = i - 1; i2 >= 0 && !game_is_black(g, i2, j); - i2--) { - if (game_get_state(g, i2, j) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - game_set_square(g, i2, j, - (game_get_state(g, i2, j) | F_LIGHTED)); - } - for (uint j2 = j - 1; j2 >= 0 && !game_is_black(g, i, j2); - j2--) { - if (game_get_state(g, i, j2) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - game_set_square(g, i, j2, - (game_get_state(g, i, j2) | F_LIGHTED)); - } - for (uint j2 = j + 1; - j2 < DEFAULT_SIZE && !game_is_black(g, i, j2); j2++) { - if (game_get_state(g, i, j2) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - game_set_square(g, i, j2, - (game_get_state(g, i, j2) | F_LIGHTED)); - } - } else if (game_is_black(g, i, j)) { - square choice[4]; - int size = 0; - int lb = 0; - int notempty = 0; - if (i > 0) { - choice[size] = game_get_square(g, i - 1, j); - size++; - } else { - notempty++; - } - if (i < DEFAULT_SIZE - 1) { - choice[size] = game_get_square(g, i + 1, j); - size++; - } else { - notempty++; - } - if (j > 0) { - choice[size] = game_get_square(g, i, j - 1); - size++; - } else { - notempty++; - } - if (j < DEFAULT_SIZE - 1) { - choice[size] = game_get_square(g, i, j + 1); - size++; - } else { - notempty++; - } - for (int l = 0; l < size; l++) { - if (choice[l] == S_LIGHTBULB || - choice[l] == (S_LIGHTBULB | F_LIGHTED) || - choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { - lb++; - } else if (choice[l] != S_BLANK) { - notempty++; - } - } - if (lb > game_get_black_number(g, i, j)) { - game_set_square(g, i, j, - (game_get_state(g, i, j) | F_ERROR)); - } - // look if there is enough empty cell around the wall - else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { - game_set_square(g, i, j, - (game_get_state(g, i, j) | F_ERROR)); - } - } - } - } + return; } bool game_is_over(cgame g) { From 5c58a81112c6205c89f09271c77868d69ac4e3ed Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 30 Nov 2021 19:23:27 +0100 Subject: [PATCH 137/281] game_is_lightbulb + edit readme --- README.md | 2 +- game.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 01e2562..2b5f77c 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Projet Techno | [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| | [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| | [game_is_blank](./game.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [X]
| -| [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [ ]
| +| [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| | [game_is_black](./game.c#L98-102) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [X]
| | [game_get_black_number](./game.c#L104-108) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thoguet | |
  • [X]
| | [game_is_marked](./game.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| diff --git a/game.c b/game.c index 2191972..dad72fa 100644 --- a/game.c +++ b/game.c @@ -17,7 +17,7 @@ game game_new(square* squares) { } game game_new_empty(void) { - game g = (game)malloc(sizeof(game)); + game g = (game)malloc(sizeof(struct game_s)); if (g == NULL) { fprintf(stderr, "not enough memory\n"); exit(EXIT_FAILURE); @@ -92,7 +92,10 @@ bool game_is_blank(cgame g, uint i, uint j) { } bool game_is_lightbulb(cgame g, uint i, uint j) { - return false; + return ((g->tab_cell[i][j] == S_LIGHTBULB) || + (g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED)) || + (g->tab_cell[i][j] == (S_LIGHTBULB | F_ERROR)) || + (g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED | F_ERROR))); } bool game_is_black(cgame g, uint i, uint j) { From 7a9fda9929fc5dd25599ed2d1595986a22e68664 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Tue, 30 Nov 2021 23:18:38 +0100 Subject: [PATCH 138/281] update game_set_square --- README.md | 2 +- game.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2b5f77c..b0fc76f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Projet Techno | [game_copy](./game.c#L43-51) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [x]
| | [game_equal](./game.c#L53-62) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [x]
| | [game_delete](./game.c#L64-72) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| -| [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [ ]
| +| [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [x]
| | [game_get_square](./game.c#L78-80) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [X]
| | [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| | [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| diff --git a/game.c b/game.c index dad72fa..8a437ad 100644 --- a/game.c +++ b/game.c @@ -72,8 +72,9 @@ void game_delete(game g) { } void game_set_square(game g, uint i, uint j, square s) { - return; -} + g->tab_cell[i][j] = s; + return; +} square game_get_square(cgame g, uint i, uint j) { return g->tab_cell[i][j]; From 53304abf589c2b5e9118243ba0af61e9352bd075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Wed, 1 Dec 2021 14:56:01 +0100 Subject: [PATCH 139/281] update flag (delete by thperrier) --- game.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 101 insertions(+), 4 deletions(-) diff --git a/game.c b/game.c index 8a437ad..2f0eada 100644 --- a/game.c +++ b/game.c @@ -72,9 +72,9 @@ void game_delete(game g) { } void game_set_square(game g, uint i, uint j, square s) { - g->tab_cell[i][j] = s; - return; -} + g->tab_cell[i][j] = s; + return; +} square game_get_square(cgame g, uint i, uint j) { return g->tab_cell[i][j]; @@ -137,7 +137,104 @@ void game_play_move(game g, uint i, uint j, square s) { } void game_update_flags(game g) { - return; + // delete prev flags + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + game_set_square(g, i, j, game_get_state(g, i, j)); + } + } + // update flags + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + if (game_get_state(g, i, j) == S_LIGHTBULB) { + game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED)); + for (uint i2 = i + 1; + i2 < DEFAULT_SIZE && !game_is_black(g, i2, j); i2++) { + if (game_get_state(g, i2, j) == S_LIGHTBULB) + // update initial lightbulb on F_ERROR + game_set_square(g, i, j, + (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + // update cases on FLIGHTED + game_set_square(g, i2, j, + (game_get_state(g, i2, j) | F_LIGHTED)); + } + for (uint i2 = i - 1; i2 >= 0 && !game_is_black(g, i2, j); + i2--) { + if (game_get_state(g, i2, j) == S_LIGHTBULB) + // update initial lightbulb on F_ERROR + game_set_square(g, i, j, + (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + game_set_square(g, i2, j, + (game_get_state(g, i2, j) | F_LIGHTED)); + } + for (uint j2 = j - 1; j2 >= 0 && !game_is_black(g, i, j2); + j2--) { + if (game_get_state(g, i, j2) == S_LIGHTBULB) + // update initial lightbulb on F_ERROR + game_set_square(g, i, j, + (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + game_set_square(g, i, j2, + (game_get_state(g, i, j2) | F_LIGHTED)); + } + for (uint j2 = j + 1; + j2 < DEFAULT_SIZE && !game_is_black(g, i, j2); j2++) { + if (game_get_state(g, i, j2) == S_LIGHTBULB) + // update initial lightbulb on F_ERROR + game_set_square(g, i, j, + (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + game_set_square(g, i, j2, + (game_get_state(g, i, j2) | F_LIGHTED)); + } + } else if (game_is_black(g, i, j)) { + square choice[4]; + int size = 0; + int lb = 0; + int notempty = 0; + if (i > 0) { + choice[size] = game_get_square(g, i - 1, j); + size++; + } else { + notempty++; + } + if (i < DEFAULT_SIZE - 1) { + choice[size] = game_get_square(g, i + 1, j); + size++; + } else { + notempty++; + } + if (j > 0) { + choice[size] = game_get_square(g, i, j - 1); + size++; + } else { + notempty++; + } + if (j < DEFAULT_SIZE - 1) { + choice[size] = game_get_square(g, i, j + 1); + size++; + } else { + notempty++; + } + for (int l = 0; l < size; l++) { + if (choice[l] == S_LIGHTBULB || + choice[l] == (S_LIGHTBULB | F_LIGHTED) || + choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + lb++; + } else if (choice[l] != S_BLANK) { + notempty++; + } + } + if (lb > game_get_black_number(g, i, j)) { + game_set_square(g, i, j, + (game_get_state(g, i, j) | F_ERROR)); + } + // look if there is enough empty cell around the wall + else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { + game_set_square(g, i, j, + (game_get_state(g, i, j) | F_ERROR)); + } + } + } + } } bool game_is_over(cgame g) { From 58abef31ecd7d26f9d0b4a2eb8cc960f0e16f6f5 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Wed, 1 Dec 2021 17:28:30 +0100 Subject: [PATCH 140/281] commit game_get_state / game_get_flags --- README.md | 4 ++-- game.c | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b0fc76f..fc98f24 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ Projet Techno | [game_delete](./game.c#L64-72) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| | [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [x]
| | [game_get_square](./game.c#L78-80) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [X]
| -| [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [ ]
| -| [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [ ]
| +| [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [x]
| +| [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [x]
| | [game_is_blank](./game.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [X]
| | [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| | [game_is_black](./game.c#L98-102) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [X]
| diff --git a/game.c b/game.c index 2f0eada..412a0f1 100644 --- a/game.c +++ b/game.c @@ -81,11 +81,27 @@ square game_get_square(cgame g, uint i, uint j) { } square game_get_state(cgame g, uint i, uint j) { - return 0; + if(g->tab_cell[i][j] >= F_ERROR) { + g->tab_cell[i][j] -= F_ERROR; + } + if(g->tab_cell[i][j] >= F_LIGHTED) { + g->tab_cell[i][j] -= F_LIGHTED; + } + return g->tab_cell[i][j]; } square game_get_flags(cgame g, uint i, uint j) { - return 0; + if (g->tab_cell[i][j] >= F_ERROR) { + g->tab_cell[i][j] -= F_ERROR; + if (g->tab_cell[i][j] >= F_LIGHTED) { + return (F_ERROR|F_LIGHTED); + } + return (F_ERROR); + } + if (g->tab_cell[i][j] >= F_LIGHTED) { + return (F_LIGHTED); + } + return (S_BLANK); } bool game_is_blank(cgame g, uint i, uint j) { From 59455f0d662a161491b9a7b1553e2d580ec27241 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Wed, 1 Dec 2021 17:47:13 +0100 Subject: [PATCH 141/281] commit last functions --- README.md | 6 +++--- game.c | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fc98f24..8573cbd 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ Projet Techno | [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| | [game_is_black](./game.c#L98-102) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [X]
| | [game_get_black_number](./game.c#L104-108) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thoguet | |
  • [X]
| -| [game_is_marked](./game.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [ ]
| -| [game_is_lighted](./game.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [ ]
| -| [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [ ]
| +| [game_is_marked](./game.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [x]
| +| [game_is_lighted](./game.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [x]
| +| [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [x]
| | [game_check_move](./game.c#L122-128) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [X]
| | [game_play_move](./game.c#L130-133) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [X]
| | [game_update_flags](./game.c#L135-234) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | |
  • [X]
| diff --git a/game.c b/game.c index 412a0f1..d22ca4e 100644 --- a/game.c +++ b/game.c @@ -128,14 +128,26 @@ int game_get_black_number(cgame g, uint i, uint j) { } bool game_is_marked(cgame g, uint i, uint j) { - return false; + return ((g->tab_cell[i][j] == S_MARK) || + (g->tab_cell[i][j] == (S_MARK | F_LIGHTED)) || + (g->tab_cell[i][j] == (S_MARK | F_ERROR)) || + (g->tab_cell[i][j] == (S_MARK | F_LIGHTED | F_ERROR))); } bool game_is_lighted(cgame g, uint i, uint j) { + if (g->tab_cell[i][j] >= F_ERROR) { + g->tab_cell[i][j] -= F_ERROR; + } + if (g->tab_cell[i][j] >= F_LIGHTED) { + return true; + } return false; } bool game_has_error(cgame g, uint i, uint j) { + if (g->tab_cell[i][j] >= F_ERROR) { + return true; + } return false; } From 73b327e41aa859157c185345b6f0ee02fea9a13d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 2 Dec 2021 11:02:53 +0100 Subject: [PATCH 142/281] started debug --- game.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/game.c b/game.c index d22ca4e..54fb9c4 100644 --- a/game.c +++ b/game.c @@ -81,10 +81,10 @@ square game_get_square(cgame g, uint i, uint j) { } square game_get_state(cgame g, uint i, uint j) { - if(g->tab_cell[i][j] >= F_ERROR) { + if (g->tab_cell[i][j] >= F_ERROR) { g->tab_cell[i][j] -= F_ERROR; } - if(g->tab_cell[i][j] >= F_LIGHTED) { + if (g->tab_cell[i][j] >= F_LIGHTED) { g->tab_cell[i][j] -= F_LIGHTED; } return g->tab_cell[i][j]; @@ -94,14 +94,14 @@ square game_get_flags(cgame g, uint i, uint j) { if (g->tab_cell[i][j] >= F_ERROR) { g->tab_cell[i][j] -= F_ERROR; if (g->tab_cell[i][j] >= F_LIGHTED) { - return (F_ERROR|F_LIGHTED); + return (F_ERROR | F_LIGHTED); } return (F_ERROR); } if (g->tab_cell[i][j] >= F_LIGHTED) { return (F_LIGHTED); } - return (S_BLANK); + return (S_BLANK); } bool game_is_blank(cgame g, uint i, uint j) { @@ -137,7 +137,7 @@ bool game_is_marked(cgame g, uint i, uint j) { bool game_is_lighted(cgame g, uint i, uint j) { if (g->tab_cell[i][j] >= F_ERROR) { g->tab_cell[i][j] -= F_ERROR; - } + } if (g->tab_cell[i][j] >= F_LIGHTED) { return true; } @@ -147,7 +147,7 @@ bool game_is_lighted(cgame g, uint i, uint j) { bool game_has_error(cgame g, uint i, uint j) { if (g->tab_cell[i][j] >= F_ERROR) { return true; - } + } return false; } @@ -186,8 +186,7 @@ void game_update_flags(game g) { game_set_square(g, i2, j, (game_get_state(g, i2, j) | F_LIGHTED)); } - for (uint i2 = i - 1; i2 >= 0 && !game_is_black(g, i2, j); - i2--) { + for (int i2 = i - 1; i2 > 0 && !game_is_black(g, i2, j); i2--) { if (game_get_state(g, i2, j) == S_LIGHTBULB) // update initial lightbulb on F_ERROR game_set_square(g, i, j, @@ -195,8 +194,7 @@ void game_update_flags(game g) { game_set_square(g, i2, j, (game_get_state(g, i2, j) | F_LIGHTED)); } - for (uint j2 = j - 1; j2 >= 0 && !game_is_black(g, i, j2); - j2--) { + for (int j2 = j - 1; j2 > 0 && !game_is_black(g, i, j2); j2--) { if (game_get_state(g, i, j2) == S_LIGHTBULB) // update initial lightbulb on F_ERROR game_set_square(g, i, j, From e5a330f56a39fce6605e9e9d2e2b0194621ed58a Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Thu, 2 Dec 2021 11:19:56 +0100 Subject: [PATCH 143/281] bug fix game_has_error --- game.c | 9 +++++---- game_test_nnunes.c | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/game.c b/game.c index 54fb9c4..672e13e 100644 --- a/game.c +++ b/game.c @@ -91,14 +91,15 @@ square game_get_state(cgame g, uint i, uint j) { } square game_get_flags(cgame g, uint i, uint j) { - if (g->tab_cell[i][j] >= F_ERROR) { - g->tab_cell[i][j] -= F_ERROR; - if (g->tab_cell[i][j] >= F_LIGHTED) { + square temp = g->tab_cell[i][j]; + if (temp >= F_ERROR) { + temp -= F_ERROR; + if (temp >= F_LIGHTED) { return (F_ERROR | F_LIGHTED); } return (F_ERROR); } - if (g->tab_cell[i][j] >= F_LIGHTED) { + if (temp >= F_LIGHTED) { return (F_LIGHTED); } return (S_BLANK); diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 935aba8..24f823f 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -344,12 +344,12 @@ bool test_game_is_lighted(void) { /* ************** game_has_error ************** */ bool test_game_has_error(void) { game g = game_new_empty(); - game_set_square(g, 0, 0, S_BLANK | F_ERROR); + game_set_square(g, 0, 0, S_LIGHTBULB | F_ERROR); if ((game_get_flags(g, 0, 0) == F_ERROR) && game_has_error(g, 0, 0)) { game_delete(g); return true; } - game_set_square(g, 0, 0, S_BLANK | F_LIGHTED | F_ERROR); + game_set_square(g, 0, 0, S_LIGHTBULB | F_LIGHTED | F_ERROR); if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && game_has_error(g, 0, 0)) { game_delete(g); From 920df3b7c515bea79045e7de7ea7dd92e0d60afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 5 Dec 2021 01:33:03 +0100 Subject: [PATCH 144/281] debug fct --- game.c | 117 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 51 deletions(-) diff --git a/game.c b/game.c index 672e13e..1ff2b26 100644 --- a/game.c +++ b/game.c @@ -81,13 +81,14 @@ square game_get_square(cgame g, uint i, uint j) { } square game_get_state(cgame g, uint i, uint j) { - if (g->tab_cell[i][j] >= F_ERROR) { - g->tab_cell[i][j] -= F_ERROR; + square tmp = g->tab_cell[i][j]; + if (tmp >= F_ERROR) { + tmp -= F_ERROR; } - if (g->tab_cell[i][j] >= F_LIGHTED) { - g->tab_cell[i][j] -= F_LIGHTED; + if (tmp >= F_LIGHTED) { + tmp -= F_LIGHTED; } - return g->tab_cell[i][j]; + return tmp; } square game_get_flags(cgame g, uint i, uint j) { @@ -172,11 +173,15 @@ void game_update_flags(game g) { game_set_square(g, i, j, game_get_state(g, i, j)); } } - // update flags + // update flags lighted and lightbulb error for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { if (game_get_state(g, i, j) == S_LIGHTBULB) { - game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED)); + if (game_get_flags(g, i, j) > 16) + game_set_square(g, i, j, + (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + else + game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED)); for (uint i2 = i + 1; i2 < DEFAULT_SIZE && !game_is_black(g, i2, j); i2++) { if (game_get_state(g, i2, j) == S_LIGHTBULB) @@ -212,52 +217,61 @@ void game_update_flags(game g) { game_set_square(g, i, j2, (game_get_state(g, i, j2) | F_LIGHTED)); } - } else if (game_is_black(g, i, j)) { - square choice[4]; - int size = 0; - int lb = 0; - int notempty = 0; - if (i > 0) { - choice[size] = game_get_square(g, i - 1, j); - size++; - } else { - notempty++; - } - if (i < DEFAULT_SIZE - 1) { - choice[size] = game_get_square(g, i + 1, j); - size++; - } else { - notempty++; - } - if (j > 0) { - choice[size] = game_get_square(g, i, j - 1); - size++; - } else { - notempty++; - } - if (j < DEFAULT_SIZE - 1) { - choice[size] = game_get_square(g, i, j + 1); - size++; - } else { - notempty++; - } - for (int l = 0; l < size; l++) { - if (choice[l] == S_LIGHTBULB || - choice[l] == (S_LIGHTBULB | F_LIGHTED) || - choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { - lb++; - } else if (choice[l] != S_BLANK) { + } + } + } + // update flags wall + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + if (game_is_black(g, i, j)) { + if (game_get_black_number(g, i, j) >= 0) { + square choice[4]; + int size = 0; + int lb = 0; + int notempty = 0; + if (i > 0) { + choice[size] = game_get_square(g, i - 1, j); + size++; + } else { notempty++; } - } - if (lb > game_get_black_number(g, i, j)) { - game_set_square(g, i, j, - (game_get_state(g, i, j) | F_ERROR)); - } - // look if there is enough empty cell around the wall - else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { - game_set_square(g, i, j, - (game_get_state(g, i, j) | F_ERROR)); + if (i < DEFAULT_SIZE - 1) { + choice[size] = game_get_square(g, i + 1, j); + size++; + } else { + notempty++; + } + if (j > 0) { + choice[size] = game_get_square(g, i, j - 1); + size++; + } else { + notempty++; + } + if (j < DEFAULT_SIZE - 1) { + choice[size] = game_get_square(g, i, j + 1); + size++; + } else { + notempty++; + } + for (int l = 0; l < size; l++) { + if (choice[l] == S_LIGHTBULB || + choice[l] == (S_LIGHTBULB | F_LIGHTED) || + choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + lb++; + } else if (choice[l] != S_BLANK) { + notempty++; + } + } + if (lb > game_get_black_number(g, i, j)) { + game_set_square(g, i, j, + (game_get_state(g, i, j) | F_ERROR)); + } + // look if there is enough empty cell around the wall + else if (notempty > + abs(game_get_black_number(g, i, j) - 4)) { + game_set_square(g, i, j, + (game_get_state(g, i, j) | F_ERROR)); + } } } } @@ -285,4 +299,5 @@ void game_restart(game g) { game_set_square(g, i, j, S_BLANK); } } + game_update_flags(g); } From 3946e3e5f1e5052ca7d7d5ca8594dc16a9988290 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 7 Dec 2021 01:35:05 +0100 Subject: [PATCH 145/281] edit game_delete --- game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game.c b/game.c index 1ff2b26..ac313ff 100644 --- a/game.c +++ b/game.c @@ -64,8 +64,8 @@ bool game_equal(cgame g1, cgame g2) { void game_delete(game g) { for (int i = 0; i < DEFAULT_SIZE; i++) { free(g->tab_cell[i]); - g->tab_cell[i] = NULL; } + free(g->tab_cell); free(g); g = NULL; return; From d3cd2d929612f46b22ef78074fc1f95983af42b6 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 7 Dec 2021 01:35:57 +0100 Subject: [PATCH 146/281] edit game_delete --- game.c | 1 - 1 file changed, 1 deletion(-) diff --git a/game.c b/game.c index ac313ff..c45f49b 100644 --- a/game.c +++ b/game.c @@ -67,7 +67,6 @@ void game_delete(game g) { } free(g->tab_cell); free(g); - g = NULL; return; } From 7b42e41b19859eaea879ecf393892f13ce43edaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 7 Dec 2021 15:47:23 +0100 Subject: [PATCH 147/281] pointer to NULL on game_delete --- game.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/game.c b/game.c index c45f49b..fcc9857 100644 --- a/game.c +++ b/game.c @@ -64,9 +64,12 @@ bool game_equal(cgame g1, cgame g2) { void game_delete(game g) { for (int i = 0; i < DEFAULT_SIZE; i++) { free(g->tab_cell[i]); + g->tab_cell[i] = NULL; } free(g->tab_cell); + g->tab_cell = NULL; free(g); + g = NULL; return; } From 3efa272882b100122beb6098ea07dd407499ade9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 7 Dec 2021 15:49:12 +0100 Subject: [PATCH 148/281] test on pointer before set to NULL --- game.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/game.c b/game.c index fcc9857..09e35d1 100644 --- a/game.c +++ b/game.c @@ -64,12 +64,15 @@ bool game_equal(cgame g1, cgame g2) { void game_delete(game g) { for (int i = 0; i < DEFAULT_SIZE; i++) { free(g->tab_cell[i]); - g->tab_cell[i] = NULL; + if (g->tab_cell[i] != NULL) + g->tab_cell[i] = NULL; } free(g->tab_cell); - g->tab_cell = NULL; + if (g->tab_cell != NULL) + g->tab_cell = NULL; free(g); - g = NULL; + if (g != NULL) + g = NULL; return; } From dcb2469a44dcc5dde9cd68cb0c1832133a1918f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 7 Dec 2021 16:04:48 +0100 Subject: [PATCH 149/281] ??? --- game_test_thperrier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index d2832a5..0d619ac 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -208,7 +208,7 @@ bool test_game_copy() { game_set_square(g2, i, j, S_BLACK3); } } - g2 = game_copy(g1); + g2 = game_copy(g1); // c koi ca ? (UNE FUITE MEMOIRE) assert(g2); if (!game_equal(g1, g2)) { game_delete(g1); From 2cb36cbcb830516b1e0d6a360de5115d9e96c527 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Tue, 7 Dec 2021 18:39:49 +0100 Subject: [PATCH 150/281] edit test_game_copy --- game_test_thperrier.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 0d619ac..0754180 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -208,15 +208,17 @@ bool test_game_copy() { game_set_square(g2, i, j, S_BLACK3); } } - g2 = game_copy(g1); // c koi ca ? (UNE FUITE MEMOIRE) - assert(g2); - if (!game_equal(g1, g2)) { + game g3 = game_copy(g2); + assert(g3); + if (!game_equal(g2, g3)) { game_delete(g1); game_delete(g2); + game_delete(g3); return false; } game_delete(g1); game_delete(g2); + game_delete(g3); return true; } /* ********** usage ********** */ From 0b2f8b535250b609ff04477f3c1695e641b6c201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 7 Dec 2021 19:56:32 +0100 Subject: [PATCH 151/281] fix bug --- game.c | 6 ++++-- game_test_thoguet.c | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/game.c b/game.c index 09e35d1..ff550ba 100644 --- a/game.c +++ b/game.c @@ -197,7 +197,8 @@ void game_update_flags(game g) { game_set_square(g, i2, j, (game_get_state(g, i2, j) | F_LIGHTED)); } - for (int i2 = i - 1; i2 > 0 && !game_is_black(g, i2, j); i2--) { + for (int i2 = i - 1; i2 >= 0 && !game_is_black(g, i2, j); + i2--) { if (game_get_state(g, i2, j) == S_LIGHTBULB) // update initial lightbulb on F_ERROR game_set_square(g, i, j, @@ -205,7 +206,8 @@ void game_update_flags(game g) { game_set_square(g, i2, j, (game_get_state(g, i2, j) | F_LIGHTED)); } - for (int j2 = j - 1; j2 > 0 && !game_is_black(g, i, j2); j2--) { + for (int j2 = j - 1; j2 >= 0 && !game_is_black(g, i, j2); + j2--) { if (game_get_state(g, i, j2) == S_LIGHTBULB) // update initial lightbulb on F_ERROR game_set_square(g, i, j, diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 26cd304..7e54964 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -278,7 +278,7 @@ bool check_update(game g) { } // loop checking every case before i wall = false; - for (int k = i - 1; k > 0; k--) { + for (int k = i - 1; k >= 0; k--) { if (/*test if current case is a wall*/ game_is_black(g, k, j)) { wall = true; @@ -308,7 +308,7 @@ bool check_update(game g) { } } wall = false; - for (int k = j - 1; k > 0; k--) { + for (int k = j - 1; k >= 0; k--) { if (/*test if current case is a wall*/ game_is_black(g, i, k)) { wall = true; From cbfde911ed0d023b715ebca867478aafa07db145 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Thu, 9 Dec 2021 10:02:29 +0100 Subject: [PATCH 152/281] commit game_ext.h --- game_ext.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 game_ext.h diff --git a/game_ext.h b/game_ext.h new file mode 100644 index 0000000..b38ed7e --- /dev/null +++ b/game_ext.h @@ -0,0 +1,92 @@ +/** + * @file game_ext.h + * @brief Extended Game Functions. + * @details See @ref index for further details. + * @copyright University of Bordeaux. All rights reserved, 2021. + **/ + +#ifndef __GAME_EXT_H__ +#define __GAME_EXT_H__ + +#include + +#include "game.h" + +/** + * @name Extended Functions + * @{ + */ + +/** + * @brief Creates a new game with extended options and initializes it. + * @details See description of game extensions on @ref index. + * @param nb_rows number of rows in game + * @param nb_cols number of columns in game + * @param squares an array describing the initial state of each square + * (row-major storage) + * @param wrapping wrapping option + * @return the created game + **/ +game game_new_ext(uint nb_rows, uint nb_cols, square* squares, bool wrapping); + +/** + * @brief Creates a new empty game with extended options. + * @details All squares are initialized with empty squares. + * @details See description of game extensions on @ref index. + * @param nb_rows number of rows in game + * @param nb_cols number of columns in game + * @param wrapping wrapping option + * @return the created game + **/ +game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping); + +/** + * @brief Gets the number of rows (or height). + * @param g the game + * @return the number of rows on this game + * @pre @p g is a valid pointer toward a cgame structure + **/ +uint game_nb_rows(cgame g); + +/** + * @brief Gets the number of columns (or width). + * @param g the game + * @return the the number of columns on this game + * @pre @p g is a valid pointer toward a cgame structure + **/ +uint game_nb_cols(cgame g); + +/** + * @brief Checks if the game has the wrapping option + * @return true, if wrapping, false otherwise + * @pre @p g is a valid pointer toward a cgame structure + **/ +bool game_is_wrapping(cgame g); + +/** + * @brief Undoes the last move. + * @details Searches in the history the last move played (by calling + * @ref game_play_move or @ref game_redo), and restores the state of the game + * before that move. If no moves have been played, this function does nothing. + * The @ref game_restart function clears the history. + * @param g the game + * @pre @p g is a valid pointer toward a cgame structure + **/ +void game_undo(game g); + +/** + * @brief Redoes the last move. + * @details Searches in the history the last cancelled move (by calling @ref + * game_undo), and replays it. If there are no more moves to be replayed, this + * function does nothing. After playing a new move with @ref game_play_move, it + * is no longer possible to redo an old cancelled move. + * @param g the game + * @pre @p g is a valid pointer toward a cgame structure + **/ +void game_redo(game g); + +/** + * @} + */ + +#endif // __GAME_EXT_H__ \ No newline at end of file From f7f3261a5c04051ac8fad34ba39ea3c9ab195df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 9 Dec 2021 10:04:02 +0100 Subject: [PATCH 153/281] readme --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 8573cbd..88c1cf0 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,18 @@ Projet Techno :warning: LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE :warning: +## game_ext.h + +| Fonction | REF | Assigned to | Notes | Finished | +| ------------------------------------ | ---------------------------------------------------------------------------- | ----------- | ----- | :--------------------: | +| [game_new_ext](./game_ext.c#L?) | [game game_new_ext(uint nb_rows, uint nb_cols, square *squares, bool wrapping)](./game_ext.h#L20-30) | @thoguet | |
  • [ ]
| +| [game_new_empty_ext](./game_ext.c#L?) | [game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping);](./game_ext.h#L32-41) | @thoguet | |
  • [ ]
| +| [game_nb_rows](./game_ext.c#L?) | [uint game_nb_rows(cgame g);](./game_ext.h#L43-59) | @nnunes | |
  • [ ]
| +| [game_nb_cols](./game_ext.c#L?) | [uint game_nb_cols(cgame g);](./game_ext.h#L51-57) | @nnunes | |
  • [ ]
| +| [game_is_wrapping](./game_ext.c#L?) | [bool game_is_wrapping(cgame g);](./game_ext.h#L59-64) | @nnunes | |
  • [ ]
| +| [game_undo](./game_ext.c#L?) | [void game_undo(game g);](./game_ext.h#L66-75) | @thperrier | |
  • [ ]
| +| [game_redo](./game_ext.c#L?) | [void game_redo(game g);](./game_ext.h#L77-86) | @thperrier | |
  • [ ]
| + ## game.c | Fonction | REF | Assigned to | Notes | Finished | From 63d3bcde8ca07d54e249a220299ee5cd69d0d856 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Thu, 9 Dec 2021 10:06:16 +0100 Subject: [PATCH 154/281] rm game_ext.h --- game_ext.h | 92 ------------------------------------------------------ 1 file changed, 92 deletions(-) delete mode 100644 game_ext.h diff --git a/game_ext.h b/game_ext.h deleted file mode 100644 index b38ed7e..0000000 --- a/game_ext.h +++ /dev/null @@ -1,92 +0,0 @@ -/** - * @file game_ext.h - * @brief Extended Game Functions. - * @details See @ref index for further details. - * @copyright University of Bordeaux. All rights reserved, 2021. - **/ - -#ifndef __GAME_EXT_H__ -#define __GAME_EXT_H__ - -#include - -#include "game.h" - -/** - * @name Extended Functions - * @{ - */ - -/** - * @brief Creates a new game with extended options and initializes it. - * @details See description of game extensions on @ref index. - * @param nb_rows number of rows in game - * @param nb_cols number of columns in game - * @param squares an array describing the initial state of each square - * (row-major storage) - * @param wrapping wrapping option - * @return the created game - **/ -game game_new_ext(uint nb_rows, uint nb_cols, square* squares, bool wrapping); - -/** - * @brief Creates a new empty game with extended options. - * @details All squares are initialized with empty squares. - * @details See description of game extensions on @ref index. - * @param nb_rows number of rows in game - * @param nb_cols number of columns in game - * @param wrapping wrapping option - * @return the created game - **/ -game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping); - -/** - * @brief Gets the number of rows (or height). - * @param g the game - * @return the number of rows on this game - * @pre @p g is a valid pointer toward a cgame structure - **/ -uint game_nb_rows(cgame g); - -/** - * @brief Gets the number of columns (or width). - * @param g the game - * @return the the number of columns on this game - * @pre @p g is a valid pointer toward a cgame structure - **/ -uint game_nb_cols(cgame g); - -/** - * @brief Checks if the game has the wrapping option - * @return true, if wrapping, false otherwise - * @pre @p g is a valid pointer toward a cgame structure - **/ -bool game_is_wrapping(cgame g); - -/** - * @brief Undoes the last move. - * @details Searches in the history the last move played (by calling - * @ref game_play_move or @ref game_redo), and restores the state of the game - * before that move. If no moves have been played, this function does nothing. - * The @ref game_restart function clears the history. - * @param g the game - * @pre @p g is a valid pointer toward a cgame structure - **/ -void game_undo(game g); - -/** - * @brief Redoes the last move. - * @details Searches in the history the last cancelled move (by calling @ref - * game_undo), and replays it. If there are no more moves to be replayed, this - * function does nothing. After playing a new move with @ref game_play_move, it - * is no longer possible to redo an old cancelled move. - * @param g the game - * @pre @p g is a valid pointer toward a cgame structure - **/ -void game_redo(game g); - -/** - * @} - */ - -#endif // __GAME_EXT_H__ \ No newline at end of file From 5e65b3c99fd19073f5bc939b7ff26f57fd139bb3 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Thu, 9 Dec 2021 10:11:27 +0100 Subject: [PATCH 155/281] adding game_ext.h + game_ext.c --- game_ext.c | 3 ++ game_ext.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 game_ext.c create mode 100644 game_ext.h diff --git a/game_ext.c b/game_ext.c new file mode 100644 index 0000000..67a10be --- /dev/null +++ b/game_ext.c @@ -0,0 +1,3 @@ +#include +#include +#include "game_ext.h" \ No newline at end of file diff --git a/game_ext.h b/game_ext.h new file mode 100644 index 0000000..b38ed7e --- /dev/null +++ b/game_ext.h @@ -0,0 +1,92 @@ +/** + * @file game_ext.h + * @brief Extended Game Functions. + * @details See @ref index for further details. + * @copyright University of Bordeaux. All rights reserved, 2021. + **/ + +#ifndef __GAME_EXT_H__ +#define __GAME_EXT_H__ + +#include + +#include "game.h" + +/** + * @name Extended Functions + * @{ + */ + +/** + * @brief Creates a new game with extended options and initializes it. + * @details See description of game extensions on @ref index. + * @param nb_rows number of rows in game + * @param nb_cols number of columns in game + * @param squares an array describing the initial state of each square + * (row-major storage) + * @param wrapping wrapping option + * @return the created game + **/ +game game_new_ext(uint nb_rows, uint nb_cols, square* squares, bool wrapping); + +/** + * @brief Creates a new empty game with extended options. + * @details All squares are initialized with empty squares. + * @details See description of game extensions on @ref index. + * @param nb_rows number of rows in game + * @param nb_cols number of columns in game + * @param wrapping wrapping option + * @return the created game + **/ +game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping); + +/** + * @brief Gets the number of rows (or height). + * @param g the game + * @return the number of rows on this game + * @pre @p g is a valid pointer toward a cgame structure + **/ +uint game_nb_rows(cgame g); + +/** + * @brief Gets the number of columns (or width). + * @param g the game + * @return the the number of columns on this game + * @pre @p g is a valid pointer toward a cgame structure + **/ +uint game_nb_cols(cgame g); + +/** + * @brief Checks if the game has the wrapping option + * @return true, if wrapping, false otherwise + * @pre @p g is a valid pointer toward a cgame structure + **/ +bool game_is_wrapping(cgame g); + +/** + * @brief Undoes the last move. + * @details Searches in the history the last move played (by calling + * @ref game_play_move or @ref game_redo), and restores the state of the game + * before that move. If no moves have been played, this function does nothing. + * The @ref game_restart function clears the history. + * @param g the game + * @pre @p g is a valid pointer toward a cgame structure + **/ +void game_undo(game g); + +/** + * @brief Redoes the last move. + * @details Searches in the history the last cancelled move (by calling @ref + * game_undo), and replays it. If there are no more moves to be replayed, this + * function does nothing. After playing a new move with @ref game_play_move, it + * is no longer possible to redo an old cancelled move. + * @param g the game + * @pre @p g is a valid pointer toward a cgame structure + **/ +void game_redo(game g); + +/** + * @} + */ + +#endif // __GAME_EXT_H__ \ No newline at end of file From 0c17df162ca549223d000d143fa5b0a74b84c2d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 9 Dec 2021 10:14:46 +0100 Subject: [PATCH 156/281] empty proto --- game_ext.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/game_ext.c b/game_ext.c index 67a10be..4e21273 100644 --- a/game_ext.c +++ b/game_ext.c @@ -1,3 +1,30 @@ +#include "game_ext.h" #include -#include -#include "game_ext.h" \ No newline at end of file + +game game_new_ext(uint nb_rows, uint nb_cols, square* squares, bool wrapping) { + return; +} + +game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { + return; +} + +uint game_nb_rows(cgame g) { + return; +} + +uint game_nb_cols(cgame g) { + return; +} + +bool game_is_wrapping(cgame g) { + return; +} + +void game_undo(game g) { + return; +} + +void game_redo(game g) { + return; +} \ No newline at end of file From 497d6022c02bb1e2bf0dba6b0441eff9097f26c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 9 Dec 2021 11:11:33 +0100 Subject: [PATCH 157/281] change struct start new empty ext --- game.c | 6 ++++++ game_ext.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/game.c b/game.c index ff550ba..4fa1b7c 100644 --- a/game.c +++ b/game.c @@ -4,6 +4,9 @@ struct game_s { square** tab_cell; + bool wrapped; + uint height; + uint width; }; game game_new(square* squares) { @@ -37,6 +40,9 @@ game game_new_empty(void) { g->tab_cell[i][j] = S_BLANK; } } + g->wrapped = false; + g->height = DEFAULT_SIZE; + g->width = DEFAULT_SIZE; return g; } diff --git a/game_ext.c b/game_ext.c index 4e21273..a7dcde0 100644 --- a/game_ext.c +++ b/game_ext.c @@ -1,8 +1,9 @@ #include "game_ext.h" #include +#include game game_new_ext(uint nb_rows, uint nb_cols, square* squares, bool wrapping) { - return; + game g = (game)malloc(sizeof(struct game_s)); } game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { From 0c381527521e3b29c52abf4a63423f8dd36a3745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 9 Dec 2021 18:22:16 +0100 Subject: [PATCH 158/281] clang format column limit x2 --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 1c5cae1..d8ebf68 100644 --- a/.clang-format +++ b/.clang-format @@ -45,7 +45,7 @@ BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true -ColumnLimit: 80 +ColumnLimit: 160 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true From 7d826b608232b8ed86501878f2bbe4636c624e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 9 Dec 2021 18:23:38 +0100 Subject: [PATCH 159/281] update clang --- game.c | 79 +++++++++++++++---------------------------- game.h | 35 ++++++++++--------- game_aux.c | 7 ++-- game_test_nnunes.c | 6 ++-- game_test_thoguet.c | 72 ++++++++++++--------------------------- game_test_thperrier.c | 3 +- game_text.c | 3 +- 7 files changed, 72 insertions(+), 133 deletions(-) diff --git a/game.c b/game.c index 4fa1b7c..95aa361 100644 --- a/game.c +++ b/game.c @@ -122,9 +122,7 @@ bool game_is_blank(cgame g, uint i, uint j) { } bool game_is_lightbulb(cgame g, uint i, uint j) { - return ((g->tab_cell[i][j] == S_LIGHTBULB) || - (g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED)) || - (g->tab_cell[i][j] == (S_LIGHTBULB | F_ERROR)) || + return ((g->tab_cell[i][j] == S_LIGHTBULB) || (g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED)) || (g->tab_cell[i][j] == (S_LIGHTBULB | F_ERROR)) || (g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED | F_ERROR))); } @@ -141,9 +139,7 @@ int game_get_black_number(cgame g, uint i, uint j) { } bool game_is_marked(cgame g, uint i, uint j) { - return ((g->tab_cell[i][j] == S_MARK) || - (g->tab_cell[i][j] == (S_MARK | F_LIGHTED)) || - (g->tab_cell[i][j] == (S_MARK | F_ERROR)) || + return ((g->tab_cell[i][j] == S_MARK) || (g->tab_cell[i][j] == (S_MARK | F_LIGHTED)) || (g->tab_cell[i][j] == (S_MARK | F_ERROR)) || (g->tab_cell[i][j] == (S_MARK | F_LIGHTED | F_ERROR))); } @@ -165,9 +161,7 @@ bool game_has_error(cgame g, uint i, uint j) { } bool game_check_move(cgame g, uint i, uint j, square s) { - if (i >= DEFAULT_SIZE || j >= DEFAULT_SIZE || - (s != S_BLANK && s != S_MARK && s != S_LIGHTBULB) || - game_is_black(g, i, j)) + if (i >= DEFAULT_SIZE || j >= DEFAULT_SIZE || (s != S_BLANK && s != S_MARK && s != S_LIGHTBULB) || game_is_black(g, i, j)) return false; return true; } @@ -177,58 +171,49 @@ void game_play_move(game g, uint i, uint j, square s) { game_update_flags(g); } -void game_update_flags(game g) { +void delete_flags(g) { // delete prev flags for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { game_set_square(g, i, j, game_get_state(g, i, j)); } } +} + +void game_update_flags(game g) { + delete_flags(g); // update flags lighted and lightbulb error for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { if (game_get_state(g, i, j) == S_LIGHTBULB) { - if (game_get_flags(g, i, j) > 16) - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + if (game_get_flags(g, i, j) == F_ERROR) + game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); else game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED)); - for (uint i2 = i + 1; - i2 < DEFAULT_SIZE && !game_is_black(g, i2, j); i2++) { + for (uint i2 = i + 1; i2 < DEFAULT_SIZE && !game_is_black(g, i2, j); i2++) { if (game_get_state(g, i2, j) == S_LIGHTBULB) // update initial lightbulb on F_ERROR - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); // update cases on FLIGHTED - game_set_square(g, i2, j, - (game_get_state(g, i2, j) | F_LIGHTED)); + game_set_square(g, i2, j, (game_get_state(g, i2, j) | F_LIGHTED)); } - for (int i2 = i - 1; i2 >= 0 && !game_is_black(g, i2, j); - i2--) { + for (int i2 = i - 1; i2 >= 0 && !game_is_black(g, i2, j); i2--) { if (game_get_state(g, i2, j) == S_LIGHTBULB) // update initial lightbulb on F_ERROR - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - game_set_square(g, i2, j, - (game_get_state(g, i2, j) | F_LIGHTED)); + game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + game_set_square(g, i2, j, (game_get_state(g, i2, j) | F_LIGHTED)); } - for (int j2 = j - 1; j2 >= 0 && !game_is_black(g, i, j2); - j2--) { + for (int j2 = j - 1; j2 >= 0 && !game_is_black(g, i, j2); j2--) { if (game_get_state(g, i, j2) == S_LIGHTBULB) // update initial lightbulb on F_ERROR - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - game_set_square(g, i, j2, - (game_get_state(g, i, j2) | F_LIGHTED)); + game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + game_set_square(g, i, j2, (game_get_state(g, i, j2) | F_LIGHTED)); } - for (uint j2 = j + 1; - j2 < DEFAULT_SIZE && !game_is_black(g, i, j2); j2++) { + for (uint j2 = j + 1; j2 < DEFAULT_SIZE && !game_is_black(g, i, j2); j2++) { if (game_get_state(g, i, j2) == S_LIGHTBULB) // update initial lightbulb on F_ERROR - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - game_set_square(g, i, j2, - (game_get_state(g, i, j2) | F_LIGHTED)); + game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + game_set_square(g, i, j2, (game_get_state(g, i, j2) | F_LIGHTED)); } } } @@ -267,23 +252,18 @@ void game_update_flags(game g) { notempty++; } for (int l = 0; l < size; l++) { - if (choice[l] == S_LIGHTBULB || - choice[l] == (S_LIGHTBULB | F_LIGHTED) || - choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + if (choice[l] == S_LIGHTBULB || choice[l] == (S_LIGHTBULB | F_LIGHTED) || choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { lb++; } else if (choice[l] != S_BLANK) { notempty++; } } if (lb > game_get_black_number(g, i, j)) { - game_set_square(g, i, j, - (game_get_state(g, i, j) | F_ERROR)); + game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); } // look if there is enough empty cell around the wall - else if (notempty > - abs(game_get_black_number(g, i, j) - 4)) { - game_set_square(g, i, j, - (game_get_state(g, i, j) | F_ERROR)); + else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { + game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); } } } @@ -294,9 +274,7 @@ void game_update_flags(game g) { bool game_is_over(cgame g) { for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { - if ((game_get_state(g, i, j) == S_BLANK && - game_get_flags(g, i, j) == S_BLANK) || - game_get_flags(g, i, j) == F_ERROR || + if ((game_get_state(g, i, j) == S_BLANK && game_get_flags(g, i, j) == S_BLANK) || game_get_flags(g, i, j) == F_ERROR || game_get_flags(g, i, j) == (F_LIGHTED | F_ERROR)) return false; } @@ -307,8 +285,7 @@ bool game_is_over(cgame g) { void game_restart(game g) { for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { - if (game_get_state(g, i, j) == S_MARK || - game_get_state(g, i, j) == S_LIGHTBULB) + if (game_get_state(g, i, j) == S_MARK || game_get_state(g, i, j) == S_LIGHTBULB) game_set_square(g, i, j, S_BLANK); } } diff --git a/game.h b/game.h index 3a2af8a..2206fb7 100644 --- a/game.h +++ b/game.h @@ -33,20 +33,20 @@ typedef unsigned int uint; * https://en.wikipedia.org/wiki/Bitwise_operations_in_C. **/ typedef enum { - /* states */ - S_BLANK = 0, /**< a blank square */ - S_LIGHTBULB = 1, /**< a light bulb */ - S_MARK = 2, /**< a marked square (as not-a-light) */ - S_BLACK = 8, /**< black wall base code */ - S_BLACK0 = S_BLACK, /**< a numbered black wall (with 0 adjacent lights) */ - S_BLACK1, /**< a numbered black wall (with 1 adjacent light) */ - S_BLACK2, /**< a numbered black wall (with 2 adjacent lights) */ - S_BLACK3, /**< a numbered black wall (with 3 adjacent lights) */ - S_BLACK4, /**< a numbered black wall (with 4 adjacent lights) */ - S_BLACKU, /**< an unnumbered black wall (any number of adjacent lights) */ - /* flags */ - F_LIGHTED = 16, /**< lighted flag */ - F_ERROR = 32 /**< error flag */ + /* states */ + S_BLANK = 0, /**< a blank square */ + S_LIGHTBULB = 1, /**< a light bulb */ + S_MARK = 2, /**< a marked square (as not-a-light) */ + S_BLACK = 8, /**< black wall base code */ + S_BLACK0 = S_BLACK, /**< a numbered black wall (with 0 adjacent lights) */ + S_BLACK1, /**< a numbered black wall (with 1 adjacent light) */ + S_BLACK2, /**< a numbered black wall (with 2 adjacent lights) */ + S_BLACK3, /**< a numbered black wall (with 3 adjacent lights) */ + S_BLACK4, /**< a numbered black wall (with 4 adjacent lights) */ + S_BLACKU, /**< an unnumbered black wall (any number of adjacent lights) */ + /* flags */ + F_LIGHTED = 16, /**< lighted flag */ + F_ERROR = 32 /**< error flag */ } square; /** state mask used in square enum */ @@ -61,14 +61,14 @@ typedef enum { /** * @brief The structure pointer that stores the game state. **/ -typedef struct game_s *game; +typedef struct game_s* game; /** * @brief The structure constant pointer that stores the game state. * @details That means that it is not possible to modify the game using this * pointer. **/ -typedef const struct game_s *cgame; +typedef const struct game_s* cgame; /** * @brief Creates a new game with default size and initializes it. @@ -78,7 +78,7 @@ typedef const struct game_s *cgame; * @pre @p squares must be an initialized array of default size squared. * @return the created game **/ -game game_new(square *squares); +game game_new(square* squares); /** * @brief Creates a new empty game with defaut size. @@ -251,7 +251,6 @@ bool game_is_lighted(cgame g, uint i, uint j); **/ bool game_has_error(cgame g, uint i, uint j); - /** * @brief Checks if a given move is legal. * @details This function checks that it is possible to play a move at a given diff --git a/game_aux.c b/game_aux.c index 9168c56..cb2c983 100644 --- a/game_aux.c +++ b/game_aux.c @@ -7,13 +7,10 @@ char charPrintCell(square sqState) { return ' '; } if ((sqState == S_LIGHTBULB) || - (sqState == (S_LIGHTBULB | F_ERROR)) | - (sqState == (S_LIGHTBULB | F_LIGHTED)) | - (sqState == (S_LIGHTBULB | F_ERROR | F_LIGHTED))) { + (sqState == (S_LIGHTBULB | F_ERROR)) | (sqState == (S_LIGHTBULB | F_LIGHTED)) | (sqState == (S_LIGHTBULB | F_ERROR | F_LIGHTED))) { return '*'; } - if ((sqState == S_MARK) || - (sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) { + if ((sqState == S_MARK) || (sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) { return '-'; } if (sqState == S_BLACK0 || sqState == (S_BLACK0 | F_ERROR)) { diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 24f823f..c418dbc 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -332,8 +332,7 @@ bool test_game_is_lighted(void) { return true; } game_set_square(g, 0, 0, S_BLANK | F_LIGHTED | F_ERROR); - if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && - game_is_lighted(g, 0, 0)) { + if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && game_is_lighted(g, 0, 0)) { game_delete(g); return true; } @@ -350,8 +349,7 @@ bool test_game_has_error(void) { return true; } game_set_square(g, 0, 0, S_LIGHTBULB | F_LIGHTED | F_ERROR); - if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && - game_has_error(g, 0, 0)) { + if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && game_has_error(g, 0, 0)) { game_delete(g); return true; } diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 7e54964..fc80d6c 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -58,9 +58,7 @@ bool test_game_restart(void) { bool test_game_new(void) { square tab[DEFAULT_SIZE * DEFAULT_SIZE]; game g; - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, - S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, - S_BLACK4, S_BLACKU, F_ERROR}; + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR}; for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { g = NULL; for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) { @@ -70,8 +68,7 @@ bool test_game_new(void) { g = game_new(tab); for (uint i2 = 0; i2 < DEFAULT_SIZE; i2++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { - printf("list :%d, get square :%d\n", list[i], - game_get_square(g, i2, j)); + printf("list :%d, get square :%d\n", list[i], game_get_square(g, i2, j)); assert(list[i] == game_get_square(g, i2, j)); } } @@ -87,8 +84,7 @@ bool test_game_new(void) { bool test_game_print(void) { square tab[DEFAULT_SIZE * DEFAULT_SIZE]; - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, - S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g; for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) { @@ -108,25 +104,14 @@ bool test_game_print(void) { bool test_game_get_square(void) { game g; square tab[DEFAULT_SIZE * DEFAULT_SIZE]; - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, - S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, - S_BLACK4, S_BLACKU, F_ERROR}; + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, 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]); + 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]); game_delete(g); } } @@ -192,8 +177,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { // if true we can break the loop because every others cases wont be lighted // by the bulb we are testing if (game_is_lightbulb(g, i, j)) { - if (/*test if this lightbulb is well updated*/ flags == S_BLANK || - flags == F_ERROR) { + if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) { // printf("156\n"); return 0; } @@ -214,8 +198,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { for (int i2 = i - 1; i2 >= 0; i2--) { flags = game_get_square(g, i2, j); // printf("i2:%d i2state:%d i2flags:%d\n",i2,state,flags); - if (flags == (S_LIGHTBULB | F_LIGHTED) || - flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { @@ -224,8 +207,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { } for (int i2 = i + 1; i2 < DEFAULT_SIZE; i2++) { flags = game_get_square(g, i2, j); - if (flags == (S_LIGHTBULB | F_LIGHTED) || - flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { @@ -234,8 +216,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { } for (int j2 = j - 1; j2 >= 0; j2--) { flags = game_get_square(g, i, j2); - if (flags == (S_LIGHTBULB | F_LIGHTED) || - flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { @@ -244,8 +225,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { } for (int j2 = j + 1; j2 < DEFAULT_SIZE; j2++) { flags = game_get_square(g, i, j2); - if (flags == (S_LIGHTBULB | F_LIGHTED) || - flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { @@ -270,17 +250,14 @@ bool check_update(game g) { for (uint j = 0; j < DEFAULT_SIZE; j++) { if (game_is_lightbulb(g, i, j)) { square flags = game_get_flags(g, i, j); - if (/*test if this lightbulb is well updated*/ flags == - S_BLANK || - flags == F_ERROR) { + if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) { // printf("196\n"); return false; } // loop checking every case before i wall = false; for (int k = i - 1; k >= 0; k--) { - if (/*test if current case is a wall*/ game_is_black(g, k, - j)) { + if (/*test if current case is a wall*/ game_is_black(g, k, j)) { wall = true; } else { int tmp = checklightbulb(g, k, j, wall); @@ -294,8 +271,7 @@ bool check_update(game g) { } wall = false; for (int k = i + 1; k < DEFAULT_SIZE; k++) { - if (/*test if current case is a wall*/ game_is_black(g, k, - j)) { + if (/*test if current case is a wall*/ game_is_black(g, k, j)) { wall = true; } else { int tmp = checklightbulb(g, k, j, wall); @@ -309,8 +285,7 @@ bool check_update(game g) { } wall = false; for (int k = j - 1; k >= 0; k--) { - if (/*test if current case is a wall*/ game_is_black(g, i, - k)) { + if (/*test if current case is a wall*/ game_is_black(g, i, k)) { wall = true; } else { int tmp = checklightbulb(g, i, k, wall); @@ -324,8 +299,7 @@ bool check_update(game g) { } wall = false; for (int k = j + 1; k < DEFAULT_SIZE; k++) { - if (/*test if current case is a wall*/ game_is_black(g, i, - k)) { + if (/*test if current case is a wall*/ game_is_black(g, i, k)) { wall = true; } else { int tmp = checklightbulb(g, i, k, wall); @@ -337,8 +311,7 @@ bool check_update(game g) { } } } - } else if (/*test if current case is a wall*/ game_is_black(g, i, - j)) { + } else if (/*test if current case is a wall*/ game_is_black(g, i, j)) { if (game_get_black_number(g, i, j) != -1) { // lookup for lightbulb and emptycells size = 0; @@ -370,8 +343,7 @@ bool check_update(game g) { notempty++; } for (int l = 0; l < size; l++) { - if (choice[l] == (S_LIGHTBULB | F_LIGHTED) || - choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + if (choice[l] == (S_LIGHTBULB | F_LIGHTED) || choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { lb++; } else if (choice[l] != S_BLANK) { notempty++; @@ -381,8 +353,7 @@ bool check_update(game g) { res = false; } // look if there is enough empty cell around the wall - else if (notempty > - abs(game_get_black_number(g, i, j) - 4)) { + else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { res = false; } if (game_get_flags(g, i, j) == F_ERROR) { @@ -410,8 +381,7 @@ bool brutforce(game g, int a, bool* deldup) { fprintf(stderr, "Not enought memory\n"); exit(EXIT_FAILURE); } - square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, - S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK}; + square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK}; for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { // printf("state: %d i:%d j:%d\n",game_get_state(g,i,j),i,j); diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 0754180..bc77498 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -122,8 +122,7 @@ bool test_game_is_black() { bool test_game_is_lightbulb() { game g = game_new_empty(); game_set_square(g, 0, 0, S_LIGHTBULB); - if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && - game_is_lightbulb(g, 0, 0)) { + if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_lightbulb(g, 0, 0)) { game_delete(g); return true; } diff --git a/game_text.c b/game_text.c index 46b9d55..57adcb1 100644 --- a/game_text.c +++ b/game_text.c @@ -79,8 +79,7 @@ int main(void) { return EXIT_SUCCESS; } else if (c == 'l' || c == 'm' || c == 'b') { if (scanf(" %u %u", &i, &j) == 2) { - if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && - !game_is_black(g, i, j)) { + if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && !game_is_black(g, i, j)) { if (c == 'l') { game_set_square(g, i, j, S_LIGHTBULB); game_update_flags(g); From ce2f96a79f83597d3a918fc5f3f8ec11103bccc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 9 Dec 2021 20:14:50 +0100 Subject: [PATCH 160/281] prob patched --- game.c | 127 +++++++++++++++++++++++---------------------------------- 1 file changed, 52 insertions(+), 75 deletions(-) diff --git a/game.c b/game.c index 95aa361..24c87a3 100644 --- a/game.c +++ b/game.c @@ -171,7 +171,7 @@ void game_play_move(game g, uint i, uint j, square s) { game_update_flags(g); } -void delete_flags(g) { +void delete_flags(game g) { // delete prev flags for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { @@ -180,92 +180,69 @@ void delete_flags(g) { } } +void addF_LIGHTED(game g, uint i, uint j) { + square flags = game_get_flags(g, i, j); + if (flags == S_BLANK) + game_set_square(g, i, j, game_get_state(g, i, j) | F_LIGHTED); + else if (flags == F_ERROR) { + game_set_square(g, i, j, game_get_state(g, i, j) | F_LIGHTED | F_ERROR); + } +} + void game_update_flags(game g) { delete_flags(g); // update flags lighted and lightbulb error - for (uint i = 0; i < DEFAULT_SIZE; i++) { - for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { if (game_get_state(g, i, j) == S_LIGHTBULB) { - if (game_get_flags(g, i, j) == F_ERROR) - game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - else - game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED)); - for (uint i2 = i + 1; i2 < DEFAULT_SIZE && !game_is_black(g, i2, j); i2++) { - if (game_get_state(g, i2, j) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - // update cases on FLIGHTED - game_set_square(g, i2, j, (game_get_state(g, i2, j) | F_LIGHTED)); - } - for (int i2 = i - 1; i2 >= 0 && !game_is_black(g, i2, j); i2--) { - if (game_get_state(g, i2, j) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - game_set_square(g, i2, j, (game_get_state(g, i2, j) | F_LIGHTED)); - } - for (int j2 = j - 1; j2 >= 0 && !game_is_black(g, i, j2); j2--) { - if (game_get_state(g, i, j2) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - game_set_square(g, i, j2, (game_get_state(g, i, j2) | F_LIGHTED)); - } - for (uint j2 = j + 1; j2 < DEFAULT_SIZE && !game_is_black(g, i, j2); j2++) { - if (game_get_state(g, i, j2) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - game_set_square(g, i, j2, (game_get_state(g, i, j2) | F_LIGHTED)); + // add FLIGHTED to the current lightbulb + addF_LIGHTED(g, i, j); + // add FLIGHTED on the 4 directions, when a wall is hit stop this direction, when another lightbulb is hit put the initial lighbulb on error + int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; + for (int x = 1; x < DEFAULT_SIZE; x++) { + for (uint y = 0; y < 7; y = y + 2) { + if (tab[y] != tab[y + 1] && j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < DEFAULT_SIZE && i + x * tab[y] >= 0 && + i + x * tab[y] < DEFAULT_SIZE) { + if (game_is_black(g, i + x * tab[y], j + x * tab[y + 1])) { + tab[y] = 0; + tab[y + 1] = 0; + } else { + // if we found another lightbulb on the line + if (game_get_state(g, i + x * tab[y], j + x * tab[y + 1]) == S_LIGHTBULB) + // update initial lightbulb on F_ERROR + game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + addF_LIGHTED(g, i + x * tab[y], j + x * tab[y + 1]); + } + } + } } } } } - // update flags wall - for (uint i = 0; i < DEFAULT_SIZE; i++) { - for (uint j = 0; j < DEFAULT_SIZE; j++) { - if (game_is_black(g, i, j)) { - if (game_get_black_number(g, i, j) >= 0) { - square choice[4]; - int size = 0; - int lb = 0; - int notempty = 0; - if (i > 0) { - choice[size] = game_get_square(g, i - 1, j); - size++; - } else { - notempty++; - } - if (i < DEFAULT_SIZE - 1) { - choice[size] = game_get_square(g, i + 1, j); - size++; - } else { - notempty++; - } - if (j > 0) { - choice[size] = game_get_square(g, i, j - 1); - size++; - } else { - notempty++; - } - if (j < DEFAULT_SIZE - 1) { - choice[size] = game_get_square(g, i, j + 1); - size++; - } else { - notempty++; - } - for (int l = 0; l < size; l++) { - if (choice[l] == S_LIGHTBULB || choice[l] == (S_LIGHTBULB | F_LIGHTED) || choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + // update flags wall (need to wait all FLIGHTED being updated) + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + if (game_is_black(g, i, j) && game_get_black_number(g, i, j) >= 0) { + int lb = 0; + int notempty = 0; + int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; + for (uint y = 0; y < 7; y = y + 2) { + if (j + tab[y + 1] >= 0 && j + tab[y + 1] < DEFAULT_SIZE && i + tab[y] >= 0 && i + tab[y] < DEFAULT_SIZE) { + if (game_is_lightbulb(g, i + tab[y], j + tab[y + 1])) lb++; - } else if (choice[l] != S_BLANK) { + else if (!game_is_blank(g, i + tab[y], j + tab[y + 1])) notempty++; - } - } - if (lb > game_get_black_number(g, i, j)) { - game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); - } - // look if there is enough empty cell around the wall - else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { - game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); + } else { + notempty++; } } + if (lb > game_get_black_number(g, i, j)) { + game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); + } + // look if there is enough empty cell around the wall + else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { + game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); + } } } } From f1fa1cc3baa94062cbd064072438195e9c03274b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 9 Dec 2021 20:33:53 +0100 Subject: [PATCH 161/281] patched game is lighted --- game.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/game.c b/game.c index 24c87a3..a04d836 100644 --- a/game.c +++ b/game.c @@ -122,14 +122,11 @@ bool game_is_blank(cgame g, uint i, uint j) { } bool game_is_lightbulb(cgame g, uint i, uint j) { - return ((g->tab_cell[i][j] == S_LIGHTBULB) || (g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED)) || (g->tab_cell[i][j] == (S_LIGHTBULB | F_ERROR)) || - (g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED | F_ERROR))); + return game_get_state(g, i, j) == S_LIGHTBULB; } bool game_is_black(cgame g, uint i, uint j) { - if (game_get_state(g, i, j) >= 8 && game_get_state(g, i, j) <= 13) - return true; - return false; + return game_get_state(g, i, j) >= S_BLACK0 && game_get_state(g, i, j) <= S_BLACKU; } int game_get_black_number(cgame g, uint i, uint j) { @@ -139,25 +136,15 @@ int game_get_black_number(cgame g, uint i, uint j) { } bool game_is_marked(cgame g, uint i, uint j) { - return ((g->tab_cell[i][j] == S_MARK) || (g->tab_cell[i][j] == (S_MARK | F_LIGHTED)) || (g->tab_cell[i][j] == (S_MARK | F_ERROR)) || - (g->tab_cell[i][j] == (S_MARK | F_LIGHTED | F_ERROR))); + return game_get_state(g, i, j) == S_MARK; } bool game_is_lighted(cgame g, uint i, uint j) { - if (g->tab_cell[i][j] >= F_ERROR) { - g->tab_cell[i][j] -= F_ERROR; - } - if (g->tab_cell[i][j] >= F_LIGHTED) { - return true; - } - return false; + return game_get_flags(g, i, j) >= F_LIGHTED; } bool game_has_error(cgame g, uint i, uint j) { - if (g->tab_cell[i][j] >= F_ERROR) { - return true; - } - return false; + return g->tab_cell[i][j] >= F_ERROR; } bool game_check_move(cgame g, uint i, uint j, square s) { From 6b956071f85fbe6157d01ca98d7cfe8dc5cfe478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 9 Dec 2021 20:37:45 +0100 Subject: [PATCH 162/281] prob patched --- game.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game.c b/game.c index a04d836..524892f 100644 --- a/game.c +++ b/game.c @@ -118,7 +118,7 @@ square game_get_flags(cgame g, uint i, uint j) { } bool game_is_blank(cgame g, uint i, uint j) { - return (g->tab_cell[i][j] == S_BLANK); + return game_get_state(g, i, j) == S_BLANK; } bool game_is_lightbulb(cgame g, uint i, uint j) { @@ -217,7 +217,7 @@ void game_update_flags(game g) { if (j + tab[y + 1] >= 0 && j + tab[y + 1] < DEFAULT_SIZE && i + tab[y] >= 0 && i + tab[y] < DEFAULT_SIZE) { if (game_is_lightbulb(g, i + tab[y], j + tab[y + 1])) lb++; - else if (!game_is_blank(g, i + tab[y], j + tab[y + 1])) + else if (!game_is_blank(g, i + tab[y], j + tab[y + 1]) || game_is_lighted(g, i + tab[y], j + tab[y + 1])) notempty++; } else { notempty++; From aac7da4685ce360fa84f3d581711d65526078670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 9 Dec 2021 20:42:04 +0100 Subject: [PATCH 163/281] oops --- .clang-format | 2 +- game.c | 189 +++++++++++++++--------------------------- game.h | 35 ++++---- game_aux.c | 7 +- game_test_nnunes.c | 6 +- game_test_thoguet.c | 72 +++++----------- game_test_thperrier.c | 3 +- game_text.c | 3 +- 8 files changed, 110 insertions(+), 207 deletions(-) diff --git a/.clang-format b/.clang-format index 1c5cae1..d8ebf68 100644 --- a/.clang-format +++ b/.clang-format @@ -45,7 +45,7 @@ BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true -ColumnLimit: 80 +ColumnLimit: 160 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true diff --git a/game.c b/game.c index ff550ba..912819d 100644 --- a/game.c +++ b/game.c @@ -112,20 +112,15 @@ square game_get_flags(cgame g, uint i, uint j) { } bool game_is_blank(cgame g, uint i, uint j) { - return (g->tab_cell[i][j] == S_BLANK); + return game_get_state(g, i, j) == S_BLANK; } bool game_is_lightbulb(cgame g, uint i, uint j) { - return ((g->tab_cell[i][j] == S_LIGHTBULB) || - (g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED)) || - (g->tab_cell[i][j] == (S_LIGHTBULB | F_ERROR)) || - (g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED | F_ERROR))); + return game_get_state(g, i, j) == S_LIGHTBULB; } bool game_is_black(cgame g, uint i, uint j) { - if (game_get_state(g, i, j) >= 8 && game_get_state(g, i, j) <= 13) - return true; - return false; + return game_get_state(g, i, j) >= S_BLACK0 && game_get_state(g, i, j) <= S_BLACKU; } int game_get_black_number(cgame g, uint i, uint j) { @@ -135,33 +130,19 @@ int game_get_black_number(cgame g, uint i, uint j) { } bool game_is_marked(cgame g, uint i, uint j) { - return ((g->tab_cell[i][j] == S_MARK) || - (g->tab_cell[i][j] == (S_MARK | F_LIGHTED)) || - (g->tab_cell[i][j] == (S_MARK | F_ERROR)) || - (g->tab_cell[i][j] == (S_MARK | F_LIGHTED | F_ERROR))); + return game_get_state(g, i, j) == S_MARK; } bool game_is_lighted(cgame g, uint i, uint j) { - if (g->tab_cell[i][j] >= F_ERROR) { - g->tab_cell[i][j] -= F_ERROR; - } - if (g->tab_cell[i][j] >= F_LIGHTED) { - return true; - } - return false; + return game_get_flags(g, i, j) >= F_LIGHTED; } bool game_has_error(cgame g, uint i, uint j) { - if (g->tab_cell[i][j] >= F_ERROR) { - return true; - } - return false; + return g->tab_cell[i][j] >= F_ERROR; } bool game_check_move(cgame g, uint i, uint j, square s) { - if (i >= DEFAULT_SIZE || j >= DEFAULT_SIZE || - (s != S_BLANK && s != S_MARK && s != S_LIGHTBULB) || - game_is_black(g, i, j)) + if (i >= DEFAULT_SIZE || j >= DEFAULT_SIZE || (s != S_BLANK && s != S_MARK && s != S_LIGHTBULB) || game_is_black(g, i, j)) return false; return true; } @@ -171,115 +152,78 @@ void game_play_move(game g, uint i, uint j, square s) { game_update_flags(g); } -void game_update_flags(game g) { +void delete_flags(game g) { // delete prev flags for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { game_set_square(g, i, j, game_get_state(g, i, j)); } } +} + +void addF_LIGHTED(game g, uint i, uint j) { + square flags = game_get_flags(g, i, j); + if (flags == S_BLANK) + game_set_square(g, i, j, game_get_state(g, i, j) | F_LIGHTED); + else if (flags == F_ERROR) { + game_set_square(g, i, j, game_get_state(g, i, j) | F_LIGHTED | F_ERROR); + } +} + +void game_update_flags(game g) { + delete_flags(g); // update flags lighted and lightbulb error - for (uint i = 0; i < DEFAULT_SIZE; i++) { - for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { if (game_get_state(g, i, j) == S_LIGHTBULB) { - if (game_get_flags(g, i, j) > 16) - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - else - game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED)); - for (uint i2 = i + 1; - i2 < DEFAULT_SIZE && !game_is_black(g, i2, j); i2++) { - if (game_get_state(g, i2, j) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - // update cases on FLIGHTED - game_set_square(g, i2, j, - (game_get_state(g, i2, j) | F_LIGHTED)); - } - for (int i2 = i - 1; i2 >= 0 && !game_is_black(g, i2, j); - i2--) { - if (game_get_state(g, i2, j) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - game_set_square(g, i2, j, - (game_get_state(g, i2, j) | F_LIGHTED)); - } - for (int j2 = j - 1; j2 >= 0 && !game_is_black(g, i, j2); - j2--) { - if (game_get_state(g, i, j2) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - game_set_square(g, i, j2, - (game_get_state(g, i, j2) | F_LIGHTED)); - } - for (uint j2 = j + 1; - j2 < DEFAULT_SIZE && !game_is_black(g, i, j2); j2++) { - if (game_get_state(g, i, j2) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, - (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - game_set_square(g, i, j2, - (game_get_state(g, i, j2) | F_LIGHTED)); + // add FLIGHTED to the current lightbulb + addF_LIGHTED(g, i, j); + // add FLIGHTED on the 4 directions, when a wall is hit stop this direction, when another lightbulb is hit put the initial lighbulb on error + int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; + for (int x = 1; x < DEFAULT_SIZE; x++) { + for (uint y = 0; y < 7; y = y + 2) { + if (tab[y] != tab[y + 1] && j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < DEFAULT_SIZE && i + x * tab[y] >= 0 && + i + x * tab[y] < DEFAULT_SIZE) { + if (game_is_black(g, i + x * tab[y], j + x * tab[y + 1])) { + tab[y] = 0; + tab[y + 1] = 0; + } else { + // if we found another lightbulb on the line + if (game_get_state(g, i + x * tab[y], j + x * tab[y + 1]) == S_LIGHTBULB) + // update initial lightbulb on F_ERROR + game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + addF_LIGHTED(g, i + x * tab[y], j + x * tab[y + 1]); + } + } + } } } } } - // update flags wall - for (uint i = 0; i < DEFAULT_SIZE; i++) { - for (uint j = 0; j < DEFAULT_SIZE; j++) { - if (game_is_black(g, i, j)) { - if (game_get_black_number(g, i, j) >= 0) { - square choice[4]; - int size = 0; - int lb = 0; - int notempty = 0; - if (i > 0) { - choice[size] = game_get_square(g, i - 1, j); - size++; - } else { - notempty++; - } - if (i < DEFAULT_SIZE - 1) { - choice[size] = game_get_square(g, i + 1, j); - size++; - } else { - notempty++; - } - if (j > 0) { - choice[size] = game_get_square(g, i, j - 1); - size++; - } else { - notempty++; - } - if (j < DEFAULT_SIZE - 1) { - choice[size] = game_get_square(g, i, j + 1); - size++; - } else { - notempty++; - } - for (int l = 0; l < size; l++) { - if (choice[l] == S_LIGHTBULB || - choice[l] == (S_LIGHTBULB | F_LIGHTED) || - choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + // update flags wall (need to wait all FLIGHTED being updated) + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + if (game_is_black(g, i, j) && game_get_black_number(g, i, j) >= 0) { + int lb = 0; + int notempty = 0; + int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; + for (uint y = 0; y < 7; y = y + 2) { + if (j + tab[y + 1] >= 0 && j + tab[y + 1] < DEFAULT_SIZE && i + tab[y] >= 0 && i + tab[y] < DEFAULT_SIZE) { + if (game_is_lightbulb(g, i + tab[y], j + tab[y + 1])) lb++; - } else if (choice[l] != S_BLANK) { + else if (!game_is_blank(g, i + tab[y], j + tab[y + 1]) || game_is_lighted(g, i + tab[y], j + tab[y + 1])) notempty++; - } - } - if (lb > game_get_black_number(g, i, j)) { - game_set_square(g, i, j, - (game_get_state(g, i, j) | F_ERROR)); - } - // look if there is enough empty cell around the wall - else if (notempty > - abs(game_get_black_number(g, i, j) - 4)) { - game_set_square(g, i, j, - (game_get_state(g, i, j) | F_ERROR)); + } else { + notempty++; } } + if (lb > game_get_black_number(g, i, j)) { + game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); + } + // look if there is enough empty cell around the wall + else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { + game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); + } } } } @@ -288,9 +232,7 @@ void game_update_flags(game g) { bool game_is_over(cgame g) { for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { - if ((game_get_state(g, i, j) == S_BLANK && - game_get_flags(g, i, j) == S_BLANK) || - game_get_flags(g, i, j) == F_ERROR || + if ((game_get_state(g, i, j) == S_BLANK && game_get_flags(g, i, j) == S_BLANK) || game_get_flags(g, i, j) == F_ERROR || game_get_flags(g, i, j) == (F_LIGHTED | F_ERROR)) return false; } @@ -301,8 +243,7 @@ bool game_is_over(cgame g) { void game_restart(game g) { for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { - if (game_get_state(g, i, j) == S_MARK || - game_get_state(g, i, j) == S_LIGHTBULB) + if (game_get_state(g, i, j) == S_MARK || game_get_state(g, i, j) == S_LIGHTBULB) game_set_square(g, i, j, S_BLANK); } } diff --git a/game.h b/game.h index 3a2af8a..2206fb7 100644 --- a/game.h +++ b/game.h @@ -33,20 +33,20 @@ typedef unsigned int uint; * https://en.wikipedia.org/wiki/Bitwise_operations_in_C. **/ typedef enum { - /* states */ - S_BLANK = 0, /**< a blank square */ - S_LIGHTBULB = 1, /**< a light bulb */ - S_MARK = 2, /**< a marked square (as not-a-light) */ - S_BLACK = 8, /**< black wall base code */ - S_BLACK0 = S_BLACK, /**< a numbered black wall (with 0 adjacent lights) */ - S_BLACK1, /**< a numbered black wall (with 1 adjacent light) */ - S_BLACK2, /**< a numbered black wall (with 2 adjacent lights) */ - S_BLACK3, /**< a numbered black wall (with 3 adjacent lights) */ - S_BLACK4, /**< a numbered black wall (with 4 adjacent lights) */ - S_BLACKU, /**< an unnumbered black wall (any number of adjacent lights) */ - /* flags */ - F_LIGHTED = 16, /**< lighted flag */ - F_ERROR = 32 /**< error flag */ + /* states */ + S_BLANK = 0, /**< a blank square */ + S_LIGHTBULB = 1, /**< a light bulb */ + S_MARK = 2, /**< a marked square (as not-a-light) */ + S_BLACK = 8, /**< black wall base code */ + S_BLACK0 = S_BLACK, /**< a numbered black wall (with 0 adjacent lights) */ + S_BLACK1, /**< a numbered black wall (with 1 adjacent light) */ + S_BLACK2, /**< a numbered black wall (with 2 adjacent lights) */ + S_BLACK3, /**< a numbered black wall (with 3 adjacent lights) */ + S_BLACK4, /**< a numbered black wall (with 4 adjacent lights) */ + S_BLACKU, /**< an unnumbered black wall (any number of adjacent lights) */ + /* flags */ + F_LIGHTED = 16, /**< lighted flag */ + F_ERROR = 32 /**< error flag */ } square; /** state mask used in square enum */ @@ -61,14 +61,14 @@ typedef enum { /** * @brief The structure pointer that stores the game state. **/ -typedef struct game_s *game; +typedef struct game_s* game; /** * @brief The structure constant pointer that stores the game state. * @details That means that it is not possible to modify the game using this * pointer. **/ -typedef const struct game_s *cgame; +typedef const struct game_s* cgame; /** * @brief Creates a new game with default size and initializes it. @@ -78,7 +78,7 @@ typedef const struct game_s *cgame; * @pre @p squares must be an initialized array of default size squared. * @return the created game **/ -game game_new(square *squares); +game game_new(square* squares); /** * @brief Creates a new empty game with defaut size. @@ -251,7 +251,6 @@ bool game_is_lighted(cgame g, uint i, uint j); **/ bool game_has_error(cgame g, uint i, uint j); - /** * @brief Checks if a given move is legal. * @details This function checks that it is possible to play a move at a given diff --git a/game_aux.c b/game_aux.c index 9168c56..cb2c983 100644 --- a/game_aux.c +++ b/game_aux.c @@ -7,13 +7,10 @@ char charPrintCell(square sqState) { return ' '; } if ((sqState == S_LIGHTBULB) || - (sqState == (S_LIGHTBULB | F_ERROR)) | - (sqState == (S_LIGHTBULB | F_LIGHTED)) | - (sqState == (S_LIGHTBULB | F_ERROR | F_LIGHTED))) { + (sqState == (S_LIGHTBULB | F_ERROR)) | (sqState == (S_LIGHTBULB | F_LIGHTED)) | (sqState == (S_LIGHTBULB | F_ERROR | F_LIGHTED))) { return '*'; } - if ((sqState == S_MARK) || - (sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) { + if ((sqState == S_MARK) || (sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) { return '-'; } if (sqState == S_BLACK0 || sqState == (S_BLACK0 | F_ERROR)) { diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 24f823f..c418dbc 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -332,8 +332,7 @@ bool test_game_is_lighted(void) { return true; } game_set_square(g, 0, 0, S_BLANK | F_LIGHTED | F_ERROR); - if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && - game_is_lighted(g, 0, 0)) { + if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && game_is_lighted(g, 0, 0)) { game_delete(g); return true; } @@ -350,8 +349,7 @@ bool test_game_has_error(void) { return true; } game_set_square(g, 0, 0, S_LIGHTBULB | F_LIGHTED | F_ERROR); - if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && - game_has_error(g, 0, 0)) { + if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && game_has_error(g, 0, 0)) { game_delete(g); return true; } diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 7e54964..fc80d6c 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -58,9 +58,7 @@ bool test_game_restart(void) { bool test_game_new(void) { square tab[DEFAULT_SIZE * DEFAULT_SIZE]; game g; - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, - S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, - S_BLACK4, S_BLACKU, F_ERROR}; + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR}; for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { g = NULL; for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) { @@ -70,8 +68,7 @@ bool test_game_new(void) { g = game_new(tab); for (uint i2 = 0; i2 < DEFAULT_SIZE; i2++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { - printf("list :%d, get square :%d\n", list[i], - game_get_square(g, i2, j)); + printf("list :%d, get square :%d\n", list[i], game_get_square(g, i2, j)); assert(list[i] == game_get_square(g, i2, j)); } } @@ -87,8 +84,7 @@ bool test_game_new(void) { bool test_game_print(void) { square tab[DEFAULT_SIZE * DEFAULT_SIZE]; - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, - S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g; for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) { @@ -108,25 +104,14 @@ bool test_game_print(void) { bool test_game_get_square(void) { game g; square tab[DEFAULT_SIZE * DEFAULT_SIZE]; - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, - S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, - S_BLACK4, S_BLACKU, F_ERROR}; + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, 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]); + 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]); game_delete(g); } } @@ -192,8 +177,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { // if true we can break the loop because every others cases wont be lighted // by the bulb we are testing if (game_is_lightbulb(g, i, j)) { - if (/*test if this lightbulb is well updated*/ flags == S_BLANK || - flags == F_ERROR) { + if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) { // printf("156\n"); return 0; } @@ -214,8 +198,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { for (int i2 = i - 1; i2 >= 0; i2--) { flags = game_get_square(g, i2, j); // printf("i2:%d i2state:%d i2flags:%d\n",i2,state,flags); - if (flags == (S_LIGHTBULB | F_LIGHTED) || - flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { @@ -224,8 +207,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { } for (int i2 = i + 1; i2 < DEFAULT_SIZE; i2++) { flags = game_get_square(g, i2, j); - if (flags == (S_LIGHTBULB | F_LIGHTED) || - flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { @@ -234,8 +216,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { } for (int j2 = j - 1; j2 >= 0; j2--) { flags = game_get_square(g, i, j2); - if (flags == (S_LIGHTBULB | F_LIGHTED) || - flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { @@ -244,8 +225,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { } for (int j2 = j + 1; j2 < DEFAULT_SIZE; j2++) { flags = game_get_square(g, i, j2); - if (flags == (S_LIGHTBULB | F_LIGHTED) || - flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { @@ -270,17 +250,14 @@ bool check_update(game g) { for (uint j = 0; j < DEFAULT_SIZE; j++) { if (game_is_lightbulb(g, i, j)) { square flags = game_get_flags(g, i, j); - if (/*test if this lightbulb is well updated*/ flags == - S_BLANK || - flags == F_ERROR) { + if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) { // printf("196\n"); return false; } // loop checking every case before i wall = false; for (int k = i - 1; k >= 0; k--) { - if (/*test if current case is a wall*/ game_is_black(g, k, - j)) { + if (/*test if current case is a wall*/ game_is_black(g, k, j)) { wall = true; } else { int tmp = checklightbulb(g, k, j, wall); @@ -294,8 +271,7 @@ bool check_update(game g) { } wall = false; for (int k = i + 1; k < DEFAULT_SIZE; k++) { - if (/*test if current case is a wall*/ game_is_black(g, k, - j)) { + if (/*test if current case is a wall*/ game_is_black(g, k, j)) { wall = true; } else { int tmp = checklightbulb(g, k, j, wall); @@ -309,8 +285,7 @@ bool check_update(game g) { } wall = false; for (int k = j - 1; k >= 0; k--) { - if (/*test if current case is a wall*/ game_is_black(g, i, - k)) { + if (/*test if current case is a wall*/ game_is_black(g, i, k)) { wall = true; } else { int tmp = checklightbulb(g, i, k, wall); @@ -324,8 +299,7 @@ bool check_update(game g) { } wall = false; for (int k = j + 1; k < DEFAULT_SIZE; k++) { - if (/*test if current case is a wall*/ game_is_black(g, i, - k)) { + if (/*test if current case is a wall*/ game_is_black(g, i, k)) { wall = true; } else { int tmp = checklightbulb(g, i, k, wall); @@ -337,8 +311,7 @@ bool check_update(game g) { } } } - } else if (/*test if current case is a wall*/ game_is_black(g, i, - j)) { + } else if (/*test if current case is a wall*/ game_is_black(g, i, j)) { if (game_get_black_number(g, i, j) != -1) { // lookup for lightbulb and emptycells size = 0; @@ -370,8 +343,7 @@ bool check_update(game g) { notempty++; } for (int l = 0; l < size; l++) { - if (choice[l] == (S_LIGHTBULB | F_LIGHTED) || - choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + if (choice[l] == (S_LIGHTBULB | F_LIGHTED) || choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { lb++; } else if (choice[l] != S_BLANK) { notempty++; @@ -381,8 +353,7 @@ bool check_update(game g) { res = false; } // look if there is enough empty cell around the wall - else if (notempty > - abs(game_get_black_number(g, i, j) - 4)) { + else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { res = false; } if (game_get_flags(g, i, j) == F_ERROR) { @@ -410,8 +381,7 @@ bool brutforce(game g, int a, bool* deldup) { fprintf(stderr, "Not enought memory\n"); exit(EXIT_FAILURE); } - square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, - S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK}; + square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK}; for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { // printf("state: %d i:%d j:%d\n",game_get_state(g,i,j),i,j); diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 0754180..bc77498 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -122,8 +122,7 @@ bool test_game_is_black() { bool test_game_is_lightbulb() { game g = game_new_empty(); game_set_square(g, 0, 0, S_LIGHTBULB); - if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && - game_is_lightbulb(g, 0, 0)) { + if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_lightbulb(g, 0, 0)) { game_delete(g); return true; } diff --git a/game_text.c b/game_text.c index 46b9d55..57adcb1 100644 --- a/game_text.c +++ b/game_text.c @@ -79,8 +79,7 @@ int main(void) { return EXIT_SUCCESS; } else if (c == 'l' || c == 'm' || c == 'b') { if (scanf(" %u %u", &i, &j) == 2) { - if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && - !game_is_black(g, i, j)) { + if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && !game_is_black(g, i, j)) { if (c == 'l') { game_set_square(g, i, j, S_LIGHTBULB); game_update_flags(g); From 977d180a79b0e3a2863bbda21e4548cfd7bb4199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Thu, 9 Dec 2021 23:52:26 +0100 Subject: [PATCH 164/281] started history --- history.c | 148 +++++++++++++++++++++++++++++++++++++++ history.h | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 350 insertions(+) create mode 100644 history.c create mode 100644 history.h diff --git a/history.c b/history.c new file mode 100644 index 0000000..5e58035 --- /dev/null +++ b/history.c @@ -0,0 +1,148 @@ +#include "history.h" +#include +#include + +void memoryError(void) { + fprintf(stderr, "Not enought memory\n"); + exit(EXIT_FAILURE); +} + +void errPointer(void) { + fprintf(stderr, "Error on the given pointer\n"); + exit(EXIT_FAILURE); +} + +history history_alloc() { + history h = (history)malloc(sizeof(struct s_history)); + if (h == NULL) + memoryError(); + h->i = 0; + h->j = 0; + h->next = NULL; + h->prev = NULL; + return h; +} + +void history_free(history h) { + free(h); + h = NULL; +} + +history history_create_empty(void) { + return NULL; +} + +bool history_is_empty(history h) { + return h == NULL; +} + +history history_next(history h) { + if (history_is_empty(h)) + errPointer(); + return h->next; +} + +history history_prev(history h) { + if (history_is_empty(h)) + errPointer(); + return h->prev; +} + +square history_state(history h) { + if (history_is_empty(h)) + errPointer(); + return h->state; +} + +square history_i(history h) { + if (history_is_empty(h)) + errPointer(); + return h->i; +} + +square history_j(history h) { + if (history_is_empty(h)) + errPointer(); + return h->j; +} + +history history_insert_first(history h, square state, uint i, uint j) { + history new = history_alloc(); + new->state = state; + new->i = i; + new->j = j; + new->next = h; + if (!history_is_empty(h)) + h->prev = new; + return new; +} + +history history_delete_first(history h) { + if (!history_is_empty(h)) { + history tmp = h->next; + history_free(h); + h = tmp; + if (!history_is_empty(h)) { + h->prev = NULL; + } + } + return h; +} + +history history_insert_after(history h, history p, square state, uint i, uint j) { + if (history_is_empty(h) || history_is_empty(p)) + errPointer(); + history new = history_alloc(); + new->state = state; + new->i = i; + new->j = j; + new->next = p->next; + p->next = new; + new->prev = p; + if (!history_is_empty(history_next(new))) + new->next->prev = new; + return h; +} + +history history_delete_after(history h, history p) { + if (history_is_empty(h) || history_is_empty(p)) + errPointer(); + if (!history_is_empty(history_next(p))) { + history to_be_deleted = p->next; + if (!history_is_empty(history_next(to_be_deleted))) { + to_be_deleted->next->prev = p; + } + p->next = to_be_deleted->next; + history_free(to_be_deleted); + } + return h; +} + +history history_insert_before(history h, history p, square state, uint i, uint j) { + if (history_is_empty(h) || history_is_empty(p)) + errPointer(); + history new = history_alloc(); + new->state = state; + new->i = i; + new->j = j; + new->next = p; + new->prev = p->prev; + p->prev = new; + if (!history_is_empty(history_prev(new))) + new->prev->next = new; + return h; +} + +history history_delete_before(history h, history p) { + if (history_is_empty(h) || history_is_empty(p)) + errPointer(); + if (!history_is_empty(history_prev(p))) { + history to_be_deleted = p->prev; + if (!history_is_empty(history_prev(to_be_deleted))) { + to_be_deleted->prev->next = p; + } + p->prev = to_be_deleted->prev; + history_free(to_be_deleted); + } + return h; +} \ No newline at end of file diff --git a/history.h b/history.h new file mode 100644 index 0000000..e117741 --- /dev/null +++ b/history.h @@ -0,0 +1,202 @@ +#ifndef __HISTORY_H__ +#define __HISTORY_H__ +#include +#include "game.h" + +struct s_history { + square state; + uint i; + uint j; + struct s_history* next; + struct s_history* prev; +}; + +typedef struct s_history* history; + +/** + * @brief fprintf not enought memory + exit + **/ +void memoryError(void); + +/** + * @brief fprintf error on the given pointer + exit + */ +void errPointer(void); + +/** + * @brief Alloc a new empty history. + * @return The allocated history. + **/ +history history_alloc(); + +/** + * @brief Free the given history. + * @param h The history to be free. + **/ +void history_free(history h); + +/** + * @brief Create a empty history object + * + * @return An empty history + **/ +history history_create_empty(void); + +/** + * @brief Delete every element after h + * + * @param h the head of the history + * @return the new history (NULL) + */ +history history_delete_entire_history(history h); + +/** + * @brief Test if the given history is empty or not. + * + * @param h the history to test. + * @pre @p h must be a valid pointer toward an history . + * @return true if the history is empty + * @return false if the history isn't empty + */ +bool history_is_empty(history h); + +/** + * @brief Gets the next element of the given history. + * + * @param h An history. + * @pre @p h must be a valid pointer toward an history . + * @return the next of the given history. + */ +history history_next(history h); + +/** + * @brief Gets the previous element of the given history. + * + * @param h An history. + * @pre @p h must be a valid pointer toward an history . + * @return the previous element of the given history. + */ +history history_prev(history h); + +/** + * @brief Gets the state of the given history + * + * @param h An history. + * @pre @p h must be a valid pointer toward an history . + * @return the state of the given history + */ +square history_state(history h); + +/** + * @brief Get the coordinates i of the given history. + * + * @param h An history. + * @pre @p h must be a valid pointer toward an history . + * @return the coordinates i. + */ +uint history_i(history h); + +/** + * @brief Get the coordinates j of the given history. + * + * @param h An history. + * @pre @p h must be a valid pointer toward an history . + * @return the coordinates j. + */ +uint history_j(history h); + +/** + * @brief Insert a new element a the beginning of the history. + * + * @param h An history (empty or not) + * @param state state of the new element + * @param i the coordinate i of the new element + * @param j the coordinate j of the new element + * @return The new first element of history + */ +history history_insert_first(history h, square state, uint i, uint j); +/** + * @brief Delete the first element of the history + * + * @param h An history + * @return the new first element of the history + */ +history history_delete_first(history h); + +/** + * @brief Insert a new element after p + * + * @param h An history + * @param p Where we insert after the new element + * @param state The state of the new element + * @param i the coordinate i of the new element + * @param j the coordinate j of the new element + * @pre @p h must be a valid pointer toward an history. + * @pre @p p must be a valid pointer toward an history element. + * @return h + */ +history history_insert_after(history h, history p, square state, uint i, uint j); + +/** + * @brief Delete the element after p + * + * @param h An history + * @param p where we delete after + * @pre @p h must be a valid pointer toward an history. + * @pre @p p must be a valid pointer toward an history element. + * @return h + */ +history history_delete_after(history h, history p); + +/** + * @brief Insert a new element before p + * + * @param h An history + * @param p Where we insert before the new element + * @param state The state of the new element + * @param i the coordinate i of the new element + * @param j the coordinate j of the new element + * @pre @p h must be a valid pointer toward an history. + * @pre @p p must be a valid pointer toward an history element. + * @return h + */ +history history_insert_before(history h, history p, square state, uint i, uint j); + +/** + * @brief Delete the element before p + * + * @param h An history + * @param p where we delete before + * @pre @p h must be a valid pointer toward an history. + * @pre @p p must be a valid pointer toward an history element. + * @return h + */ +history history_delete_before(history h, history p); + +/** + * @brief Gets the last element of the history + * + * @param h An history + * @return The last element of the given history + */ +history history_last(history h); + +/** + * @brief Gets the first element of the history + * + * @param h An history + * @return The first element of the history. + */ +history history_first(history h); + +/** + * @brief Add an element at the end of the list. + * + * @param h an history + * @param state the state of the new element + * @param i the coordinate i of the new element + * @param j the coordinate j of the new element + * @return h + */ +history history_append(history h, square state, uint i, uint j); +#endif \ No newline at end of file From 4c5933477f9da41bb3612c72f73d28f4cab5fe7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Fri, 10 Dec 2021 01:46:14 +0100 Subject: [PATCH 165/281] finished history + tests --- CMakeLists.txt | 22 ++++- history.c | 69 ++++++++++++--- history.h | 12 ++- history_test.c | 221 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 308 insertions(+), 16 deletions(-) create mode 100644 history_test.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d9796b0..09c7f15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,13 +16,17 @@ add_executable(game_text game_text.c) add_executable(game_test_thoguet game_test_thoguet.c) add_executable(game_test_thperrier game_test_thperrier.c) add_executable(game_test_nnunes game_test_nnunes.c) +add_executable(history_test history_test.c) #les dépendances sont calculées automatiquement target_link_libraries(game_text game) target_link_libraries(game_test_thoguet game) target_link_libraries(game_test_thperrier game) target_link_libraries(game_test_nnunes game) +target_link_libraries(history_test game history) + add_library (game game.c game_aux.c) +add_library(history history.c) add_test(test_thoguet_dummy ./game_test_thoguet dummy) add_test(test_thoguet_game_new ./game_test_thoguet game_new) @@ -52,4 +56,20 @@ add_test(test_nnunes_game_get_state ./game_test_nnunes game_get_state) add_test(test_nnunes_game_get_flags ./game_test_nnunes game_get_flags) add_test(test_nnunes_game_is_marked ./game_test_nnunes game_is_marked) add_test(test_nnunes_game_is_lighted ./game_test_nnunes game_is_lighted) -add_test(test_nnunes_game_has_error ./game_test_nnunes game_has_error) \ No newline at end of file +add_test(test_nnunes_game_has_error ./game_test_nnunes game_has_error) + +add_test(test_history_history_alloc ./history_test history_alloc) +add_test(test_history_create_empty ./history_test history_create_empty) +add_test(test_history_delete_entire_history ./history_test history_delete_entire_history) +add_test(test_history_is_empty ./history_test history_is_empty) +add_test(test_history_next ./history_test history_next) +add_test(test_history_prev ./history_test history_prev) +add_test(test_history_insert_first ./history_test history_insert_first) +add_test(test_history_delete_first ./history_test history_delete_first) +add_test(test_history_insert_after ./history_test history_insert_after) +add_test(test_history_delete_after ./history_test history_delete_after) +add_test(test_history_insert_before ./history_test history_insert_before) +add_test(test_history_delete_before ./history_test history_delete_before) +add_test(test_history_last ./history_test history_last) +add_test(test_history_first ./history_test history_first) +add_test(test_history_append ./history_test history_append) \ No newline at end of file diff --git a/history.c b/history.c index 5e58035..734c425 100644 --- a/history.c +++ b/history.c @@ -77,18 +77,6 @@ history history_insert_first(history h, square state, uint i, uint j) { return new; } -history history_delete_first(history h) { - if (!history_is_empty(h)) { - history tmp = h->next; - history_free(h); - h = tmp; - if (!history_is_empty(h)) { - h->prev = NULL; - } - } - return h; -} - history history_insert_after(history h, history p, square state, uint i, uint j) { if (history_is_empty(h) || history_is_empty(p)) errPointer(); @@ -105,7 +93,7 @@ history history_insert_after(history h, history p, square state, uint i, uint j) } history history_delete_after(history h, history p) { - if (history_is_empty(h) || history_is_empty(p)) + if (history_is_empty(p)) errPointer(); if (!history_is_empty(history_next(p))) { history to_be_deleted = p->next; @@ -145,4 +133,59 @@ history history_delete_before(history h, history p) { history_free(to_be_deleted); } return h; +} + +history history_last(history h) { + if (history_is_empty(h)) + errPointer(); + if (history_is_empty(history_next(h))) + return h; + return history_last(history_next(h)); +} + +history history_first(history h) { + if (history_is_empty(h)) + errPointer(); + if (history_is_empty(history_prev(h))) + return h; + return history_first(history_prev(h)); +} + +history history_delete_first(history h) { + if (!history_is_empty(h)) { + h = history_first(h); + history tmp = h->next; + history_free(h); + h = tmp; + if (!history_is_empty(h)) { + h->prev = NULL; + } + } + return h; +} + +history history_append(history h, square state, uint i, uint j) { + if (history_is_empty(h)) + return history_insert_first(h, state, i, j); + if (history_is_empty(history_next(h))) + return history_insert_after(h, h, state, i, j); + history_append(history_next(h), state, i, j); + return h; +} + +history history_delete_all_after(history h, history p) { + if (history_is_empty(p)) + return h; + if (history_is_empty(history_next(p))) + return h; + history_delete_all_after(h, history_next(p)); + return history_delete_after(h, p); +} + +void history_delete_entire_history(history h) { + if (history_is_empty(h)) + return; + if (history_is_empty(history_prev(h))) + return history_free(history_delete_all_after(h, h)); + return history_delete_entire_history(history_prev(h)); } \ No newline at end of file diff --git a/history.h b/history.h index e117741..9efc4dc 100644 --- a/history.h +++ b/history.h @@ -46,9 +46,8 @@ history history_create_empty(void); * @brief Delete every element after h * * @param h the head of the history - * @return the new history (NULL) */ -history history_delete_entire_history(history h); +void history_delete_entire_history(history h); /** * @brief Test if the given history is empty or not. @@ -199,4 +198,13 @@ history history_first(history h); * @return h */ history history_append(history h, square state, uint i, uint j); + +/** + * @brief Delete all the elements after p + * + * @param h an history + * @param p an element of h + * @return h + */ +history history_delete_all_after(history h, history p); #endif \ No newline at end of file diff --git a/history_test.c b/history_test.c new file mode 100644 index 0000000..1222520 --- /dev/null +++ b/history_test.c @@ -0,0 +1,221 @@ +#include "history.h" +#include +#include +#include +#include +#include + +bool test_history_alloc(void) { + history new = history_alloc(); + assert(new); + history_free(new); + return true; +} + +bool test_history_create_empty(void) { + assert(history_create_empty() == NULL); + return true; +} + +bool test_history_delete_entire_history(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + assert(new); + history_insert_after(new, new, S_MARK, 3, 3); + assert(new->next); + history_delete_entire_history(new); + return true; +} + +bool test_history_is_empty(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + assert(new); + assert(!history_is_empty(new)); + assert(history_is_empty(history_create_empty())); + history_free(new); + return true; +} + +bool test_history_next(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + new = history_insert_after(new, new, S_BLACKU, 2, 6); + assert(new->next == history_next(new)); + history_delete_entire_history(new); + return true; +} + +bool test_history_prev(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + new = history_insert_after(new, new, S_BLACKU, 2, 6); + new = history_next(new); + assert(new->prev == history_prev(new)); + history_delete_entire_history(new); + return true; +} + +bool test_history_insert_first(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + assert(new); + history_free(new); + return true; +} + +bool test_history_delete_first(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + assert(new); + new = history_insert_after(new, new, S_BLACK3, 2, 5); + new = history_next(new); + history_delete_first(new); + assert(new->prev == NULL); + history_delete_entire_history(new); + return true; +} + +bool test_history_insert_after(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + assert(new); + history newafter = history_alloc(); + newafter->prev = new; + new->next = newafter; + history_insert_after(new, new, S_BLACK2, 4, 3); + assert(new->next->next == newafter); + assert(new == newafter->prev->prev); + assert(new->next->state == S_BLACK2); + assert(new->next->i == 4); + assert(new->next->j == 3); + history_delete_entire_history(new); + return true; +} + +bool test_history_delete_after(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + assert(new); + history newafter = history_alloc(); + newafter->prev = new; + new->next = newafter; + history_insert_after(new, new, S_BLACK2, 4, 3); + history_delete_after(new, new); + assert(new->next == newafter); + assert(new == newafter->prev); + history_delete_entire_history(new); + return true; +} + +bool test_history_insert_before(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + assert(new); + history newafter = history_alloc(); + newafter->prev = new; + new->next = newafter; + history_insert_before(new, newafter, S_BLACK2, 4, 3); + assert(new->next->next == newafter); + assert(new == newafter->prev->prev); + assert(new->next->state == S_BLACK2); + assert(new->next->i == 4); + assert(new->next->j == 3); + history_delete_entire_history(new); + return true; +} + +bool test_history_delete_before(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + assert(new); + history newafter = history_alloc(); + newafter->prev = new; + new->next = newafter; + history_insert_after(new, new, S_BLACK2, 4, 3); + history_delete_before(new, newafter); + assert(new->next == newafter); + assert(new == newafter->prev); + history_delete_entire_history(new); + return true; +} + +bool test_history_last(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + assert(new); + history newafter = history_alloc(); + newafter->prev = new; + new->next = newafter; + assert(history_last(new) == newafter); + history_delete_entire_history(new); + return true; +} + +bool test_history_first(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + assert(new); + history newafter = history_alloc(); + newafter->prev = new; + new->next = newafter; + assert(history_first(newafter) == new); + history_delete_entire_history(new); + return true; +} + +bool test_history_append(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + assert(new); + history_append(new, S_BLACK3, 2, 4); + history last = history_last(new); + assert(new->next == last); + assert(last->state == S_BLACK3); + assert(last->i == 2); + assert(last->j == 4); + history_delete_entire_history(new); + return true; +} + +int usage(int argc, char* argv[]) { + fprintf(stderr, "Usage: %s [<...>]\n", argv[0]); + exit(EXIT_FAILURE); +} + +int main(int argc, char* argv[]) { + if (argc == 1) { + usage(argc, argv); + } + fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); + bool ok = true; + if (strcmp("history_alloc", argv[1]) == 0) + ok = test_history_alloc(); + else if (strcmp("history_create_empty", argv[1]) == 0) + ok = test_history_create_empty(); + else if (strcmp("history_delete_entire_history", argv[1]) == 0) + ok = test_history_delete_entire_history(); + else if (strcmp("history_is_empty", argv[1]) == 0) + ok = test_history_is_empty(); + else if (strcmp("history_next", argv[1]) == 0) + ok = test_history_next(); + else if (strcmp("history_prev", argv[1]) == 0) + ok = test_history_prev(); + else if (strcmp("history_insert_first", argv[1]) == 0) + ok = test_history_insert_first(); + else if (strcmp("history_delete_first", argv[1]) == 0) + ok = test_history_delete_first(); + else if (strcmp("history_insert_after", argv[1]) == 0) + ok = test_history_insert_after(); + else if (strcmp("history_delete_after", argv[1]) == 0) + ok = test_history_delete_after(); + else if (strcmp("history_insert_before", argv[1]) == 0) + ok = test_history_insert_before(); + else if (strcmp("history_delete_before", argv[1]) == 0) + ok = test_history_delete_before(); + else if (strcmp("history_last", argv[1]) == 0) + ok = test_history_last(); + else if (strcmp("history_first", argv[1]) == 0) + ok = test_history_first(); + else if (strcmp("history_append", argv[1]) == 0) + ok = test_history_append(); + else { + fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); + exit(EXIT_FAILURE); + } + // print test result + if (ok) { + fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); + return EXIT_SUCCESS; + } else { + fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]); + return EXIT_FAILURE; + } +} \ No newline at end of file From 0e3620e6dd7c4ace81c4178de068dfeb48775d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Fri, 10 Dec 2021 02:13:46 +0100 Subject: [PATCH 166/281] opti + memory leak fixed --- game_aux.c | 43 ++++++++----------------------------------- game_text.c | 39 +++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 55 deletions(-) diff --git a/game_aux.c b/game_aux.c index cb2c983..91c2ba8 100644 --- a/game_aux.c +++ b/game_aux.c @@ -2,39 +2,13 @@ #include #include "game.h" -char charPrintCell(square sqState) { - if (sqState == S_BLANK) { - return ' '; - } - if ((sqState == S_LIGHTBULB) || - (sqState == (S_LIGHTBULB | F_ERROR)) | (sqState == (S_LIGHTBULB | F_LIGHTED)) | (sqState == (S_LIGHTBULB | F_ERROR | F_LIGHTED))) { - return '*'; - } - if ((sqState == S_MARK) || (sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) { - return '-'; - } - if (sqState == S_BLACK0 || sqState == (S_BLACK0 | F_ERROR)) { - return '0'; - } - if (sqState == S_BLACK1 || sqState == (S_BLACK1 | F_ERROR)) { - return '1'; - } - if (sqState == S_BLACK2 || sqState == (S_BLACK2 | F_ERROR)) { - return '2'; - } - if (sqState == S_BLACK3 || sqState == (S_BLACK3 | F_ERROR)) { - return '3'; - } - if (sqState == S_BLACK4 || sqState == (S_BLACK4 | F_ERROR)) { - return '4'; - } - if (sqState == S_BLACKU || sqState == (S_BLACKU | F_ERROR)) { - return 'w'; - } - if (sqState == F_LIGHTED) { - return '.'; - } - return -1; +char charPrintCell(cgame g, uint i, uint j) { + square sqState = game_get_state(g, i, j); + square sqFlags = game_get_flags(g, i, j); + char tab[] = {' ', '*', '-', '?', '?', '?', '?', '?', '0', '1', '2', '3', '4', 'w', '?', '?', '.'}; + if (!sqState) + return tab[sqFlags]; + return tab[sqState]; } void game_print(cgame g) { @@ -52,7 +26,7 @@ void game_print(cgame g) { for (i = 0; i < DEFAULT_SIZE; i++) { printf("%u |", i); for (uint j = 0; j < DEFAULT_SIZE; j++) { - printf("%c", charPrintCell(game_get_square(g, i, j))); + printf("%c", charPrintCell(g, i, j)); } printf("|\n"); } @@ -88,6 +62,5 @@ game game_default_solution(void) { game_set_square(g, 5, 0, S_LIGHTBULB); game_set_square(g, 5, 5, S_LIGHTBULB); game_set_square(g, 6, 1, S_LIGHTBULB); - game_update_flags(g); return g; } \ No newline at end of file diff --git a/game_text.c b/game_text.c index 57adcb1..3648dc8 100644 --- a/game_text.c +++ b/game_text.c @@ -4,7 +4,7 @@ #include "game.h" #include "game_aux.h" -bool checkerr(game g, char taberr[]) { +bool checkerr(cgame g, char taberr[]) { if (taberr == NULL || g == NULL) { return -1; } @@ -74,36 +74,35 @@ int main(void) { game_print(g); } else if (c == 'q') { printf("Solution: \n"); - game_print(game_default_solution()); + game sol = game_default_solution(); + game_update_flags(sol); + game_print(sol); + game_delete(sol); + game_delete(g); printf("shame\n"); return EXIT_SUCCESS; } else if (c == 'l' || c == 'm' || c == 'b') { if (scanf(" %u %u", &i, &j) == 2) { - if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && !game_is_black(g, i, j)) { - if (c == 'l') { - game_set_square(g, i, j, S_LIGHTBULB); - game_update_flags(g); - game_print(g); - } else if (c == 'm') { - game_set_square(g, i, j, S_MARK); - game_update_flags(g); - game_print(g); - } else if (c == 'b') { - game_set_square(g, i, j, S_BLANK); - game_update_flags(g); - game_print(g); - } - } else { + if (c == 'l' && game_check_move(g, i, j, S_LIGHTBULB)) { + game_play_move(g, i, j, S_LIGHTBULB); + game_print(g); + } else if (c == 'm' && game_check_move(g, i, j, S_MARK)) { + game_play_move(g, i, j, S_MARK); + game_print(g); + } else if (c == 'b' && game_check_move(g, i, j, S_BLANK)) { + game_play_move(g, i, j, S_BLANK); + game_print(g); + } else printf("Erreur: (,) invalide.\n"); - } - } else { - printf("Commande inconnue.\n"); } } else { printf("Commande inconnue.\n"); } + } else { + printf("Commande inconnue.\n"); } } printf("congratulation\n"); + game_delete(g); return EXIT_SUCCESS; } \ No newline at end of file From 0f88c8a7732c14b06b4d536ed8fbdbfd1be41916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Fri, 10 Dec 2021 02:22:32 +0100 Subject: [PATCH 167/281] Revert "opti + memory leak fixed" This reverts commit 0e3620e6dd7c4ace81c4178de068dfeb48775d4a. --- game_aux.c | 43 +++++++++++++++++++++++++++++++++++-------- game_text.c | 39 ++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 27 deletions(-) diff --git a/game_aux.c b/game_aux.c index 91c2ba8..cb2c983 100644 --- a/game_aux.c +++ b/game_aux.c @@ -2,13 +2,39 @@ #include #include "game.h" -char charPrintCell(cgame g, uint i, uint j) { - square sqState = game_get_state(g, i, j); - square sqFlags = game_get_flags(g, i, j); - char tab[] = {' ', '*', '-', '?', '?', '?', '?', '?', '0', '1', '2', '3', '4', 'w', '?', '?', '.'}; - if (!sqState) - return tab[sqFlags]; - return tab[sqState]; +char charPrintCell(square sqState) { + if (sqState == S_BLANK) { + return ' '; + } + if ((sqState == S_LIGHTBULB) || + (sqState == (S_LIGHTBULB | F_ERROR)) | (sqState == (S_LIGHTBULB | F_LIGHTED)) | (sqState == (S_LIGHTBULB | F_ERROR | F_LIGHTED))) { + return '*'; + } + if ((sqState == S_MARK) || (sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) { + return '-'; + } + if (sqState == S_BLACK0 || sqState == (S_BLACK0 | F_ERROR)) { + return '0'; + } + if (sqState == S_BLACK1 || sqState == (S_BLACK1 | F_ERROR)) { + return '1'; + } + if (sqState == S_BLACK2 || sqState == (S_BLACK2 | F_ERROR)) { + return '2'; + } + if (sqState == S_BLACK3 || sqState == (S_BLACK3 | F_ERROR)) { + return '3'; + } + if (sqState == S_BLACK4 || sqState == (S_BLACK4 | F_ERROR)) { + return '4'; + } + if (sqState == S_BLACKU || sqState == (S_BLACKU | F_ERROR)) { + return 'w'; + } + if (sqState == F_LIGHTED) { + return '.'; + } + return -1; } void game_print(cgame g) { @@ -26,7 +52,7 @@ void game_print(cgame g) { for (i = 0; i < DEFAULT_SIZE; i++) { printf("%u |", i); for (uint j = 0; j < DEFAULT_SIZE; j++) { - printf("%c", charPrintCell(g, i, j)); + printf("%c", charPrintCell(game_get_square(g, i, j))); } printf("|\n"); } @@ -62,5 +88,6 @@ game game_default_solution(void) { game_set_square(g, 5, 0, S_LIGHTBULB); game_set_square(g, 5, 5, S_LIGHTBULB); game_set_square(g, 6, 1, S_LIGHTBULB); + game_update_flags(g); return g; } \ No newline at end of file diff --git a/game_text.c b/game_text.c index 3648dc8..57adcb1 100644 --- a/game_text.c +++ b/game_text.c @@ -4,7 +4,7 @@ #include "game.h" #include "game_aux.h" -bool checkerr(cgame g, char taberr[]) { +bool checkerr(game g, char taberr[]) { if (taberr == NULL || g == NULL) { return -1; } @@ -74,35 +74,36 @@ int main(void) { game_print(g); } else if (c == 'q') { printf("Solution: \n"); - game sol = game_default_solution(); - game_update_flags(sol); - game_print(sol); - game_delete(sol); - game_delete(g); + game_print(game_default_solution()); printf("shame\n"); return EXIT_SUCCESS; } else if (c == 'l' || c == 'm' || c == 'b') { if (scanf(" %u %u", &i, &j) == 2) { - if (c == 'l' && game_check_move(g, i, j, S_LIGHTBULB)) { - game_play_move(g, i, j, S_LIGHTBULB); - game_print(g); - } else if (c == 'm' && game_check_move(g, i, j, S_MARK)) { - game_play_move(g, i, j, S_MARK); - game_print(g); - } else if (c == 'b' && game_check_move(g, i, j, S_BLANK)) { - game_play_move(g, i, j, S_BLANK); - game_print(g); - } else + if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && !game_is_black(g, i, j)) { + if (c == 'l') { + game_set_square(g, i, j, S_LIGHTBULB); + game_update_flags(g); + game_print(g); + } else if (c == 'm') { + game_set_square(g, i, j, S_MARK); + game_update_flags(g); + game_print(g); + } else if (c == 'b') { + game_set_square(g, i, j, S_BLANK); + game_update_flags(g); + game_print(g); + } + } else { printf("Erreur: (,) invalide.\n"); + } + } else { + printf("Commande inconnue.\n"); } } else { printf("Commande inconnue.\n"); } - } else { - printf("Commande inconnue.\n"); } } printf("congratulation\n"); - game_delete(g); return EXIT_SUCCESS; } \ No newline at end of file From f61621a9270c1180f56e8d536d5aab179622446f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Fri, 10 Dec 2021 02:14:55 +0100 Subject: [PATCH 168/281] opti + memory leak fixed --- game_aux.c | 43 ++++++++----------------------------------- game_text.c | 39 +++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 55 deletions(-) diff --git a/game_aux.c b/game_aux.c index cb2c983..91c2ba8 100644 --- a/game_aux.c +++ b/game_aux.c @@ -2,39 +2,13 @@ #include #include "game.h" -char charPrintCell(square sqState) { - if (sqState == S_BLANK) { - return ' '; - } - if ((sqState == S_LIGHTBULB) || - (sqState == (S_LIGHTBULB | F_ERROR)) | (sqState == (S_LIGHTBULB | F_LIGHTED)) | (sqState == (S_LIGHTBULB | F_ERROR | F_LIGHTED))) { - return '*'; - } - if ((sqState == S_MARK) || (sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) { - return '-'; - } - if (sqState == S_BLACK0 || sqState == (S_BLACK0 | F_ERROR)) { - return '0'; - } - if (sqState == S_BLACK1 || sqState == (S_BLACK1 | F_ERROR)) { - return '1'; - } - if (sqState == S_BLACK2 || sqState == (S_BLACK2 | F_ERROR)) { - return '2'; - } - if (sqState == S_BLACK3 || sqState == (S_BLACK3 | F_ERROR)) { - return '3'; - } - if (sqState == S_BLACK4 || sqState == (S_BLACK4 | F_ERROR)) { - return '4'; - } - if (sqState == S_BLACKU || sqState == (S_BLACKU | F_ERROR)) { - return 'w'; - } - if (sqState == F_LIGHTED) { - return '.'; - } - return -1; +char charPrintCell(cgame g, uint i, uint j) { + square sqState = game_get_state(g, i, j); + square sqFlags = game_get_flags(g, i, j); + char tab[] = {' ', '*', '-', '?', '?', '?', '?', '?', '0', '1', '2', '3', '4', 'w', '?', '?', '.'}; + if (!sqState) + return tab[sqFlags]; + return tab[sqState]; } void game_print(cgame g) { @@ -52,7 +26,7 @@ void game_print(cgame g) { for (i = 0; i < DEFAULT_SIZE; i++) { printf("%u |", i); for (uint j = 0; j < DEFAULT_SIZE; j++) { - printf("%c", charPrintCell(game_get_square(g, i, j))); + printf("%c", charPrintCell(g, i, j)); } printf("|\n"); } @@ -88,6 +62,5 @@ game game_default_solution(void) { game_set_square(g, 5, 0, S_LIGHTBULB); game_set_square(g, 5, 5, S_LIGHTBULB); game_set_square(g, 6, 1, S_LIGHTBULB); - game_update_flags(g); return g; } \ No newline at end of file diff --git a/game_text.c b/game_text.c index 57adcb1..3648dc8 100644 --- a/game_text.c +++ b/game_text.c @@ -4,7 +4,7 @@ #include "game.h" #include "game_aux.h" -bool checkerr(game g, char taberr[]) { +bool checkerr(cgame g, char taberr[]) { if (taberr == NULL || g == NULL) { return -1; } @@ -74,36 +74,35 @@ int main(void) { game_print(g); } else if (c == 'q') { printf("Solution: \n"); - game_print(game_default_solution()); + game sol = game_default_solution(); + game_update_flags(sol); + game_print(sol); + game_delete(sol); + game_delete(g); printf("shame\n"); return EXIT_SUCCESS; } else if (c == 'l' || c == 'm' || c == 'b') { if (scanf(" %u %u", &i, &j) == 2) { - if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && !game_is_black(g, i, j)) { - if (c == 'l') { - game_set_square(g, i, j, S_LIGHTBULB); - game_update_flags(g); - game_print(g); - } else if (c == 'm') { - game_set_square(g, i, j, S_MARK); - game_update_flags(g); - game_print(g); - } else if (c == 'b') { - game_set_square(g, i, j, S_BLANK); - game_update_flags(g); - game_print(g); - } - } else { + if (c == 'l' && game_check_move(g, i, j, S_LIGHTBULB)) { + game_play_move(g, i, j, S_LIGHTBULB); + game_print(g); + } else if (c == 'm' && game_check_move(g, i, j, S_MARK)) { + game_play_move(g, i, j, S_MARK); + game_print(g); + } else if (c == 'b' && game_check_move(g, i, j, S_BLANK)) { + game_play_move(g, i, j, S_BLANK); + game_print(g); + } else printf("Erreur: (,) invalide.\n"); - } - } else { - printf("Commande inconnue.\n"); } } else { printf("Commande inconnue.\n"); } + } else { + printf("Commande inconnue.\n"); } } printf("congratulation\n"); + game_delete(g); return EXIT_SUCCESS; } \ No newline at end of file From 5001605391b220ca44d850a09bfe2cfa2c1b8ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Fri, 10 Dec 2021 14:18:10 +0100 Subject: [PATCH 169/281] moved struct on game.h + debug game equal --- game.c | 7 ------- game.h | 7 +++++++ game_test_thoguet.c | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/game.c b/game.c index 524892f..b92e99c 100644 --- a/game.c +++ b/game.c @@ -2,13 +2,6 @@ #include #include -struct game_s { - square** tab_cell; - bool wrapped; - uint height; - uint width; -}; - game game_new(square* squares) { game g = game_new_empty(); for (int i = 0; i < DEFAULT_SIZE; i++) { diff --git a/game.h b/game.h index 2206fb7..f43b87d 100644 --- a/game.h +++ b/game.h @@ -58,6 +58,13 @@ typedef enum { /** square mask used in square enum */ #define A_MASK 0xFF +struct game_s { + square** tab_cell; + bool wrapped; + uint height; + uint width; +}; + /** * @brief The structure pointer that stores the game state. **/ diff --git a/game_test_thoguet.c b/game_test_thoguet.c index fc80d6c..99ca309 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -162,6 +162,7 @@ bool test_game_default_solution(void) { game_set_square(g1, 5, 5, S_LIGHTBULB); game_set_square(g1, 6, 1, S_LIGHTBULB); game_update_flags(g1); + game_update_flags(g); assert(game_equal(g, g1)); game_delete(g); game_delete(g1); From 0d6ccc4094ac91d8a9899a586fb21ebaa2c2ade9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl?= Date: Fri, 10 Dec 2021 14:20:42 +0100 Subject: [PATCH 170/281] revert changes on default sol --- game_aux.c | 1 + game_test_thoguet.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/game_aux.c b/game_aux.c index 91c2ba8..282b0ed 100644 --- a/game_aux.c +++ b/game_aux.c @@ -62,5 +62,6 @@ game game_default_solution(void) { game_set_square(g, 5, 0, S_LIGHTBULB); game_set_square(g, 5, 5, S_LIGHTBULB); game_set_square(g, 6, 1, S_LIGHTBULB); + game_update_flags(g); return g; } \ No newline at end of file diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 99ca309..fc80d6c 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -162,7 +162,6 @@ bool test_game_default_solution(void) { game_set_square(g1, 5, 5, S_LIGHTBULB); game_set_square(g1, 6, 1, S_LIGHTBULB); game_update_flags(g1); - game_update_flags(g); assert(game_equal(g, g1)); game_delete(g); game_delete(g1); From 256556e1f8bfe717815bd56e2600cb4739aed0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 10 Dec 2021 14:36:41 +0100 Subject: [PATCH 171/281] pushed settings and launch .vscode --- .vscode/launch.json | 35 +++++++++++++++++++++++++++++++++++ .vscode/settings.json | 7 +++++++ 2 files changed, 42 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4617c19 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,35 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) debug tests thoguet", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/game_test_thoguet", + "args": [ + "game_default_solution" + ], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "make_build" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7441b23 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "game_ext.h": "c", + "game.h": "c" + }, + "editor.formatOnSave": true +} \ No newline at end of file From b48d52bb6b3c19f67e197d49e5bd0a8dfb66bcd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 10 Dec 2021 14:38:18 +0100 Subject: [PATCH 172/281] implementation of history in struct game and fcts --- game.c | 4 ++++ game.h | 2 ++ history.h | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/game.c b/game.c index b92e99c..440283c 100644 --- a/game.c +++ b/game.c @@ -36,6 +36,7 @@ game game_new_empty(void) { g->wrapped = false; g->height = DEFAULT_SIZE; g->width = DEFAULT_SIZE; + g->hist = NULL; return g; } @@ -69,6 +70,9 @@ void game_delete(game g) { free(g->tab_cell); if (g->tab_cell != NULL) g->tab_cell = NULL; + history_delete_entire_history(g->hist); + if (g->hist != NULL) + g->hist = NULL; free(g); if (g != NULL) g = NULL; diff --git a/game.h b/game.h index f43b87d..53cf9f6 100644 --- a/game.h +++ b/game.h @@ -8,6 +8,7 @@ #ifndef __GAME_H__ #define __GAME_H__ #include +#include "history.h" /** * @brief Standard unsigned integer type. @@ -63,6 +64,7 @@ struct game_s { bool wrapped; uint height; uint width; + history hist; }; /** diff --git a/history.h b/history.h index 9efc4dc..5f1864c 100644 --- a/history.h +++ b/history.h @@ -43,7 +43,7 @@ void history_free(history h); history history_create_empty(void); /** - * @brief Delete every element after h + * @brief Delete every element of h (before and after) * * @param h the head of the history */ From 4f5a7b358c75bcccb16a2654ea9e7192b8559080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 10 Dec 2021 14:46:24 +0100 Subject: [PATCH 173/281] update game print with g->height and g->width --- game_aux.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/game_aux.c b/game_aux.c index 282b0ed..76a4335 100644 --- a/game_aux.c +++ b/game_aux.c @@ -15,23 +15,23 @@ void game_print(cgame g) { if (g != NULL) { uint i; printf(" 0"); - for (i = 1; i < DEFAULT_SIZE; i++) { + for (i = 1; i < g->width; i++) { printf("%u", i); } printf("\n -"); - for (i = 1; i < DEFAULT_SIZE; i++) { + for (i = 1; i < g->width; i++) { printf("-"); } printf("\n"); - for (i = 0; i < DEFAULT_SIZE; i++) { + for (i = 0; i < g->height; i++) { printf("%u |", i); - for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (uint j = 0; j < g->width; j++) { printf("%c", charPrintCell(g, i, j)); } printf("|\n"); } printf(" -"); - for (i = 1; i < DEFAULT_SIZE; i++) { + for (i = 1; i < g->width; i++) { printf("-"); } printf("\n"); From a3d2cf79366c28f0f4bd58964bae0c697d13c226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 10 Dec 2021 15:15:21 +0100 Subject: [PATCH 174/281] update precedent fct to new game struct + include --- CMakeLists.txt | 8 ++-- game.c | 86 +++++++++++++++++++++++-------------------- game.h | 7 ++-- game_ext.c | 4 +- game_test_thoguet.c | 28 +++++++------- game_test_thperrier.c | 10 ++--- game_text.c | 6 +-- history.h | 5 ++- 8 files changed, 80 insertions(+), 74 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 09c7f15..617489c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,10 +19,10 @@ add_executable(game_test_nnunes game_test_nnunes.c) add_executable(history_test history_test.c) #les dépendances sont calculées automatiquement -target_link_libraries(game_text game) -target_link_libraries(game_test_thoguet game) -target_link_libraries(game_test_thperrier game) -target_link_libraries(game_test_nnunes game) +target_link_libraries(game_text game history) +target_link_libraries(game_test_thoguet game history) +target_link_libraries(game_test_thperrier game history) +target_link_libraries(game_test_nnunes game history) target_link_libraries(history_test game history) add_library (game game.c game_aux.c) diff --git a/game.c b/game.c index 440283c..f65b0be 100644 --- a/game.c +++ b/game.c @@ -2,54 +2,64 @@ #include #include +int max(int a, int b) { + if (a > b) + return a; + return b; +} + game game_new(square* squares) { game g = game_new_empty(); - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { - g->tab_cell[i][j] = squares[DEFAULT_SIZE * i + j]; + for (int i = 0; i < g->height; i++) { + for (int j = 0; j < g->width; j++) { + g->tab_cell[i][j] = squares[g->width * i + j]; } } return g; } game game_new_empty(void) { + // alloc struct game g = (game)malloc(sizeof(struct game_s)); if (g == NULL) { fprintf(stderr, "not enough memory\n"); exit(EXIT_FAILURE); } - g->tab_cell = (square**)malloc(sizeof(square*) * DEFAULT_SIZE); - if (g->tab_cell == NULL) { - fprintf(stderr, "not enough memory\n"); - exit(EXIT_FAILURE); - } - for (int i = 0; i < DEFAULT_SIZE; i++) { - g->tab_cell[i] = (square*)malloc(sizeof(square) * DEFAULT_SIZE); - if (g->tab_cell[i] == NULL) { - fprintf(stderr, "not enough memory\n"); - exit(EXIT_FAILURE); - } - for (int j = 0; j < DEFAULT_SIZE; j++) { - g->tab_cell[i][j] = S_BLANK; - } - } + // set variable of struct g->wrapped = false; g->height = DEFAULT_SIZE; g->width = DEFAULT_SIZE; g->hist = NULL; + // alloc the tab with variables set before + g->tab_cell = (square**)malloc(sizeof(square*) * g->height); + if (g->tab_cell == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + for (int i = 0; i < g->height; i++) { + g->tab_cell[i] = (square*)malloc(sizeof(square) * g->width); + if (g->tab_cell[i] == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + for (int j = 0; j < g->width; j++) { + g->tab_cell[i][j] = S_BLANK; + } + } return g; } - +// TODO game game_copy(cgame g1) { game g2 = game_new_empty(); - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g2->height; i++) { + for (int j = 0; j < g2->width; j++) { g2->tab_cell[i][j] = g1->tab_cell[i][j]; } } return g2; } +// TODO bool game_equal(cgame g1, cgame g2) { for (int i = 0; i < DEFAULT_SIZE; i++) { for (int j = 0; j < DEFAULT_SIZE; j++) { @@ -62,7 +72,7 @@ bool game_equal(cgame g1, cgame g2) { } void game_delete(game g) { - for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int i = 0; i < g->height; i++) { free(g->tab_cell[i]); if (g->tab_cell[i] != NULL) g->tab_cell[i] = NULL; @@ -145,9 +155,7 @@ bool game_has_error(cgame g, uint i, uint j) { } bool game_check_move(cgame g, uint i, uint j, square s) { - if (i >= DEFAULT_SIZE || j >= DEFAULT_SIZE || (s != S_BLANK && s != S_MARK && s != S_LIGHTBULB) || game_is_black(g, i, j)) - return false; - return true; + return !(i >= g->height || j >= g->width || (s != S_BLANK && s != S_MARK && s != S_LIGHTBULB) || game_is_black(g, i, j)); } void game_play_move(game g, uint i, uint j, square s) { @@ -157,8 +165,8 @@ void game_play_move(game g, uint i, uint j, square s) { void delete_flags(game g) { // delete prev flags - for (uint i = 0; i < DEFAULT_SIZE; i++) { - for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (uint i = 0; i < g->height; i++) { + for (uint j = 0; j < g->width; j++) { game_set_square(g, i, j, game_get_state(g, i, j)); } } @@ -176,17 +184,17 @@ void addF_LIGHTED(game g, uint i, uint j) { void game_update_flags(game g) { delete_flags(g); // update flags lighted and lightbulb error - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g->height; i++) { + for (int j = 0; j < g->width; j++) { if (game_get_state(g, i, j) == S_LIGHTBULB) { // add FLIGHTED to the current lightbulb addF_LIGHTED(g, i, j); // add FLIGHTED on the 4 directions, when a wall is hit stop this direction, when another lightbulb is hit put the initial lighbulb on error int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (int x = 1; x < DEFAULT_SIZE; x++) { + for (int x = 1; x < max(g->width, g->height); x++) { for (uint y = 0; y < 7; y = y + 2) { - if (tab[y] != tab[y + 1] && j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < DEFAULT_SIZE && i + x * tab[y] >= 0 && - i + x * tab[y] < DEFAULT_SIZE) { + if (tab[y] != tab[y + 1] && j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 && + i + x * tab[y] < g->height) { if (game_is_black(g, i + x * tab[y], j + x * tab[y + 1])) { tab[y] = 0; tab[y + 1] = 0; @@ -204,14 +212,14 @@ void game_update_flags(game g) { } } // update flags wall (need to wait all FLIGHTED being updated) - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g->height; i++) { + for (int j = 0; j < g->width; j++) { if (game_is_black(g, i, j) && game_get_black_number(g, i, j) >= 0) { int lb = 0; int notempty = 0; int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; for (uint y = 0; y < 7; y = y + 2) { - if (j + tab[y + 1] >= 0 && j + tab[y + 1] < DEFAULT_SIZE && i + tab[y] >= 0 && i + tab[y] < DEFAULT_SIZE) { + if (j + tab[y + 1] >= 0 && j + tab[y + 1] < g->width && i + tab[y] >= 0 && i + tab[y] < g->height) { if (game_is_lightbulb(g, i + tab[y], j + tab[y + 1])) lb++; else if (!game_is_blank(g, i + tab[y], j + tab[y + 1]) || game_is_lighted(g, i + tab[y], j + tab[y + 1])) @@ -233,8 +241,8 @@ void game_update_flags(game g) { } bool game_is_over(cgame g) { - for (uint i = 0; i < DEFAULT_SIZE; i++) { - for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (uint i = 0; i < g->height; i++) { + for (uint j = 0; j < g->width; j++) { if ((game_get_state(g, i, j) == S_BLANK && game_get_flags(g, i, j) == S_BLANK) || game_get_flags(g, i, j) == F_ERROR || game_get_flags(g, i, j) == (F_LIGHTED | F_ERROR)) return false; @@ -244,8 +252,8 @@ bool game_is_over(cgame g) { } void game_restart(game g) { - for (uint i = 0; i < DEFAULT_SIZE; i++) { - for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (uint i = 0; i < g->height; i++) { + for (uint j = 0; j < g->width; j++) { if (game_get_state(g, i, j) == S_MARK || game_get_state(g, i, j) == S_LIGHTBULB) game_set_square(g, i, j, S_BLANK); } diff --git a/game.h b/game.h index 53cf9f6..fb82e34 100644 --- a/game.h +++ b/game.h @@ -8,8 +8,6 @@ #ifndef __GAME_H__ #define __GAME_H__ #include -#include "history.h" - /** * @brief Standard unsigned integer type. **/ @@ -59,11 +57,12 @@ typedef enum { /** square mask used in square enum */ #define A_MASK 0xFF +#include "history.h" struct game_s { square** tab_cell; bool wrapped; - uint height; - uint width; + uint height; // i in general + uint width; // j in general history hist; }; diff --git a/game_ext.c b/game_ext.c index a7dcde0..bb63417 100644 --- a/game_ext.c +++ b/game_ext.c @@ -3,11 +3,11 @@ #include game game_new_ext(uint nb_rows, uint nb_cols, square* squares, bool wrapping) { - game g = (game)malloc(sizeof(struct game_s)); + return; } game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { - return; + game g = (game)malloc(sizeof(struct game_s)); } uint game_nb_rows(cgame g) { diff --git a/game_test_thoguet.c b/game_test_thoguet.c index fc80d6c..47b40bc 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -80,8 +80,6 @@ bool test_game_new(void) { /* ******** game_print ******** */ -// est ce qu'il faut faire avec un tab invalide ? - bool test_game_print(void) { square tab[DEFAULT_SIZE * DEFAULT_SIZE]; square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; @@ -205,7 +203,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { break; } } - for (int i2 = i + 1; i2 < DEFAULT_SIZE; i2++) { + for (int i2 = i + 1; i2 < g->height; i2++) { flags = game_get_square(g, i2, j); if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; @@ -223,7 +221,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { break; } } - for (int j2 = j + 1; j2 < DEFAULT_SIZE; j2++) { + for (int j2 = j + 1; j2 < g->width; j2++) { flags = game_get_square(g, i, j2); if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; @@ -246,8 +244,8 @@ bool check_update(game g) { uint notempty; bool res; bool wall; - for (uint i = 0; i < DEFAULT_SIZE; i++) { - for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (uint i = 0; i < g->height; i++) { + for (uint j = 0; j < g->width; j++) { if (game_is_lightbulb(g, i, j)) { square flags = game_get_flags(g, i, j); if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) { @@ -270,7 +268,7 @@ bool check_update(game g) { } } wall = false; - for (int k = i + 1; k < DEFAULT_SIZE; k++) { + for (int k = i + 1; k < g->height; k++) { if (/*test if current case is a wall*/ game_is_black(g, k, j)) { wall = true; } else { @@ -298,7 +296,7 @@ bool check_update(game g) { } } wall = false; - for (int k = j + 1; k < DEFAULT_SIZE; k++) { + for (int k = j + 1; k < g->width; k++) { if (/*test if current case is a wall*/ game_is_black(g, i, k)) { wall = true; } else { @@ -324,7 +322,7 @@ bool check_update(game g) { } else { notempty++; } - if (i < DEFAULT_SIZE - 1) { + if (i < g->height - 1) { choice[size] = game_get_square(g, i + 1, j); size++; } else { @@ -336,7 +334,7 @@ bool check_update(game g) { } else { notempty++; } - if (j < DEFAULT_SIZE - 1) { + if (j < g->width - 1) { choice[size] = game_get_square(g, i, j + 1); size++; } else { @@ -376,19 +374,19 @@ bool check_update(game g) { // a > 2 = temps d'exec > 3 min et expo bool brutforce(game g, int a, bool* deldup) { // char c; - bool* delDupNext = (bool*)calloc(DEFAULT_SIZE * DEFAULT_SIZE, sizeof(bool)); + bool* delDupNext = (bool*)calloc(g->height * g->width, sizeof(bool)); if (delDupNext == NULL) { fprintf(stderr, "Not enought memory\n"); exit(EXIT_FAILURE); } square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK}; - for (uint i = 0; i < DEFAULT_SIZE; i++) { - for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (uint i = 0; i < g->height; i++) { + for (uint j = 0; j < g->width; j++) { // printf("state: %d i:%d j:%d\n",game_get_state(g,i,j),i,j); - if (deldup == NULL || !(deldup[i * DEFAULT_SIZE + j])) { + if (deldup == NULL || !(deldup[i * g->width + j])) { if (game_get_state(g, i, j) == S_BLANK) { if (delDupNext != NULL && a > 0) - delDupNext[i * DEFAULT_SIZE + j] = true; + delDupNext[i * g->width + j] = true; for (uint k = 0; k < 9; k++) { game_set_square(g, i, j, list[k]); // if (k == 0){ diff --git a/game_test_thperrier.c b/game_test_thperrier.c index bc77498..f6f7339 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -171,8 +171,8 @@ bool test_game_equal() { bool test_game_new_empty() { game g = game_new_empty(); assert(g); - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g->height; i++) { + for (int j = 0; j < g->width; j++) { if (game_get_square(g, i, j) != S_BLANK) { game_delete(g); return false; @@ -186,7 +186,7 @@ bool test_game_new_empty() { /* ********** game_copy ********** */ bool test_game_copy() { game g1 = game_new_empty(); - for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int i = 0; i < g1->height; i++) { game_set_square(g1, i, 0, S_LIGHTBULB); game_set_square(g1, i, 1, S_MARK); game_set_square(g1, i, 2, S_BLACKU); @@ -202,8 +202,8 @@ bool test_game_copy() { game_delete(g2); return false; } - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g2->height; i++) { + for (int j = 0; j < g2->width; j++) { game_set_square(g2, i, j, S_BLACK3); } } diff --git a/game_text.c b/game_text.c index 3648dc8..b798dcf 100644 --- a/game_text.c +++ b/game_text.c @@ -10,8 +10,8 @@ bool checkerr(cgame g, char taberr[]) { } uint err = 0; taberr[0] = '\0'; - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g->height; i++) { + for (int j = 0; j < g->width; j++) { // check each case if (game_has_error(g, i, j)) { // if error append taberr with coo+, @@ -54,7 +54,7 @@ int main(void) { // test if game is over uint i; uint j; - char taberr[DEFAULT_SIZE * DEFAULT_SIZE * 4]; + char taberr[g->height * g->width * 4]; char c; // print game game_print(g); diff --git a/history.h b/history.h index 5f1864c..e88331e 100644 --- a/history.h +++ b/history.h @@ -1,6 +1,9 @@ #ifndef __HISTORY_H__ #define __HISTORY_H__ #include + +typedef struct s_history* history; + #include "game.h" struct s_history { @@ -11,8 +14,6 @@ struct s_history { struct s_history* prev; }; -typedef struct s_history* history; - /** * @brief fprintf not enought memory + exit **/ From 3649e8207584b343c793a060f0b1612608e530f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 10 Dec 2021 15:44:47 +0100 Subject: [PATCH 175/281] game_new_ext and game_new_empty_ext --- game_ext.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/game_ext.c b/game_ext.c index bb63417..39a7866 100644 --- a/game_ext.c +++ b/game_ext.c @@ -3,11 +3,44 @@ #include game game_new_ext(uint nb_rows, uint nb_cols, square* squares, bool wrapping) { - return; + game g = game_new_empty_ext(nb_rows, nb_cols, wrapping); + for (int i = 0; i < g->height; i++) { + for (int j = 0; j < g->width; j++) { + g->tab_cell[i][j] = squares[g->width * i + j]; + } + } + return g; } game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { + // alloc struct game g = (game)malloc(sizeof(struct game_s)); + if (g == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + // set variable of struct + g->wrapped = wrapping; + g->height = nb_rows; + g->width = nb_cols; + g->hist = history_create_empty(); + // alloc the tab with variables set before + g->tab_cell = (square**)malloc(sizeof(square*) * g->height); + if (g->tab_cell == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + for (int i = 0; i < g->height; i++) { + g->tab_cell[i] = (square*)malloc(sizeof(square) * g->width); + if (g->tab_cell[i] == NULL) { + fprintf(stderr, "not enough memory\n"); + exit(EXIT_FAILURE); + } + for (int j = 0; j < g->width; j++) { + g->tab_cell[i][j] = S_BLANK; + } + } + return g; } uint game_nb_rows(cgame g) { From e85b0f17770a54b887c32500065159a663a17b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 10 Dec 2021 16:29:11 +0100 Subject: [PATCH 176/281] void --- history.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/history.c b/history.c index 734c425..adc9234 100644 --- a/history.c +++ b/history.c @@ -12,7 +12,7 @@ void errPointer(void) { exit(EXIT_FAILURE); } -history history_alloc() { +history history_alloc(void) { history h = (history)malloc(sizeof(struct s_history)); if (h == NULL) memoryError(); From 00b8f92e0c9776df2ac295b6486168cad0dc11e4 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Fri, 10 Dec 2021 19:52:55 +0100 Subject: [PATCH 177/281] bool wrapped -> wrapping + edit game copy add hist --- game.c | 9 +++++++-- game.h | 2 +- game_ext.c | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/game.c b/game.c index f65b0be..34c4e19 100644 --- a/game.c +++ b/game.c @@ -26,7 +26,7 @@ game game_new_empty(void) { exit(EXIT_FAILURE); } // set variable of struct - g->wrapped = false; + g->wrapping = false; g->height = DEFAULT_SIZE; g->width = DEFAULT_SIZE; g->hist = NULL; @@ -50,10 +50,15 @@ game game_new_empty(void) { } // TODO game game_copy(cgame g1) { - game g2 = game_new_empty(); + game g2 = game_new_empty_ext(g1->height, g1->width, g1->wrapping); for (int i = 0; i < g2->height; i++) { for (int j = 0; j < g2->width; j++) { + if (g1->tab_cell[i][j] == (S_BLANK | S_LIGHTBULB | S_MARK)){ + game_play_move(g2, i, j, g1->tab_cell[i][j]); + } + else { g2->tab_cell[i][j] = g1->tab_cell[i][j]; + } } } return g2; diff --git a/game.h b/game.h index fb82e34..f1c54d2 100644 --- a/game.h +++ b/game.h @@ -60,7 +60,7 @@ typedef enum { #include "history.h" struct game_s { square** tab_cell; - bool wrapped; + bool wrapping; uint height; // i in general uint width; // j in general history hist; diff --git a/game_ext.c b/game_ext.c index 39a7866..ee7854e 100644 --- a/game_ext.c +++ b/game_ext.c @@ -20,7 +20,7 @@ game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { exit(EXIT_FAILURE); } // set variable of struct - g->wrapped = wrapping; + g->wrapping = wrapping; g->height = nb_rows; g->width = nb_cols; g->hist = history_create_empty(); From ef565007ec28144609be83503d192c9f13ce738a Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Fri, 10 Dec 2021 20:19:19 +0100 Subject: [PATCH 178/281] edit game_play_move (adding history management); --- game.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/game.c b/game.c index 34c4e19..b0f3c4f 100644 --- a/game.c +++ b/game.c @@ -166,6 +166,13 @@ bool game_check_move(cgame g, uint i, uint j, square s) { void game_play_move(game g, uint i, uint j, square s) { game_set_square(g, i, j, s); game_update_flags(g); + if (g->hist == NULL){ + g->hist = history_create_empty(); + g->hist = history_insert_first(g->hist, s, i, j); + } + else { + g->hist = history_next(history_insert_after(g->hist,g->hist,s,i,j)); + } } void delete_flags(game g) { From d70f8a3516aa976156bce967337e6b03d863a955 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Fri, 10 Dec 2021 20:45:58 +0100 Subject: [PATCH 179/281] edit game copy + adding game_undo --- game.c | 3 ++- game_ext.c | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/game.c b/game.c index b0f3c4f..3af4735 100644 --- a/game.c +++ b/game.c @@ -53,7 +53,7 @@ game game_copy(cgame g1) { game g2 = game_new_empty_ext(g1->height, g1->width, g1->wrapping); for (int i = 0; i < g2->height; i++) { for (int j = 0; j < g2->width; j++) { - if (g1->tab_cell[i][j] == (S_BLANK | S_LIGHTBULB | S_MARK)){ + if (g1->tab_cell[i][j] == S_BLANK || g1->tab_cell[i][j] == S_LIGHTBULB || g1->tab_cell[i][j] == S_MARK){ game_play_move(g2, i, j, g1->tab_cell[i][j]); } else { @@ -172,6 +172,7 @@ void game_play_move(game g, uint i, uint j, square s) { } else { g->hist = history_next(history_insert_after(g->hist,g->hist,s,i,j)); + g->hist = history_delete_all_after(g->hist, g->hist); } } diff --git a/game_ext.c b/game_ext.c index ee7854e..9dca5b1 100644 --- a/game_ext.c +++ b/game_ext.c @@ -56,6 +56,14 @@ bool game_is_wrapping(cgame g) { } void game_undo(game g) { + if (history_prev(g->hist) == NULL){ + printf("waiting for your first move"); + } + else{ + game_set_square(g, history_i(history_prev(g->hist)), history_j(history_prev(g->hist)), history_state(history_prev(g->hist))); + game_update_flags(g); + g->hist = history_prev(g->hist); + } return; } From adcbed3276a127ca219266a9dfc2b9f6268a320c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sat, 11 Dec 2021 15:36:29 +0100 Subject: [PATCH 180/281] game equal --- game.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/game.c b/game.c index 3af4735..33ae41c 100644 --- a/game.c +++ b/game.c @@ -53,19 +53,19 @@ game game_copy(cgame g1) { game g2 = game_new_empty_ext(g1->height, g1->width, g1->wrapping); for (int i = 0; i < g2->height; i++) { for (int j = 0; j < g2->width; j++) { - if (g1->tab_cell[i][j] == S_BLANK || g1->tab_cell[i][j] == S_LIGHTBULB || g1->tab_cell[i][j] == S_MARK){ + if (g1->tab_cell[i][j] == S_BLANK || g1->tab_cell[i][j] == S_LIGHTBULB || g1->tab_cell[i][j] == S_MARK) { game_play_move(g2, i, j, g1->tab_cell[i][j]); - } - else { - g2->tab_cell[i][j] = g1->tab_cell[i][j]; + } else { + g2->tab_cell[i][j] = g1->tab_cell[i][j]; } } } return g2; } -// TODO bool game_equal(cgame g1, cgame g2) { + if (g1->height != g2->height || g1->width != g2->width || g1->wrapping != g2->wrapping) + return false; for (int i = 0; i < DEFAULT_SIZE; i++) { for (int j = 0; j < DEFAULT_SIZE; j++) { if (g1->tab_cell[i][j] != g2->tab_cell[i][j]) { @@ -166,12 +166,11 @@ bool game_check_move(cgame g, uint i, uint j, square s) { void game_play_move(game g, uint i, uint j, square s) { game_set_square(g, i, j, s); game_update_flags(g); - if (g->hist == NULL){ + if (g->hist == NULL) { g->hist = history_create_empty(); g->hist = history_insert_first(g->hist, s, i, j); - } - else { - g->hist = history_next(history_insert_after(g->hist,g->hist,s,i,j)); + } else { + g->hist = history_next(history_insert_after(g->hist, g->hist, s, i, j)); g->hist = history_delete_all_after(g->hist, g->hist); } } From 31d66f800816d3dca0494387557bd11a6b31c5fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 12 Dec 2021 01:48:01 +0100 Subject: [PATCH 181/281] update flags + cmake --- .vscode/launch.json | 25 +++++++++++++++++++++++++ CMakeLists.txt | 7 ++++++- game.c | 25 +++++++++++++++---------- game_ext.c | 17 ++++++++--------- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4617c19..0736de3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,31 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "(gdb) game_text", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/game_text", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "make_build" + }, { "name": "(gdb) debug tests thoguet", "type": "cppdbg", diff --git a/CMakeLists.txt b/CMakeLists.txt index 617489c..31732b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,11 @@ target_link_libraries(game_test_thperrier game history) target_link_libraries(game_test_nnunes game history) target_link_libraries(history_test game history) -add_library (game game.c game_aux.c) +#Libraries +add_library (game game.c game_aux.c game_ext.c) add_library(history history.c) +#Tests THOGUET add_test(test_thoguet_dummy ./game_test_thoguet dummy) add_test(test_thoguet_game_new ./game_test_thoguet game_new) add_test(test_thoguet_game_print ./game_test_thoguet game_print) @@ -40,6 +42,7 @@ add_test(test_thoguet_game_update_flags ./game_test_thoguet game_update_flags) add_test(test_thoguet_game_play_move ./game_test_thoguet game_play_move) add_test(test_thoguet_game_check_move ./game_test_thoguet game_check_move) +#Tests THPERRIER add_test(test_thperrier_dummy ./game_test_thperrier dummy) add_test(test_thperrier_game_copy ./game_test_thperrier game_copy) add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty) @@ -50,6 +53,7 @@ add_test(test_thperrier_game_is_lightbulb ./game_test_thperrier game_is_lightbul add_test(test_thperrier_game_is_black ./game_test_thperrier game_is_black) add_test(test_thperrier_game_get_black_number ./game_test_thperrier game_get_black_number) +#Tests NNUNES add_test(test_nnunes_dummy ./game_test_nnunes dummy) add_test(test_nnunes_game_set_square ./game_test_nnunes game_set_square) add_test(test_nnunes_game_get_state ./game_test_nnunes game_get_state) @@ -58,6 +62,7 @@ add_test(test_nnunes_game_is_marked ./game_test_nnunes game_is_marked) add_test(test_nnunes_game_is_lighted ./game_test_nnunes game_is_lighted) add_test(test_nnunes_game_has_error ./game_test_nnunes game_has_error) +#Tests HISTORY add_test(test_history_history_alloc ./history_test history_alloc) add_test(test_history_create_empty ./history_test history_create_empty) add_test(test_history_delete_entire_history ./history_test history_delete_entire_history) diff --git a/game.c b/game.c index 33ae41c..9dcf934 100644 --- a/game.c +++ b/game.c @@ -1,6 +1,7 @@ #include "game.h" #include #include +#include "game_ext.h" int max(int a, int b) { if (a > b) @@ -203,19 +204,21 @@ void game_update_flags(game g) { addF_LIGHTED(g, i, j); // add FLIGHTED on the 4 directions, when a wall is hit stop this direction, when another lightbulb is hit put the initial lighbulb on error int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (int x = 1; x < max(g->width, g->height); x++) { - for (uint y = 0; y < 7; y = y + 2) { - if (tab[y] != tab[y + 1] && j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 && - i + x * tab[y] < g->height) { - if (game_is_black(g, i + x * tab[y], j + x * tab[y + 1])) { + for (int x = 1; x <= max(g->width, g->height); x++) { + for (uint y = 0; y < 7 /*tab size*/; y = y + 2) { + if (/* test if both tab are not 0*/ tab[y] != tab[y + 1] && + (/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 && + i + x * tab[y] < g->height) || + /* wrapping check*/ g->wrapping)) { + if (game_is_black(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width))) { tab[y] = 0; tab[y + 1] = 0; } else { // if we found another lightbulb on the line - if (game_get_state(g, i + x * tab[y], j + x * tab[y + 1]) == S_LIGHTBULB) + if (game_get_state(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width)) == S_LIGHTBULB) // update initial lightbulb on F_ERROR game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - addF_LIGHTED(g, i + x * tab[y], j + x * tab[y + 1]); + addF_LIGHTED(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width)); } } } @@ -231,10 +234,12 @@ void game_update_flags(game g) { int notempty = 0; int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; for (uint y = 0; y < 7; y = y + 2) { - if (j + tab[y + 1] >= 0 && j + tab[y + 1] < g->width && i + tab[y] >= 0 && i + tab[y] < g->height) { - if (game_is_lightbulb(g, i + tab[y], j + tab[y + 1])) + if (/* normal check*/ (j + tab[y + 1] >= 0 && j + tab[y + 1] < g->width && i + tab[y] >= 0 && i + tab[y] < g->height) || + /*wrapping check*/ g->wrapping) { + if (game_is_lightbulb(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width)) lb++; - else if (!game_is_blank(g, i + tab[y], j + tab[y + 1]) || game_is_lighted(g, i + tab[y], j + tab[y + 1])) + else if (!game_is_blank(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width) || + game_is_lighted(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width)) notempty++; } else { notempty++; diff --git a/game_ext.c b/game_ext.c index 9dca5b1..737bfc7 100644 --- a/game_ext.c +++ b/game_ext.c @@ -44,25 +44,24 @@ game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { } uint game_nb_rows(cgame g) { - return; + return 0; } uint game_nb_cols(cgame g) { - return; + return 0; } bool game_is_wrapping(cgame g) { - return; + return false; } void game_undo(game g) { - if (history_prev(g->hist) == NULL){ + if (history_prev(g->hist) == NULL) { printf("waiting for your first move"); - } - else{ - game_set_square(g, history_i(history_prev(g->hist)), history_j(history_prev(g->hist)), history_state(history_prev(g->hist))); - game_update_flags(g); - g->hist = history_prev(g->hist); + } else { + game_set_square(g, history_i(history_prev(g->hist)), history_j(history_prev(g->hist)), history_state(history_prev(g->hist))); + game_update_flags(g); + g->hist = history_prev(g->hist); } return; } From 9f1c7b58ad460a1f53b33d595f927963a1f1e6e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 12 Dec 2021 19:26:32 +0100 Subject: [PATCH 182/281] add include --- game_text.c | 1 + 1 file changed, 1 insertion(+) diff --git a/game_text.c b/game_text.c index b798dcf..a2ae372 100644 --- a/game_text.c +++ b/game_text.c @@ -3,6 +3,7 @@ #include #include "game.h" #include "game_aux.h" +#include "game_ext.h" bool checkerr(cgame g, char taberr[]) { if (taberr == NULL || g == NULL) { From ec1b78be905c7bf31ffbf9707353f9c5b8d5c8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 12 Dec 2021 19:40:45 +0100 Subject: [PATCH 183/281] remove lightbulb error itself --- game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game.c b/game.c index 9dcf934..75dc9ad 100644 --- a/game.c +++ b/game.c @@ -204,7 +204,7 @@ void game_update_flags(game g) { addF_LIGHTED(g, i, j); // add FLIGHTED on the 4 directions, when a wall is hit stop this direction, when another lightbulb is hit put the initial lighbulb on error int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (int x = 1; x <= max(g->width, g->height); x++) { + for (int x = 1; x < max(g->width, g->height); x++) { for (uint y = 0; y < 7 /*tab size*/; y = y + 2) { if (/* test if both tab are not 0*/ tab[y] != tab[y + 1] && (/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 && From bdf5009b4a1df34afb5d815420e014124eaba21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 12 Dec 2021 19:56:32 +0100 Subject: [PATCH 184/281] useless update --- game_text.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/game_text.c b/game_text.c index a2ae372..933a0aa 100644 --- a/game_text.c +++ b/game_text.c @@ -71,12 +71,10 @@ int main(void) { } else if (c == 'r') { game_restart(g); printf("Partie réinitialisé avec success !\n"); - game_update_flags(g); game_print(g); } else if (c == 'q') { printf("Solution: \n"); game sol = game_default_solution(); - game_update_flags(sol); game_print(sol); game_delete(sol); game_delete(g); From 9b6775d6ae894bb4160a2846153c91242f937e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 12 Dec 2021 20:05:25 +0100 Subject: [PATCH 185/281] opti --- game_text.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/game_text.c b/game_text.c index 933a0aa..921330c 100644 --- a/game_text.c +++ b/game_text.c @@ -82,17 +82,15 @@ int main(void) { return EXIT_SUCCESS; } else if (c == 'l' || c == 'm' || c == 'b') { if (scanf(" %u %u", &i, &j) == 2) { - if (c == 'l' && game_check_move(g, i, j, S_LIGHTBULB)) { + if (c == 'l' && game_check_move(g, i, j, S_LIGHTBULB)) game_play_move(g, i, j, S_LIGHTBULB); - game_print(g); - } else if (c == 'm' && game_check_move(g, i, j, S_MARK)) { + else if (c == 'm' && game_check_move(g, i, j, S_MARK)) game_play_move(g, i, j, S_MARK); - game_print(g); - } else if (c == 'b' && game_check_move(g, i, j, S_BLANK)) { + else if (c == 'b' && game_check_move(g, i, j, S_BLANK)) game_play_move(g, i, j, S_BLANK); - game_print(g); - } else + else printf("Erreur: (,) invalide.\n"); + game_print(g); } } else { printf("Commande inconnue.\n"); From 81b4ce358f98b8077e4e26f1accbe580fc1ebc5c Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 16 Dec 2021 10:01:24 +0100 Subject: [PATCH 186/281] edit undo & redo + edit readme --- README.md | 4 ++-- game_ext.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 88c1cf0..e5f84cd 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ Projet Techno | [game_nb_rows](./game_ext.c#L?) | [uint game_nb_rows(cgame g);](./game_ext.h#L43-59) | @nnunes | |
  • [ ]
| | [game_nb_cols](./game_ext.c#L?) | [uint game_nb_cols(cgame g);](./game_ext.h#L51-57) | @nnunes | |
  • [ ]
| | [game_is_wrapping](./game_ext.c#L?) | [bool game_is_wrapping(cgame g);](./game_ext.h#L59-64) | @nnunes | |
  • [ ]
| -| [game_undo](./game_ext.c#L?) | [void game_undo(game g);](./game_ext.h#L66-75) | @thperrier | |
  • [ ]
| -| [game_redo](./game_ext.c#L?) | [void game_redo(game g);](./game_ext.h#L77-86) | @thperrier | |
  • [ ]
| +| [game_undo](./game_ext.c#L?) | [void game_undo(game g);](./game_ext.h#L66-75) | @thperrier | |
  • [X]
| +| [game_redo](./game_ext.c#L?) | [void game_redo(game g);](./game_ext.h#L77-86) | @thperrier | |
  • [X]
| ## game.c diff --git a/game_ext.c b/game_ext.c index 9dca5b1..6d58039 100644 --- a/game_ext.c +++ b/game_ext.c @@ -64,9 +64,15 @@ void game_undo(game g) { game_update_flags(g); g->hist = history_prev(g->hist); } - return; } void game_redo(game g) { - return; + if (history_next(g->hist) == NULL){ + printf("waiting for you to undo first"); + } + else{ + game_set_square(g, history_i(history_next(g->hist)), history_j(history_next(g->hist)), history_state(history_next(g->hist))); + game_update_flags(g); + g->hist = history_next(g->hist); + } } \ No newline at end of file From a6acbba9aa2a70743c764df299456db70fac67c2 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 16 Dec 2021 10:15:04 +0100 Subject: [PATCH 187/281] tabs on game_redo --- game_ext.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/game_ext.c b/game_ext.c index 43fba90..0d5c28f 100644 --- a/game_ext.c +++ b/game_ext.c @@ -70,8 +70,8 @@ void game_redo(game g) { printf("waiting for you to undo first"); } else{ - game_set_square(g, history_i(history_next(g->hist)), history_j(history_next(g->hist)), history_state(history_next(g->hist))); - game_update_flags(g); - g->hist = history_next(g->hist); + game_set_square(g, history_i(history_next(g->hist)), history_j(history_next(g->hist)), history_state(history_next(g->hist))); + game_update_flags(g); + g->hist = history_next(g->hist); } } \ No newline at end of file From 2f39616e60b899baf768af281be4cdd477d7410b Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 16 Dec 2021 10:56:39 +0100 Subject: [PATCH 188/281] adding test_game_undo + edit CMake --- CMakeLists.txt | 1 + game_test_thperrier.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31732b6..920b08a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ add_test(test_thperrier_game_is_blank ./game_test_thperrier game_is_blank) add_test(test_thperrier_game_is_lightbulb ./game_test_thperrier game_is_lightbulb) add_test(test_thperrier_game_is_black ./game_test_thperrier game_is_black) add_test(test_thperrier_game_get_black_number ./game_test_thperrier game_get_black_number) +add_test(test_thperrier_game_undo ./game_test_thperrier game_undo) #Tests NNUNES add_test(test_nnunes_dummy ./game_test_nnunes dummy) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index f6f7339..b833b60 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -5,6 +5,7 @@ #include #include "game.h" #include "game_aux.h" +#include "game_ext.h" /* ********** DUMMY ********** */ bool test_dummy() { @@ -220,6 +221,32 @@ bool test_game_copy() { game_delete(g3); return true; } + +/* ********** game_undo ********** */ +bool test_game_undo(){ + game g1 = game_new_empty(); + game_play_move(g1, 2, 3, S_LIGHTBULB); + game_play_move(g1, 0, 0, S_MARK); + game_play_move(g1, 2, 3, S_BLANK); + game g2 = game_copy(g1); + game_play_move(g2, 2, 3, S_LIGHTBULB); + game_undo(g1); + if (!game_equal(g1, g2)){ + return false; + } + game_play_move(g2, 0, 0, S_BLANK); + game_undo(g1); + if (!game_equal(g1, g2)){ + return false; + } + game_play_move(g2, 2, 3, S_BLANK); + game_undo(g1); + if (!game_equal(g1, g2)){ + return false; + } + return true; +} + /* ********** usage ********** */ void usage(int argc, char* argv[]) { fprintf(stderr, "Usage: %s \n", argv[0]); @@ -248,6 +275,8 @@ int main(int argc, char* argv[]) { success = test_game_is_black(); } else if (strcmp("game_get_black_number", argv[1]) == 0) { success = test_game_get_black_number(); + } else if (strcmp("game_undo", argv[1]) == 0) { + success = test_game_undo(); } else { fprintf(stderr, "test \"%s\" is not a valid test name.\n", argv[1]); return EXIT_FAILURE; From ee2a78ed9d807ae0eedec37522ade2106d89082c Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 16 Dec 2021 11:06:01 +0100 Subject: [PATCH 189/281] edit game_copy --- game.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/game.c b/game.c index 75dc9ad..9a74a96 100644 --- a/game.c +++ b/game.c @@ -54,12 +54,9 @@ game game_copy(cgame g1) { game g2 = game_new_empty_ext(g1->height, g1->width, g1->wrapping); for (int i = 0; i < g2->height; i++) { for (int j = 0; j < g2->width; j++) { - if (g1->tab_cell[i][j] == S_BLANK || g1->tab_cell[i][j] == S_LIGHTBULB || g1->tab_cell[i][j] == S_MARK) { - game_play_move(g2, i, j, g1->tab_cell[i][j]); - } else { - g2->tab_cell[i][j] = g1->tab_cell[i][j]; - } + g2->tab_cell[i][j] = g1->tab_cell[i][j]; } + //g2->hist = history_copy(g1); } return g2; } From fcfee786d7e57eba7e4fec7d05846f67dc50b60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 16 Dec 2021 11:25:48 +0100 Subject: [PATCH 190/281] TOFIX historycopy --- .vscode/launch.json | 27 +++++++++++++++++++++++++++ CMakeLists.txt | 3 ++- history.c | 24 ++++++++++++++++++++++++ history_test.c | 14 ++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 0736de3..16b2d79 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -55,6 +55,33 @@ } ], "preLaunchTask": "make_build" + }, + { + "name": "(gdb) debug tests histo", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/history_test", + "args": [ + "history_copy" + ], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "make_build" } ] } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 31732b6..8568a66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,4 +77,5 @@ add_test(test_history_insert_before ./history_test history_insert_before) add_test(test_history_delete_before ./history_test history_delete_before) add_test(test_history_last ./history_test history_last) add_test(test_history_first ./history_test history_first) -add_test(test_history_append ./history_test history_append) \ No newline at end of file +add_test(test_history_append ./history_test history_append) +add_test(test_history_copy ./history_test history_copy) \ No newline at end of file diff --git a/history.c b/history.c index adc9234..845a4aa 100644 --- a/history.c +++ b/history.c @@ -188,4 +188,28 @@ void history_delete_entire_history(history h) { if (history_is_empty(history_prev(h))) return history_free(history_delete_all_after(h, h)); return history_delete_entire_history(history_prev(h)); +} + +history history_copy(history h) { + history tmp = h; + if (history_is_empty(h)) { + return h; + } + h = history_first(h); + uint cpt = 0; + while (h != tmp) { + h = history_next(h); + cpt++; + } + history h2 = history_insert_first(history_create_empty(), h->state, h->i, h->j); + while (!history_is_empty(history_next(h))) { + h = history_next(h); + h2 = history_insert_after(h2, h2, h->state, h->i, h->j); + h2 = history_next(h2); + } + h2 = history_first(h2); + for (uint i = 0; i < cpt; i++) { + h2 = history_next(h2); + } + return h2; } \ No newline at end of file diff --git a/history_test.c b/history_test.c index 1222520..76a30b4 100644 --- a/history_test.c +++ b/history_test.c @@ -165,6 +165,18 @@ bool test_history_append(void) { return true; } +bool test_history_copy(void) { + history new = history_insert_first(history_create_empty(), S_LIGHTBULB, 4, 3); + assert(new); + new = history_insert_after(new, new, S_BLANK, 5, 8); + history h2 = history_copy(new); + assert(history_state(h2) != history_state(new)); + assert(history_state(history_next(h2)) == history_state(history_next(new))); + history_delete_entire_history(h2); + history_delete_entire_history(new); + return true; +} + int usage(int argc, char* argv[]) { fprintf(stderr, "Usage: %s [<...>]\n", argv[0]); exit(EXIT_FAILURE); @@ -206,6 +218,8 @@ int main(int argc, char* argv[]) { ok = test_history_first(); else if (strcmp("history_append", argv[1]) == 0) ok = test_history_append(); + else if (strcmp("history_copy", argv[1]) == 0) + ok = test_history_copy(); else { fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); exit(EXIT_FAILURE); From 4d994a1cb3fd273ee0b8c7023d5d37603d9f02f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 16 Dec 2021 11:30:22 +0100 Subject: [PATCH 191/281] update .h xd --- history.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/history.h b/history.h index e88331e..b8e7396 100644 --- a/history.h +++ b/history.h @@ -208,4 +208,12 @@ history history_append(history h, square state, uint i, uint j); * @return h */ history history_delete_all_after(history h, history p); + +/** + * @brief Copy history + * + * @param h an history + * @return the new history + */ +history history_copy(history h); #endif \ No newline at end of file From ed19ad91a2169578c6ccd6a32a580ca38e9897f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 16 Dec 2021 12:13:27 +0100 Subject: [PATCH 192/281] histo_test_done --- history_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/history_test.c b/history_test.c index 76a30b4..11b33c5 100644 --- a/history_test.c +++ b/history_test.c @@ -170,7 +170,7 @@ bool test_history_copy(void) { assert(new); new = history_insert_after(new, new, S_BLANK, 5, 8); history h2 = history_copy(new); - assert(history_state(h2) != history_state(new)); + assert(history_state(h2) == history_state(new)); assert(history_state(history_next(h2)) == history_state(history_next(new))); history_delete_entire_history(h2); history_delete_entire_history(new); From 3839e59097271b39633cf9dcca3dec11e04ec6fc Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Tue, 21 Dec 2021 16:18:41 +0100 Subject: [PATCH 193/281] last functions + tests fail --- CMakeLists.txt | 3 +++ game_ext.c | 6 +++--- game_test_nnunes.c | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a370dc..047703f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,9 @@ add_test(test_nnunes_game_get_flags ./game_test_nnunes game_get_flags) add_test(test_nnunes_game_is_marked ./game_test_nnunes game_is_marked) add_test(test_nnunes_game_is_lighted ./game_test_nnunes game_is_lighted) add_test(test_nnunes_game_has_error ./game_test_nnunes game_has_error) +add_test(test_nnunes_game_nb_rows ./game_test_nnunes game_nb_rows) +add_test(test_nnunes_game_nb_cols ./game_test_nnunes game_nb_cols) +add_test(test_nnunes_game_is_wrapping ./game_test_nnunes game_is_wrapping) #Tests HISTORY add_test(test_history_history_alloc ./history_test history_alloc) diff --git a/game_ext.c b/game_ext.c index 0d5c28f..d731453 100644 --- a/game_ext.c +++ b/game_ext.c @@ -44,15 +44,15 @@ game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { } uint game_nb_rows(cgame g) { - return 0; + return g->height; } uint game_nb_cols(cgame g) { - return 0; + return g->width; } bool game_is_wrapping(cgame g) { - return false; + return g->wrapping; } void game_undo(game g) { diff --git a/game_test_nnunes.c b/game_test_nnunes.c index c418dbc..5eb8c9f 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -357,6 +357,33 @@ bool test_game_has_error(void) { return false; } +/* ************** game_nb_rows ************** */ +bool test_game_nb_rows(void) { + game g = game_new_empty(); + if (game_nb_rows(g) != g->height){ + return false; + } + return true; +} + +/* ************** game_nb_cols ************** */ +bool test_game_nb_cols(void) { + game g = game_new_empty(); + if (game_nb_cols(g) != g->width){ + return false; + } + return true; +} + +/* ************** game_is_wrapping ************** */ +bool test_game_is_wrapping(void) { + game g = game_new_empty(); + if (game_is_wrapping(g) != g->wrapping){ + return false; + } + return true; +} + int main(int argc, char* argv[]) { if (argc != 2) { usage(argc, argv); From bec7cbdc10b1c83634df5d7b9448646e6168d5eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 23 Dec 2021 14:15:47 +0100 Subject: [PATCH 194/281] patch + update game_text --- game.c | 10 +++++----- game_ext.c | 7 +++---- game_test_nnunes.c | 7 ++++--- game_text.c | 8 ++++++++ history.c | 4 ++-- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/game.c b/game.c index 9a74a96..bb5e6c2 100644 --- a/game.c +++ b/game.c @@ -56,7 +56,7 @@ game game_copy(cgame g1) { for (int j = 0; j < g2->width; j++) { g2->tab_cell[i][j] = g1->tab_cell[i][j]; } - //g2->hist = history_copy(g1); + // g2->hist = history_copy(g1); } return g2; } @@ -162,15 +162,15 @@ bool game_check_move(cgame g, uint i, uint j, square s) { } void game_play_move(game g, uint i, uint j, square s) { - game_set_square(g, i, j, s); - game_update_flags(g); if (g->hist == NULL) { g->hist = history_create_empty(); - g->hist = history_insert_first(g->hist, s, i, j); + g->hist = history_insert_first(g->hist, game_get_square(g, i, j), i, j); } else { - g->hist = history_next(history_insert_after(g->hist, g->hist, s, i, j)); + g->hist = history_next(history_insert_after(g->hist, g->hist, game_get_square(g, i, j), i, j)); g->hist = history_delete_all_after(g->hist, g->hist); } + game_set_square(g, i, j, s); + game_update_flags(g); } void delete_flags(game g) { diff --git a/game_ext.c b/game_ext.c index d731453..0ed18f4 100644 --- a/game_ext.c +++ b/game_ext.c @@ -57,7 +57,7 @@ bool game_is_wrapping(cgame g) { void game_undo(game g) { if (history_prev(g->hist) == NULL) { - printf("waiting for your first move"); + printf("waiting for your first move\n"); } else { game_set_square(g, history_i(history_prev(g->hist)), history_j(history_prev(g->hist)), history_state(history_prev(g->hist))); game_update_flags(g); @@ -66,10 +66,9 @@ void game_undo(game g) { } void game_redo(game g) { - if (history_next(g->hist) == NULL){ + if (history_next(g->hist) == NULL) { printf("waiting for you to undo first"); - } - else{ + } else { game_set_square(g, history_i(history_next(g->hist)), history_j(history_next(g->hist)), history_state(history_next(g->hist))); game_update_flags(g); g->hist = history_next(g->hist); diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 5eb8c9f..7536ddb 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -5,6 +5,7 @@ #include #include "game.h" #include "game_aux.h" +#include "game_ext.h" bool test_dummy(void) { return true; @@ -360,7 +361,7 @@ bool test_game_has_error(void) { /* ************** game_nb_rows ************** */ bool test_game_nb_rows(void) { game g = game_new_empty(); - if (game_nb_rows(g) != g->height){ + if (game_nb_rows(g) != g->height) { return false; } return true; @@ -369,7 +370,7 @@ bool test_game_nb_rows(void) { /* ************** game_nb_cols ************** */ bool test_game_nb_cols(void) { game g = game_new_empty(); - if (game_nb_cols(g) != g->width){ + if (game_nb_cols(g) != g->width) { return false; } return true; @@ -378,7 +379,7 @@ bool test_game_nb_cols(void) { /* ************** game_is_wrapping ************** */ bool test_game_is_wrapping(void) { game g = game_new_empty(); - if (game_is_wrapping(g) != g->wrapping){ + if (game_is_wrapping(g) != g->wrapping) { return false; } return true; diff --git a/game_text.c b/game_text.c index 921330c..88c169d 100644 --- a/game_text.c +++ b/game_text.c @@ -40,6 +40,8 @@ void printhelp(void) { printf("h : Affiche cette aide.\n"); printf("r : Réinitialise la partie.\n"); printf("q : Quitter la partie (abandon).\n"); + printf("z : Annulez le coup (undo).\n"); + printf("y : Annulez l'annulation du coup (redo).\n"); printf( "l : Place une ampoule (*light bulb*) dans la case " "(,).\n"); @@ -80,6 +82,12 @@ int main(void) { game_delete(g); printf("shame\n"); return EXIT_SUCCESS; + } else if (c == 'z') { + game_undo(g); + game_print(g); + } else if (c == 'y') { + game_redo(g); + game_print(g); } else if (c == 'l' || c == 'm' || c == 'b') { if (scanf(" %u %u", &i, &j) == 2) { if (c == 'l' && game_check_move(g, i, j, S_LIGHTBULB)) diff --git a/history.c b/history.c index 845a4aa..4f8a8da 100644 --- a/history.c +++ b/history.c @@ -54,13 +54,13 @@ square history_state(history h) { return h->state; } -square history_i(history h) { +uint history_i(history h) { if (history_is_empty(h)) errPointer(); return h->i; } -square history_j(history h) { +uint history_j(history h) { if (history_is_empty(h)) errPointer(); return h->j; From f5ba336ced39618c8fab2f2ce7d80c11feb3b842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 23 Dec 2021 17:03:00 +0100 Subject: [PATCH 195/281] usage + argc ; argv --- game_text.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/game_text.c b/game_text.c index 88c169d..8121fb2 100644 --- a/game_text.c +++ b/game_text.c @@ -51,9 +51,18 @@ void printhelp(void) { "(,).\n"); } -int main(void) { - // Create new game - game g = game_default(); +void usage(int argc, char* argv[]) { + printf("Usage : %s => play the default game\n", argv[0]); + exit(EXIT_FAILURE); +} + +int main(int argc, char* argv[]) { + game g; + if (argc == 1) + // Create new game + g = game_default(); + else + usage(argc, argv); // test if game is over uint i; uint j; From e5cad43174761d236ada929ecb437e9e08898a69 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Thu, 23 Dec 2021 18:16:27 +0100 Subject: [PATCH 196/281] fix game_test --- README.md | 6 +++--- game_test_nnunes.c | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e5f84cd..8ad1474 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ Projet Techno | ------------------------------------ | ---------------------------------------------------------------------------- | ----------- | ----- | :--------------------: | | [game_new_ext](./game_ext.c#L?) | [game game_new_ext(uint nb_rows, uint nb_cols, square *squares, bool wrapping)](./game_ext.h#L20-30) | @thoguet | |
  • [ ]
| | [game_new_empty_ext](./game_ext.c#L?) | [game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping);](./game_ext.h#L32-41) | @thoguet | |
  • [ ]
| -| [game_nb_rows](./game_ext.c#L?) | [uint game_nb_rows(cgame g);](./game_ext.h#L43-59) | @nnunes | |
  • [ ]
| -| [game_nb_cols](./game_ext.c#L?) | [uint game_nb_cols(cgame g);](./game_ext.h#L51-57) | @nnunes | |
  • [ ]
| -| [game_is_wrapping](./game_ext.c#L?) | [bool game_is_wrapping(cgame g);](./game_ext.h#L59-64) | @nnunes | |
  • [ ]
| +| [game_nb_rows](./game_ext.c#L?) | [uint game_nb_rows(cgame g);](./game_ext.h#L43-59) | @nnunes | |
  • [X]
| +| [game_nb_cols](./game_ext.c#L?) | [uint game_nb_cols(cgame g);](./game_ext.h#L51-57) | @nnunes | |
  • [X]
| +| [game_is_wrapping](./game_ext.c#L?) | [bool game_is_wrapping(cgame g);](./game_ext.h#L59-64) | @nnunes | |
  • [X]
| | [game_undo](./game_ext.c#L?) | [void game_undo(game g);](./game_ext.h#L66-75) | @thperrier | |
  • [X]
| | [game_redo](./game_ext.c#L?) | [void game_redo(game g);](./game_ext.h#L77-86) | @thperrier | |
  • [X]
| diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 7536ddb..8d313c1 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -405,6 +405,12 @@ int main(int argc, char* argv[]) { success = test_game_is_lighted(); } else if (strcmp("game_has_error", argv[1]) == 0) { success = test_game_has_error(); + } else if (strcmp("game_nb_rows", argv[1]) == 0) { + success = test_game_nb_rows(); + } else if (strcmp("game_nb_cols", argv[1]) == 0) { + success = test_game_nb_cols(); + } else if (strcmp("game_is_wrapping", argv[1]) == 0) { + success = test_game_is_wrapping(); } else { fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); exit(EXIT_FAILURE); From 4ecd2dd25adc0ff608631e5575821450aef45b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 23 Dec 2021 19:50:57 +0100 Subject: [PATCH 197/281] succes --- game_text.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_text.c b/game_text.c index 8121fb2..f2d8bce 100644 --- a/game_text.c +++ b/game_text.c @@ -81,7 +81,7 @@ int main(int argc, char* argv[]) { printhelp(); } else if (c == 'r') { game_restart(g); - printf("Partie réinitialisé avec success !\n"); + printf("Partie réinitialisé avec succes !\n"); game_print(g); } else if (c == 'q') { printf("Solution: \n"); From 6ab5074e0c28d18e6ef3b5f3a56ac3ba2ee3311f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 23 Dec 2021 20:06:55 +0100 Subject: [PATCH 198/281] game restart delete history --- game.c | 1 + 1 file changed, 1 insertion(+) diff --git a/game.c b/game.c index bb5e6c2..5a52536 100644 --- a/game.c +++ b/game.c @@ -273,4 +273,5 @@ void game_restart(game g) { } } game_update_flags(g); + history_delete_entire_history(g->hist); } From b2fccde1a26bb4cfbf745fd01f76a369c20e1c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Wed, 5 Jan 2022 23:46:07 +0100 Subject: [PATCH 199/281] problem on hist delete entire hist solved --- game.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/game.c b/game.c index 5a52536..3cf2c88 100644 --- a/game.c +++ b/game.c @@ -77,18 +77,14 @@ bool game_equal(cgame g1, cgame g2) { void game_delete(game g) { for (int i = 0; i < g->height; i++) { free(g->tab_cell[i]); - if (g->tab_cell[i] != NULL) - g->tab_cell[i] = NULL; + g->tab_cell[i] = NULL; } free(g->tab_cell); - if (g->tab_cell != NULL) - g->tab_cell = NULL; + g->tab_cell = NULL; history_delete_entire_history(g->hist); - if (g->hist != NULL) - g->hist = NULL; + g->hist = NULL; free(g); - if (g != NULL) - g = NULL; + g = NULL; return; } @@ -274,4 +270,5 @@ void game_restart(game g) { } game_update_flags(g); history_delete_entire_history(g->hist); + g->hist = NULL; } From 87e5ebe7416d36a4b962f651822a669f92b51d6a Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 6 Jan 2022 02:20:36 +0100 Subject: [PATCH 200/281] edit game_undo + struct game_redo + copy hist --- game.c | 6 +++--- game_ext.c | 10 +++++----- game_test_thperrier.c | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/game.c b/game.c index 5a52536..3e5ac66 100644 --- a/game.c +++ b/game.c @@ -56,7 +56,7 @@ game game_copy(cgame g1) { for (int j = 0; j < g2->width; j++) { g2->tab_cell[i][j] = g1->tab_cell[i][j]; } - // g2->hist = history_copy(g1); + g2->hist = history_copy(g1->hist); } return g2; } @@ -164,9 +164,9 @@ bool game_check_move(cgame g, uint i, uint j, square s) { void game_play_move(game g, uint i, uint j, square s) { if (g->hist == NULL) { g->hist = history_create_empty(); - g->hist = history_insert_first(g->hist, game_get_square(g, i, j), i, j); + g->hist = history_insert_first(g->hist, game_get_state(g, i, j), i, j); } else { - g->hist = history_next(history_insert_after(g->hist, g->hist, game_get_square(g, i, j), i, j)); + g->hist = history_next(history_insert_after(g->hist, g->hist, game_get_state(g, i, j), i, j)); g->hist = history_delete_all_after(g->hist, g->hist); } game_set_square(g, i, j, s); diff --git a/game_ext.c b/game_ext.c index 0ed18f4..c094965 100644 --- a/game_ext.c +++ b/game_ext.c @@ -56,17 +56,17 @@ bool game_is_wrapping(cgame g) { } void game_undo(game g) { - if (history_prev(g->hist) == NULL) { - printf("waiting for your first move\n"); + if (g->hist == NULL) { + printf("you are at your first move\n"); } else { - game_set_square(g, history_i(history_prev(g->hist)), history_j(history_prev(g->hist)), history_state(history_prev(g->hist))); + game_set_square(g, history_i(g->hist), history_j(g->hist), history_state(g->hist)); game_update_flags(g); - g->hist = history_prev(g->hist); + g->hist = history_append(g->hist, g->hist->state, g->hist->i, g->hist->j); } } void game_redo(game g) { - if (history_next(g->hist) == NULL) { + if ((g->hist == NULL && (history_next(g->hist) == NULL)) || g->hist == NULL) { printf("waiting for you to undo first"); } else { game_set_square(g, history_i(history_next(g->hist)), history_j(history_next(g->hist)), history_state(history_next(g->hist))); diff --git a/game_test_thperrier.c b/game_test_thperrier.c index b833b60..cca5ce5 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -247,6 +247,22 @@ bool test_game_undo(){ return true; } +/* ********** game_redo ********** */ +bool test_game_redo(){ + game g1 = game_new_empty(); + game_play_move(g1, 0, 0, S_LIGHTBULB); + game_play_move(g1, 0, 1, S_MARK); + game_play_move(g1, 0, 0, S_BLANK); + game g2 = game_copy(g1); + game_undo(g1); + game_redo(g1); + if (!game_equal(g1, g2)){ + return false; + } + + return true; +} + /* ********** usage ********** */ void usage(int argc, char* argv[]) { fprintf(stderr, "Usage: %s \n", argv[0]); @@ -277,6 +293,8 @@ int main(int argc, char* argv[]) { success = test_game_get_black_number(); } else if (strcmp("game_undo", argv[1]) == 0) { success = test_game_undo(); + } else if (strcmp("game_redo", argv[1]) == 0) { + success = test_game_redo(); } else { fprintf(stderr, "test \"%s\" is not a valid test name.\n", argv[1]); return EXIT_FAILURE; From 1411c19bfe66306db6c4df707a47eaec34fc2078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 6 Jan 2022 06:09:57 +0100 Subject: [PATCH 201/281] calloc instead of malloc + for --- game_ext.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/game_ext.c b/game_ext.c index c094965..be70b22 100644 --- a/game_ext.c +++ b/game_ext.c @@ -31,14 +31,11 @@ game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { exit(EXIT_FAILURE); } for (int i = 0; i < g->height; i++) { - g->tab_cell[i] = (square*)malloc(sizeof(square) * g->width); + g->tab_cell[i] = (square*)calloc(g->width, sizeof(square)); if (g->tab_cell[i] == NULL) { fprintf(stderr, "not enough memory\n"); exit(EXIT_FAILURE); } - for (int j = 0; j < g->width; j++) { - g->tab_cell[i][j] = S_BLANK; - } } return g; } From a315c6c009ffd1e4123c7e4e72513ea72e58bff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 6 Jan 2022 06:10:24 +0100 Subject: [PATCH 202/281] tests game_print game ; game_get_state --- game_test_thoguet.c | 51 ++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 47b40bc..46e9821 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -5,6 +5,7 @@ #include #include "game.h" #include "game_aux.h" +#include "game_ext.h" typedef unsigned int uint; /* ********** DUMMY ********** */ @@ -81,18 +82,22 @@ bool test_game_new(void) { /* ******** game_print ******** */ bool test_game_print(void) { - square tab[DEFAULT_SIZE * DEFAULT_SIZE]; - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; - game g; - 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]; + for (int h = 1; h <= 10; h++) { + for (int w = 1; w <= 10; w++) { + square tab[w * h]; + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; + game g; + for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { + for (uint j = 0; j < w * h; j++) { + tab[j] = list[i]; + } + printf("%d\n", i); + g = game_new_ext(h, w, tab, false); + assert(g); + game_print(g); + game_delete(g); + } } - printf("%d\n", i); - g = game_new(tab); - assert(g); - game_print(g); - game_delete(g); } return EXIT_SUCCESS; } @@ -101,16 +106,20 @@ bool test_game_print(void) { bool test_game_get_square(void) { game g; - square tab[DEFAULT_SIZE * DEFAULT_SIZE]; - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, 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]); - game_delete(g); + for (int h = 1; h <= 10; h++) { + for (int w = 1; w <= 10; w++) { + square* tab = calloc(w * h, sizeof(square)); + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR}; + for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { + for (uint j = 0; j < h * w; j++) { + tab[j] = list[i]; + g = game_new_ext(h, w, tab, false); + printf("[%d, %d] %d %d\n", j / g->width, j % g->width, game_get_square(g, j / g->width, j % g->width), tab[j]); + assert(game_get_square(g, j / g->width, j % g->width) == tab[j]); + game_delete(g); + } + } + free(tab); } } return EXIT_SUCCESS; From 05516d686457dc63d88e8c17b2a3a6ffa623660c Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 6 Jan 2022 15:39:00 +0100 Subject: [PATCH 203/281] =?UTF-8?q?edit=20undo=20(=C3=A7a=20fonctionne)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game_ext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_ext.c b/game_ext.c index be70b22..d2efaf8 100644 --- a/game_ext.c +++ b/game_ext.c @@ -58,7 +58,7 @@ void game_undo(game g) { } else { game_set_square(g, history_i(g->hist), history_j(g->hist), history_state(g->hist)); game_update_flags(g); - g->hist = history_append(g->hist, g->hist->state, g->hist->i, g->hist->j); + g->hist = history_prev(g->hist); } } From 7cbf8776cceed40ab0ea72fa883829c4aff4d2c8 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 6 Jan 2022 17:21:53 +0100 Subject: [PATCH 204/281] edit undo + redo + game_new_ext --- game.c | 3 ++- game_ext.c | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/game.c b/game.c index 9897774..13b6c28 100644 --- a/game.c +++ b/game.c @@ -30,7 +30,7 @@ game game_new_empty(void) { g->wrapping = false; g->height = DEFAULT_SIZE; g->width = DEFAULT_SIZE; - g->hist = NULL; + g->hist = history_create_empty(); // alloc the tab with variables set before g->tab_cell = (square**)malloc(sizeof(square*) * g->height); if (g->tab_cell == NULL) { @@ -47,6 +47,7 @@ game game_new_empty(void) { g->tab_cell[i][j] = S_BLANK; } } + g->hist = history_insert_first(g->hist,F_ERROR,0,0); return g; } // TODO diff --git a/game_ext.c b/game_ext.c index d2efaf8..6dd5270 100644 --- a/game_ext.c +++ b/game_ext.c @@ -37,6 +37,7 @@ game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { exit(EXIT_FAILURE); } } + g->hist = history_insert_first(g->hist,F_ERROR,0,0); return g; } @@ -53,21 +54,25 @@ bool game_is_wrapping(cgame g) { } void game_undo(game g) { - if (g->hist == NULL) { + if (g->hist == NULL || history_is_empty(history_prev(g->hist))) { printf("you are at your first move\n"); } else { + square tmp = game_get_state(g, history_i(g->hist), history_j(g->hist)); game_set_square(g, history_i(g->hist), history_j(g->hist), history_state(g->hist)); game_update_flags(g); + g->hist->state = tmp; g->hist = history_prev(g->hist); } } void game_redo(game g) { - if ((g->hist == NULL && (history_next(g->hist) == NULL)) || g->hist == NULL) { - printf("waiting for you to undo first"); + if (g->hist == NULL || history_next(g->hist) == NULL) { + printf("you are at your last move\n"); } else { - game_set_square(g, history_i(history_next(g->hist)), history_j(history_next(g->hist)), history_state(history_next(g->hist))); - game_update_flags(g); g->hist = history_next(g->hist); + square tmp = game_get_state(g, history_i(g->hist), history_j(g->hist)); + game_set_square(g, history_i(g->hist), history_j(g->hist), history_state(g->hist)); + game_update_flags(g); + g->hist->state = tmp; } } \ No newline at end of file From 6d2378395ca45a5cd29028d05d782fb19118fc48 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 6 Jan 2022 17:35:52 +0100 Subject: [PATCH 205/281] edit game_restart --- game.c | 2 +- game_text.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/game.c b/game.c index 13b6c28..5f5336e 100644 --- a/game.c +++ b/game.c @@ -271,5 +271,5 @@ void game_restart(game g) { } game_update_flags(g); history_delete_entire_history(g->hist); - g->hist = NULL; + g->hist = history_insert_first(history_create_empty(),F_ERROR,0,0); } diff --git a/game_text.c b/game_text.c index f2d8bce..8621ed1 100644 --- a/game_text.c +++ b/game_text.c @@ -78,7 +78,7 @@ int main(int argc, char* argv[]) { printf("Entrez une commande (h pour afficher l'aide): "); if (scanf(" %c", &c)) { if (c == 'h') { - printhelp(); + printhelp(); } else if (c == 'r') { game_restart(g); printf("Partie réinitialisé avec succes !\n"); From 106aeb8db4f94312ed2d1e4734abbd4b907a1b5d Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 6 Jan 2022 17:59:28 +0100 Subject: [PATCH 206/281] add test redo + edit json gdb + edit test undo --- .vscode/launch.json | 29 ++++++++++++++++++++++++++++- CMakeLists.txt | 1 + game_test_thperrier.c | 22 ++++------------------ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 16b2d79..ccee47d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -82,6 +82,33 @@ } ], "preLaunchTask": "make_build" - } + }, + { + "name": "(gdb) debug tests thperrier", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/game_test_thperrier", + "args": [ + "game_undo" + ], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "make_build" + }, ] } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 047703f..ef1a473 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ add_test(test_thperrier_game_is_lightbulb ./game_test_thperrier game_is_lightbul add_test(test_thperrier_game_is_black ./game_test_thperrier game_is_black) add_test(test_thperrier_game_get_black_number ./game_test_thperrier game_get_black_number) add_test(test_thperrier_game_undo ./game_test_thperrier game_undo) +add_test(test_thperrier_game_undo ./game_test_thperrier game_redo) #Tests NNUNES add_test(test_nnunes_dummy ./game_test_nnunes dummy) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index cca5ce5..22c65ec 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -225,26 +225,12 @@ bool test_game_copy() { /* ********** game_undo ********** */ bool test_game_undo(){ game g1 = game_new_empty(); - game_play_move(g1, 2, 3, S_LIGHTBULB); - game_play_move(g1, 0, 0, S_MARK); - game_play_move(g1, 2, 3, S_BLANK); + game_play_move(g1, 0, 0, S_LIGHTBULB); + game_play_move(g1, 1, 1, S_MARK); game g2 = game_copy(g1); - game_play_move(g2, 2, 3, S_LIGHTBULB); + game_play_move(g2, 1, 1, S_BLANK); game_undo(g1); - if (!game_equal(g1, g2)){ - return false; - } - game_play_move(g2, 0, 0, S_BLANK); - game_undo(g1); - if (!game_equal(g1, g2)){ - return false; - } - game_play_move(g2, 2, 3, S_BLANK); - game_undo(g1); - if (!game_equal(g1, g2)){ - return false; - } - return true; + return game_equal(g1, g2); } /* ********** game_redo ********** */ From 0736126dbf6cf87be9aa6183f4ccf3bbf88ca154 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 6 Jan 2022 18:02:56 +0100 Subject: [PATCH 207/281] edit game_copy --- game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game.c b/game.c index 5f5336e..24b33e1 100644 --- a/game.c +++ b/game.c @@ -57,8 +57,8 @@ game game_copy(cgame g1) { for (int j = 0; j < g2->width; j++) { g2->tab_cell[i][j] = g1->tab_cell[i][j]; } - g2->hist = history_copy(g1->hist); } + g2->hist = history_copy(g1->hist); return g2; } From 463aa5900cc29502d703278a786768a2bb4beae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 6 Jan 2022 18:06:59 +0100 Subject: [PATCH 208/281] bug history copy --- history.c | 1 + 1 file changed, 1 insertion(+) diff --git a/history.c b/history.c index 4f8a8da..c0dd89c 100644 --- a/history.c +++ b/history.c @@ -201,6 +201,7 @@ history history_copy(history h) { h = history_next(h); cpt++; } + h = history_first(h); history h2 = history_insert_first(history_create_empty(), h->state, h->i, h->j); while (!history_is_empty(history_next(h))) { h = history_next(h); From c880ee14caaec9dda0887f1cba7f6e5ce6eacbf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 6 Jan 2022 18:07:13 +0100 Subject: [PATCH 209/281] clang format --- game.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game.c b/game.c index 24b33e1..41abf66 100644 --- a/game.c +++ b/game.c @@ -47,7 +47,7 @@ game game_new_empty(void) { g->tab_cell[i][j] = S_BLANK; } } - g->hist = history_insert_first(g->hist,F_ERROR,0,0); + g->hist = history_insert_first(g->hist, F_ERROR, 0, 0); return g; } // TODO @@ -271,5 +271,5 @@ void game_restart(game g) { } game_update_flags(g); history_delete_entire_history(g->hist); - g->hist = history_insert_first(history_create_empty(),F_ERROR,0,0); + g->hist = history_insert_first(history_create_empty(), F_ERROR, 0, 0); } From ec6126af3167377ff4eab55e6ebbf5ac349f8b45 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 6 Jan 2022 18:33:42 +0100 Subject: [PATCH 210/281] edit cmake test redo + edit test redo + edit json --- .vscode/settings.json | 3 ++- CMakeLists.txt | 2 +- game_test_thperrier.c | 57 +++++++++++++++++++++++++++++++------------ 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7441b23..604d63d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,6 @@ "game_ext.h": "c", "game.h": "c" }, - "editor.formatOnSave": true + "editor.formatOnSave": true, + "C_Cpp.clang_format_path": "/usr/bin/clang-format" } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ef1a473..f83e5cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ add_test(test_thperrier_game_is_lightbulb ./game_test_thperrier game_is_lightbul add_test(test_thperrier_game_is_black ./game_test_thperrier game_is_black) add_test(test_thperrier_game_get_black_number ./game_test_thperrier game_get_black_number) add_test(test_thperrier_game_undo ./game_test_thperrier game_undo) -add_test(test_thperrier_game_undo ./game_test_thperrier game_redo) +add_test(test_thperrier_game_redo ./game_test_thperrier game_redo) #Tests NNUNES add_test(test_nnunes_dummy ./game_test_nnunes dummy) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 22c65ec..1fae9af 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -223,29 +223,56 @@ bool test_game_copy() { } /* ********** game_undo ********** */ -bool test_game_undo(){ +bool test_game_undo() { + game g1 = game_new_empty(); + game g2 = game_copy(g1); + game_undo(g1); + if (!game_equal(g1, g2)) { + game_delete(g1); + game_delete(g2); + return false; + } + game_play_move(g1, 0, 0, S_LIGHTBULB); + game_play_move(g1, 1, 1, S_MARK); + game g3 = game_copy(g1); + game_play_move(g3, 1, 1, S_BLANK); + game_undo(g1); + if (!game_equal(g1, g3)) { + game_delete(g1); + game_delete(g2); + game_delete(g3); + return false; + } + game_delete(g1); + game_delete(g2); + game_delete(g3); + return true; +} + +/* ********** game_redo ********** */ +bool test_game_redo() { game g1 = game_new_empty(); game_play_move(g1, 0, 0, S_LIGHTBULB); game_play_move(g1, 1, 1, S_MARK); game g2 = game_copy(g1); - game_play_move(g2, 1, 1, S_BLANK); - game_undo(g1); - return game_equal(g1, g2); -} - -/* ********** game_redo ********** */ -bool test_game_redo(){ - game g1 = game_new_empty(); - game_play_move(g1, 0, 0, S_LIGHTBULB); - game_play_move(g1, 0, 1, S_MARK); - game_play_move(g1, 0, 0, S_BLANK); - game g2 = game_copy(g1); game_undo(g1); game_redo(g1); - if (!game_equal(g1, g2)){ + game_redo(g1); + if (!game_equal(g1, g2)) { + game_delete(g1); + game_delete(g2); return false; } - + game_play_move(g1, 2, 2, S_LIGHTBULB); + game_play_move(g2, 2, 2, S_LIGHTBULB); + game_redo(g1); + if (!game_equal(g1, g2)) { + game_delete(g1); + game_delete(g2); + return false; + } + game_delete(g1); + game_delete(g2); return true; } From 49c2fdd5ab455901afa440886ed788174d9e7133 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 6 Jan 2022 18:47:56 +0100 Subject: [PATCH 211/281] sa mere --- game.c | 1 + 1 file changed, 1 insertion(+) diff --git a/game.c b/game.c index 41abf66..40543b7 100644 --- a/game.c +++ b/game.c @@ -58,6 +58,7 @@ game game_copy(cgame g1) { g2->tab_cell[i][j] = g1->tab_cell[i][j]; } } + history_delete_entire_history(g2->hist); g2->hist = history_copy(g1->hist); return g2; } From 2c8679d077fc0379576dc73b313ad23b7e9fdbb3 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 6 Jan 2022 18:59:24 +0100 Subject: [PATCH 212/281] edit json gdb + edit test_game_copy --- game_test_thperrier.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 1fae9af..65ac3dd 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -188,13 +188,13 @@ bool test_game_new_empty() { bool test_game_copy() { game g1 = game_new_empty(); for (int i = 0; i < g1->height; i++) { - game_set_square(g1, i, 0, S_LIGHTBULB); - game_set_square(g1, i, 1, S_MARK); - game_set_square(g1, i, 2, S_BLACKU); - game_set_square(g1, i, 3, S_BLACK0); - game_set_square(g1, i, 4, S_BLACK1); - game_set_square(g1, 1, 2, F_LIGHTED); - game_set_square(g1, 1, 3, F_ERROR); + game_play_move(g1, i, 0, S_LIGHTBULB); + game_play_move(g1, i, 1, S_MARK); + game_play_move(g1, i, 2, S_BLACKU); + game_play_move(g1, i, 3, S_BLACK0); + game_play_move(g1, i, 4, S_BLACK1); + game_play_move(g1, i, 5, F_LIGHTED); + game_play_move(g1, i, 6, F_ERROR); } game g2 = game_copy(g1); assert(g2); From fb593823612c0ac487233a79245a6547284be70f Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 6 Jan 2022 18:59:41 +0100 Subject: [PATCH 213/281] edit json gdb --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index ccee47d..7686160 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -89,7 +89,7 @@ "request": "launch", "program": "${workspaceFolder}/build/game_test_thperrier", "args": [ - "game_undo" + "game_copy" ], "stopAtEntry": false, "cwd": "${fileDirname}", From 3485b9ec6804a7cb050a28bd7a7db356ff6ccc79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sat, 8 Jan 2022 23:05:17 +0100 Subject: [PATCH 214/281] game_private to not change others .h --- .vscode/settings.json | 3 ++- game.c | 2 +- game.h | 16 +++++----------- game_aux.c | 1 + game_aux.h | 3 ++- game_ext.c | 3 ++- game_private.h | 13 +++++++++++++ game_test_nnunes.c | 3 ++- game_test_thoguet.c | 2 ++ game_test_thperrier.c | 1 + game_text.c | 3 ++- 11 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 game_private.h diff --git a/.vscode/settings.json b/.vscode/settings.json index 604d63d..8431ee7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,8 @@ { "files.associations": { "game_ext.h": "c", - "game.h": "c" + "game.h": "c", + "game_private.h": "c" }, "editor.formatOnSave": true, "C_Cpp.clang_format_path": "/usr/bin/clang-format" diff --git a/game.c b/game.c index 40543b7..7c2ac5c 100644 --- a/game.c +++ b/game.c @@ -2,6 +2,7 @@ #include #include #include "game_ext.h" +#include "game_private.h" int max(int a, int b) { if (a > b) @@ -50,7 +51,6 @@ game game_new_empty(void) { g->hist = history_insert_first(g->hist, F_ERROR, 0, 0); return g; } -// TODO game game_copy(cgame g1) { game g2 = game_new_empty_ext(g1->height, g1->width, g1->wrapping); for (int i = 0; i < g2->height; i++) { diff --git a/game.h b/game.h index f1c54d2..4c0ecb0 100644 --- a/game.h +++ b/game.h @@ -7,11 +7,12 @@ #ifndef __GAME_H__ #define __GAME_H__ + #include + /** * @brief Standard unsigned integer type. **/ - typedef unsigned int uint; /** @@ -57,15 +58,6 @@ typedef enum { /** square mask used in square enum */ #define A_MASK 0xFF -#include "history.h" -struct game_s { - square** tab_cell; - bool wrapping; - uint height; // i in general - uint width; // j in general - history hist; -}; - /** * @brief The structure pointer that stores the game state. **/ @@ -217,6 +209,8 @@ bool game_is_black(cgame g, uint i, uint j); * @pre @p g must be a valid pointer toward a game structure. * @pre @p i < game height * @pre @p j < game width + * @pre The square at position (i,j) must be a black wall (either numbered or + * unumbered). * @return the back wall number, or -1 if it is unumbered **/ int game_get_black_number(cgame g, uint i, uint j); @@ -319,4 +313,4 @@ bool game_is_over(cgame g); **/ void game_restart(game g); -#endif // __GAME_H__ +#endif // __GAME_H__ \ No newline at end of file diff --git a/game_aux.c b/game_aux.c index 76a4335..6dd606f 100644 --- a/game_aux.c +++ b/game_aux.c @@ -1,6 +1,7 @@ #include #include #include "game.h" +#include "game_private.h" char charPrintCell(cgame g, uint i, uint j) { square sqState = game_get_state(g, i, j); diff --git a/game_aux.h b/game_aux.h index 294f997..1e425a6 100644 --- a/game_aux.h +++ b/game_aux.h @@ -8,6 +8,7 @@ #ifndef __GAME_AUX_H__ #define __GAME_AUX_H__ #include + #include "game.h" /** @@ -35,4 +36,4 @@ game game_default(void); **/ game game_default_solution(void); -#endif // __GAME_AUX_H__ +#endif // __GAME_AUX_H__ \ No newline at end of file diff --git a/game_ext.c b/game_ext.c index 6dd5270..8f8e486 100644 --- a/game_ext.c +++ b/game_ext.c @@ -1,6 +1,7 @@ #include "game_ext.h" #include #include +#include "game_private.h" game game_new_ext(uint nb_rows, uint nb_cols, square* squares, bool wrapping) { game g = game_new_empty_ext(nb_rows, nb_cols, wrapping); @@ -37,7 +38,7 @@ game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { exit(EXIT_FAILURE); } } - g->hist = history_insert_first(g->hist,F_ERROR,0,0); + g->hist = history_insert_first(g->hist, F_ERROR, 0, 0); return g; } diff --git a/game_private.h b/game_private.h new file mode 100644 index 0000000..462e29e --- /dev/null +++ b/game_private.h @@ -0,0 +1,13 @@ +#ifndef __GAME_PRIVATE_H__ +#define __GAME_PRIVATE_H__ +#include "history.h" + +struct game_s { + square** tab_cell; + bool wrapping; + uint height; // i in general + uint width; // j in general + history hist; +}; + +#endif \ No newline at end of file diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 8d313c1..ef72fec 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -6,6 +6,7 @@ #include "game.h" #include "game_aux.h" #include "game_ext.h" +#include "game_private.h" bool test_dummy(void) { return true; @@ -410,7 +411,7 @@ int main(int argc, char* argv[]) { } else if (strcmp("game_nb_cols", argv[1]) == 0) { success = test_game_nb_cols(); } else if (strcmp("game_is_wrapping", argv[1]) == 0) { - success = test_game_is_wrapping(); + success = test_game_is_wrapping(); } else { fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); exit(EXIT_FAILURE); diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 46e9821..8534665 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -6,6 +6,8 @@ #include "game.h" #include "game_aux.h" #include "game_ext.h" +#include "game_private.h" + typedef unsigned int uint; /* ********** DUMMY ********** */ diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 65ac3dd..50e4749 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -6,6 +6,7 @@ #include "game.h" #include "game_aux.h" #include "game_ext.h" +#include "game_private.h" /* ********** DUMMY ********** */ bool test_dummy() { diff --git a/game_text.c b/game_text.c index 8621ed1..3e66832 100644 --- a/game_text.c +++ b/game_text.c @@ -4,6 +4,7 @@ #include "game.h" #include "game_aux.h" #include "game_ext.h" +#include "game_private.h" bool checkerr(cgame g, char taberr[]) { if (taberr == NULL || g == NULL) { @@ -78,7 +79,7 @@ int main(int argc, char* argv[]) { printf("Entrez une commande (h pour afficher l'aide): "); if (scanf(" %c", &c)) { if (c == 'h') { - printhelp(); + printhelp(); } else if (c == 'r') { game_restart(g); printf("Partie réinitialisé avec succes !\n"); From e638de8f69c8a66d29f17b35b138b1fdc388ebc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 9 Jan 2022 20:04:39 +0100 Subject: [PATCH 215/281] finished V2 --- CMakeLists.txt | 4 +- game.c | 6 - game_private.c | 5 + game_private.h | 2 + game_test_nnunes.c | 6 + game_test_thoguet.c | 263 +++++++++++++++++++++----------------------- 6 files changed, 142 insertions(+), 144 deletions(-) create mode 100644 game_private.c diff --git a/CMakeLists.txt b/CMakeLists.txt index f83e5cd..192ce31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ target_link_libraries(game_test_nnunes game history) target_link_libraries(history_test game history) #Libraries -add_library (game game.c game_aux.c game_ext.c) +add_library (game game.c game_aux.c game_ext.c game_private.c) add_library(history history.c) #Tests THOGUET @@ -41,6 +41,8 @@ add_test(test_thoguet_game_is_over ./game_test_thoguet game_is_over) add_test(test_thoguet_game_update_flags ./game_test_thoguet game_update_flags) add_test(test_thoguet_game_play_move ./game_test_thoguet game_play_move) add_test(test_thoguet_game_check_move ./game_test_thoguet game_check_move) +add_test(test_thoguet_game_new_empty_ext ./game_test_thoguet game_new_empty_ext) +add_test(test_thoguet_game_new_ext ./game_test_thoguet game_new_ext) #Tests THPERRIER add_test(test_thperrier_dummy ./game_test_thperrier dummy) diff --git a/game.c b/game.c index 7c2ac5c..385277b 100644 --- a/game.c +++ b/game.c @@ -4,12 +4,6 @@ #include "game_ext.h" #include "game_private.h" -int max(int a, int b) { - if (a > b) - return a; - return b; -} - game game_new(square* squares) { game g = game_new_empty(); for (int i = 0; i < g->height; i++) { diff --git a/game_private.c b/game_private.c new file mode 100644 index 0000000..95f7327 --- /dev/null +++ b/game_private.c @@ -0,0 +1,5 @@ +int max(int a, int b) { + if (a > b) + return a; + return b; +} \ No newline at end of file diff --git a/game_private.h b/game_private.h index 462e29e..3c0134c 100644 --- a/game_private.h +++ b/game_private.h @@ -10,4 +10,6 @@ struct game_s { history hist; }; +int max(int a, int b); + #endif \ No newline at end of file diff --git a/game_test_nnunes.c b/game_test_nnunes.c index ef72fec..893ecaa 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -363,8 +363,10 @@ bool test_game_has_error(void) { bool test_game_nb_rows(void) { game g = game_new_empty(); if (game_nb_rows(g) != g->height) { + game_delete(g); return false; } + game_delete(g); return true; } @@ -372,8 +374,10 @@ bool test_game_nb_rows(void) { bool test_game_nb_cols(void) { game g = game_new_empty(); if (game_nb_cols(g) != g->width) { + game_delete(g); return false; } + game_delete(g); return true; } @@ -381,8 +385,10 @@ bool test_game_nb_cols(void) { bool test_game_is_wrapping(void) { game g = game_new_empty(); if (game_is_wrapping(g) != g->wrapping) { + game_delete(g); return false; } + game_delete(g); return true; } diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 8534665..ae7aa4e 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "game.h" #include "game_aux.h" #include "game_ext.h" @@ -15,6 +16,51 @@ bool test_dummy(void) { return EXIT_SUCCESS; } +/* ******* game_new_ext_empty ******* */ + +bool test_game_new_empty_ext(void) { + for (int h = 1; h <= 10; h++) { + for (int w = 1; w <= 10; w++) { + for (int wrap = 0; wrap < 2; wrap++) { + game g = game_new_empty_ext(h, w, wrap); + assert(g); + game_delete(g); + } + } + } + return EXIT_SUCCESS; +} + +/* ******* game_new_ext ******* */ + +bool test_game_new_ext(void) { + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR}; + for (int h = 1; h <= 10; h++) { + for (int w = 1; w <= 10; w++) { + square tab[h * w]; + game g; + for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { + g = NULL; + for (uint j = 0; j < h * w; j++) { + tab[j] = list[i]; + } + for (int wrap = 0; wrap < 2; wrap++) { + printf("%d\n", i); + g = game_new_ext(h, w, tab, wrap); + assert(g); + for (uint i2 = 0; i2 < g->height; i2++) { + for (uint j = 0; j < g->width; j++) { + printf("list :%d, get square :%d\n", list[i], game_get_square(g, i2, j)); + assert(list[i] == game_get_square(g, i2, j)); + } + } + game_delete(g); + } + } + } + } + return EXIT_SUCCESS; +} /* ******* game_is_over ******* */ bool test_game_is_over(void) { @@ -51,6 +97,8 @@ bool test_game_restart(void) { game_restart(g1); game_restart(g); assert(game_equal(g, g1)); + assert(g1->hist->next == NULL && g->hist->prev == NULL && g1->hist->state == F_ERROR); + assert(g->hist->next == NULL && g->hist->prev == NULL && g->hist->state == F_ERROR); game_delete(g); game_delete(g1); return EXIT_SUCCESS; @@ -110,7 +158,7 @@ bool test_game_get_square(void) { game g; for (int h = 1; h <= 10; h++) { for (int w = 1; w <= 10; w++) { - square* tab = calloc(w * h, sizeof(square)); + square tab[w * h]; square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR}; for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { for (uint j = 0; j < h * w; j++) { @@ -121,7 +169,6 @@ bool test_game_get_square(void) { game_delete(g); } } - free(tab); } } return EXIT_SUCCESS; @@ -203,45 +250,22 @@ int checklightbulb(game g, uint i, uint j, bool wall) { } else { if (/*test if the current case is lighted*/ flags == F_LIGHTED) { - // printf("i:%d j:%d\n",i,j); - for (int i2 = i - 1; i2 >= 0; i2--) { - flags = game_get_square(g, i2, j); - // printf("i2:%d i2state:%d i2flags:%d\n",i2,state,flags); - if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { - return -1; - } - if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { - break; + int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; + for (uint y = 0; y < 7 /*tab size*/; y = y + 2) { + for (int x = 1; x < max(g->width, g->height); x++) { + if (/* test if both tab are not 0*/ tab[y] != tab[y + 1] && + (/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 && i + x * tab[y] < g->height) || + /* wrapping check*/ g->wrapping)) { + flags = game_get_square(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width)); + if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + return -1; + } + if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { + break; + } + } } } - for (int i2 = i + 1; i2 < g->height; i2++) { - flags = game_get_square(g, i2, j); - if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { - return -1; - } - if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { - break; - } - } - for (int j2 = j - 1; j2 >= 0; j2--) { - flags = game_get_square(g, i, j2); - if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { - return -1; - } - if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { - break; - } - } - for (int j2 = j + 1; j2 < g->width; j2++) { - flags = game_get_square(g, i, j2); - if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { - return -1; - } - if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { - break; - } - } - // printf("220\n"); return 0; } } @@ -249,12 +273,6 @@ int checklightbulb(game g, uint i, uint j, bool wall) { } bool check_update(game g) { - uint size; - square choice[4]; - uint lb; - uint notempty; - bool res; - bool wall; for (uint i = 0; i < g->height; i++) { for (uint j = 0; j < g->width; j++) { if (game_is_lightbulb(g, i, j)) { @@ -263,98 +281,45 @@ bool check_update(game g) { // printf("196\n"); return false; } - // loop checking every case before i - wall = false; - for (int k = i - 1; k >= 0; k--) { - if (/*test if current case is a wall*/ game_is_black(g, k, j)) { - wall = true; - } else { - int tmp = checklightbulb(g, k, j, wall); - if (tmp == -1) { - break; - } - if (!tmp) { - return tmp; - } - } - } - wall = false; - for (int k = i + 1; k < g->height; k++) { - if (/*test if current case is a wall*/ game_is_black(g, k, j)) { - wall = true; - } else { - int tmp = checklightbulb(g, k, j, wall); - if (tmp == -1) { - break; - } - if (!tmp) { - return tmp; - } - } - } - wall = false; - for (int k = j - 1; k >= 0; k--) { - if (/*test if current case is a wall*/ game_is_black(g, i, k)) { - wall = true; - } else { - int tmp = checklightbulb(g, i, k, wall); - if (tmp == -1) { - break; - } - if (!tmp) { - return tmp; - } - } - } - wall = false; - for (int k = j + 1; k < g->width; k++) { - if (/*test if current case is a wall*/ game_is_black(g, i, k)) { - wall = true; - } else { - int tmp = checklightbulb(g, i, k, wall); - if (tmp == -1) { - break; - } - if (!tmp) { - return tmp; + int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; + for (uint y = 0; y < 7 /*tab size*/; y = y + 2) { + bool wall = false; + for (int x = 1; x < max(g->width, g->height); x++) { + if (/* test if both tab are not 0*/ tab[y] != tab[y + 1] && + (/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 && + i + x * tab[y] < g->height) || + /* wrapping check*/ g->wrapping)) { + if (/*test if current case is a wall*/ game_is_black(g, ((i + g->height + x * tab[y]) % g->height), + ((j + g->width + x * tab[y + 1]) % g->width))) { + wall = true; + } else { + int tmp = checklightbulb(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width), wall); + if (tmp == -1) { + break; + } + if (!tmp) { + return tmp; + } + } } } } } else if (/*test if current case is a wall*/ game_is_black(g, i, j)) { if (game_get_black_number(g, i, j) != -1) { // lookup for lightbulb and emptycells - size = 0; - lb = 0; - notempty = 0; - res = true; - if (i > 0) { - choice[size] = game_get_square(g, i - 1, j); - size++; - } else { - notempty++; - } - if (i < g->height - 1) { - choice[size] = game_get_square(g, i + 1, j); - size++; - } else { - notempty++; - } - if (j > 0) { - choice[size] = game_get_square(g, i, j - 1); - size++; - } else { - notempty++; - } - if (j < g->width - 1) { - choice[size] = game_get_square(g, i, j + 1); - size++; - } else { - notempty++; - } - for (int l = 0; l < size; l++) { - if (choice[l] == (S_LIGHTBULB | F_LIGHTED) || choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { - lb++; - } else if (choice[l] != S_BLANK) { + int lb = 0; + int notempty = 0; + int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; + bool res = true; + for (uint y = 0; y < 7; y = y + 2) { + if (/* normal check*/ (j + tab[y + 1] >= 0 && j + tab[y + 1] < g->width && i + tab[y] >= 0 && i + tab[y] < g->height) || + /*wrapping check*/ g->wrapping) { + if (game_is_lightbulb(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width)) + lb++; + else if (!game_is_blank(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width) || + game_is_lighted(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width)) + notempty++; + } else { notempty++; } } @@ -428,14 +393,34 @@ bool brutforce(game g, int a, bool* deldup) { return true; } -bool test_game_update_flags(void) { - game g = game_default(); +void randomise(game g) { + time_t t; + srand((unsigned)time(&t)); assert(g); - if (!brutforce(g, 1, NULL)) { - game_delete(g); - return EXIT_FAILURE; + square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, + S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK}; + for (uint h = 0; h < g->height; h++) { + for (uint w = 0; w < g->width; w++) { + game_set_square(g, h, w, list[rand() % 16]); + } + } +} + +bool test_game_update_flags(void) { + for (uint h = 1; h <= 6; h++) { + for (uint w = 1; w <= 6; w++) { + for (int wrap = 0; wrap < 2; wrap++) { + game g = game_new_empty_ext(h, w, wrap); + assert(g); + randomise(g); + if (!brutforce(g, 1, NULL)) { + game_delete(g); + return EXIT_FAILURE; + } + game_delete(g); + } + } } - game_delete(g); return EXIT_SUCCESS; } @@ -531,6 +516,10 @@ int main(int argc, char* argv[]) { ok = test_game_play_move(); else if (strcmp("game_check_move", argv[1]) == 0) ok = test_game_check_move(); + else if (strcmp("game_new_empty_ext", argv[1]) == 0) + ok = test_game_new_empty_ext(); + else if (strcmp("game_new_ext", argv[1]) == 0) + ok = test_game_new_ext(); else { fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); exit(EXIT_FAILURE); From 3e633347d446aa53acc98ba3f05546d1f4eb7b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 11 Jan 2022 19:19:38 +0100 Subject: [PATCH 216/281] history on libgame --- CMakeLists.txt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 192ce31..40dafa4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,15 +19,14 @@ add_executable(game_test_nnunes game_test_nnunes.c) add_executable(history_test history_test.c) #les dépendances sont calculées automatiquement -target_link_libraries(game_text game history) -target_link_libraries(game_test_thoguet game history) -target_link_libraries(game_test_thperrier game history) -target_link_libraries(game_test_nnunes game history) -target_link_libraries(history_test game history) +target_link_libraries(game_text game) +target_link_libraries(game_test_thoguet game) +target_link_libraries(game_test_thperrier game) +target_link_libraries(game_test_nnunes game) +target_link_libraries(history_test game) #Libraries -add_library (game game.c game_aux.c game_ext.c game_private.c) -add_library(history history.c) +add_library (game game.c game_aux.c game_ext.c game_private.c history.c) #Tests THOGUET add_test(test_thoguet_dummy ./game_test_thoguet dummy) From 5cc29e88e0b39a8cffb80e94a9b6b37d66ad06cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 11 Jan 2022 19:24:21 +0100 Subject: [PATCH 217/281] game equal missed a game_default --- game.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game.c b/game.c index 385277b..09f173d 100644 --- a/game.c +++ b/game.c @@ -60,8 +60,8 @@ game game_copy(cgame g1) { bool game_equal(cgame g1, cgame g2) { if (g1->height != g2->height || g1->width != g2->width || g1->wrapping != g2->wrapping) return false; - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g1->height; i++) { + for (int j = 0; j < g1->width; j++) { if (g1->tab_cell[i][j] != g2->tab_cell[i][j]) { return false; } From e57ddb3f78b9ee56c8211d17d3cd0068b325b9e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 11 Jan 2022 20:17:07 +0100 Subject: [PATCH 218/281] update flags wrapped --- game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game.c b/game.c index 09f173d..eb59444 100644 --- a/game.c +++ b/game.c @@ -198,7 +198,7 @@ void game_update_flags(game g) { if (/* test if both tab are not 0*/ tab[y] != tab[y + 1] && (/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 && i + x * tab[y] < g->height) || - /* wrapping check*/ g->wrapping)) { + /* wrapping check*/ (g->wrapping && (((i + g->height + x * tab[y]) != i) && ((j + g->width + x * tab[y + 1]) % g->width) != j)))) { if (game_is_black(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width))) { tab[y] = 0; tab[y + 1] = 0; From 842afc0ec4991bc53a5155d0c0132d232605c126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 11 Jan 2022 20:20:24 +0100 Subject: [PATCH 219/281] black wall updateflags wrapping --- game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game.c b/game.c index eb59444..1e3a792 100644 --- a/game.c +++ b/game.c @@ -224,7 +224,7 @@ void game_update_flags(game g) { int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; for (uint y = 0; y < 7; y = y + 2) { if (/* normal check*/ (j + tab[y + 1] >= 0 && j + tab[y + 1] < g->width && i + tab[y] >= 0 && i + tab[y] < g->height) || - /*wrapping check*/ g->wrapping) { + /*wrapping check*/ (g->wrapping && (((i + g->height + x * tab[y]) != i) && ((j + g->width + x * tab[y + 1]) % g->width) != j))) { if (game_is_lightbulb(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width)) lb++; else if (!game_is_blank(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width) || From 1205bbcd254b4e913a46ffc451c5908d7f09b7aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 11 Jan 2022 20:37:32 +0100 Subject: [PATCH 220/281] black wall updateflags wrapping --- game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game.c b/game.c index 1e3a792..7e29bec 100644 --- a/game.c +++ b/game.c @@ -224,7 +224,7 @@ void game_update_flags(game g) { int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; for (uint y = 0; y < 7; y = y + 2) { if (/* normal check*/ (j + tab[y + 1] >= 0 && j + tab[y + 1] < g->width && i + tab[y] >= 0 && i + tab[y] < g->height) || - /*wrapping check*/ (g->wrapping && (((i + g->height + x * tab[y]) != i) && ((j + g->width + x * tab[y + 1]) % g->width) != j))) { + /*wrapping check*/ (g->wrapping && (((i + g->height + 1 * tab[y]) != i) && ((j + g->width + 1 * tab[y + 1]) % g->width) != j))) { if (game_is_lightbulb(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width)) lb++; else if (!game_is_blank(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width) || From 586c152da48cc339eeb1b324f1abbd50e86a3d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 11 Jan 2022 23:03:04 +0100 Subject: [PATCH 221/281] fixed --- game.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/game.c b/game.c index 7e29bec..d68a5f9 100644 --- a/game.c +++ b/game.c @@ -198,7 +198,8 @@ void game_update_flags(game g) { if (/* test if both tab are not 0*/ tab[y] != tab[y + 1] && (/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 && i + x * tab[y] < g->height) || - /* wrapping check*/ (g->wrapping && (((i + g->height + x * tab[y]) != i) && ((j + g->width + x * tab[y + 1]) % g->width) != j)))) { + /* wrapping check*/ ( + g->wrapping && !((((i + g->height + x * tab[y]) % g->height) == i) && (((j + g->width + x * tab[y + 1]) % g->width) == j))))) { if (game_is_black(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width))) { tab[y] = 0; tab[y + 1] = 0; @@ -224,7 +225,8 @@ void game_update_flags(game g) { int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; for (uint y = 0; y < 7; y = y + 2) { if (/* normal check*/ (j + tab[y + 1] >= 0 && j + tab[y + 1] < g->width && i + tab[y] >= 0 && i + tab[y] < g->height) || - /*wrapping check*/ (g->wrapping && (((i + g->height + 1 * tab[y]) != i) && ((j + g->width + 1 * tab[y + 1]) % g->width) != j))) { + /*wrapping check*/ (g->wrapping && + !((((i + g->height + tab[y]) % g->height) == i) && (((j + g->width + tab[y + 1]) % g->width) == j)))) { if (game_is_lightbulb(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width)) lb++; else if (!game_is_blank(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width) || From 78960c6ef989467a89f3f4abb860b63247b026dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Tue, 11 Jan 2022 23:05:58 +0100 Subject: [PATCH 222/281] Lenght commit message fixed as been fixed --- game.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/game.c b/game.c index d68a5f9..928a4cd 100644 --- a/game.c +++ b/game.c @@ -198,8 +198,9 @@ void game_update_flags(game g) { if (/* test if both tab are not 0*/ tab[y] != tab[y + 1] && (/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 && i + x * tab[y] < g->height) || - /* wrapping check*/ ( - g->wrapping && !((((i + g->height + x * tab[y]) % g->height) == i) && (((j + g->width + x * tab[y + 1]) % g->width) == j))))) { + /* wrapping check*/ (g->wrapping && + /*not the same case*/ !((((i + g->height + x * tab[y]) % g->height) == i) && + (((j + g->width + x * tab[y + 1]) % g->width) == j))))) { if (game_is_black(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width))) { tab[y] = 0; tab[y + 1] = 0; @@ -225,8 +226,9 @@ void game_update_flags(game g) { int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; for (uint y = 0; y < 7; y = y + 2) { if (/* normal check*/ (j + tab[y + 1] >= 0 && j + tab[y + 1] < g->width && i + tab[y] >= 0 && i + tab[y] < g->height) || - /*wrapping check*/ (g->wrapping && - !((((i + g->height + tab[y]) % g->height) == i) && (((j + g->width + tab[y + 1]) % g->width) == j)))) { + /*wrapping check*/ ( + g->wrapping && + /*not the same case*/ !((((i + g->height + tab[y]) % g->height) == i) && (((j + g->width + tab[y + 1]) % g->width) == j)))) { if (game_is_lightbulb(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width)) lb++; else if (!game_is_blank(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width) || From bd2ce3c07b61b551d361fe47796e50f78fa08f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Wed, 12 Jan 2022 22:19:20 +0100 Subject: [PATCH 223/281] readme update --- README.md | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 8ad1474..76e3fbf 100644 --- a/README.md +++ b/README.md @@ -6,36 +6,36 @@ Projet Techno ## game_ext.h -| Fonction | REF | Assigned to | Notes | Finished | -| ------------------------------------ | ---------------------------------------------------------------------------- | ----------- | ----- | :--------------------: | -| [game_new_ext](./game_ext.c#L?) | [game game_new_ext(uint nb_rows, uint nb_cols, square *squares, bool wrapping)](./game_ext.h#L20-30) | @thoguet | |
  • [ ]
| -| [game_new_empty_ext](./game_ext.c#L?) | [game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping);](./game_ext.h#L32-41) | @thoguet | |
  • [ ]
| -| [game_nb_rows](./game_ext.c#L?) | [uint game_nb_rows(cgame g);](./game_ext.h#L43-59) | @nnunes | |
  • [X]
| -| [game_nb_cols](./game_ext.c#L?) | [uint game_nb_cols(cgame g);](./game_ext.h#L51-57) | @nnunes | |
  • [X]
| -| [game_is_wrapping](./game_ext.c#L?) | [bool game_is_wrapping(cgame g);](./game_ext.h#L59-64) | @nnunes | |
  • [X]
| -| [game_undo](./game_ext.c#L?) | [void game_undo(game g);](./game_ext.h#L66-75) | @thperrier | |
  • [X]
| -| [game_redo](./game_ext.c#L?) | [void game_redo(game g);](./game_ext.h#L77-86) | @thperrier | |
  • [X]
| +| Fonction | REF | Assigned to | Notes | Finished | +| ------------------------------------- | ---------------------------------------------------------------------------------------------------- | ----------- | ----- | :--------------------: | +| [game_new_ext](./game_ext.c#L?) | [game game_new_ext(uint nb_rows, uint nb_cols, square *squares, bool wrapping)](./game_ext.h#L20-30) | @thoguet | |
  • [X]
| +| [game_new_empty_ext](./game_ext.c#L?) | [game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping);](./game_ext.h#L32-41) | @thoguet | |
  • [X]
| +| [game_nb_rows](./game_ext.c#L?) | [uint game_nb_rows(cgame g);](./game_ext.h#L43-59) | @nnunes | |
  • [X]
| +| [game_nb_cols](./game_ext.c#L?) | [uint game_nb_cols(cgame g);](./game_ext.h#L51-57) | @nnunes | |
  • [X]
| +| [game_is_wrapping](./game_ext.c#L?) | [bool game_is_wrapping(cgame g);](./game_ext.h#L59-64) | @nnunes | |
  • [X]
| +| [game_undo](./game_ext.c#L?) | [void game_undo(game g);](./game_ext.h#L66-75) | @thperrier | |
  • [X]
| +| [game_redo](./game_ext.c#L?) | [void game_redo(game g);](./game_ext.h#L77-86) | @thperrier | |
  • [X]
| ## game.c -| Fonction | REF | Assigned to | Notes | Finished | -| ------------------------------------ | ---------------------------------------------------------------------------- | ----------- | ----- | :--------------------: | -| [game_new](./game.c#L9-17) | [game game_new(square *squares)](./game.h#L73-81) | @thperrier | |
  • [x]
| -| [game_new_empty](./game.c#L19-41) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [x]
| -| [game_copy](./game.c#L43-51) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [x]
| -| [game_equal](./game.c#L53-62) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [x]
| -| [game_delete](./game.c#L64-72) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| -| [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [x]
| -| [game_get_square](./game.c#L78-80) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [X]
| -| [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [x]
| -| [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [x]
| -| [game_is_blank](./game.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [X]
| -| [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| -| [game_is_black](./game.c#L98-102) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [X]
| +| Fonction | REF | Assigned to | Notes | Finished | +| ------------------------------------------ | ---------------------------------------------------------------------------- | ----------- | ----- | :--------------------: | +| [game_new](./game.c#L9-17) | [game game_new(square *squares)](./game.h#L73-81) | @thperrier | |
  • [x]
| +| [game_new_empty](./game.c#L19-41) | [game game_new_empty(void)](./game.h#L83-88) | @thperrier | |
  • [x]
| +| [game_copy](./game.c#L43-51) | [game game_copy(cgame g)](./game.h#L90-96) | @thperrier | |
  • [x]
| +| [game_equal](./game.c#L53-62) | [bool game_equal(cgame g1, cgame g2)](./game.h#L98-106) | @thperrier | |
  • [x]
| +| [game_delete](./game.c#L64-72) | [void game_delete(game g);](./game.h#L108-113) | @thperrier | |
  • [x]
| +| [game_set_square](./game.c#L?) | [void game_set_square(game g, uint i, uint j, square s)](./game.h#L115-128) | @nnunes | |
  • [x]
| +| [game_get_square](./game.c#L78-80) | [square game_get_square(cgame g, uint i, uint j)](./game.h#L130-140) | @thoguet | |
  • [X]
| +| [game_get_state](./game.c#L?) | [square game_get_state(cgame g, uint i, uint j)](./game.h#L142-153) | @nnunes | |
  • [x]
| +| [game_get_flags](./game.c#L?) | [square game_get_flags(cgame g, uint i, uint j)](./game.h#L155-166) | @nnunes | |
  • [x]
| +| [game_is_blank](./game.c#L?) | [bool game_is_blank(cgame g, uint i, uint j)](./game.h#L168-178) | @thperrier | |
  • [X]
| +| [game_is_lightbulb](./game.c#L?) | [bool game_is_lightbulb(cgame g, uint i, uint j)](./game.h#L180-190) | @thperrier | |
  • [x]
| +| [game_is_black](./game.c#L98-102) | [bool game_is_black(cgame g, uint i, uint j)](./game.h#L192-202) | @thoguet | |
  • [X]
| | [game_get_black_number](./game.c#L104-108) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thoguet | |
  • [X]
| -| [game_is_marked](./game.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [x]
| -| [game_is_lighted](./game.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [x]
| -| [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [x]
| +| [game_is_marked](./game.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | |
  • [x]
| +| [game_is_lighted](./game.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | |
  • [x]
| +| [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | |
  • [x]
| | [game_check_move](./game.c#L122-128) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | |
  • [X]
| | [game_play_move](./game.c#L130-133) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | |
  • [X]
| | [game_update_flags](./game.c#L135-234) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | |
  • [X]
| From fafb1550fe054980a9fa9f66b29d7ed08ff62a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sat, 15 Jan 2022 22:19:36 +0100 Subject: [PATCH 224/281] add comments + errpoitner --- game_private.c | 10 ++++++++++ game_private.h | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/game_private.c b/game_private.c index 95f7327..5dbbd6e 100644 --- a/game_private.c +++ b/game_private.c @@ -1,5 +1,15 @@ +#include +#include + int max(int a, int b) { if (a > b) return a; return b; +} + +void checkPointer(void* p) { + if (!p) { + fprintf(stderr, "Error on given pointer.\n"); + exit(EXIT_FAILURE); + } } \ No newline at end of file diff --git a/game_private.h b/game_private.h index 3c0134c..28fef93 100644 --- a/game_private.h +++ b/game_private.h @@ -3,13 +3,29 @@ #include "history.h" struct game_s { + // tab of tab of square (eg: tab_cell[i][j]) square** tab_cell; bool wrapping; uint height; // i in general uint width; // j in general + // case of history history hist; }; +/** + * @brief return the max between a and b + * + * @param a int to test + * @param b int to test + * @return the max between a and b + */ int max(int a, int b); +/** + * @brief check if the pointer is NULL fprinf and exit else nothing + * + * @param p any pointer + */ +void checkPointer(void* p); + #endif \ No newline at end of file From fb0de1f20d00675de725bd9e4fc7613cb62b1bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sat, 15 Jan 2022 22:21:19 +0100 Subject: [PATCH 225/281] change lisible game_text + comments --- game_text.c | 153 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 89 insertions(+), 64 deletions(-) diff --git a/game_text.c b/game_text.c index 3e66832..eb068b0 100644 --- a/game_text.c +++ b/game_text.c @@ -6,36 +6,63 @@ #include "game_ext.h" #include "game_private.h" -bool checkerr(cgame g, char taberr[]) { - if (taberr == NULL || g == NULL) { +#define NBCHARERR 4 +#define CHAR0ASCII 48 + +/** + * @brief Edit the stringError with all errors of g + * @param g the game to analyze + * @param stringError A pointer toward a string allocated before + * @pre @p stringError size must be at least g->height * g->width * NBCHARERR + * @return true if there is an error on the game g and the stringError has been modified + */ +bool checkerrors(cgame g, char* stringError) { + if (stringError == NULL || g == NULL) { return -1; } - uint err = 0; - taberr[0] = '\0'; + uint index_taberr = 0; + // initialize stringError + stringError[0] = '\0'; for (int i = 0; i < g->height; i++) { for (int j = 0; j < g->width; j++) { // check each case if (game_has_error(g, i, j)) { - // if error append taberr with coo+, - taberr[err] = i + 48; - err++; - taberr[err] = ':'; - err++; - taberr[err] = j + 48; - err++; - taberr[err] = ' '; - err++; + // if error append stringError with coordinate of the error, + stringError[index_taberr] = i + CHAR0ASCII; + stringError[index_taberr] = ':'; + stringError[index_taberr] = j + CHAR0ASCII; + stringError[index_taberr] = ' '; + index_taberr = index_taberr + NBCHARERR; } } } - // if taberr changes print - if (taberr[0] != '\0') { - taberr[err] = '\0'; + // if stringError changed return true + if (stringError[0] != '\0') { + stringError[index_taberr] = '\0'; return true; } return false; } +/** + * @brief scan the coordinate and check if the move is possible if yes play it + * @param g the game to check and play + * @param s the square to update + */ +void checkPlayMove(game g, square s) { + uint i; + uint j; + if (scanf(" %u %u", &i, &j) == 2) { + if (game_check_move(g, i, j, s)) + game_play_move(g, i, j, s); + else + printf("Coordonnées invalide.\n"); + game_print(g); + return; + } + printf("Commande inconnue.\n"); +} + void printhelp(void) { printf("Liste des différentes commandes :\n"); printf("h : Affiche cette aide.\n"); @@ -43,17 +70,13 @@ void printhelp(void) { printf("q : Quitter la partie (abandon).\n"); printf("z : Annulez le coup (undo).\n"); printf("y : Annulez l'annulation du coup (redo).\n"); - printf( - "l : Place une ampoule (*light bulb*) dans la case " - "(,).\n"); - printf("m : Place une marque (*mark*) dans la case (,).\n"); - printf( - "b : Place placer une case vide (*blank*) à la position " - "(,).\n"); + printf("l : Place une ampoule (*) à la position (,).\n"); + printf("m : Place une marque (-) à la position (,).\n"); + printf("b : Place une case vide ( ) à la position (,).\n"); } void usage(int argc, char* argv[]) { - printf("Usage : %s => play the default game\n", argv[0]); + printf("Usage : %s => Joue la partie par défaut\n", argv[0]); exit(EXIT_FAILURE); } @@ -64,54 +87,56 @@ int main(int argc, char* argv[]) { g = game_default(); else usage(argc, argv); - // test if game is over - uint i; - uint j; - char taberr[g->height * g->width * 4]; + // init string for errors + char stringError[g->height * g->width * NBCHARERR]; char c; // print game game_print(g); + // test if game is over while (!game_is_over(g)) { // print errors - if (checkerr(g, taberr)) { - printf("Il y a un problème case: %s\n", taberr); - } + if (checkerrors(g, stringError)) + printf("Il y a un problème case(s): %s .\n", stringError); printf("Entrez une commande (h pour afficher l'aide): "); + // scan the first command without args if (scanf(" %c", &c)) { - if (c == 'h') { - printhelp(); - } else if (c == 'r') { - game_restart(g); - printf("Partie réinitialisé avec succes !\n"); - game_print(g); - } else if (c == 'q') { - printf("Solution: \n"); - game sol = game_default_solution(); - game_print(sol); - game_delete(sol); - game_delete(g); - printf("shame\n"); - return EXIT_SUCCESS; - } else if (c == 'z') { - game_undo(g); - game_print(g); - } else if (c == 'y') { - game_redo(g); - game_print(g); - } else if (c == 'l' || c == 'm' || c == 'b') { - if (scanf(" %u %u", &i, &j) == 2) { - if (c == 'l' && game_check_move(g, i, j, S_LIGHTBULB)) - game_play_move(g, i, j, S_LIGHTBULB); - else if (c == 'm' && game_check_move(g, i, j, S_MARK)) - game_play_move(g, i, j, S_MARK); - else if (c == 'b' && game_check_move(g, i, j, S_BLANK)) - game_play_move(g, i, j, S_BLANK); - else - printf("Erreur: (,) invalide.\n"); + switch (c) { + case 'h': + printhelp(); + break; + case 'r': + game_restart(g); + printf("Partie réinitialisé avec succes !\n"); game_print(g); - } - } else { - printf("Commande inconnue.\n"); + break; + case 'q': + printf("Solution: \n"); + game solution = game_default_solution(); + game_print(solution); + game_delete(solution); + game_delete(g); + printf("shame\n"); + return EXIT_SUCCESS; + break; + case 'z': + game_undo(g); + game_print(g); + break; + case 'y': + game_redo(g); + game_print(g); + break; + case 'l': + checkPlayMove(g, S_LIGHTBULB); + break; + case 'm': + checkPlayMove(g, S_MARK); + break; + case 'b': + checkPlayMove(g, S_BLANK); + break; + default: + printf("Commande inconnue.\n"); } } else { printf("Commande inconnue.\n"); From 76cc227c23260e1b9547bdb546f5e452a9787b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sat, 15 Jan 2022 22:22:37 +0100 Subject: [PATCH 226/281] game new and game new empty comments + opti --- game.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/game.c b/game.c index 928a4cd..b16ab64 100644 --- a/game.c +++ b/game.c @@ -18,8 +18,7 @@ game game_new_empty(void) { // alloc struct game g = (game)malloc(sizeof(struct game_s)); if (g == NULL) { - fprintf(stderr, "not enough memory\n"); - exit(EXIT_FAILURE); + memoryError(); } // set variable of struct g->wrapping = false; @@ -29,22 +28,22 @@ game game_new_empty(void) { // alloc the tab with variables set before g->tab_cell = (square**)malloc(sizeof(square*) * g->height); if (g->tab_cell == NULL) { - fprintf(stderr, "not enough memory\n"); - exit(EXIT_FAILURE); + memoryError(); } for (int i = 0; i < g->height; i++) { g->tab_cell[i] = (square*)malloc(sizeof(square) * g->width); if (g->tab_cell[i] == NULL) { - fprintf(stderr, "not enough memory\n"); - exit(EXIT_FAILURE); + memoryError(); } for (int j = 0; j < g->width; j++) { g->tab_cell[i][j] = S_BLANK; } } + // init history with an cell (if there is only this cell we consider the history as empty) g->hist = history_insert_first(g->hist, F_ERROR, 0, 0); return g; } + game game_copy(cgame g1) { game g2 = game_new_empty_ext(g1->height, g1->width, g1->wrapping); for (int i = 0; i < g2->height; i++) { From 78e92617f9a8f73e8e3a8ca126e15557b475bd6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sat, 15 Jan 2022 22:23:01 +0100 Subject: [PATCH 227/281] started hitsory comment + lisibility --- history.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/history.c b/history.c index c0dd89c..9303f56 100644 --- a/history.c +++ b/history.c @@ -66,14 +66,32 @@ uint history_j(history h) { return h->j; } +history history_last(history h) { + if (history_is_empty(h)) + errPointer(); + if (history_is_empty(history_next(h))) + return h; + return history_last(history_next(h)); +} + +history history_first(history h) { + if (history_is_empty(h)) + errPointer(); + if (history_is_empty(history_prev(h))) + return h; + return history_first(history_prev(h)); +} + history history_insert_first(history h, square state, uint i, uint j) { history new = history_alloc(); new->state = state; new->i = i; new->j = j; new->next = h; - if (!history_is_empty(h)) + if (!history_is_empty(h)) { + h = history_first(h); h->prev = new; + } return new; } @@ -135,22 +153,6 @@ history history_delete_before(history h, history p) { return h; } -history history_last(history h) { - if (history_is_empty(h)) - errPointer(); - if (history_is_empty(history_next(h))) - return h; - return history_last(history_next(h)); -} - -history history_first(history h) { - if (history_is_empty(h)) - errPointer(); - if (history_is_empty(history_prev(h))) - return h; - return history_first(history_prev(h)); -} - history history_delete_first(history h) { if (!history_is_empty(h)) { h = history_first(h); @@ -191,15 +193,15 @@ void history_delete_entire_history(history h) { } history history_copy(history h) { - history tmp = h; + history copy_h = h; if (history_is_empty(h)) { return h; } h = history_first(h); - uint cpt = 0; - while (h != tmp) { + uint index_h = 0; + while (h != copy_h) { h = history_next(h); - cpt++; + index_h++; } h = history_first(h); history h2 = history_insert_first(history_create_empty(), h->state, h->i, h->j); @@ -209,7 +211,7 @@ history history_copy(history h) { h2 = history_next(h2); } h2 = history_first(h2); - for (uint i = 0; i < cpt; i++) { + for (uint i = 0; i < index_h; i++) { h2 = history_next(h2); } return h2; From 2d76a0fb32eabc71e9f5f4f9db0b983eb7f78b88 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Wed, 19 Jan 2022 10:11:01 +0100 Subject: [PATCH 228/281] cleaning game_test_thperrier --- game_test_thperrier.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 50e4749..58b76ed 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -53,10 +53,6 @@ bool test_game_is_black() { return false; } game_set_square(g, 0, 0, S_BLACKU); - if (!game_is_black(g, 0, 0)) { - game_delete(g); - return false; - } if (!((game_get_square(g, 0, 0) == S_BLACKU) && game_is_black(g, 0, 0))) { game_delete(g); return false; @@ -123,24 +119,33 @@ bool test_game_is_black() { /* ********** game_is_lightbulb ********** */ bool test_game_is_lightbulb() { game g = game_new_empty(); - game_set_square(g, 0, 0, S_LIGHTBULB); - if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_lightbulb(g, 0, 0)) { + if (game_is_lightbulb(g, 0, 0)) { game_delete(g); - return true; + return false; + } + game_set_square(g, 0, 0, S_LIGHTBULB); + if (!((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_lightbulb(g, 0, 0))) { + game_delete(g); + return false; } game_delete(g); - return false; + return true; } /* ********** game_is_blank ********** */ bool test_game_is_blank() { game g = game_new_empty(); + if (!game_is_blank(g, 0, 0)) { + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK0); if (game_is_blank(g, 0, 0)) { game_delete(g); - return true; + return false; } game_delete(g); - return false; + return true; } /* ********** game_delete ********** */ From a10df5eabfdace7382fe17e46ba58bae712b46fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Wed, 19 Jan 2022 10:12:53 +0100 Subject: [PATCH 229/281] patched game_text checkerrors --- game_text.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/game_text.c b/game_text.c index eb068b0..886c787 100644 --- a/game_text.c +++ b/game_text.c @@ -29,10 +29,13 @@ bool checkerrors(cgame g, char* stringError) { if (game_has_error(g, i, j)) { // if error append stringError with coordinate of the error, stringError[index_taberr] = i + CHAR0ASCII; + index_taberr++; stringError[index_taberr] = ':'; + index_taberr++; stringError[index_taberr] = j + CHAR0ASCII; + index_taberr++; stringError[index_taberr] = ' '; - index_taberr = index_taberr + NBCHARERR; + index_taberr++; } } } @@ -96,7 +99,7 @@ int main(int argc, char* argv[]) { while (!game_is_over(g)) { // print errors if (checkerrors(g, stringError)) - printf("Il y a un problème case(s): %s .\n", stringError); + printf("Il y a un problème case(s): %s\n", stringError); printf("Entrez une commande (h pour afficher l'aide): "); // scan the first command without args if (scanf(" %c", &c)) { From c66ad4e22c1365c0cefa09d34d091fa8f8576c2a Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Wed, 19 Jan 2022 11:31:00 +0100 Subject: [PATCH 230/281] edit game_is_black + game_get_black_number --- game_test_thperrier.c | 119 ++++++++++++------------------------------ 1 file changed, 32 insertions(+), 87 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 58b76ed..553f736 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -15,31 +15,19 @@ bool test_dummy() { /* ********** game_get_black_number ********** */ bool test_game_get_black_number() { + square tab_square[] = {S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4}; game g = game_new_empty(); - game_set_square(g, 0, 0, S_BLACK0); - if (game_get_black_number(g, 0, 0) != 0) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK1); - if (game_get_black_number(g, 0, 0) != 1) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK2); - if (game_get_black_number(g, 0, 0) != 2) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK3); - if (game_get_black_number(g, 0, 0) != 3) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK4); - if (game_get_black_number(g, 0, 0) != 4) { - game_delete(g); - return false; + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + // check for each case given in tab_square if the function return the expected result + for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { + game_set_square(g, i, j, tab_square[tab_index]); + if (game_get_black_number(g, i, j) != tab_index) { + game_delete(g); + return false; + } + } + } } game_delete(g); return true; @@ -47,71 +35,28 @@ bool test_game_get_black_number() { /* ********** game_is_black ********** */ bool test_game_is_black() { + square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g = game_new_empty(); - if (game_is_black(g, 0, 0)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACKU); - if (!((game_get_square(g, 0, 0) == S_BLACKU) && game_is_black(g, 0, 0))) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK0); - if (!((game_get_square(g, 0, 0) == S_BLACK0) && game_is_black(g, 0, 0))) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK1); - if (!((game_get_square(g, 0, 0) == S_BLACK1) && game_is_black(g, 0, 0))) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK2); - if (!((game_get_square(g, 0, 0) == S_BLACK2) && game_is_black(g, 0, 0))) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK3); - if (!((game_get_square(g, 0, 0) == S_BLACK3) && game_is_black(g, 0, 0))) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK4); - if (!((game_get_square(g, 0, 0) == S_BLACK4) && game_is_black(g, 0, 0))) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_MARK); - if ((game_get_square(g, 0, 0) == S_MARK) && game_is_black(g, 0, 0)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_MARK); - if ((game_get_square(g, 0, 0) == S_MARK) && game_is_black(g, 0, 0)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_LIGHTBULB); - if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_black(g, 0, 0)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_LIGHTBULB); - if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_black(g, 0, 0)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, F_ERROR); - if ((game_get_square(g, 0, 0) == F_ERROR) && game_is_black(g, 0, 0)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, F_LIGHTED); - if ((game_get_square(g, 0, 0) == F_LIGHTED) && game_is_black(g, 0, 0)) { - game_delete(g); - return false; + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + // check for each case given in tab_square if the function return the expected result + for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { + game_set_square(g, i, j, tab_square[tab_index]); + if (tab_square[tab_index] <= S_MARK) { + if (game_is_black(g, i, j)) { + game_delete(g); + return false; + } + } else { + if (!((game_get_square(g, i, j) == tab_square[tab_index]) && game_is_black(g, i, j))) { + game_delete(g); + return false; + } + } + } + } } + game_delete(g); return true; } From 8798d680a3185893c5d4e832f4272a9e1b4b9c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Wed, 19 Jan 2022 11:48:02 +0100 Subject: [PATCH 231/281] cleaning --- game.c | 12 +++++++++--- game_ext.c | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/game.c b/game.c index b16ab64..5aee299 100644 --- a/game.c +++ b/game.c @@ -51,6 +51,7 @@ game game_copy(cgame g1) { g2->tab_cell[i][j] = g1->tab_cell[i][j]; } } + // delete first allocated hist (by game new) of g2 history_delete_entire_history(g2->hist); g2->hist = history_copy(g1->hist); return g2; @@ -70,6 +71,7 @@ bool game_equal(cgame g1, cgame g2) { } void game_delete(game g) { + // free each tab of tabcell for (int i = 0; i < g->height; i++) { free(g->tab_cell[i]); g->tab_cell[i] = NULL; @@ -133,7 +135,7 @@ bool game_is_black(cgame g, uint i, uint j) { int game_get_black_number(cgame g, uint i, uint j) { if (game_get_state(g, i, j) == S_BLACKU) return -1; - return game_get_state(g, i, j) - 8; + return game_get_state(g, i, j) - S_BLACK; } bool game_is_marked(cgame g, uint i, uint j) { @@ -149,16 +151,19 @@ bool game_has_error(cgame g, uint i, uint j) { } bool game_check_move(cgame g, uint i, uint j, square s) { - return !(i >= g->height || j >= g->width || (s != S_BLANK && s != S_MARK && s != S_LIGHTBULB) || game_is_black(g, i, j)); + return (i < g->height && j < g->width && (s == S_BLANK || s == S_MARK || s == S_LIGHTBULB) && !game_is_black(g, i, j)); } void game_play_move(game g, uint i, uint j, square s) { + // shouldn't happen because we initalized in game new if (g->hist == NULL) { g->hist = history_create_empty(); g->hist = history_insert_first(g->hist, game_get_state(g, i, j), i, j); } else { - g->hist = history_next(history_insert_after(g->hist, g->hist, game_get_state(g, i, j), i, j)); + // to avoid redo after play g->hist = history_delete_all_after(g->hist, g->hist); + // get the last element of + g->hist = history_next(history_insert_after(g->hist, g->hist, game_get_state(g, i, j), i, j)); } game_set_square(g, i, j, s); game_update_flags(g); @@ -269,5 +274,6 @@ void game_restart(game g) { } game_update_flags(g); history_delete_entire_history(g->hist); + // insert f_error on first cell of histo. initalized to avoid bug on first move undo g->hist = history_insert_first(history_create_empty(), F_ERROR, 0, 0); } diff --git a/game_ext.c b/game_ext.c index 8f8e486..8d7eeb2 100644 --- a/game_ext.c +++ b/game_ext.c @@ -26,11 +26,13 @@ game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { g->width = nb_cols; g->hist = history_create_empty(); // alloc the tab with variables set before + // alloc first tab g->tab_cell = (square**)malloc(sizeof(square*) * g->height); if (g->tab_cell == NULL) { fprintf(stderr, "not enough memory\n"); exit(EXIT_FAILURE); } + // alloc each tab of tab_cell for (int i = 0; i < g->height; i++) { g->tab_cell[i] = (square*)calloc(g->width, sizeof(square)); if (g->tab_cell[i] == NULL) { @@ -38,6 +40,7 @@ game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { exit(EXIT_FAILURE); } } + // insert f_error on first cell of histo. initalized to avoid bug on first move undo g->hist = history_insert_first(g->hist, F_ERROR, 0, 0); return g; } From 1111782a04c876327ff9040cd7f961545843f594 Mon Sep 17 00:00:00 2001 From: Thibault Perrier Date: Wed, 19 Jan 2022 11:49:21 +0100 Subject: [PATCH 232/281] starting editing game_is_lightbulb --- game_test_thperrier.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 553f736..8f302c1 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -60,19 +60,28 @@ bool test_game_is_black() { game_delete(g); return true; } - +// changer l'intérieur de la boucle /* ********** game_is_lightbulb ********** */ bool test_game_is_lightbulb() { + square tab_square[] = {S_BLANK, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g = game_new_empty(); - if (game_is_lightbulb(g, 0, 0)) { - game_delete(g); - return false; - } game_set_square(g, 0, 0, S_LIGHTBULB); if (!((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_lightbulb(g, 0, 0))) { game_delete(g); return false; } + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + // check for each case given in tab_square if the function return the expected result + for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { + game_set_square(g, i, j, tab_square[tab_index]); + if (game_get_black_number(g, i, j) != tab_index) { + game_delete(g); + return false; + } + } + } + } game_delete(g); return true; } From 2f5800563242347ae3e87d8078cba4f010c8e639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Wed, 19 Jan 2022 14:05:34 +0100 Subject: [PATCH 233/281] start cleaning --- game.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/game.c b/game.c index b16ab64..bdfc981 100644 --- a/game.c +++ b/game.c @@ -188,27 +188,32 @@ void game_update_flags(game g) { for (int i = 0; i < g->height; i++) { for (int j = 0; j < g->width; j++) { if (game_get_state(g, i, j) == S_LIGHTBULB) { - // add FLIGHTED to the current lightbulb + // add F_LIGHTED to the current lightbulb addF_LIGHTED(g, i, j); - // add FLIGHTED on the 4 directions, when a wall is hit stop this direction, when another lightbulb is hit put the initial lighbulb on error + // add F_LIGHTED on the 4 directions, when reaching a wall by following a direction, remove it from tab, when reaching another lightbulb, put a + // F_ERROR on the initial lightbulb + // tab[] = { i, j, i, j, i, j, i, j} int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (int x = 1; x < max(g->width, g->height); x++) { - for (uint y = 0; y < 7 /*tab size*/; y = y + 2) { - if (/* test if both tab are not 0*/ tab[y] != tab[y + 1] && - (/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 && - i + x * tab[y] < g->height) || + for (int gap_position = 1; gap_position < max(g->width, g->height); gap_position++) { + for (uint index_tab = 0; index_tab < sizeof(tab) / sizeof(tab[0]) - 1; index_tab += 2) { + if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] && + (/* normal check */ (j + gap_position * tab[index_tab + 1] >= 0 && j + gap_position * tab[index_tab + 1] < g->width && + i + gap_position * tab[index_tab] >= 0 && i + gap_position * tab[index_tab] < g->height) || /* wrapping check*/ (g->wrapping && - /*not the same case*/ !((((i + g->height + x * tab[y]) % g->height) == i) && - (((j + g->width + x * tab[y + 1]) % g->width) == j))))) { - if (game_is_black(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width))) { - tab[y] = 0; - tab[y + 1] = 0; + /*not the same case*/ !(((i + g->height + gap_position * tab[index_tab]) % g->height == i) && + ((j + g->width + gap_position * tab[index_tab + 1]) % g->width == j))))) { + if (game_is_black(g, ((i + g->height + gap_position * tab[index_tab]) % g->height), + ((j + g->width + gap_position * tab[index_tab + 1]) % g->width))) { + tab[index_tab] = 0; + tab[index_tab + 1] = 0; } else { // if we found another lightbulb on the line - if (game_get_state(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width)) == S_LIGHTBULB) + if (game_get_state(g, ((i + g->height + gap_position * tab[index_tab]) % g->height), + ((j + g->width + gap_position * tab[index_tab + 1]) % g->width)) == S_LIGHTBULB) // update initial lightbulb on F_ERROR game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - addF_LIGHTED(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width)); + addF_LIGHTED(g, ((i + g->height + gap_position * tab[index_tab]) % g->height), + ((j + g->width + gap_position * tab[index_tab + 1]) % g->width)); } } } From b87f3b4b80cc69e27a31a69ed8d058b607911902 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 20 Jan 2022 16:11:51 +0100 Subject: [PATCH 234/281] edit game_is_lightbulb --- game_test_thperrier.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 8f302c1..893afc9 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -60,7 +60,7 @@ bool test_game_is_black() { game_delete(g); return true; } -// changer l'intérieur de la boucle + /* ********** game_is_lightbulb ********** */ bool test_game_is_lightbulb() { square tab_square[] = {S_BLANK, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; @@ -75,7 +75,7 @@ bool test_game_is_lightbulb() { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); - if (game_get_black_number(g, i, j) != tab_index) { + if (game_is_lightbulb(g, 0, 0)) { game_delete(g); return false; } From 59a3e7771b83c78243d03d10473e8f0320a1fafe Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Thu, 20 Jan 2022 16:25:21 +0100 Subject: [PATCH 235/281] edit test_game_set_square --- game_test_nnunes.c | 150 +++++++-------------------------------------- 1 file changed, 21 insertions(+), 129 deletions(-) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 893ecaa..87ef98e 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -20,135 +20,27 @@ void usage(int argc, char* argv[]) { /* ************** game_set_square ************** */ bool test_game_set_square(void) { game g = game_new_empty(); - game_set_square(g, 0, 0, S_LIGHTBULB); - if (game_get_square(g, 0, 0) != S_LIGHTBULB) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLANK); - if (game_get_square(g, 0, 0) != S_BLANK) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_MARK); - if (game_get_square(g, 0, 0) != S_MARK) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK); - if (game_get_square(g, 0, 0) != S_BLACK) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK0); - if (game_get_square(g, 0, 0) != S_BLACK0) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK1); - if (game_get_square(g, 0, 0) != S_BLACK1) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK2); - if (game_get_square(g, 0, 0) != S_BLACK2) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK3); - if (game_get_square(g, 0, 0) != S_BLACK3) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK4); - if (game_get_square(g, 0, 0) != S_BLACK4) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACKU); - if (game_get_square(g, 0, 0) != S_BLACKU) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_LIGHTBULB | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_LIGHTBULB | F_ERROR)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLANK | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLANK | F_ERROR)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_MARK | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_MARK | F_ERROR)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACK | F_ERROR)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK0 | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACK0 | F_ERROR)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK1 | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACK1 | F_ERROR)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK2 | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACK2 | F_ERROR)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK3 | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACK3 | F_ERROR)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK4 | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACK4 | F_ERROR)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACKU | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLACKU | F_ERROR)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_LIGHTBULB | F_LIGHTED)); - if (game_get_square(g, 0, 0) != (S_LIGHTBULB | F_LIGHTED)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLANK | F_LIGHTED)); - if (game_get_square(g, 0, 0) != (S_BLANK | F_LIGHTED)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_MARK | F_LIGHTED)); - if (game_get_square(g, 0, 0) != (S_MARK | F_LIGHTED)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLANK | F_LIGHTED | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_BLANK | F_LIGHTED | F_ERROR)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_MARK | F_LIGHTED | F_ERROR)); - if (game_get_square(g, 0, 0) != (S_MARK | F_LIGHTED | F_ERROR)) { - game_delete(g); - return false; + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; + square list_flag[] = {F_ERROR, F_LIGHTED, (F_ERROR | F_LIGHTED)}; + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (uint tab_index = 0; tab_index < sizeof(list) / sizeof(list[0]); tab_index++) { + game_set_square(g, i, j, list[tab_index]); + if (game_get_square(g, i, j) != list[tab_index]) { + game_delete(g); + return false; + } + } + for (uint flag_index = 0; flag_index < sizeof(list_flag) / sizeof(list_flag[0]); flag_index++) { + for (uint tab_index = 0; tab_index < sizeof(list) / sizeof(list[0]); tab_index++) { + game_set_square(g, i, j, (list[tab_index] | list_flag[flag_index])); + if (game_get_square(g, i, j) != (list[tab_index] | list_flag[flag_index])) { + game_delete(g); + return false; + } + } + } + } } game_delete(g); return true; From e92889661eb042b663b0c55c3c2d4fe317311edc Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 20 Jan 2022 16:28:44 +0100 Subject: [PATCH 236/281] cleaning test_game_is_blank --- game_test_thperrier.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 893afc9..df8afec 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -88,15 +88,19 @@ bool test_game_is_lightbulb() { /* ********** game_is_blank ********** */ bool test_game_is_blank() { + square tab_square[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g = game_new_empty(); - if (!game_is_blank(g, 0, 0)) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK0); - if (game_is_blank(g, 0, 0)) { - game_delete(g); - return false; + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + // check for each case given in tab_square if the function return the expected result + for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { + game_set_square(g, i, j, tab_square[tab_index]); + if (game_is_blank(g, i, j)) { + game_delete(g); + return false; + } + } + } } game_delete(g); return true; From bea852ea2ad36e57eb5d77694f36dce9271b776a Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Thu, 20 Jan 2022 16:33:35 +0100 Subject: [PATCH 237/281] edit test_game_set_square & test_game_get_state --- game_test_nnunes.c | 150 +++++---------------------------------------- 1 file changed, 14 insertions(+), 136 deletions(-) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 87ef98e..8d12229 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -24,13 +24,6 @@ bool test_game_set_square(void) { square list_flag[] = {F_ERROR, F_LIGHTED, (F_ERROR | F_LIGHTED)}; for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { - for (uint tab_index = 0; tab_index < sizeof(list) / sizeof(list[0]); tab_index++) { - game_set_square(g, i, j, list[tab_index]); - if (game_get_square(g, i, j) != list[tab_index]) { - game_delete(g); - return false; - } - } for (uint flag_index = 0; flag_index < sizeof(list_flag) / sizeof(list_flag[0]); flag_index++) { for (uint tab_index = 0; tab_index < sizeof(list) / sizeof(list[0]); tab_index++) { game_set_square(g, i, j, (list[tab_index] | list_flag[flag_index])); @@ -49,135 +42,20 @@ bool test_game_set_square(void) { /* ************** game_get_state ************** */ bool test_game_get_state(void) { game g = game_new_empty(); - game_set_square(g, 0, 0, S_LIGHTBULB); - if (game_get_state(g, 0, 0) != S_LIGHTBULB) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLANK); - if (game_get_state(g, 0, 0) != S_BLANK) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_MARK); - if (game_get_state(g, 0, 0) != S_MARK) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK); - if (game_get_state(g, 0, 0) != S_BLACK) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK0); - if (game_get_state(g, 0, 0) != S_BLACK0) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK1); - if (game_get_state(g, 0, 0) != S_BLACK1) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK2); - if (game_get_state(g, 0, 0) != S_BLACK2) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK3); - if (game_get_state(g, 0, 0) != S_BLACK3) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACK4); - if (game_get_state(g, 0, 0) != S_BLACK4) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLACKU); - if (game_get_state(g, 0, 0) != S_BLACKU) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_LIGHTBULB | F_ERROR)); - if (game_get_state(g, 0, 0) != S_LIGHTBULB) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLANK | F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLANK) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_MARK | F_ERROR)); - if (game_get_state(g, 0, 0) != S_MARK) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK | F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACK) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK0 | F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACK0) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK1 | F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACK1) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK2 | F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACK2) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK3 | F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACK3) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACK4 | F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACK4) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLACKU | F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLACKU) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_LIGHTBULB | F_LIGHTED)); - if (game_get_state(g, 0, 0) != S_LIGHTBULB) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLANK | F_LIGHTED)); - if (game_get_state(g, 0, 0) != S_BLANK) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_MARK | F_LIGHTED)); - if (game_get_state(g, 0, 0) != S_MARK) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - if (game_get_state(g, 0, 0) != S_LIGHTBULB) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_BLANK | F_LIGHTED | F_ERROR)); - if (game_get_state(g, 0, 0) != S_BLANK) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, (S_MARK | F_LIGHTED | F_ERROR)); - if (game_get_state(g, 0, 0) != S_MARK) { - game_delete(g); - return false; + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; + square list_flag[] = {S_BLANK, F_ERROR, F_LIGHTED, (F_ERROR | F_LIGHTED)}; + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (uint flag_index = 0; flag_index < sizeof(list_flag) / sizeof(list_flag[0]); flag_index++) { + for (uint tab_index = 0; tab_index < sizeof(list) / sizeof(list[0]); tab_index++) { + game_set_square(g, i, j, (list[tab_index] | list_flag[flag_index])); + if (game_get_state(g, i, j) != list[tab_index]) { + game_delete(g); + return false; + } + } + } + } } game_delete(g); return true; From 6dd9e3a5de404683237487dece8cb7be8ae599ae Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Thu, 20 Jan 2022 16:42:15 +0100 Subject: [PATCH 238/281] edit test_game_get_flags --- game_test_nnunes.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 8d12229..3588685 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -64,20 +64,17 @@ bool test_game_get_state(void) { /* ************** game_get_flags ************** */ bool test_game_get_flags(void) { game g = game_new_empty(); - game_set_square(g, 0, 0, S_BLANK | F_LIGHTED); - if (game_get_flags(g, 0, 0) != F_LIGHTED) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLANK | F_ERROR); - if (game_get_flags(g, 0, 0) != F_ERROR) { - game_delete(g); - return false; - } - game_set_square(g, 0, 0, S_BLANK | F_ERROR | F_LIGHTED); - if (game_get_flags(g, 0, 0) != (F_ERROR | F_LIGHTED)) { - game_delete(g); - return false; + square list_flag[] = {F_ERROR, F_LIGHTED, (F_ERROR | F_LIGHTED)}; + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (uint flag_index = 0; flag_index < sizeof(list_flag) / sizeof(list_flag[0]); flag_index++) { + game_set_square(g, i, j, (S_BLANK | list_flag[flag_index])); + if (game_get_flags(g, i, j) != list_flag[flag_index]) { + game_delete(g); + return false; + } + } + } } game_delete(g); return true; From 56aa5a1ca9d7af12ebf2e0ca60462ac156ac7717 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Thu, 20 Jan 2022 16:53:04 +0100 Subject: [PATCH 239/281] edit test_game_is_marked & is_lighted & has_error --- game_test_nnunes.c | 55 +++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 3588685..06f0b09 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -83,10 +83,17 @@ bool test_game_get_flags(void) { /* ************** game_is_marked ************** */ bool test_game_is_marked(void) { game g = game_new_empty(); - game_set_square(g, 0, 0, S_MARK); - if ((game_get_square(g, 0, 0) == S_MARK) && game_is_marked(g, 0, 0)) { - game_delete(g); - return true; + square list_flag[] = {S_BLANK, F_ERROR, F_LIGHTED, (F_ERROR | F_LIGHTED)}; + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (uint flag_index = 0; flag_index < sizeof(list_flag) / sizeof(list_flag[0]); flag_index++) { + game_set_square(g, i, j, (S_MARK | list_flag[flag_index])); + if ((game_get_state(g, i, j) == S_MARK) && game_is_marked(g, i, j)) { + game_delete(g); + return true; + } + } + } } game_delete(g); return false; @@ -95,15 +102,17 @@ bool test_game_is_marked(void) { /* ************** game_is_lighted ************** */ bool test_game_is_lighted(void) { game g = game_new_empty(); - game_set_square(g, 0, 0, S_BLANK | F_LIGHTED); - if ((game_get_square(g, 0, 0) == F_LIGHTED) && game_is_lighted(g, 0, 0)) { - game_delete(g); - return true; - } - game_set_square(g, 0, 0, S_BLANK | F_LIGHTED | F_ERROR); - if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && game_is_lighted(g, 0, 0)) { - game_delete(g); - return true; + square list_flag[] = {F_LIGHTED, (F_ERROR | F_LIGHTED)}; + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (uint flag_index = 0; flag_index < sizeof(list_flag) / sizeof(list_flag[0]); flag_index++) { + game_set_square(g, i, j, (S_BLANK | list_flag[flag_index])); + if ((game_get_flags(g, i, j) == list_flag[flag_index]) && game_is_lighted(g, i, j)) { + game_delete(g); + return true; + } + } + } } game_delete(g); return false; @@ -112,15 +121,17 @@ bool test_game_is_lighted(void) { /* ************** game_has_error ************** */ bool test_game_has_error(void) { game g = game_new_empty(); - game_set_square(g, 0, 0, S_LIGHTBULB | F_ERROR); - if ((game_get_flags(g, 0, 0) == F_ERROR) && game_has_error(g, 0, 0)) { - game_delete(g); - return true; - } - game_set_square(g, 0, 0, S_LIGHTBULB | F_LIGHTED | F_ERROR); - if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && game_has_error(g, 0, 0)) { - game_delete(g); - return true; + square list_flag[] = {F_ERROR, (F_ERROR | F_LIGHTED)}; + for (uint i = 0; i < DEFAULT_SIZE; i++) { + for (uint j = 0; j < DEFAULT_SIZE; j++) { + for (uint flag_index = 0; flag_index < sizeof(list_flag) / sizeof(list_flag[0]); flag_index++) { + game_set_square(g, i, j, (S_BLANK | list_flag[flag_index])); + if ((game_get_flags(g, i, j) == list_flag[flag_index]) && game_has_error(g, i, j)) { + game_delete(g); + return true; + } + } + } } game_delete(g); return false; From a23ef5ddf9324c0d5316ced36ffa1f3d6a8a1bb3 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Thu, 20 Jan 2022 16:53:09 +0100 Subject: [PATCH 240/281] edit test_game_equal --- game_test_thperrier.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index df8afec..80ae02d 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -116,9 +116,21 @@ bool test_game_delete() { /* ********** game_equal ********** */ bool test_game_equal() { + square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; bool equal = true; + uint index_tab = 0; game g1 = game_new_empty(); - game g2 = game_new_empty(); + for (int i = 0; i < DEFAULT_SIZE; i++) { + for (int j = 0; j < DEFAULT_SIZE; j++) { + // check if index_tab reach end of tab + if (index_tab == sizeof(tab_square) / sizeof(tab_square[0])) { + index_tab = 0; + } + game_set_square(g1, i, j, tab_square[index_tab]); + index_tab++; + } + } + game g2 = game_copy(g1); for (int i = 0; i < DEFAULT_SIZE; i++) { for (int j = 0; j < DEFAULT_SIZE; j++) { if (game_get_square(g1, i, j) != game_get_square(g2, i, j)) { @@ -135,7 +147,6 @@ bool test_game_equal() { /* ********** game_new_empty ********** */ bool test_game_new_empty() { game g = game_new_empty(); - assert(g); for (int i = 0; i < g->height; i++) { for (int j = 0; j < g->width; j++) { if (game_get_square(g, i, j) != S_BLANK) { From 5ba186422c64c0b256c36d9b04279b4a068251d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 20 Jan 2022 17:04:33 +0100 Subject: [PATCH 241/281] game c thoguet cleaned --- game.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/game.c b/game.c index 5ecb008..e5e0a86 100644 --- a/game.c +++ b/game.c @@ -198,9 +198,13 @@ void game_update_flags(game g) { // add F_LIGHTED on the 4 directions, when reaching a wall by following a direction, remove it from tab, when reaching another lightbulb, put a // F_ERROR on the initial lightbulb // tab[] = { i, j, i, j, i, j, i, j} + // index_tab => pair = i + // index_tab => odd = j int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; for (int gap_position = 1; gap_position < max(g->width, g->height); gap_position++) { for (uint index_tab = 0; index_tab < sizeof(tab) / sizeof(tab[0]) - 1; index_tab += 2) { + // (j + gap_position * tab[index_tab + 1]) == j + // (i + gap_position * tab[index_tab]) == i if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] && (/* normal check */ (j + gap_position * tab[index_tab + 1] >= 0 && j + gap_position * tab[index_tab + 1] < g->width && i + gap_position * tab[index_tab] >= 0 && i + gap_position * tab[index_tab] < g->height) || @@ -230,27 +234,28 @@ void game_update_flags(game g) { for (int i = 0; i < g->height; i++) { for (int j = 0; j < g->width; j++) { if (game_is_black(g, i, j) && game_get_black_number(g, i, j) >= 0) { - int lb = 0; + int lightbulb = 0; int notempty = 0; int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (uint y = 0; y < 7; y = y + 2) { - if (/* normal check*/ (j + tab[y + 1] >= 0 && j + tab[y + 1] < g->width && i + tab[y] >= 0 && i + tab[y] < g->height) || - /*wrapping check*/ ( - g->wrapping && - /*not the same case*/ !((((i + g->height + tab[y]) % g->height) == i) && (((j + g->width + tab[y + 1]) % g->width) == j)))) { - if (game_is_lightbulb(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width)) - lb++; - else if (!game_is_blank(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width) || - game_is_lighted(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width)) + for (uint tab_index = 0; tab_index < (sizeof(tab) / sizeof(tab[0])); tab_index = tab_index + 2) { + if (/* normal check*/ (j + tab[tab_index + 1] >= 0 && j + tab[tab_index + 1] < g->width && i + tab[tab_index] >= 0 && + i + tab[tab_index] < g->height) || + /*wrapping check*/ (g->wrapping && + /*not the same case*/ !((((i + g->height + tab[tab_index]) % g->height) == i) && + (((j + g->width + tab[tab_index + 1]) % g->width) == j)))) { + if (game_is_lightbulb(g, (i + g->height + tab[tab_index]) % g->height, (j + g->width + tab[tab_index + 1]) % g->width)) + lightbulb++; + else if (!game_is_blank(g, (i + g->height + tab[tab_index]) % g->height, (j + g->width + tab[tab_index + 1]) % g->width) || + game_is_lighted(g, (i + g->height + tab[tab_index]) % g->height, (j + g->width + tab[tab_index + 1]) % g->width)) notempty++; } else { notempty++; } } - if (lb > game_get_black_number(g, i, j)) { + if (lightbulb > game_get_black_number(g, i, j)) { game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); } - // look if there is enough empty cell around the wall + // look if there is enough empty cell around the wall (4 directions) else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); } From 15750679b22508f47e3c21416c6a2b0a2efa2cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 20 Jan 2022 17:05:21 +0100 Subject: [PATCH 242/281] libgame.a dependencies --- CMakeLists.txt | 36 ++++++++++++++++++------------------ game_test_thoguet.c | 25 ++++++------------------- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40dafa4..eeb2c12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,14 +16,14 @@ add_executable(game_text game_text.c) add_executable(game_test_thoguet game_test_thoguet.c) add_executable(game_test_thperrier game_test_thperrier.c) add_executable(game_test_nnunes game_test_nnunes.c) -add_executable(history_test history_test.c) +#add_executable(history_test history_test.c) #les dépendances sont calculées automatiquement target_link_libraries(game_text game) target_link_libraries(game_test_thoguet game) target_link_libraries(game_test_thperrier game) target_link_libraries(game_test_nnunes game) -target_link_libraries(history_test game) +#target_link_libraries(history_test game) #Libraries add_library (game game.c game_aux.c game_ext.c game_private.c history.c) @@ -69,19 +69,19 @@ add_test(test_nnunes_game_nb_cols ./game_test_nnunes game_nb_cols) add_test(test_nnunes_game_is_wrapping ./game_test_nnunes game_is_wrapping) #Tests HISTORY -add_test(test_history_history_alloc ./history_test history_alloc) -add_test(test_history_create_empty ./history_test history_create_empty) -add_test(test_history_delete_entire_history ./history_test history_delete_entire_history) -add_test(test_history_is_empty ./history_test history_is_empty) -add_test(test_history_next ./history_test history_next) -add_test(test_history_prev ./history_test history_prev) -add_test(test_history_insert_first ./history_test history_insert_first) -add_test(test_history_delete_first ./history_test history_delete_first) -add_test(test_history_insert_after ./history_test history_insert_after) -add_test(test_history_delete_after ./history_test history_delete_after) -add_test(test_history_insert_before ./history_test history_insert_before) -add_test(test_history_delete_before ./history_test history_delete_before) -add_test(test_history_last ./history_test history_last) -add_test(test_history_first ./history_test history_first) -add_test(test_history_append ./history_test history_append) -add_test(test_history_copy ./history_test history_copy) \ No newline at end of file +# add_test(test_history_history_alloc ./history_test history_alloc) +# add_test(test_history_create_empty ./history_test history_create_empty) +# add_test(test_history_delete_entire_history ./history_test history_delete_entire_history) +# add_test(test_history_is_empty ./history_test history_is_empty) +# add_test(test_history_next ./history_test history_next) +# add_test(test_history_prev ./history_test history_prev) +# add_test(test_history_insert_first ./history_test history_insert_first) +# add_test(test_history_delete_first ./history_test history_delete_first) +# add_test(test_history_insert_after ./history_test history_insert_after) +# add_test(test_history_delete_after ./history_test history_delete_after) +# add_test(test_history_insert_before ./history_test history_insert_before) +# add_test(test_history_delete_before ./history_test history_delete_before) +# add_test(test_history_last ./history_test history_last) +# add_test(test_history_first ./history_test history_first) +# add_test(test_history_append ./history_test history_append) +# add_test(test_history_copy ./history_test history_copy) \ No newline at end of file diff --git a/game_test_thoguet.c b/game_test_thoguet.c index ae7aa4e..eeaa211 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -9,7 +9,11 @@ #include "game_ext.h" #include "game_private.h" -typedef unsigned int uint; +int max(int a, int b) { + if (a > b) + return a; + return b; +} /* ********** DUMMY ********** */ bool test_dummy(void) { @@ -178,7 +182,6 @@ bool test_game_get_square(void) { bool test_game_default(void) { game g = game_default(); - // a verif aps sur assert(g); // clang-format off square tab[49] = @@ -234,7 +237,6 @@ int checklightbulb(game g, uint i, uint j, bool wall) { // by the bulb we are testing if (game_is_lightbulb(g, i, j)) { if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) { - // printf("156\n"); return 0; } return -1; @@ -244,7 +246,6 @@ int checklightbulb(game g, uint i, uint j, bool wall) { if (!wall) { // test if the current case is not lighted if (flags != F_LIGHTED) { - // printf("170\n"); return 0; } @@ -278,7 +279,6 @@ bool check_update(game g) { if (game_is_lightbulb(g, i, j)) { square flags = game_get_flags(g, i, j); if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) { - // printf("196\n"); return false; } int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; @@ -334,10 +334,6 @@ bool check_update(game g) { res = !res; } if (!res) { - // printf("386\n"); - // printf("lb:%d notempty:%d i:%d j:%d state : %d, - // flags: - // %d\n",lb,notempty,i,j,game_get_state(g,i,j),game_get_flags(g,i,j)); return res; } } @@ -347,9 +343,8 @@ bool check_update(game g) { return true; } -// a > 2 = temps d'exec > 3 min et expo +// a > 2 = temps d'exec > 3 min et exponentiel bool brutforce(game g, int a, bool* deldup) { - // char c; bool* delDupNext = (bool*)calloc(g->height * g->width, sizeof(bool)); if (delDupNext == NULL) { fprintf(stderr, "Not enought memory\n"); @@ -358,20 +353,14 @@ bool brutforce(game g, int a, bool* deldup) { square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK}; for (uint i = 0; i < g->height; i++) { for (uint j = 0; j < g->width; j++) { - // printf("state: %d i:%d j:%d\n",game_get_state(g,i,j),i,j); if (deldup == NULL || !(deldup[i * g->width + j])) { if (game_get_state(g, i, j) == S_BLANK) { if (delDupNext != NULL && a > 0) delDupNext[i * g->width + j] = true; for (uint k = 0; k < 9; k++) { game_set_square(g, i, j, list[k]); - // if (k == 0){ - // game_print(g); - // scanf("%c",&c); - // } if (a > 0) { if (!brutforce(g, a - 1, delDupNext)) { - // printf("341\n"); free(delDupNext); return false; } @@ -379,8 +368,6 @@ bool brutforce(game g, int a, bool* deldup) { game_update_flags(g); if (!check_update(g)) { game_print(g); - // printf("i:%d j:%d state : %d, flags: - // %d\n",i,j,game_get_state(g,i,j),game_get_flags(g,i,j)); free(delDupNext); return false; } From 1ce7331c73e38efb070b3c78cdc42714b6eca8fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 20 Jan 2022 17:45:49 +0100 Subject: [PATCH 243/281] start cleaning of game_test_thoguet --- game_test_thoguet.c | 54 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index eeaa211..79ffbb1 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -229,9 +229,17 @@ bool test_game_default_solution(void) { /* **** game_update_flags **** */ +/** + * @brief check if the case i j have his flags well updated + * + * @param g the game to test + * @param i the i coordiante of the case to test + * @param j the j coordiante of the case to test + * @param wall if there is a wall before + * @return 0 if the case is well updated ; -1 else + */ int checklightbulb(game g, uint i, uint j, bool wall) { square flags = game_get_flags(g, i, j); - // square state = game_get_state(g,i,j); // 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 @@ -250,6 +258,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { } } else { + // test if all case are not lighted or lighted by another lightbulb if (/*test if the current case is lighted*/ flags == F_LIGHTED) { int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; for (uint y = 0; y < 7 /*tab size*/; y = y + 2) { @@ -273,6 +282,13 @@ int checklightbulb(game g, uint i, uint j, bool wall) { return 1; } +/** + * @brief check if the all flags are correctly updated + * + * @param g the game to test + * @return true if all flags are corrects + * @return false if one flags isn't correct + */ bool check_update(game g) { for (uint i = 0; i < g->height; i++) { for (uint j = 0; j < g->width; j++) { @@ -282,18 +298,20 @@ bool check_update(game g) { return false; } int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (uint y = 0; y < 7 /*tab size*/; y = y + 2) { + for (uint tab_index = 0; tab_index < sizeof(tab) / sizeof(tab[0]); tab_index = tab_index + 2) { bool wall = false; - for (int x = 1; x < max(g->width, g->height); x++) { - if (/* test if both tab are not 0*/ tab[y] != tab[y + 1] && - (/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 && - i + x * tab[y] < g->height) || + for (int gap_distance = 1; gap_distance < max(g->width, g->height); gap_distance++) { + if (/* test if both tab are not 0*/ tab[tab_index] != tab[tab_index + 1] && + (/* normal check */ (j + gap_distance * tab[tab_index + 1] >= 0 && j + gap_distance * tab[tab_index + 1] < g->width && + i + gap_distance * tab[tab_index] >= 0 && i + gap_distance * tab[tab_index] < g->height) || /* wrapping check*/ g->wrapping)) { - if (/*test if current case is a wall*/ game_is_black(g, ((i + g->height + x * tab[y]) % g->height), - ((j + g->width + x * tab[y + 1]) % g->width))) { + // test if current case is a wall + if (game_is_black(g, ((i + g->height + gap_distance * tab[tab_index]) % g->height), + ((j + g->width + gap_distance * tab[tab_index + 1]) % g->width))) { wall = true; } else { - int tmp = checklightbulb(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width), wall); + int tmp = checklightbulb(g, ((i + g->height + gap_distance * tab[tab_index]) % g->height), + ((j + g->width + gap_distance * tab[tab_index + 1]) % g->width), wall); if (tmp == -1) { break; } @@ -343,7 +361,15 @@ bool check_update(game g) { return true; } -// a > 2 = temps d'exec > 3 min et exponentiel +/** + * @brief tests if the update_flags works well and update each case of g with every square with a deepness of a. + * + * @param g the game to test + * @param a the deepness of test (a > 2 : execution time > 3 minutes and exponential) + * @param deldup List of each case already tested (to avoid duplicates) + * @return true if update flags works fine in every tested cases + * @return false if there is a update_flags error. + */ bool brutforce(game g, int a, bool* deldup) { bool* delDupNext = (bool*)calloc(g->height * g->width, sizeof(bool)); if (delDupNext == NULL) { @@ -380,6 +406,11 @@ bool brutforce(game g, int a, bool* deldup) { return true; } +/** + * @brief randomise a game g 100% random => not 100% resolvable + * + * @param g the game to randomise + */ void randomise(game g) { time_t t; srand((unsigned)time(&t)); @@ -394,9 +425,10 @@ void randomise(game g) { } bool test_game_update_flags(void) { + // test game between 1 and 6 (we can change 6) for (uint h = 1; h <= 6; h++) { for (uint w = 1; w <= 6; w++) { - for (int wrap = 0; wrap < 2; wrap++) { + for (int wrap = 0; wrap != 1; wrap++) { game g = game_new_empty_ext(h, w, wrap); assert(g); randomise(g); From 1b88c80b43da916de48b65e7fcb7bffc976364ae Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Fri, 21 Jan 2022 17:14:28 +0100 Subject: [PATCH 244/281] replacing DEFAULT_SIZE by g->height --- game_test_thperrier.c | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 80ae02d..fb3fb9a 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -17,8 +17,8 @@ bool test_dummy() { bool test_game_get_black_number() { square tab_square[] = {S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4}; game g = game_new_empty(); - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g->height; i++) { + for (int j = 0; j < g->height; j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); @@ -37,8 +37,8 @@ bool test_game_get_black_number() { bool test_game_is_black() { square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g = game_new_empty(); - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g->height; i++) { + for (int j = 0; j < g->height; j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); @@ -70,8 +70,8 @@ bool test_game_is_lightbulb() { game_delete(g); return false; } - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g->height; i++) { + for (int j = 0; j < g->height; j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); @@ -90,8 +90,8 @@ bool test_game_is_lightbulb() { bool test_game_is_blank() { square tab_square[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g = game_new_empty(); - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g->height; i++) { + for (int j = 0; j < g->height; j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); @@ -120,8 +120,8 @@ bool test_game_equal() { bool equal = true; uint index_tab = 0; game g1 = game_new_empty(); - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g1->height; i++) { + for (int j = 0; j < g1->height; j++) { // check if index_tab reach end of tab if (index_tab == sizeof(tab_square) / sizeof(tab_square[0])) { index_tab = 0; @@ -131,8 +131,8 @@ bool test_game_equal() { } } game g2 = game_copy(g1); - for (int i = 0; i < DEFAULT_SIZE; i++) { - for (int j = 0; j < DEFAULT_SIZE; j++) { + for (int i = 0; i < g1->height; i++) { + for (int j = 0; j < g1->height; j++) { if (game_get_square(g1, i, j) != game_get_square(g2, i, j)) { equal = false; } @@ -158,21 +158,23 @@ bool test_game_new_empty() { game_delete(g); return true; } - +// faire une boucle pour play_move /* ********** game_copy ********** */ bool test_game_copy() { + square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; + uint index_tab = 0; game g1 = game_new_empty(); for (int i = 0; i < g1->height; i++) { - game_play_move(g1, i, 0, S_LIGHTBULB); - game_play_move(g1, i, 1, S_MARK); - game_play_move(g1, i, 2, S_BLACKU); - game_play_move(g1, i, 3, S_BLACK0); - game_play_move(g1, i, 4, S_BLACK1); - game_play_move(g1, i, 5, F_LIGHTED); - game_play_move(g1, i, 6, F_ERROR); + for (int j = 0; j < g1->height; j++) { + // check if index_tab reach end of tab + if (index_tab == sizeof(tab_square) / sizeof(tab_square[0])) { + index_tab = 0; + } + game_set_square(g1, i, j, tab_square[index_tab]); + index_tab++; + } } game g2 = game_copy(g1); - assert(g2); if (!game_equal(g1, g2)) { game_delete(g1); game_delete(g2); From 299f18fbb355b8b96ff824e1ccb89b8ebb353c45 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Fri, 21 Jan 2022 17:18:03 +0100 Subject: [PATCH 245/281] replacing g->height on for (j...) by g->width --- game_test_thperrier.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index fb3fb9a..226489b 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -18,7 +18,7 @@ bool test_game_get_black_number() { square tab_square[] = {S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4}; game g = game_new_empty(); for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->height; j++) { + for (int j = 0; j < g->width; j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); @@ -38,7 +38,7 @@ bool test_game_is_black() { square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g = game_new_empty(); for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->height; j++) { + for (int j = 0; j < g->width; j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); @@ -71,7 +71,7 @@ bool test_game_is_lightbulb() { return false; } for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->height; j++) { + for (int j = 0; j < g->width; j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); @@ -91,7 +91,7 @@ bool test_game_is_blank() { square tab_square[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g = game_new_empty(); for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->height; j++) { + for (int j = 0; j < g->width; j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); @@ -121,7 +121,7 @@ bool test_game_equal() { uint index_tab = 0; game g1 = game_new_empty(); for (int i = 0; i < g1->height; i++) { - for (int j = 0; j < g1->height; j++) { + for (int j = 0; j < g1->width; j++) { // check if index_tab reach end of tab if (index_tab == sizeof(tab_square) / sizeof(tab_square[0])) { index_tab = 0; @@ -132,7 +132,7 @@ bool test_game_equal() { } game g2 = game_copy(g1); for (int i = 0; i < g1->height; i++) { - for (int j = 0; j < g1->height; j++) { + for (int j = 0; j < g1->width; j++) { if (game_get_square(g1, i, j) != game_get_square(g2, i, j)) { equal = false; } @@ -165,7 +165,7 @@ bool test_game_copy() { uint index_tab = 0; game g1 = game_new_empty(); for (int i = 0; i < g1->height; i++) { - for (int j = 0; j < g1->height; j++) { + for (int j = 0; j < g1->width; j++) { // check if index_tab reach end of tab if (index_tab == sizeof(tab_square) / sizeof(tab_square[0])) { index_tab = 0; From d4153ede7c2a5a0074e2ea6cf8191068dfdab3c3 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Fri, 21 Jan 2022 17:24:58 +0100 Subject: [PATCH 246/281] edit game_get_state & game_get_flags --- game.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/game.c b/game.c index e5e0a86..d6204ad 100644 --- a/game.c +++ b/game.c @@ -95,27 +95,23 @@ square game_get_square(cgame g, uint i, uint j) { } square game_get_state(cgame g, uint i, uint j) { - square tmp = g->tab_cell[i][j]; - if (tmp >= F_ERROR) { - tmp -= F_ERROR; + square temp = g->tab_cell[i][j]; + square list_flag[] = {F_ERROR, F_LIGHTED}; + for (uint flag_index = 0; flag_index < sizeof(list_flag) / sizeof(list_flag[0]); flag_index++) { + if (temp >= list_flag[flag_index]) { + temp -= list_flag[flag_index]; + } } - if (tmp >= F_LIGHTED) { - tmp -= F_LIGHTED; - } - return tmp; + return temp; } square game_get_flags(cgame g, uint i, uint j) { square temp = g->tab_cell[i][j]; - if (temp >= F_ERROR) { - temp -= F_ERROR; - if (temp >= F_LIGHTED) { - return (F_ERROR | F_LIGHTED); + square list_flag[] = {(F_ERROR | F_LIGHTED), F_ERROR, F_LIGHTED}; + for (uint flag_index = 0; flag_index < sizeof(list_flag) / sizeof(list_flag[0]); flag_index++) { + if(temp >= list_flag[flag_index]) { + return list_flag[flag_index]; } - return (F_ERROR); - } - if (temp >= F_LIGHTED) { - return (F_LIGHTED); } return (S_BLANK); } From 9b12054132021d04371d8ee61f8b8ba75337c995 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Fri, 21 Jan 2022 17:26:05 +0100 Subject: [PATCH 247/281] edit test_game_copy --- game_test_thperrier.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 226489b..3071b52 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -158,7 +158,7 @@ bool test_game_new_empty() { game_delete(g); return true; } -// faire une boucle pour play_move + /* ********** game_copy ********** */ bool test_game_copy() { square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; @@ -175,27 +175,14 @@ bool test_game_copy() { } } game g2 = game_copy(g1); + // check if g2 is a correct copy of g1 if (!game_equal(g1, g2)) { game_delete(g1); game_delete(g2); return false; } - for (int i = 0; i < g2->height; i++) { - for (int j = 0; j < g2->width; j++) { - game_set_square(g2, i, j, S_BLACK3); - } - } - game g3 = game_copy(g2); - assert(g3); - if (!game_equal(g2, g3)) { - game_delete(g1); - game_delete(g2); - game_delete(g3); - return false; - } game_delete(g1); game_delete(g2); - game_delete(g3); return true; } From 75db9fa6fb61c0c76f4d3c481ffd946306b8a62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 21 Jan 2022 22:13:31 +0100 Subject: [PATCH 248/281] replaced g->height, g->width and g->wrapping --- game_aux.c | 11 ++++---- game_ext.c | 12 ++++----- game_test_thoguet.c | 63 ++++++++++++++++++++++--------------------- game_test_thperrier.c | 20 +++++++------- game_text.c | 8 +++--- 5 files changed, 59 insertions(+), 55 deletions(-) diff --git a/game_aux.c b/game_aux.c index 6dd606f..b9ab3bb 100644 --- a/game_aux.c +++ b/game_aux.c @@ -1,6 +1,7 @@ #include #include #include "game.h" +#include "game_ext.h" #include "game_private.h" char charPrintCell(cgame g, uint i, uint j) { @@ -16,23 +17,23 @@ void game_print(cgame g) { if (g != NULL) { uint i; printf(" 0"); - for (i = 1; i < g->width; i++) { + for (i = 1; i < game_nb_cols(g); i++) { printf("%u", i); } printf("\n -"); - for (i = 1; i < g->width; i++) { + for (i = 1; i < game_nb_cols(g); i++) { printf("-"); } printf("\n"); - for (i = 0; i < g->height; i++) { + for (i = 0; i < game_nb_rows(g); i++) { printf("%u |", i); - for (uint j = 0; j < g->width; j++) { + for (uint j = 0; j < game_nb_cols(g); j++) { printf("%c", charPrintCell(g, i, j)); } printf("|\n"); } printf(" -"); - for (i = 1; i < g->width; i++) { + for (i = 1; i < game_nb_cols(g); i++) { printf("-"); } printf("\n"); diff --git a/game_ext.c b/game_ext.c index 8d7eeb2..e9ab380 100644 --- a/game_ext.c +++ b/game_ext.c @@ -5,9 +5,9 @@ game game_new_ext(uint nb_rows, uint nb_cols, square* squares, bool wrapping) { game g = game_new_empty_ext(nb_rows, nb_cols, wrapping); - for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->width; j++) { - g->tab_cell[i][j] = squares[g->width * i + j]; + for (int i = 0; i < game_nb_rows(g); i++) { + for (int j = 0; j < game_nb_cols(g); j++) { + g->tab_cell[i][j] = squares[game_nb_cols(g) * i + j]; } } return g; @@ -27,14 +27,14 @@ game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) { g->hist = history_create_empty(); // alloc the tab with variables set before // alloc first tab - g->tab_cell = (square**)malloc(sizeof(square*) * g->height); + g->tab_cell = (square**)malloc(sizeof(square*) * game_nb_rows(g)); if (g->tab_cell == NULL) { fprintf(stderr, "not enough memory\n"); exit(EXIT_FAILURE); } // alloc each tab of tab_cell - for (int i = 0; i < g->height; i++) { - g->tab_cell[i] = (square*)calloc(g->width, sizeof(square)); + for (int i = 0; i < game_nb_rows(g); i++) { + g->tab_cell[i] = (square*)calloc(game_nb_cols(g), sizeof(square)); if (g->tab_cell[i] == NULL) { fprintf(stderr, "not enough memory\n"); exit(EXIT_FAILURE); diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 79ffbb1..c18f2a5 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -52,8 +52,8 @@ bool test_game_new_ext(void) { printf("%d\n", i); g = game_new_ext(h, w, tab, wrap); assert(g); - for (uint i2 = 0; i2 < g->height; i2++) { - for (uint j = 0; j < g->width; j++) { + for (uint i2 = 0; i2 < game_nb_rows(g); i2++) { + for (uint j = 0; j < game_nb_cols(g); j++) { printf("list :%d, get square :%d\n", list[i], game_get_square(g, i2, j)); assert(list[i] == game_get_square(g, i2, j)); } @@ -168,8 +168,8 @@ bool test_game_get_square(void) { for (uint j = 0; j < h * w; j++) { tab[j] = list[i]; g = game_new_ext(h, w, tab, false); - printf("[%d, %d] %d %d\n", j / g->width, j % g->width, game_get_square(g, j / g->width, j % g->width), tab[j]); - assert(game_get_square(g, j / g->width, j % g->width) == tab[j]); + printf("[%d, %d] %d %d\n", j / game_nb_cols(g), j % game_nb_cols(g), game_get_square(g, j / game_nb_cols(g), j % game_nb_cols(g)), tab[j]); + assert(game_get_square(g, j / game_nb_cols(g), j % game_nb_cols(g)) == tab[j]); game_delete(g); } } @@ -262,11 +262,13 @@ int checklightbulb(game g, uint i, uint j, bool wall) { if (/*test if the current case is lighted*/ flags == F_LIGHTED) { int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; for (uint y = 0; y < 7 /*tab size*/; y = y + 2) { - for (int x = 1; x < max(g->width, g->height); x++) { + for (int x = 1; x < max(game_nb_cols(g), game_nb_rows(g)); x++) { if (/* test if both tab are not 0*/ tab[y] != tab[y + 1] && - (/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 && i + x * tab[y] < g->height) || - /* wrapping check*/ g->wrapping)) { - flags = game_get_square(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width)); + (/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < game_nb_cols(g) && i + x * tab[y] >= 0 && + i + x * tab[y] < game_nb_rows(g)) || + /* wrapping check*/ game_is_wrapping(g))) { + flags = game_get_square(g, ((i + game_nb_rows(g) + x * tab[y]) % game_nb_rows(g)), + ((j + game_nb_cols(g) + x * tab[y + 1]) % game_nb_cols(g))); if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; } @@ -290,8 +292,8 @@ int checklightbulb(game g, uint i, uint j, bool wall) { * @return false if one flags isn't correct */ bool check_update(game g) { - for (uint i = 0; i < g->height; i++) { - for (uint j = 0; j < g->width; j++) { + for (uint i = 0; i < game_nb_rows(g); i++) { + for (uint j = 0; j < game_nb_cols(g); j++) { if (game_is_lightbulb(g, i, j)) { square flags = game_get_flags(g, i, j); if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) { @@ -300,18 +302,18 @@ bool check_update(game g) { int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; for (uint tab_index = 0; tab_index < sizeof(tab) / sizeof(tab[0]); tab_index = tab_index + 2) { bool wall = false; - for (int gap_distance = 1; gap_distance < max(g->width, g->height); gap_distance++) { + for (int gap_distance = 1; gap_distance < max(game_nb_cols(g), game_nb_rows(g)); gap_distance++) { if (/* test if both tab are not 0*/ tab[tab_index] != tab[tab_index + 1] && - (/* normal check */ (j + gap_distance * tab[tab_index + 1] >= 0 && j + gap_distance * tab[tab_index + 1] < g->width && - i + gap_distance * tab[tab_index] >= 0 && i + gap_distance * tab[tab_index] < g->height) || - /* wrapping check*/ g->wrapping)) { + (/* normal check */ (j + gap_distance * tab[tab_index + 1] >= 0 && j + gap_distance * tab[tab_index + 1] < game_nb_cols(g) && + i + gap_distance * tab[tab_index] >= 0 && i + gap_distance * tab[tab_index] < game_nb_rows(g)) || + /* wrapping check*/ game_is_wrapping(g))) { // test if current case is a wall - if (game_is_black(g, ((i + g->height + gap_distance * tab[tab_index]) % g->height), - ((j + g->width + gap_distance * tab[tab_index + 1]) % g->width))) { + if (game_is_black(g, ((i + game_nb_rows(g) + gap_distance * tab[tab_index]) % game_nb_rows(g)), + ((j + game_nb_cols(g) + gap_distance * tab[tab_index + 1]) % game_nb_cols(g)))) { wall = true; } else { - int tmp = checklightbulb(g, ((i + g->height + gap_distance * tab[tab_index]) % g->height), - ((j + g->width + gap_distance * tab[tab_index + 1]) % g->width), wall); + int tmp = checklightbulb(g, ((i + game_nb_rows(g) + gap_distance * tab[tab_index]) % game_nb_rows(g)), + ((j + game_nb_cols(g) + gap_distance * tab[tab_index + 1]) % game_nb_cols(g)), wall); if (tmp == -1) { break; } @@ -330,12 +332,13 @@ bool check_update(game g) { int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; bool res = true; for (uint y = 0; y < 7; y = y + 2) { - if (/* normal check*/ (j + tab[y + 1] >= 0 && j + tab[y + 1] < g->width && i + tab[y] >= 0 && i + tab[y] < g->height) || - /*wrapping check*/ g->wrapping) { - if (game_is_lightbulb(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width)) + if (/* normal check*/ (j + tab[y + 1] >= 0 && j + tab[y + 1] < game_nb_cols(g) && i + tab[y] >= 0 && i + tab[y] < game_nb_rows(g)) || + /*wrapping check*/ game_is_wrapping(g)) { + if (game_is_lightbulb(g, (i + game_nb_rows(g) + tab[y]) % game_nb_rows(g), (j + game_nb_cols(g) + tab[y + 1]) % game_nb_cols(g))) lb++; - else if (!game_is_blank(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width) || - game_is_lighted(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width)) + else if (!game_is_blank(g, (i + game_nb_rows(g) + tab[y]) % game_nb_rows(g), + (j + game_nb_cols(g) + tab[y + 1]) % game_nb_cols(g)) || + game_is_lighted(g, (i + game_nb_rows(g) + tab[y]) % game_nb_rows(g), (j + game_nb_cols(g) + tab[y + 1]) % game_nb_cols(g))) notempty++; } else { notempty++; @@ -371,18 +374,18 @@ bool check_update(game g) { * @return false if there is a update_flags error. */ bool brutforce(game g, int a, bool* deldup) { - bool* delDupNext = (bool*)calloc(g->height * g->width, sizeof(bool)); + bool* delDupNext = (bool*)calloc(game_nb_rows(g) * game_nb_cols(g), sizeof(bool)); if (delDupNext == NULL) { fprintf(stderr, "Not enought memory\n"); exit(EXIT_FAILURE); } square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK}; - for (uint i = 0; i < g->height; i++) { - for (uint j = 0; j < g->width; j++) { - if (deldup == NULL || !(deldup[i * g->width + j])) { + for (uint i = 0; i < game_nb_rows(g); i++) { + for (uint j = 0; j < game_nb_cols(g); j++) { + if (deldup == NULL || !(deldup[i * game_nb_cols(g) + j])) { if (game_get_state(g, i, j) == S_BLANK) { if (delDupNext != NULL && a > 0) - delDupNext[i * g->width + j] = true; + delDupNext[i * game_nb_cols(g) + j] = true; for (uint k = 0; k < 9; k++) { game_set_square(g, i, j, list[k]); if (a > 0) { @@ -417,8 +420,8 @@ void randomise(game g) { assert(g); square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK}; - for (uint h = 0; h < g->height; h++) { - for (uint w = 0; w < g->width; w++) { + for (uint h = 0; h < game_nb_rows(g); h++) { + for (uint w = 0; w < game_nb_cols(g); w++) { game_set_square(g, h, w, list[rand() % 16]); } } diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 3071b52..a470f2f 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -17,8 +17,8 @@ bool test_dummy() { bool test_game_get_black_number() { square tab_square[] = {S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4}; game g = game_new_empty(); - for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->width; j++) { + for (int i = 0; i < game_nb_rows(g); i++) { + for (int j = 0; j < game_nb_cols(g); j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); @@ -37,8 +37,8 @@ bool test_game_get_black_number() { bool test_game_is_black() { square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g = game_new_empty(); - for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->width; j++) { + for (int i = 0; i < game_nb_rows(g); i++) { + for (int j = 0; j < game_nb_cols(g); j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); @@ -70,8 +70,8 @@ bool test_game_is_lightbulb() { game_delete(g); return false; } - for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->width; j++) { + for (int i = 0; i < game_nb_rows(g); i++) { + for (int j = 0; j < game_nb_cols(g); j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); @@ -90,8 +90,8 @@ bool test_game_is_lightbulb() { bool test_game_is_blank() { square tab_square[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g = game_new_empty(); - for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->width; j++) { + for (int i = 0; i < game_nb_rows(g); i++) { + for (int j = 0; j < game_nb_cols(g); j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); @@ -147,8 +147,8 @@ bool test_game_equal() { /* ********** game_new_empty ********** */ bool test_game_new_empty() { game g = game_new_empty(); - for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->width; j++) { + for (int i = 0; i < game_nb_rows(g); i++) { + for (int j = 0; j < game_nb_cols(g); j++) { if (game_get_square(g, i, j) != S_BLANK) { game_delete(g); return false; diff --git a/game_text.c b/game_text.c index 886c787..ae3024b 100644 --- a/game_text.c +++ b/game_text.c @@ -13,7 +13,7 @@ * @brief Edit the stringError with all errors of g * @param g the game to analyze * @param stringError A pointer toward a string allocated before - * @pre @p stringError size must be at least g->height * g->width * NBCHARERR + * @pre @p stringError size must be at least height * width * NBCHARERR * @return true if there is an error on the game g and the stringError has been modified */ bool checkerrors(cgame g, char* stringError) { @@ -23,8 +23,8 @@ bool checkerrors(cgame g, char* stringError) { uint index_taberr = 0; // initialize stringError stringError[0] = '\0'; - for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->width; j++) { + for (int i = 0; i < game_nb_rows(g); i++) { + for (int j = 0; j < game_nb_cols(g); j++) { // check each case if (game_has_error(g, i, j)) { // if error append stringError with coordinate of the error, @@ -91,7 +91,7 @@ int main(int argc, char* argv[]) { else usage(argc, argv); // init string for errors - char stringError[g->height * g->width * NBCHARERR]; + char stringError[game_nb_rows(g) * game_nb_cols(g) * NBCHARERR]; char c; // print game game_print(g); From e8a3b07055c56e0592cdc8ca35d54def8a0a0328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 21 Jan 2022 22:13:57 +0100 Subject: [PATCH 249/281] cleaned update flags --- game.c | 183 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 94 insertions(+), 89 deletions(-) diff --git a/game.c b/game.c index d6204ad..8055bf3 100644 --- a/game.c +++ b/game.c @@ -4,11 +4,17 @@ #include "game_ext.h" #include "game_private.h" +// JWRAPPING and IWRAPPING have a "+ game_nb_xxxx(g)" to avoid falling in negative when we are at 0 for exemple +#define JWRAPPING (j + game_nb_cols(g) + gap_position * tab[index_tab + 1]) % game_nb_cols(g) +#define IWRAPPING (i + game_nb_rows(g) + gap_position * tab[index_tab]) % game_nb_rows(g) +#define JNORMAL j + gap_position* tab[index_tab + 1] +#define INORMAL i + gap_position* tab[index_tab] + game game_new(square* squares) { game g = game_new_empty(); - for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->width; j++) { - g->tab_cell[i][j] = squares[g->width * i + j]; + for (int i = 0; i < game_nb_rows(g); i++) { + for (int j = 0; j < game_nb_cols(g); j++) { + g->tab_cell[i][j] = squares[game_nb_cols(g) * i + j]; } } return g; @@ -26,16 +32,16 @@ game game_new_empty(void) { g->width = DEFAULT_SIZE; g->hist = history_create_empty(); // alloc the tab with variables set before - g->tab_cell = (square**)malloc(sizeof(square*) * g->height); + g->tab_cell = (square**)malloc(sizeof(square*) * game_nb_rows(g)); if (g->tab_cell == NULL) { memoryError(); } - for (int i = 0; i < g->height; i++) { - g->tab_cell[i] = (square*)malloc(sizeof(square) * g->width); + for (int i = 0; i < game_nb_rows(g); i++) { + g->tab_cell[i] = (square*)malloc(sizeof(square) * game_nb_cols(g)); if (g->tab_cell[i] == NULL) { memoryError(); } - for (int j = 0; j < g->width; j++) { + for (int j = 0; j < game_nb_cols(g); j++) { g->tab_cell[i][j] = S_BLANK; } } @@ -72,7 +78,7 @@ bool game_equal(cgame g1, cgame g2) { void game_delete(game g) { // free each tab of tabcell - for (int i = 0; i < g->height; i++) { + for (int i = 0; i < game_nb_rows(g); i++) { free(g->tab_cell[i]); g->tab_cell[i] = NULL; } @@ -109,7 +115,7 @@ square game_get_flags(cgame g, uint i, uint j) { square temp = g->tab_cell[i][j]; square list_flag[] = {(F_ERROR | F_LIGHTED), F_ERROR, F_LIGHTED}; for (uint flag_index = 0; flag_index < sizeof(list_flag) / sizeof(list_flag[0]); flag_index++) { - if(temp >= list_flag[flag_index]) { + if (temp >= list_flag[flag_index]) { return list_flag[flag_index]; } } @@ -147,7 +153,7 @@ bool game_has_error(cgame g, uint i, uint j) { } bool game_check_move(cgame g, uint i, uint j, square s) { - return (i < g->height && j < g->width && (s == S_BLANK || s == S_MARK || s == S_LIGHTBULB) && !game_is_black(g, i, j)); + return (i < game_nb_rows(g) && j < game_nb_cols(g) && (s == S_BLANK || s == S_MARK || s == S_LIGHTBULB) && !game_is_black(g, i, j)); } void game_play_move(game g, uint i, uint j, square s) { @@ -158,7 +164,7 @@ void game_play_move(game g, uint i, uint j, square s) { } else { // to avoid redo after play g->hist = history_delete_all_after(g->hist, g->hist); - // get the last element of + // add new played element to hist and get the last element of hist g->hist = history_next(history_insert_after(g->hist, g->hist, game_get_state(g, i, j), i, j)); } game_set_square(g, i, j, s); @@ -167,8 +173,8 @@ void game_play_move(game g, uint i, uint j, square s) { void delete_flags(game g) { // delete prev flags - for (uint i = 0; i < g->height; i++) { - for (uint j = 0; j < g->width; j++) { + for (uint i = 0; i < game_nb_rows(g); i++) { + for (uint j = 0; j < game_nb_cols(g); j++) { game_set_square(g, i, j, game_get_state(g, i, j)); } } @@ -183,86 +189,85 @@ void addF_LIGHTED(game g, uint i, uint j) { } } -void game_update_flags(game g) { - delete_flags(g); - // update flags lighted and lightbulb error - for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->width; j++) { - if (game_get_state(g, i, j) == S_LIGHTBULB) { - // add F_LIGHTED to the current lightbulb - addF_LIGHTED(g, i, j); - // add F_LIGHTED on the 4 directions, when reaching a wall by following a direction, remove it from tab, when reaching another lightbulb, put a - // F_ERROR on the initial lightbulb - // tab[] = { i, j, i, j, i, j, i, j} - // index_tab => pair = i - // index_tab => odd = j - int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (int gap_position = 1; gap_position < max(g->width, g->height); gap_position++) { - for (uint index_tab = 0; index_tab < sizeof(tab) / sizeof(tab[0]) - 1; index_tab += 2) { - // (j + gap_position * tab[index_tab + 1]) == j - // (i + gap_position * tab[index_tab]) == i - if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] && - (/* normal check */ (j + gap_position * tab[index_tab + 1] >= 0 && j + gap_position * tab[index_tab + 1] < g->width && - i + gap_position * tab[index_tab] >= 0 && i + gap_position * tab[index_tab] < g->height) || - /* wrapping check*/ (g->wrapping && - /*not the same case*/ !(((i + g->height + gap_position * tab[index_tab]) % g->height == i) && - ((j + g->width + gap_position * tab[index_tab + 1]) % g->width == j))))) { - if (game_is_black(g, ((i + g->height + gap_position * tab[index_tab]) % g->height), - ((j + g->width + gap_position * tab[index_tab + 1]) % g->width))) { - tab[index_tab] = 0; - tab[index_tab + 1] = 0; - } else { - // if we found another lightbulb on the line - if (game_get_state(g, ((i + g->height + gap_position * tab[index_tab]) % g->height), - ((j + g->width + gap_position * tab[index_tab + 1]) % g->width)) == S_LIGHTBULB) - // update initial lightbulb on F_ERROR - game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); - addF_LIGHTED(g, ((i + g->height + gap_position * tab[index_tab]) % g->height), - ((j + g->width + gap_position * tab[index_tab + 1]) % g->width)); - } - } - } - } - } - } - } - // update flags wall (need to wait all FLIGHTED being updated) - for (int i = 0; i < g->height; i++) { - for (int j = 0; j < g->width; j++) { - if (game_is_black(g, i, j) && game_get_black_number(g, i, j) >= 0) { - int lightbulb = 0; - int notempty = 0; - int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (uint tab_index = 0; tab_index < (sizeof(tab) / sizeof(tab[0])); tab_index = tab_index + 2) { - if (/* normal check*/ (j + tab[tab_index + 1] >= 0 && j + tab[tab_index + 1] < g->width && i + tab[tab_index] >= 0 && - i + tab[tab_index] < g->height) || - /*wrapping check*/ (g->wrapping && - /*not the same case*/ !((((i + g->height + tab[tab_index]) % g->height) == i) && - (((j + g->width + tab[tab_index + 1]) % g->width) == j)))) { - if (game_is_lightbulb(g, (i + g->height + tab[tab_index]) % g->height, (j + g->width + tab[tab_index + 1]) % g->width)) - lightbulb++; - else if (!game_is_blank(g, (i + g->height + tab[tab_index]) % g->height, (j + g->width + tab[tab_index + 1]) % g->width) || - game_is_lighted(g, (i + g->height + tab[tab_index]) % g->height, (j + g->width + tab[tab_index + 1]) % g->width)) - notempty++; - } else { - notempty++; - } - } - if (lightbulb > game_get_black_number(g, i, j)) { - game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); - } - // look if there is enough empty cell around the wall (4 directions) - else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { - game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); +void update_flags_lightbulb(game g, uint i, uint j) { + // add F_LIGHTED to the current lightbulb + addF_LIGHTED(g, i, j); + // add F_LIGHTED on the 4 directions, when reaching a wall by following a direction, remove it from tab, when reaching another lightbulb, put a + // F_ERROR on the initial lightbulb + // tab[] = { i, j, i, j, i, j, i, j} + int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; + for (int gap_position = 1; gap_position < max(game_nb_cols(g), game_nb_rows(g)); gap_position++) { + // index_tab => pair = i + // index_tab => odd = j + for (uint index_tab = 0; index_tab < sizeof(tab) / sizeof(tab[0]) - 1; index_tab += 2) { + // big if to check if INORMAL and JNORMAL are correct or if wrapping is true and IWRAPPING and JWRAPPING are not the initial case + if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] && + (/* normal check */ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) || + /* wrapping check + not the inital case*/ (game_is_wrapping(g) && !(IWRAPPING == i && JWRAPPING == j)))) { + if (game_is_black(g, IWRAPPING, JWRAPPING)) { + tab[index_tab] = 0; + tab[index_tab + 1] = 0; + } else { + // if we found another lightbulb on the line + if (game_is_lightbulb(g, IWRAPPING, JWRAPPING)) + // update initial lightbulb on F_ERROR + game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR)); + addF_LIGHTED(g, IWRAPPING, JWRAPPING); } } } } } +void update_flags_walls(game g, uint i, uint j) { + int lightbulb = 0; + int not_empty = 0; + int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; + for (uint index_tab = 0; index_tab < (sizeof(tab) / sizeof(tab[0])); index_tab = index_tab + 2) { + uint gap_position = 1; + if (/* normal check*/ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) || + /*wrapping check*/ (game_is_wrapping(g) && + /*not the same case*/ !(IWRAPPING == i && JWRAPPING == j))) { + if (game_is_lightbulb(g, IWRAPPING, JWRAPPING)) + lightbulb++; + else if (!game_is_blank(g, IWRAPPING, JWRAPPING) || game_is_lighted(g, IWRAPPING, JWRAPPING)) + not_empty++; + } else { + not_empty++; + } + } + if (lightbulb > game_get_black_number(g, i, j)) { + game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); + } + // look if there is enough empty cell around the wall (4 directions) + else if (not_empty > abs(game_get_black_number(g, i, j) - 4)) { + game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); + } +} + +void game_update_flags(game g) { + delete_flags(g); + // update flags lighted and lightbulb error + for (uint i = 0; i < game_nb_rows(g); i++) { + for (uint j = 0; j < game_nb_cols(g); j++) { + if (game_is_lightbulb(g, i, j)) { + update_flags_lightbulb(g, i, j); + } + } + } + // update flags wall (need to wait all FLIGHTED being updated) + for (uint i = 0; i < game_nb_rows(g); i++) { + for (uint j = 0; j < game_nb_cols(g); j++) { + if (game_is_black(g, i, j) && game_get_black_number(g, i, j) >= 0) { + update_flags_walls(g, i, j); + } + } + } +} + bool game_is_over(cgame g) { - for (uint i = 0; i < g->height; i++) { - for (uint j = 0; j < g->width; j++) { + for (uint i = 0; i < game_nb_rows(g); i++) { + for (uint j = 0; j < game_nb_cols(g); j++) { if ((game_get_state(g, i, j) == S_BLANK && game_get_flags(g, i, j) == S_BLANK) || game_get_flags(g, i, j) == F_ERROR || game_get_flags(g, i, j) == (F_LIGHTED | F_ERROR)) return false; @@ -272,9 +277,9 @@ bool game_is_over(cgame g) { } void game_restart(game g) { - for (uint i = 0; i < g->height; i++) { - for (uint j = 0; j < g->width; j++) { - if (game_get_state(g, i, j) == S_MARK || game_get_state(g, i, j) == S_LIGHTBULB) + for (uint i = 0; i < game_nb_rows(g); i++) { + for (uint j = 0; j < game_nb_cols(g); j++) { + if (game_get_state(g, i, j) == S_MARK || game_is_lightbulb(g, i, j)) game_set_square(g, i, j, S_BLANK); } } From 230c0e3480a102856c05cf2c96d716e21f5e01d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 21 Jan 2022 22:30:55 +0100 Subject: [PATCH 250/281] coverage ++ --- game_test_thoguet.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index c18f2a5..45e1012 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -42,15 +42,13 @@ bool test_game_new_ext(void) { for (int h = 1; h <= 10; h++) { for (int w = 1; w <= 10; w++) { square tab[h * w]; - game g; for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { - g = NULL; - for (uint j = 0; j < h * w; j++) { + for (uint j = 0; j < h * w; j++) { tab[j] = list[i]; } for (int wrap = 0; wrap < 2; wrap++) { printf("%d\n", i); - g = game_new_ext(h, w, tab, wrap); + game g = game_new_ext(h, w, tab, wrap); assert(g); for (uint i2 = 0; i2 < game_nb_rows(g); i2++) { for (uint j = 0; j < game_nb_cols(g); j++) { @@ -59,6 +57,7 @@ bool test_game_new_ext(void) { } } game_delete(g); + g = NULL; } } } @@ -112,15 +111,13 @@ bool test_game_restart(void) { bool test_game_new(void) { square tab[DEFAULT_SIZE * DEFAULT_SIZE]; - game g; square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR}; for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { - g = NULL; for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) { tab[j] = list[i]; } printf("%d\n", i); - g = game_new(tab); + game g = game_new(tab); for (uint i2 = 0; i2 < DEFAULT_SIZE; i2++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { printf("list :%d, get square :%d\n", list[i], game_get_square(g, i2, j)); @@ -129,6 +126,7 @@ bool test_game_new(void) { } assert(g); game_delete(g); + g = NULL; } return EXIT_SUCCESS; } @@ -159,7 +157,6 @@ bool test_game_print(void) { /* ******* game_get_square ******* */ bool test_game_get_square(void) { - game g; for (int h = 1; h <= 10; h++) { for (int w = 1; w <= 10; w++) { square tab[w * h]; @@ -167,7 +164,7 @@ bool test_game_get_square(void) { for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { for (uint j = 0; j < h * w; j++) { tab[j] = list[i]; - g = game_new_ext(h, w, tab, false); + game g = game_new_ext(h, w, tab, false); printf("[%d, %d] %d %d\n", j / game_nb_cols(g), j % game_nb_cols(g), game_get_square(g, j / game_nb_cols(g), j % game_nb_cols(g)), tab[j]); assert(game_get_square(g, j / game_nb_cols(g), j % game_nb_cols(g)) == tab[j]); game_delete(g); From b8ac9d94950738dbbf0dd3bcc7ddfecc3e4e7ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 21 Jan 2022 22:54:02 +0100 Subject: [PATCH 251/281] remove g-> in tests --- game_test_thoguet.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 45e1012..8f3a5be 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -43,7 +43,7 @@ bool test_game_new_ext(void) { for (int w = 1; w <= 10; w++) { square tab[h * w]; for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { - for (uint j = 0; j < h * w; j++) { + for (uint j = 0; j < h * w; j++) { tab[j] = list[i]; } for (int wrap = 0; wrap < 2; wrap++) { @@ -92,16 +92,24 @@ bool test_game_restart(void) { game_set_square(g1, 1, 5, S_BLACK4); game_set_square(g, 3, 2, S_BLACK3); game_set_square(g1, 3, 2, S_BLACK3); - game_set_square(g, 0, 1, S_LIGHTBULB); - game_set_square(g1, 0, 1, S_LIGHTBULB); + game_play_move(g, 0, 1, S_LIGHTBULB); + game_play_move(g1, 0, 1, S_LIGHTBULB); game_play_move(g, 2, 0, S_MARK); game_play_move(g1, 2, 0, S_MARK); + game_play_move(g, 1, 1, S_LIGHTBULB); + game_play_move(g1, 1, 1, S_LIGHTBULB); + game_play_move(g, 1, 1, S_MARK); + game_play_move(g1, 1, 1, S_MARK); + game_undo(g); + game_undo(g1); assert(!game_equal(g, g1)); game_restart(g1); game_restart(g); assert(game_equal(g, g1)); - assert(g1->hist->next == NULL && g->hist->prev == NULL && g1->hist->state == F_ERROR); - assert(g->hist->next == NULL && g->hist->prev == NULL && g->hist->state == F_ERROR); + game_redo(g); + assert(game_equal(g, g1)); + game_undo(g); + assert(game_equal(g, g1)); game_delete(g); game_delete(g1); return EXIT_SUCCESS; @@ -425,7 +433,7 @@ void randomise(game g) { } bool test_game_update_flags(void) { - // test game between 1 and 6 (we can change 6) + // test game of size between 1 and 6 (we can change 6) for (uint h = 1; h <= 6; h++) { for (uint w = 1; w <= 6; w++) { for (int wrap = 0; wrap != 1; wrap++) { From 71934890dddda76f4dedde8660f3371ca0bf3f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 21 Jan 2022 23:25:51 +0100 Subject: [PATCH 252/281] remove #include game_private and lasts -> thp test --- game_test_thoguet.c | 6 +++++- game_test_thperrier.c | 13 ++++++------- game_text.c | 1 - 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 8f3a5be..0f857d3 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -7,7 +7,11 @@ #include "game.h" #include "game_aux.h" #include "game_ext.h" -#include "game_private.h" + +#define JWRAPPING (j + game_nb_cols(g) + gap_position * tab[index_tab + 1]) % game_nb_cols(g) +#define IWRAPPING (i + game_nb_rows(g) + gap_position * tab[index_tab]) % game_nb_rows(g) +#define JNORMAL j + gap_position* tab[index_tab + 1] +#define INORMAL i + gap_position* tab[index_tab] int max(int a, int b) { if (a > b) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index a470f2f..ccc4472 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -6,7 +6,6 @@ #include "game.h" #include "game_aux.h" #include "game_ext.h" -#include "game_private.h" /* ********** DUMMY ********** */ bool test_dummy() { @@ -120,8 +119,8 @@ bool test_game_equal() { bool equal = true; uint index_tab = 0; game g1 = game_new_empty(); - for (int i = 0; i < g1->height; i++) { - for (int j = 0; j < g1->width; j++) { + for (int i = 0; i < game_nb_rows(g1); i++) { + for (int j = 0; j < game_nb_cols(g1); j++) { // check if index_tab reach end of tab if (index_tab == sizeof(tab_square) / sizeof(tab_square[0])) { index_tab = 0; @@ -131,8 +130,8 @@ bool test_game_equal() { } } game g2 = game_copy(g1); - for (int i = 0; i < g1->height; i++) { - for (int j = 0; j < g1->width; j++) { + for (int i = 0; i < game_nb_rows(g1); i++) { + for (int j = 0; j < game_nb_cols(g1); j++) { if (game_get_square(g1, i, j) != game_get_square(g2, i, j)) { equal = false; } @@ -164,8 +163,8 @@ bool test_game_copy() { square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; uint index_tab = 0; game g1 = game_new_empty(); - for (int i = 0; i < g1->height; i++) { - for (int j = 0; j < g1->width; j++) { + for (int i = 0; i < game_nb_rows(g1); i++) { + for (int j = 0; j < game_nb_cols(g1); j++) { // check if index_tab reach end of tab if (index_tab == sizeof(tab_square) / sizeof(tab_square[0])) { index_tab = 0; diff --git a/game_text.c b/game_text.c index ae3024b..6e7e089 100644 --- a/game_text.c +++ b/game_text.c @@ -4,7 +4,6 @@ #include "game.h" #include "game_aux.h" #include "game_ext.h" -#include "game_private.h" #define NBCHARERR 4 #define CHAR0ASCII 48 From 74f5a947b9d9a4f00fa1172f3fd580f90cecbf0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Fri, 21 Jan 2022 23:54:39 +0100 Subject: [PATCH 253/281] +=2 on game.c --- game.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game.c b/game.c index 8055bf3..7bb2e2e 100644 --- a/game.c +++ b/game.c @@ -199,7 +199,7 @@ void update_flags_lightbulb(game g, uint i, uint j) { for (int gap_position = 1; gap_position < max(game_nb_cols(g), game_nb_rows(g)); gap_position++) { // index_tab => pair = i // index_tab => odd = j - for (uint index_tab = 0; index_tab < sizeof(tab) / sizeof(tab[0]) - 1; index_tab += 2) { + for (uint index_tab = 0; index_tab < sizeof(tab) / sizeof(tab[0]); index_tab += 2) { // big if to check if INORMAL and JNORMAL are correct or if wrapping is true and IWRAPPING and JWRAPPING are not the initial case if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] && (/* normal check */ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) || @@ -223,7 +223,7 @@ void update_flags_walls(game g, uint i, uint j) { int lightbulb = 0; int not_empty = 0; int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (uint index_tab = 0; index_tab < (sizeof(tab) / sizeof(tab[0])); index_tab = index_tab + 2) { + for (uint index_tab = 0; index_tab < (sizeof(tab) / sizeof(tab[0])); index_tab += 2) { uint gap_position = 1; if (/* normal check*/ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) || /*wrapping check*/ (game_is_wrapping(g) && From ab0a63f54ec9c5532e4c012d03a26ebfc05cbd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sat, 22 Jan 2022 17:48:55 +0100 Subject: [PATCH 254/281] cleaned thoguet tests --- game_test_thoguet.c | 160 +++++++++++++++++++++++--------------------- 1 file changed, 82 insertions(+), 78 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 0f857d3..48a9153 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -265,34 +265,91 @@ int checklightbulb(game g, uint i, uint j, bool wall) { if (flags != F_LIGHTED) { return 0; } - - } else { - // test if all case are not lighted or lighted by another lightbulb - if (/*test if the current case is lighted*/ flags == F_LIGHTED) { - int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (uint y = 0; y < 7 /*tab size*/; y = y + 2) { - for (int x = 1; x < max(game_nb_cols(g), game_nb_rows(g)); x++) { - if (/* test if both tab are not 0*/ tab[y] != tab[y + 1] && - (/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < game_nb_cols(g) && i + x * tab[y] >= 0 && - i + x * tab[y] < game_nb_rows(g)) || - /* wrapping check*/ game_is_wrapping(g))) { - flags = game_get_square(g, ((i + game_nb_rows(g) + x * tab[y]) % game_nb_rows(g)), - ((j + game_nb_cols(g) + x * tab[y + 1]) % game_nb_cols(g))); - if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { - return -1; - } - if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { - break; - } + return 1; + } + // test if all case are not lighted or lighted by another lightbulb + if (/*test if the current case is lighted*/ flags == F_LIGHTED) { + int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; + for (uint index_tab = 0; index_tab < 7 /*tab size*/; index_tab = index_tab + 2) { + for (int gap_position = 1; gap_position < max(game_nb_cols(g), game_nb_rows(g)); gap_position++) { + if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] && + (/* normal check */ JWRAPPING >= 0 && JWRAPPING < game_nb_cols(g) && IWRAPPING >= 0 && IWRAPPING < game_nb_rows(g)) || + /* wrapping check*/ game_is_wrapping(g)) { + flags = game_get_square(g, IWRAPPING, JWRAPPING); + if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { + return -1; + } + if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { + break; } } } - return 0; } + return 0; } return 1; } +int test_update_flags_lightbulb(game g, uint i, uint j) { + square flags = game_get_flags(g, i, j); + if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) { + return false; + } + int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; + for (uint index_tab = 0; index_tab < sizeof(tab) / sizeof(tab[0]); index_tab += 2) { + bool wall = false; + for (int gap_position = 1; gap_position < max(game_nb_cols(g), game_nb_rows(g)); gap_position++) { + if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] && + (/* normal check */ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) || + /* wrapping check*/ game_is_wrapping(g))) { + // test if current case is a wall + if (game_is_black(g, IWRAPPING, JWRAPPING)) { + wall = true; + } else { + int tmp = checklightbulb(g, IWRAPPING, JWRAPPING, wall); + if (tmp == -1) { + break; + } + if (!tmp) + return tmp; + } + } + } + } + return true; +} + +bool test_update_flags_walls(game g, uint i, uint j) { + // lookup for lightbulb and emptycells + int lb = 0; + int notempty = 0; + int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; + bool res = true; + int gap_position = 1; + for (uint index_tab = 0; index_tab < sizeof(tab) / sizeof(tab[0]); index_tab += 2) { + if (/* normal check*/ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) || + /*wrapping check*/ game_is_wrapping(g)) { + if (game_is_lightbulb(g, IWRAPPING, JWRAPPING)) + lb++; + else if (!game_is_blank(g, IWRAPPING, JWRAPPING) || game_is_lighted(g, IWRAPPING, JWRAPPING)) + notempty++; + } else { + notempty++; + } + } + if (lb > game_get_black_number(g, i, j)) { + res = false; + } + // look if there is enough empty cell around the wall + else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { + res = false; + } + if (game_get_flags(g, i, j) == F_ERROR) { + res = !res; + } + return res; +} + /** * @brief check if the all flags are correctly updated * @@ -304,67 +361,14 @@ bool check_update(game g) { for (uint i = 0; i < game_nb_rows(g); i++) { for (uint j = 0; j < game_nb_cols(g); j++) { if (game_is_lightbulb(g, i, j)) { - square flags = game_get_flags(g, i, j); - if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) { + if (!test_update_flags_lightbulb(g, i, j)) { return false; } - int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (uint tab_index = 0; tab_index < sizeof(tab) / sizeof(tab[0]); tab_index = tab_index + 2) { - bool wall = false; - for (int gap_distance = 1; gap_distance < max(game_nb_cols(g), game_nb_rows(g)); gap_distance++) { - if (/* test if both tab are not 0*/ tab[tab_index] != tab[tab_index + 1] && - (/* normal check */ (j + gap_distance * tab[tab_index + 1] >= 0 && j + gap_distance * tab[tab_index + 1] < game_nb_cols(g) && - i + gap_distance * tab[tab_index] >= 0 && i + gap_distance * tab[tab_index] < game_nb_rows(g)) || - /* wrapping check*/ game_is_wrapping(g))) { - // test if current case is a wall - if (game_is_black(g, ((i + game_nb_rows(g) + gap_distance * tab[tab_index]) % game_nb_rows(g)), - ((j + game_nb_cols(g) + gap_distance * tab[tab_index + 1]) % game_nb_cols(g)))) { - wall = true; - } else { - int tmp = checklightbulb(g, ((i + game_nb_rows(g) + gap_distance * tab[tab_index]) % game_nb_rows(g)), - ((j + game_nb_cols(g) + gap_distance * tab[tab_index + 1]) % game_nb_cols(g)), wall); - if (tmp == -1) { - break; - } - if (!tmp) { - return tmp; - } - } - } - } - } - } else if (/*test if current case is a wall*/ game_is_black(g, i, j)) { + // test if current case is a wall + } else if (game_is_black(g, i, j)) { if (game_get_black_number(g, i, j) != -1) { - // lookup for lightbulb and emptycells - int lb = 0; - int notempty = 0; - int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - bool res = true; - for (uint y = 0; y < 7; y = y + 2) { - if (/* normal check*/ (j + tab[y + 1] >= 0 && j + tab[y + 1] < game_nb_cols(g) && i + tab[y] >= 0 && i + tab[y] < game_nb_rows(g)) || - /*wrapping check*/ game_is_wrapping(g)) { - if (game_is_lightbulb(g, (i + game_nb_rows(g) + tab[y]) % game_nb_rows(g), (j + game_nb_cols(g) + tab[y + 1]) % game_nb_cols(g))) - lb++; - else if (!game_is_blank(g, (i + game_nb_rows(g) + tab[y]) % game_nb_rows(g), - (j + game_nb_cols(g) + tab[y + 1]) % game_nb_cols(g)) || - game_is_lighted(g, (i + game_nb_rows(g) + tab[y]) % game_nb_rows(g), (j + game_nb_cols(g) + tab[y + 1]) % game_nb_cols(g))) - notempty++; - } else { - notempty++; - } - } - if (lb > game_get_black_number(g, i, j)) { - res = false; - } - // look if there is enough empty cell around the wall - else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { - res = false; - } - if (game_get_flags(g, i, j) == F_ERROR) { - res = !res; - } - if (!res) { - return res; + if (!test_update_flags_walls(g, i, j)) { + return false; } } } From cbc738d4f030202e847df7419bb98a230821b2c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sat, 22 Jan 2022 17:59:03 +0100 Subject: [PATCH 255/281] missed two (;) --- game_test_thoguet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 48a9153..cae18d8 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -273,8 +273,8 @@ int checklightbulb(game g, uint i, uint j, bool wall) { for (uint index_tab = 0; index_tab < 7 /*tab size*/; index_tab = index_tab + 2) { for (int gap_position = 1; gap_position < max(game_nb_cols(g), game_nb_rows(g)); gap_position++) { if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] && - (/* normal check */ JWRAPPING >= 0 && JWRAPPING < game_nb_cols(g) && IWRAPPING >= 0 && IWRAPPING < game_nb_rows(g)) || - /* wrapping check*/ game_is_wrapping(g)) { + (/* normal check */ (JWRAPPING >= 0 && JWRAPPING < game_nb_cols(g) && IWRAPPING >= 0 && IWRAPPING < game_nb_rows(g)) || + /* wrapping check*/ game_is_wrapping(g))) { flags = game_get_square(g, IWRAPPING, JWRAPPING); if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; From 952fca3a0a91432702cac061ea0b18fa512e6a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sat, 22 Jan 2022 18:20:08 +0100 Subject: [PATCH 256/281] finished cleaning of thoguet tests --- game_test_thoguet.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index cae18d8..6f94754 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -239,13 +239,13 @@ bool test_game_default_solution(void) { /* **** game_update_flags **** */ /** - * @brief check if the case i j have his flags well updated + * @brief check if the case (i,j) have its flags well updated * * @param g the game to test * @param i the i coordiante of the case to test * @param j the j coordiante of the case to test * @param wall if there is a wall before - * @return 0 if the case is well updated ; -1 else + * @return 1 if the case is well updated ; 0 if there is an error on the update ; -1 if the case is irrelevant */ int checklightbulb(game g, uint i, uint j, bool wall) { square flags = game_get_flags(g, i, j); @@ -268,7 +268,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) { return 1; } // test if all case are not lighted or lighted by another lightbulb - if (/*test if the current case is lighted*/ flags == F_LIGHTED) { + if (flags == F_LIGHTED) { int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; for (uint index_tab = 0; index_tab < 7 /*tab size*/; index_tab = index_tab + 2) { for (int gap_position = 1; gap_position < max(game_nb_cols(g), game_nb_rows(g)); gap_position++) { From fc2eb4745be2b66ee894e733d539d499066c914e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sat, 22 Jan 2022 19:15:29 +0100 Subject: [PATCH 257/281] test_update_flags maybe fixed --- game_test_thoguet.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 6f94754..9fa4120 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -273,8 +273,8 @@ int checklightbulb(game g, uint i, uint j, bool wall) { for (uint index_tab = 0; index_tab < 7 /*tab size*/; index_tab = index_tab + 2) { for (int gap_position = 1; gap_position < max(game_nb_cols(g), game_nb_rows(g)); gap_position++) { if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] && - (/* normal check */ (JWRAPPING >= 0 && JWRAPPING < game_nb_cols(g) && IWRAPPING >= 0 && IWRAPPING < game_nb_rows(g)) || - /* wrapping check*/ game_is_wrapping(g))) { + (/* normal check */ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) || + /* wrapping check + not the inital case*/ (game_is_wrapping(g) && !(IWRAPPING == i && JWRAPPING == j)))) { flags = game_get_square(g, IWRAPPING, JWRAPPING); if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { return -1; @@ -301,7 +301,7 @@ int test_update_flags_lightbulb(game g, uint i, uint j) { for (int gap_position = 1; gap_position < max(game_nb_cols(g), game_nb_rows(g)); gap_position++) { if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] && (/* normal check */ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) || - /* wrapping check*/ game_is_wrapping(g))) { + /* wrapping check + not the inital case*/ (game_is_wrapping(g) && !(IWRAPPING == i && JWRAPPING == j)))) { // test if current case is a wall if (game_is_black(g, IWRAPPING, JWRAPPING)) { wall = true; @@ -328,7 +328,8 @@ bool test_update_flags_walls(game g, uint i, uint j) { int gap_position = 1; for (uint index_tab = 0; index_tab < sizeof(tab) / sizeof(tab[0]); index_tab += 2) { if (/* normal check*/ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) || - /*wrapping check*/ game_is_wrapping(g)) { + /*wrapping check*/ (game_is_wrapping(g) && + /*not the same case*/ !(IWRAPPING == i && JWRAPPING == j))) { if (game_is_lightbulb(g, IWRAPPING, JWRAPPING)) lb++; else if (!game_is_blank(g, IWRAPPING, JWRAPPING) || game_is_lighted(g, IWRAPPING, JWRAPPING)) From c20d58f60a497550a427ec0a210b46cca34fd2cc Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Sun, 23 Jan 2022 13:47:27 +0100 Subject: [PATCH 258/281] edit test_game_nb_rows / cols --- game_test_nnunes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 06f0b09..fe5ca33 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -140,7 +140,7 @@ bool test_game_has_error(void) { /* ************** game_nb_rows ************** */ bool test_game_nb_rows(void) { game g = game_new_empty(); - if (game_nb_rows(g) != g->height) { + if (game_nb_rows(g) != DEFAULT_SIZE) { game_delete(g); return false; } @@ -151,7 +151,7 @@ bool test_game_nb_rows(void) { /* ************** game_nb_cols ************** */ bool test_game_nb_cols(void) { game g = game_new_empty(); - if (game_nb_cols(g) != g->width) { + if (game_nb_cols(g) != DEFAULT_SIZE) { game_delete(g); return false; } From f5ca9b45056c55936e7ee4fe0f6e411e9e959f6a Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Sun, 23 Jan 2022 16:58:17 +0100 Subject: [PATCH 259/281] edit game_is_wrapping --- game_test_nnunes.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index fe5ca33..fe68b32 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -162,12 +162,21 @@ bool test_game_nb_cols(void) { /* ************** game_is_wrapping ************** */ bool test_game_is_wrapping(void) { game g = game_new_empty(); - if (game_is_wrapping(g) != g->wrapping) { - game_delete(g); - return false; - } + game_set_square(g, 0, 0, S_LIGHTBULB); + game_set_square(g, 1, 0, S_BLACK); + game_set_square(g, 0, 1, S_BLACK); + for (uint i = 0; i < DEFAULT_SIZE; i++) { + if (!(game_is_lighted(g, 0, i) && game_is_wrapping(g))) { + game_delete(g); + return true; + } + if (!(game_is_lighted(g, i, 0) && game_is_wrapping(g))) { + game_delete(g); + return true; + } game_delete(g); - return true; + return false; + } } int main(int argc, char* argv[]) { From 2dfe4168c83174d9069566dfa22e3dfcc2138cd2 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sun, 23 Jan 2022 17:29:38 +0100 Subject: [PATCH 260/281] edit test redo & undo + adding comments --- game_test_thperrier.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index ccc4472..7c5a252 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -189,7 +189,8 @@ bool test_game_copy() { bool test_game_undo() { game g1 = game_new_empty(); game g2 = game_copy(g1); - game_undo(g1); + // check if you can undo without playing a move + game_undo(g2); if (!game_equal(g1, g2)) { game_delete(g1); game_delete(g2); @@ -198,8 +199,9 @@ bool test_game_undo() { game_play_move(g1, 0, 0, S_LIGHTBULB); game_play_move(g1, 1, 1, S_MARK); game g3 = game_copy(g1); - game_play_move(g3, 1, 1, S_BLANK); - game_undo(g1); + // check if the function undo correctly + game_play_move(g3, 2, 2, S_LIGHTBULB); + game_undo(g3); if (!game_equal(g1, g3)) { game_delete(g1); game_delete(g2); @@ -218,6 +220,7 @@ bool test_game_redo() { game_play_move(g1, 0, 0, S_LIGHTBULB); game_play_move(g1, 1, 1, S_MARK); game g2 = game_copy(g1); + // check if you can redo a non existant move game_undo(g1); game_redo(g1); game_redo(g1); @@ -228,6 +231,8 @@ bool test_game_redo() { } game_play_move(g1, 2, 2, S_LIGHTBULB); game_play_move(g2, 2, 2, S_LIGHTBULB); + // check if the function redo correctly + game_undo(g1); game_redo(g1); if (!game_equal(g1, g2)) { game_delete(g1); From 5ce6b2d0114c63e54d167db15cb929862a77a1cd Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sun, 23 Jan 2022 17:57:03 +0100 Subject: [PATCH 261/281] edit test_game_is_blank + wrapping in g equal test --- game_test_thperrier.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 7c5a252..cf02e63 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -89,6 +89,11 @@ bool test_game_is_lightbulb() { bool test_game_is_blank() { square tab_square[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; game g = game_new_empty(); + game_set_square(g, 0, 0, S_BLANK); + if (!((game_get_square(g, 0, 0) == S_BLANK) && game_is_blank(g, 0, 0))) { + game_delete(g); + return false; + } for (int i = 0; i < game_nb_rows(g); i++) { for (int j = 0; j < game_nb_cols(g); j++) { // check for each case given in tab_square if the function return the expected result @@ -130,6 +135,9 @@ bool test_game_equal() { } } game g2 = game_copy(g1); + if (!(game_nb_rows(g1) == game_nb_rows(g2)) || !(game_nb_cols(g1) == game_nb_cols(g2)) || !(game_is_wrapping(g1) == game_is_wrapping(g2))){ + equal = false; + } for (int i = 0; i < game_nb_rows(g1); i++) { for (int j = 0; j < game_nb_cols(g1); j++) { if (game_get_square(g1, i, j) != game_get_square(g2, i, j)) { From 9a135672e3291e4725682c43807279aaceabe829 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sun, 23 Jan 2022 18:21:43 +0100 Subject: [PATCH 262/281] edit some tests + adding some comments --- game_test_thperrier.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index cf02e63..d2b8c3c 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -135,16 +135,21 @@ bool test_game_equal() { } } game g2 = game_copy(g1); + // check if the two games have the same height, width, and if the two have the wrapping option or not if (!(game_nb_rows(g1) == game_nb_rows(g2)) || !(game_nb_cols(g1) == game_nb_cols(g2)) || !(game_is_wrapping(g1) == game_is_wrapping(g2))){ equal = false; - } - for (int i = 0; i < game_nb_rows(g1); i++) { - for (int j = 0; j < game_nb_cols(g1); j++) { - if (game_get_square(g1, i, j) != game_get_square(g2, i, j)) { - equal = false; + } + // check if each square is the same on each game + else { + for (int i = 0; i < game_nb_rows(g1); i++) { + for (int j = 0; j < game_nb_cols(g1); j++) { + if (game_get_square(g1, i, j) != game_get_square(g2, i, j)) { + equal = false; + } } } } + // check if game_equal return the expected result equal = (equal == game_equal(g1, g2)); game_delete(g1); game_delete(g2); @@ -154,6 +159,7 @@ bool test_game_equal() { /* ********** game_new_empty ********** */ bool test_game_new_empty() { game g = game_new_empty(); + // check if each square is a S_BLANK for (int i = 0; i < game_nb_rows(g); i++) { for (int j = 0; j < game_nb_cols(g); j++) { if (game_get_square(g, i, j) != S_BLANK) { From 88d04aaa1e92a25c0156a59e1d9cd18f442227d3 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sun, 23 Jan 2022 18:34:51 +0100 Subject: [PATCH 263/281] adding comments in game_redo + game_undo --- game_ext.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/game_ext.c b/game_ext.c index e9ab380..c2f4044 100644 --- a/game_ext.c +++ b/game_ext.c @@ -58,6 +58,7 @@ bool game_is_wrapping(cgame g) { } void game_undo(game g) { + // check if g->hist is not empty or if it is possible to undo if (g->hist == NULL || history_is_empty(history_prev(g->hist))) { printf("you are at your first move\n"); } else { @@ -70,6 +71,7 @@ void game_undo(game g) { } void game_redo(game g) { + // check if g->hist is not empty or if it is possible to redo if (g->hist == NULL || history_next(g->hist) == NULL) { printf("you are at your last move\n"); } else { From 20f17dced127861ffbf90db47bb12e48c0a86e3d Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sun, 23 Jan 2022 18:45:33 +0100 Subject: [PATCH 264/281] edit test_game_equal check nb cols/rows + wrapping --- game_test_thperrier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index d2b8c3c..c972de0 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -136,7 +136,7 @@ bool test_game_equal() { } game g2 = game_copy(g1); // check if the two games have the same height, width, and if the two have the wrapping option or not - if (!(game_nb_rows(g1) == game_nb_rows(g2)) || !(game_nb_cols(g1) == game_nb_cols(g2)) || !(game_is_wrapping(g1) == game_is_wrapping(g2))){ + if (game_nb_rows(g1) != game_nb_rows(g2) || game_nb_cols(g1) != game_nb_cols(g2) || game_is_wrapping(g1) != game_is_wrapping(g2)){ equal = false; } // check if each square is the same on each game From 1ed716b9e67b62929e85e523ac4c163fc26d866d Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sun, 23 Jan 2022 18:49:08 +0100 Subject: [PATCH 265/281] adding comments and correcting some --- game.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/game.c b/game.c index 7bb2e2e..f40b3b2 100644 --- a/game.c +++ b/game.c @@ -45,7 +45,7 @@ game game_new_empty(void) { g->tab_cell[i][j] = S_BLANK; } } - // init history with an cell (if there is only this cell we consider the history as empty) + // init history with a cell to avoid falling off of g->hist (if there is only this cell we consider the history as empty) g->hist = history_insert_first(g->hist, F_ERROR, 0, 0); return g; } @@ -64,8 +64,10 @@ game game_copy(cgame g1) { } bool game_equal(cgame g1, cgame g2) { + // check if the two games have the same options if (g1->height != g2->height || g1->width != g2->width || g1->wrapping != g2->wrapping) return false; + // check each cell and seek any difference between g1 and g2 for (int i = 0; i < g1->height; i++) { for (int j = 0; j < g1->width; j++) { if (g1->tab_cell[i][j] != g2->tab_cell[i][j]) { @@ -77,7 +79,7 @@ bool game_equal(cgame g1, cgame g2) { } void game_delete(game g) { - // free each tab of tabcell + // free each tab of tab_cell for (int i = 0; i < game_nb_rows(g); i++) { free(g->tab_cell[i]); g->tab_cell[i] = NULL; From 3b1804166c434fa49a679782349f492c2edda93a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 23 Jan 2022 19:27:39 +0100 Subject: [PATCH 266/281] changed test_update_flags --- game_test_thoguet.c | 330 ++++++++++++++++---------------------------- 1 file changed, 122 insertions(+), 208 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 9fa4120..8099c2c 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -237,226 +237,140 @@ bool test_game_default_solution(void) { } /* **** game_update_flags **** */ - /** - * @brief check if the case (i,j) have its flags well updated + * @brief count the number of F_ERROR on the entire game g * - * @param g the game to test - * @param i the i coordiante of the case to test - * @param j the j coordiante of the case to test - * @param wall if there is a wall before - * @return 1 if the case is well updated ; 0 if there is an error on the update ; -1 if the case is irrelevant + * @param g the game to analyze + * @return uint the number of F_ERROR on the game g */ -int checklightbulb(game g, uint i, uint j, bool wall) { - square flags = game_get_flags(g, i, j); - // 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 (game_is_lightbulb(g, i, j)) { - if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) { - return 0; - } - return -1; - } - // if no wall(s) before test if the light of the lightbulb has been well - // updated - if (!wall) { - // test if the current case is not lighted - if (flags != F_LIGHTED) { - return 0; - } - return 1; - } - // test if all case are not lighted or lighted by another lightbulb - if (flags == F_LIGHTED) { - int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (uint index_tab = 0; index_tab < 7 /*tab size*/; index_tab = index_tab + 2) { - for (int gap_position = 1; gap_position < max(game_nb_cols(g), game_nb_rows(g)); gap_position++) { - if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] && - (/* normal check */ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) || - /* wrapping check + not the inital case*/ (game_is_wrapping(g) && !(IWRAPPING == i && JWRAPPING == j)))) { - flags = game_get_square(g, IWRAPPING, JWRAPPING); - if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) { - return -1; - } - if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { - break; - } - } - } - } - return 0; - } - return 1; -} - -int test_update_flags_lightbulb(game g, uint i, uint j) { - square flags = game_get_flags(g, i, j); - if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) { - return false; - } - int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - for (uint index_tab = 0; index_tab < sizeof(tab) / sizeof(tab[0]); index_tab += 2) { - bool wall = false; - for (int gap_position = 1; gap_position < max(game_nb_cols(g), game_nb_rows(g)); gap_position++) { - if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] && - (/* normal check */ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) || - /* wrapping check + not the inital case*/ (game_is_wrapping(g) && !(IWRAPPING == i && JWRAPPING == j)))) { - // test if current case is a wall - if (game_is_black(g, IWRAPPING, JWRAPPING)) { - wall = true; - } else { - int tmp = checklightbulb(g, IWRAPPING, JWRAPPING, wall); - if (tmp == -1) { - break; - } - if (!tmp) - return tmp; - } - } - } - } - return true; -} - -bool test_update_flags_walls(game g, uint i, uint j) { - // lookup for lightbulb and emptycells - int lb = 0; - int notempty = 0; - int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1}; - bool res = true; - int gap_position = 1; - for (uint index_tab = 0; index_tab < sizeof(tab) / sizeof(tab[0]); index_tab += 2) { - if (/* normal check*/ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) || - /*wrapping check*/ (game_is_wrapping(g) && - /*not the same case*/ !(IWRAPPING == i && JWRAPPING == j))) { - if (game_is_lightbulb(g, IWRAPPING, JWRAPPING)) - lb++; - else if (!game_is_blank(g, IWRAPPING, JWRAPPING) || game_is_lighted(g, IWRAPPING, JWRAPPING)) - notempty++; - } else { - notempty++; - } - } - if (lb > game_get_black_number(g, i, j)) { - res = false; - } - // look if there is enough empty cell around the wall - else if (notempty > abs(game_get_black_number(g, i, j) - 4)) { - res = false; - } - if (game_get_flags(g, i, j) == F_ERROR) { - res = !res; - } - return res; -} - -/** - * @brief check if the all flags are correctly updated - * - * @param g the game to test - * @return true if all flags are corrects - * @return false if one flags isn't correct - */ -bool check_update(game g) { +uint counterF_ERROR(game g) { + uint cpt = 0; for (uint i = 0; i < game_nb_rows(g); i++) { for (uint j = 0; j < game_nb_cols(g); j++) { - if (game_is_lightbulb(g, i, j)) { - if (!test_update_flags_lightbulb(g, i, j)) { - return false; - } - // test if current case is a wall - } else if (game_is_black(g, i, j)) { - if (game_get_black_number(g, i, j) != -1) { - if (!test_update_flags_walls(g, i, j)) { - return false; - } - } - } + if (game_has_error(g, i, j)) + cpt++; } } - return true; + return cpt; } +/*Tests de sans l'option wrapping -/** - * @brief tests if the update_flags works well and update each case of g with every square with a deepness of a. - * - * @param g the game to test - * @param a the deepness of test (a > 2 : execution time > 3 minutes and exponential) - * @param deldup List of each case already tested (to avoid duplicates) - * @return true if update flags works fine in every tested cases - * @return false if there is a update_flags error. - */ -bool brutforce(game g, int a, bool* deldup) { - bool* delDupNext = (bool*)calloc(game_nb_rows(g) * game_nb_cols(g), sizeof(bool)); - if (delDupNext == NULL) { - fprintf(stderr, "Not enought memory\n"); - exit(EXIT_FAILURE); - } - square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK}; - for (uint i = 0; i < game_nb_rows(g); i++) { - for (uint j = 0; j < game_nb_cols(g); j++) { - if (deldup == NULL || !(deldup[i * game_nb_cols(g) + j])) { - if (game_get_state(g, i, j) == S_BLANK) { - if (delDupNext != NULL && a > 0) - delDupNext[i * game_nb_cols(g) + j] = true; - for (uint k = 0; k < 9; k++) { - game_set_square(g, i, j, list[k]); - if (a > 0) { - if (!brutforce(g, a - 1, delDupNext)) { - free(delDupNext); - return false; - } - } - game_update_flags(g); - if (!check_update(g)) { - game_print(g); - free(delDupNext); - return false; - } - } - } - } - } - } - free(delDupNext); - return true; -} +test d'un jeu 2x2 sans l'option *wrapping* (cas limite) +test d'un jeu 3x3 sans l'option *wrapping* +test d'un jeu 5x3 sans l'option *wrapping* +test du flag *error* dans des cas spécifique à l'option *wrapping* -/** - * @brief randomise a game g 100% random => not 100% resolvable - * - * @param g the game to randomise - */ -void randomise(game g) { - time_t t; - srand((unsigned)time(&t)); - assert(g); - square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, - S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK}; - for (uint h = 0; h < game_nb_rows(g); h++) { - for (uint w = 0; w < game_nb_cols(g); w++) { - game_set_square(g, h, w, list[rand() % 16]); - } - } -} +Dans les tests 2x2, 3x3 et 5x3, on joue les coups ci-dessous pour gagner le jeu +et on vérifie que la grille est correcte. + 01 012 012 + -- --- --- +0 |2*| 0 |.w0| 0 |*..| +1 |*.| 1 |*1w| 1 |w*1| + -- 2 |..*| 2 |*2.| + (2x2) --- 3 |..*| + (3x3) 4 |.*.| + --- + (5x3) + +Tests de l'option wrapping + +test d'un jeu 2x2 avec l'option *wrapping* (cas limite) +test d'un jeu 3x3 avec l'option *wrapping* +test d'un jeu 5x3 avec l'option *wrapping* +test du flag *error* dans des cas spécifique à l'option *wrapping* + +Dans les tests 2x2, 3x3 et 5x3, on joue les coups ci-dessous pour gagner le jeu +et on vérifie que la grille est correcte. + + 01 012 012 + -- --- --- +0 |4*| 0 |*w2| 0 |...| +1 |*.| 1 |.ww| 1 |w*1| + -- 2 |..*| 2 |*2.| + (2x2) --- 3 |..*| + (3x3) 4 |...| + --- + (5x3) +*/ bool test_game_update_flags(void) { - // test game of size between 1 and 6 (we can change 6) - for (uint h = 1; h <= 6; h++) { - for (uint w = 1; w <= 6; w++) { - for (int wrap = 0; wrap != 1; wrap++) { - game g = game_new_empty_ext(h, w, wrap); - assert(g); - randomise(g); - if (!brutforce(g, 1, NULL)) { - game_delete(g); - return EXIT_FAILURE; - } - game_delete(g); - } - } - } + square test2x2w[4] = {S_BLACK4, S_BLANK, S_BLANK, S_BLANK}; + square test3x3w[9] = {S_BLANK, S_BLACKU, S_BLACK2, S_BLANK, S_BLACKU, S_BLACKU, S_BLANK, S_BLANK, S_BLANK}; + square test5x3[15] = {S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLACK1, S_BLANK, S_BLACK2, + S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK}; + square test2x2[4] = {S_BLACK2, S_BLANK, S_BLANK, S_BLANK}; + square test3x3[9] = {S_BLANK, S_BLACKU, S_BLACK0, S_BLANK, S_BLACK1, S_BLACKU, S_BLANK, S_BLANK, S_BLANK}; + // avec wrapping + game g2x2w = game_new_ext(2, 2, test2x2w, true); + game g3x3w = game_new_ext(3, 3, test3x3w, true); + game g5x3w = game_new_ext(5, 3, test5x3, true); + game_play_move(g2x2w, 0, 1, S_LIGHTBULB); + game_play_move(g2x2w, 1, 0, S_LIGHTBULB); + assert(game_is_over(g2x2w)); + game_play_move(g3x3w, 0, 0, S_LIGHTBULB); + game_play_move(g3x3w, 2, 2, S_LIGHTBULB); + assert(game_is_over(g3x3w)); + game_play_move(g5x3w, 1, 1, S_LIGHTBULB); + game_play_move(g5x3w, 2, 0, S_LIGHTBULB); + game_play_move(g5x3w, 3, 2, S_LIGHTBULB); + assert(game_is_over(g5x3w)); + game_restart(g2x2w); + game_restart(g5x3w); + game_play_move(g2x2w, 0, 1, S_MARK); + assert(!game_is_over(g2x2w)); + assert(game_has_error(g2x2w, 0, 0)); + assert(counterF_ERROR(g2x2w) == 1); + game_play_move(g5x3w, 0, 2, S_LIGHTBULB); + game_play_move(g5x3w, 2, 2, S_LIGHTBULB); + game_play_move(g5x3w, 1, 1, S_LIGHTBULB); + game_play_move(g5x3w, 2, 0, S_LIGHTBULB); + assert(!game_is_over(g5x3w)); + assert(game_has_error(g5x3w, 0, 2)); + assert(game_has_error(g5x3w, 1, 2)); + assert(game_has_error(g5x3w, 2, 2)); + assert(game_has_error(g5x3w, 2, 0)); + assert(game_has_error(g5x3w, 2, 1)); + assert(counterF_ERROR(g5x3w) == 5); + game_delete(g2x2w); + game_delete(g3x3w); + game_delete(g5x3w); + // sans wrapping + game g2x2 = game_new_ext(2, 2, test2x2, false); + game g3x3 = game_new_ext(3, 3, test3x3, false); + game g5x3 = game_new_ext(5, 3, test5x3, false); + game_play_move(g2x2, 0, 1, S_LIGHTBULB); + game_play_move(g2x2, 1, 0, S_LIGHTBULB); + assert(game_is_over(g2x2)); + game_play_move(g3x3, 1, 0, S_LIGHTBULB); + game_play_move(g3x3, 2, 2, S_LIGHTBULB); + assert(game_is_over(g3x3)); + game_play_move(g5x3, 0, 0, S_LIGHTBULB); + game_play_move(g5x3, 1, 1, S_LIGHTBULB); + game_play_move(g5x3, 2, 0, S_LIGHTBULB); + game_play_move(g5x3, 3, 2, S_LIGHTBULB); + game_play_move(g5x3, 4, 1, S_LIGHTBULB); + assert(game_is_over(g5x3)); + game_restart(g2x2); + game_restart(g5x3); + game_play_move(g2x2, 1, 0, S_MARK); + assert(!game_is_over(g2x2)); + assert(game_has_error(g2x2, 0, 0)); + assert(counterF_ERROR(g2x2) == 1); + game_play_move(g5x3, 0, 2, S_LIGHTBULB); + game_play_move(g5x3, 1, 1, S_LIGHTBULB); + game_play_move(g5x3, 2, 0, S_LIGHTBULB); + game_play_move(g5x3, 2, 2, S_LIGHTBULB); + game_play_move(g5x3, 3, 2, S_LIGHTBULB); + game_play_move(g5x3, 4, 1, S_LIGHTBULB); + assert(!game_is_over(g5x3)); + assert(game_has_error(g5x3, 1, 2)); + assert(game_has_error(g5x3, 2, 1)); + assert(game_has_error(g5x3, 2, 2)); + assert(game_has_error(g5x3, 3, 2)); + assert(counterF_ERROR(g5x3) == 4); + game_delete(g5x3); + game_delete(g3x3); + game_delete(g2x2); return EXIT_SUCCESS; } From 612419ac1e9dfbfc08922ee32fd8c957efba669e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 23 Jan 2022 19:52:33 +0100 Subject: [PATCH 267/281] corrected comments --- game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game.c b/game.c index f40b3b2..b025fc3 100644 --- a/game.c +++ b/game.c @@ -241,7 +241,7 @@ void update_flags_walls(game g, uint i, uint j) { if (lightbulb > game_get_black_number(g, i, j)) { game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); } - // look if there is enough empty cell around the wall (4 directions) + // look if there is enough empty cell around the wall (4 for the four directions) else if (not_empty > abs(game_get_black_number(g, i, j) - 4)) { game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR)); } From f70c95c66f0c7bc858b2a98651561cee1d1d8260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 23 Jan 2022 19:52:53 +0100 Subject: [PATCH 268/281] corrected comments + game_check_move --- game_test_thoguet.c | 60 ++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 8099c2c..d95a62a 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -8,11 +8,6 @@ #include "game_aux.h" #include "game_ext.h" -#define JWRAPPING (j + game_nb_cols(g) + gap_position * tab[index_tab + 1]) % game_nb_cols(g) -#define IWRAPPING (i + game_nb_rows(g) + gap_position * tab[index_tab]) % game_nb_rows(g) -#define JNORMAL j + gap_position* tab[index_tab + 1] -#define INORMAL i + gap_position* tab[index_tab] - int max(int a, int b) { if (a > b) return a; @@ -253,15 +248,15 @@ uint counterF_ERROR(game g) { } return cpt; } -/*Tests de sans l'option wrapping +/* +Tests without the wrapping option -test d'un jeu 2x2 sans l'option *wrapping* (cas limite) -test d'un jeu 3x3 sans l'option *wrapping* -test d'un jeu 5x3 sans l'option *wrapping* -test du flag *error* dans des cas spécifique à l'option *wrapping* +test on a 2x2 game without *wrapping* +test on a 3x3 game without *wrapping* +test on a 5x3 game without *wrapping* +test flags *error* on specifics cases -Dans les tests 2x2, 3x3 et 5x3, on joue les coups ci-dessous pour gagner le jeu -et on vérifie que la grille est correcte. +On the 2x2, 3x3 and 5x3 tests, we play these move to win and we test if the grid is correct 01 012 012 -- --- --- @@ -273,15 +268,14 @@ et on vérifie que la grille est correcte. --- (5x3) -Tests de l'option wrapping +Tests of the wrapping option -test d'un jeu 2x2 avec l'option *wrapping* (cas limite) -test d'un jeu 3x3 avec l'option *wrapping* -test d'un jeu 5x3 avec l'option *wrapping* -test du flag *error* dans des cas spécifique à l'option *wrapping* +test on a 2x2 game with option *wrapping* (cas limite) +test on a 3x3 game with option *wrapping* +test on a 5x3 game with option *wrapping* +test of the flags *error* in the specifics cases of the option *wrapping* -Dans les tests 2x2, 3x3 et 5x3, on joue les coups ci-dessous pour gagner le jeu -et on vérifie que la grille est correcte. +On the 2x2, 3x3 and 5x3 tests, we play these move to win and we test if the grid is correct 01 012 012 -- --- --- @@ -406,25 +400,25 @@ bool test_game_play_move(void) { bool test_game_check_move(void) { game g = game_new_empty(); - assert(!game_check_move(g, 10, 10, S_BLANK)); - assert(!game_check_move(g, 10, 10, S_BLACK0)); - assert(!game_check_move(g, 0, 0, S_BLACK0)); - assert(!game_check_move(g, 0, 0, S_BLACK1)); - assert(!game_check_move(g, 0, 0, S_BLACK2)); - assert(!game_check_move(g, 0, 0, S_BLACK3)); - assert(!game_check_move(g, 0, 0, S_BLACK4)); - assert(!game_check_move(g, 0, 0, S_BLACKU)); - assert(!game_check_move(g, 0, 0, F_LIGHTED)); - assert(!game_check_move(g, 0, 0, F_ERROR)); + square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR, F_LIGHTED}; + // test if we can place something else than S_BLANK, S_LIGHTBULB, S_MARK + if we can place something over the limits + for (uint i = 0; i < 20; i++) { + for (uint j = 0; j < 20; j++) { + for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) { + if (i >= game_nb_rows(g) || j >= game_nb_cols(g) || index_list > 2) + assert(!game_check_move(g, i, j, list[index_list])); + else + assert(game_check_move(g, i, j, list[index_list])); + } + } + } + // test if we can place something on a wall for (uint i = 0; i < S_BLACKU - S_BLACK0; i++) { - game_set_square(g, 0, 0, S_BLACK0 + i); + game_set_square(g, 0, 0, S_BLACK + i); assert(!game_check_move(g, 0, 0, S_BLANK)); assert(!game_check_move(g, 0, 0, S_MARK)); assert(!game_check_move(g, 0, 0, S_LIGHTBULB)); } - assert(game_check_move(g, 1, 0, S_BLANK)); - assert(game_check_move(g, 1, 0, S_MARK)); - assert(game_check_move(g, 1, 0, S_LIGHTBULB)); game_delete(g); return EXIT_SUCCESS; } From ef875f445810171f8b7d80ccb76f0f08875e7542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 23 Jan 2022 20:09:11 +0100 Subject: [PATCH 269/281] return on void function XD --- game.c | 1 - 1 file changed, 1 deletion(-) diff --git a/game.c b/game.c index b025fc3..1eb4cd5 100644 --- a/game.c +++ b/game.c @@ -90,7 +90,6 @@ void game_delete(game g) { g->hist = NULL; free(g); g = NULL; - return; } void game_set_square(game g, uint i, uint j, square s) { From 2eebb009284a51f40180fcc380a4cf9af4ca92bc Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Sun, 23 Jan 2022 20:46:10 +0100 Subject: [PATCH 270/281] edit test_game_nb_rows / cols --- game_test_nnunes.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index fe68b32..55cdc0d 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -140,25 +140,26 @@ bool test_game_has_error(void) { /* ************** game_nb_rows ************** */ bool test_game_nb_rows(void) { game g = game_new_empty(); - if (game_nb_rows(g) != DEFAULT_SIZE) { + if (game_get_square(g, game_nb_rows(g) -1, 0) == S_BLANK) { game_delete(g); - return false; - } + return true; + } game_delete(g); - return true; + return false; } /* ************** game_nb_cols ************** */ bool test_game_nb_cols(void) { game g = game_new_empty(); - if (game_nb_cols(g) != DEFAULT_SIZE) { + if (game_get_square(g, 0, game_nb_cols(g) - 1) == S_BLANK) { game_delete(g); - return false; + return true; } game_delete(g); - return true; + return false; } + /* ************** game_is_wrapping ************** */ bool test_game_is_wrapping(void) { game g = game_new_empty(); @@ -173,10 +174,10 @@ bool test_game_is_wrapping(void) { if (!(game_is_lighted(g, i, 0) && game_is_wrapping(g))) { game_delete(g); return true; - } + } + } game_delete(g); return false; - } } int main(int argc, char* argv[]) { From b0658c0cbdd75ebb6e9452bb44c0da9bc3215714 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sun, 23 Jan 2022 21:35:20 +0100 Subject: [PATCH 271/281] edit test_game_equal for testing wrapping option --- game_test_thperrier.c | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index c972de0..840802e 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -123,36 +123,38 @@ bool test_game_equal() { square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; bool equal = true; uint index_tab = 0; - game g1 = game_new_empty(); - for (int i = 0; i < game_nb_rows(g1); i++) { - for (int j = 0; j < game_nb_cols(g1); j++) { - // check if index_tab reach end of tab - if (index_tab == sizeof(tab_square) / sizeof(tab_square[0])) { - index_tab = 0; - } - game_set_square(g1, i, j, tab_square[index_tab]); - index_tab++; - } - } - game g2 = game_copy(g1); - // check if the two games have the same height, width, and if the two have the wrapping option or not - if (game_nb_rows(g1) != game_nb_rows(g2) || game_nb_cols(g1) != game_nb_cols(g2) || game_is_wrapping(g1) != game_is_wrapping(g2)){ - equal = false; - } - // check if each square is the same on each game - else { + for(int wrap = 0; wrap < 2 /*we only need to test two versions (with and without wrapping)*/; wrap++){ + game g1 = game_new_empty_ext(DEFAULT_SIZE, DEFAULT_SIZE, wrap); for (int i = 0; i < game_nb_rows(g1); i++) { for (int j = 0; j < game_nb_cols(g1); j++) { - if (game_get_square(g1, i, j) != game_get_square(g2, i, j)) { - equal = false; + // check if index_tab reach end of tab + if (index_tab == sizeof(tab_square) / sizeof(tab_square[0])) { + index_tab = 0; + } + game_set_square(g1, i, j, tab_square[index_tab]); + index_tab++; + } + } + game g2 = game_copy(g1); + // check if the two games have the same height, width, and if the two have the wrapping option or not + if (game_nb_rows(g1) != game_nb_rows(g2) || game_nb_cols(g1) != game_nb_cols(g2) || game_is_wrapping(g1) != game_is_wrapping(g2)){ + equal = false; + } + // check if each square is the same on each game + else { + for (int i = 0; i < game_nb_rows(g1); i++) { + for (int j = 0; j < game_nb_cols(g1); j++) { + if (game_get_square(g1, i, j) != game_get_square(g2, i, j)) { + equal = false; + } } } } - } // check if game_equal return the expected result equal = (equal == game_equal(g1, g2)); game_delete(g1); game_delete(g2); + } return equal; } From 73d1835dc9e8381253fa4bd51ce3f00e00877bb9 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sun, 23 Jan 2022 21:40:55 +0100 Subject: [PATCH 272/281] edit test_game_copy now testing option wrapping --- game_test_thperrier.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 840802e..e9bff1d 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -178,26 +178,28 @@ bool test_game_new_empty() { bool test_game_copy() { square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; uint index_tab = 0; - game g1 = game_new_empty(); - for (int i = 0; i < game_nb_rows(g1); i++) { - for (int j = 0; j < game_nb_cols(g1); j++) { - // check if index_tab reach end of tab - if (index_tab == sizeof(tab_square) / sizeof(tab_square[0])) { - index_tab = 0; + for(int wrap = 0; wrap < 2 /*we only need to test two versions (with and without wrapping)*/; wrap++){ + game g1 = game_new_empty_ext(DEFAULT_SIZE, DEFAULT_SIZE, wrap); + for (int i = 0; i < game_nb_rows(g1); i++) { + for (int j = 0; j < game_nb_cols(g1); j++) { + // check if index_tab reach end of tab + if (index_tab == sizeof(tab_square) / sizeof(tab_square[0])) { + index_tab = 0; + } + game_set_square(g1, i, j, tab_square[index_tab]); + index_tab++; } - game_set_square(g1, i, j, tab_square[index_tab]); - index_tab++; } - } - game g2 = game_copy(g1); - // check if g2 is a correct copy of g1 - if (!game_equal(g1, g2)) { + game g2 = game_copy(g1); + // check if g2 is a correct copy of g1 + if (!game_equal(g1, g2)) { + game_delete(g1); + game_delete(g2); + return false; + } game_delete(g1); game_delete(g2); - return false; } - game_delete(g1); - game_delete(g2); return true; } From 0d2eac60abcbdd7d1287296d6a6a0d374ab0e48d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 23 Jan 2022 22:30:04 +0100 Subject: [PATCH 273/281] comments + remove dupli code --- game_test_thoguet.c | 355 +++++++++++++++++++++++++------------------- 1 file changed, 206 insertions(+), 149 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index d95a62a..5a108df 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -8,11 +8,10 @@ #include "game_aux.h" #include "game_ext.h" -int max(int a, int b) { - if (a > b) - return a; - return b; -} +#define SIZE_LIMIT_GAME 10 +// put usable square at the start of the list +#define LIST_OF_SQUARE square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_LIGHTED, F_ERROR}; +#define USABLE_SQUARE 2 /* ********** DUMMY ********** */ bool test_dummy(void) { @@ -20,14 +19,19 @@ bool test_dummy(void) { } /* ******* game_new_ext_empty ******* */ - +/** + * @brief test creating every game between size 0 to SIZE_LIMIT_GAME + * + * @return EXIT_SUCCESS if every game has been created well + */ bool test_game_new_empty_ext(void) { - for (int h = 1; h <= 10; h++) { - for (int w = 1; w <= 10; w++) { + for (uint height = 1; height <= SIZE_LIMIT_GAME; height++) { + for (uint width = 1; width <= SIZE_LIMIT_GAME; width++) { for (int wrap = 0; wrap < 2; wrap++) { - game g = game_new_empty_ext(h, w, wrap); + game g = game_new_empty_ext(height, width, wrap); assert(g); game_delete(g); + g = NULL; } } } @@ -35,24 +39,28 @@ bool test_game_new_empty_ext(void) { } /* ******* game_new_ext ******* */ - +/** + * @brief test creating every game between size 0 to SIZE_LIMIT_GAME + fill it with every square of list + * + * @return EXIT_SUCCESS if every game has been created well and well filled + */ bool test_game_new_ext(void) { - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR}; - for (int h = 1; h <= 10; h++) { - for (int w = 1; w <= 10; w++) { - square tab[h * w]; - for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { - for (uint j = 0; j < h * w; j++) { - tab[j] = list[i]; + LIST_OF_SQUARE; + for (uint height = 1; height <= SIZE_LIMIT_GAME; height++) { + for (uint width = 1; width <= SIZE_LIMIT_GAME; width++) { + square tab[height * width]; + for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) { + for (uint index_tab = 0; index_tab < height * width; index_tab++) { + tab[index_tab] = list[index_list]; } for (int wrap = 0; wrap < 2; wrap++) { - printf("%d\n", i); - game g = game_new_ext(h, w, tab, wrap); + printf("%d\n", index_list); + game g = game_new_ext(height, width, tab, wrap); assert(g); - for (uint i2 = 0; i2 < game_nb_rows(g); i2++) { + for (uint i = 0; i < game_nb_rows(g); i++) { for (uint j = 0; j < game_nb_cols(g); j++) { - printf("list :%d, get square :%d\n", list[i], game_get_square(g, i2, j)); - assert(list[i] == game_get_square(g, i2, j)); + printf("list :%d, get square :%d\n", list[index_list], game_get_square(g, i, j)); + assert(list[index_list] == game_get_square(g, i, j)); } } game_delete(g); @@ -64,7 +72,11 @@ bool test_game_new_ext(void) { return EXIT_SUCCESS; } /* ******* game_is_over ******* */ - +/** + * @brief test if game_is_over return true with default_solution, false with one flag F_ERROR, false with one S_BLANK and false with game_default + * + * @return EXIT_SUCCESS if there is no errors + */ bool test_game_is_over(void) { game g = game_default_solution(); game_update_flags(g); @@ -83,52 +95,60 @@ bool test_game_is_over(void) { } /* ******* game_restart ******* */ - +/** + * @brief test if game_restart remove every S_LIGHTBULB, S_MARK, and F_LIGHTED but nothing else and if the history has been reset + * + * @return EXIT_SUCCESS if there is no error + */ bool test_game_restart(void) { - game g = game_default(); - game g1 = game_default_solution(); - game_set_square(g, 1, 5, S_BLACK4); - game_set_square(g1, 1, 5, S_BLACK4); - game_set_square(g, 3, 2, S_BLACK3); - game_set_square(g1, 3, 2, S_BLACK3); - game_play_move(g, 0, 1, S_LIGHTBULB); - game_play_move(g1, 0, 1, S_LIGHTBULB); - game_play_move(g, 2, 0, S_MARK); - game_play_move(g1, 2, 0, S_MARK); - game_play_move(g, 1, 1, S_LIGHTBULB); - game_play_move(g1, 1, 1, S_LIGHTBULB); - game_play_move(g, 1, 1, S_MARK); - game_play_move(g1, 1, 1, S_MARK); - game_undo(g); - game_undo(g1); - assert(!game_equal(g, g1)); - game_restart(g1); - game_restart(g); - assert(game_equal(g, g1)); - game_redo(g); - assert(game_equal(g, g1)); - game_undo(g); - assert(game_equal(g, g1)); - game_delete(g); - game_delete(g1); + game game_def = game_default(); + game game_def_solution = game_default_solution(); + game_set_square(game_def, 1, 5, S_BLACK4); + game_set_square(game_def_solution, 1, 5, S_BLACK4); + game_set_square(game_def, 3, 2, S_BLACK3); + game_set_square(game_def_solution, 3, 2, S_BLACK3); + game_play_move(game_def, 0, 1, S_LIGHTBULB); + game_play_move(game_def_solution, 0, 1, S_LIGHTBULB); + game_play_move(game_def, 2, 0, S_MARK); + game_play_move(game_def_solution, 2, 0, S_MARK); + game_play_move(game_def, 1, 1, S_LIGHTBULB); + game_play_move(game_def_solution, 1, 1, S_LIGHTBULB); + game_play_move(game_def, 1, 1, S_MARK); + game_play_move(game_def_solution, 1, 1, S_MARK); + game_undo(game_def); + game_undo(game_def_solution); + assert(!game_equal(game_def, game_def_solution)); + game_restart(game_def_solution); + game_restart(game_def); + assert(game_equal(game_def, game_def_solution)); + game_redo(game_def); + assert(game_equal(game_def, game_def_solution)); + game_undo(game_def); + assert(game_equal(game_def, game_def_solution)); + game_delete(game_def); + game_delete(game_def_solution); return EXIT_SUCCESS; } /* ********* game_new ********* */ - +/** + * @brief test if created game with game_new are well filled by the tab + * + * @return EXIT_SUCCESS if there is no error + */ bool test_game_new(void) { square tab[DEFAULT_SIZE * DEFAULT_SIZE]; - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, 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]; + LIST_OF_SQUARE; + for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) { + for (uint index_tab = 0; index_tab < DEFAULT_SIZE * DEFAULT_SIZE; index_tab++) { + tab[index_tab] = list[index_list]; } - printf("%d\n", i); + printf("%d\n", index_list); game g = game_new(tab); - for (uint i2 = 0; i2 < DEFAULT_SIZE; i2++) { + for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint j = 0; j < DEFAULT_SIZE; j++) { - printf("list :%d, get square :%d\n", list[i], game_get_square(g, i2, j)); - assert(list[i] == game_get_square(g, i2, j)); + printf("list :%d, get square :%d\n", list[index_list], game_get_square(g, i, j)); + assert(list[index_list] == game_get_square(g, i, j)); } } assert(g); @@ -139,19 +159,23 @@ bool test_game_new(void) { } /* ******** game_print ******** */ - +/** + * @brief test if there is no major problems by printing every square of list + * + * @return EXIT_SUCCESS if there is no error + */ bool test_game_print(void) { - for (int h = 1; h <= 10; h++) { - for (int w = 1; w <= 10; w++) { - square tab[w * h]; - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; + for (int height = 1; height <= SIZE_LIMIT_GAME; height++) { + for (int width = 1; width <= SIZE_LIMIT_GAME; width++) { + square tab[width * height]; + LIST_OF_SQUARE; game g; - for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { - for (uint j = 0; j < w * h; j++) { - tab[j] = list[i]; + for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) { + for (uint index_tab = 0; index_tab < width * height; index_tab++) { + tab[index_tab] = list[index_list]; } - printf("%d\n", i); - g = game_new_ext(h, w, tab, false); + printf("%d\n", list[index_list]); + g = game_new_ext(height, width, tab, false); assert(g); game_print(g); game_delete(g); @@ -162,18 +186,23 @@ bool test_game_print(void) { } /* ******* game_get_square ******* */ - +/** + * @brief test if get_square return the same as tab, used to create the game + * + * @return EXIT_SUCCESS if there is no error + */ bool test_game_get_square(void) { - for (int h = 1; h <= 10; h++) { - for (int w = 1; w <= 10; w++) { - square tab[w * h]; - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR}; - for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { - for (uint j = 0; j < h * w; j++) { - tab[j] = list[i]; - game g = game_new_ext(h, w, tab, false); - printf("[%d, %d] %d %d\n", j / game_nb_cols(g), j % game_nb_cols(g), game_get_square(g, j / game_nb_cols(g), j % game_nb_cols(g)), tab[j]); - assert(game_get_square(g, j / game_nb_cols(g), j % game_nb_cols(g)) == tab[j]); + for (int height = 1; height <= SIZE_LIMIT_GAME; height++) { + for (int width = 1; width <= SIZE_LIMIT_GAME; width++) { + square tab[width * height]; + LIST_OF_SQUARE; + for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) { + for (uint index_tab = 0; index_tab < height * width; index_tab++) { + tab[index_tab] = list[index_list]; + game g = game_new_ext(height, width, tab, false); + printf("[%d, %d] %d %d\n", index_tab / game_nb_cols(g), index_tab % game_nb_cols(g), + game_get_square(g, index_tab / game_nb_cols(g), index_tab % game_nb_cols(g)), tab[index_tab]); + assert(game_get_square(g, index_tab / game_nb_cols(g), index_tab % game_nb_cols(g)) == tab[index_tab]); game_delete(g); } } @@ -183,10 +212,14 @@ bool test_game_get_square(void) { } /* ******* game_default ******* */ - +/** + * @brief test if the game_default is the same as tab (tab is game_default) + * + * @return EXIT_SUCCESS if there is no error + */ bool test_game_default(void) { - game g = game_default(); - assert(g); + game game_def = game_default(); + assert(game_def); // clang-format off square tab[49] = { @@ -200,34 +233,38 @@ bool test_game_default(void) { /*Y 6*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLANK }; // clang-format on - game g1 = game_new(tab); - assert(game_equal(g, g1)); - game_delete(g); - game_delete(g1); + game game_test = game_new(tab); + assert(game_equal(game_def, game_test)); + game_delete(game_def); + game_delete(game_test); return EXIT_SUCCESS; } /* *** game_default_solution *** */ - +/** + * @brief test if game_default_solution is the same as game_default with moves needed to win + * + * @return EXIT_SUCCESS if there is no error + */ bool test_game_default_solution(void) { - game g = game_default_solution(); - game g1 = game_default(); - assert(g); + game game_def_solution = game_default_solution(); + game game_def = game_default(); + assert(game_def_solution); // solution - game_set_square(g1, 0, 0, S_LIGHTBULB); - game_set_square(g1, 1, 1, S_LIGHTBULB); - game_set_square(g1, 0, 3, S_LIGHTBULB); - game_set_square(g1, 1, 6, S_LIGHTBULB); - game_set_square(g1, 2, 2, S_LIGHTBULB); - game_set_square(g1, 3, 6, S_LIGHTBULB); - game_set_square(g1, 4, 4, S_LIGHTBULB); - game_set_square(g1, 5, 0, S_LIGHTBULB); - game_set_square(g1, 5, 5, S_LIGHTBULB); - game_set_square(g1, 6, 1, S_LIGHTBULB); - game_update_flags(g1); - assert(game_equal(g, g1)); - game_delete(g); - game_delete(g1); + game_set_square(game_def, 0, 0, S_LIGHTBULB); + game_set_square(game_def, 1, 1, S_LIGHTBULB); + game_set_square(game_def, 0, 3, S_LIGHTBULB); + game_set_square(game_def, 1, 6, S_LIGHTBULB); + game_set_square(game_def, 2, 2, S_LIGHTBULB); + game_set_square(game_def, 3, 6, S_LIGHTBULB); + game_set_square(game_def, 4, 4, S_LIGHTBULB); + game_set_square(game_def, 5, 0, S_LIGHTBULB); + game_set_square(game_def, 5, 5, S_LIGHTBULB); + game_set_square(game_def, 6, 1, S_LIGHTBULB); + game_update_flags(game_def); + assert(game_equal(game_def_solution, game_def)); + game_delete(game_def_solution); + game_delete(game_def); return EXIT_SUCCESS; } @@ -290,20 +327,21 @@ On the 2x2, 3x3 and 5x3 tests, we play these move to win and we test if the grid bool test_game_update_flags(void) { square test2x2w[4] = {S_BLACK4, S_BLANK, S_BLANK, S_BLANK}; square test3x3w[9] = {S_BLANK, S_BLACKU, S_BLACK2, S_BLANK, S_BLACKU, S_BLACKU, S_BLANK, S_BLANK, S_BLANK}; - square test5x3[15] = {S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLACK1, S_BLANK, S_BLACK2, - S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK}; square test2x2[4] = {S_BLACK2, S_BLANK, S_BLANK, S_BLANK}; square test3x3[9] = {S_BLANK, S_BLACKU, S_BLACK0, S_BLANK, S_BLACK1, S_BLACKU, S_BLANK, S_BLANK, S_BLANK}; - // avec wrapping + square test5x3[15] = {S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLACK1, S_BLANK, S_BLACK2, + S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK}; + // with wrapping game g2x2w = game_new_ext(2, 2, test2x2w, true); - game g3x3w = game_new_ext(3, 3, test3x3w, true); - game g5x3w = game_new_ext(5, 3, test5x3, true); game_play_move(g2x2w, 0, 1, S_LIGHTBULB); game_play_move(g2x2w, 1, 0, S_LIGHTBULB); assert(game_is_over(g2x2w)); + game g3x3w = game_new_ext(3, 3, test3x3w, true); game_play_move(g3x3w, 0, 0, S_LIGHTBULB); game_play_move(g3x3w, 2, 2, S_LIGHTBULB); assert(game_is_over(g3x3w)); + game_delete(g3x3w); + game g5x3w = game_new_ext(5, 3, test5x3, true); game_play_move(g5x3w, 1, 1, S_LIGHTBULB); game_play_move(g5x3w, 2, 0, S_LIGHTBULB); game_play_move(g5x3w, 3, 2, S_LIGHTBULB); @@ -314,6 +352,7 @@ bool test_game_update_flags(void) { assert(!game_is_over(g2x2w)); assert(game_has_error(g2x2w, 0, 0)); assert(counterF_ERROR(g2x2w) == 1); + game_delete(g2x2w); game_play_move(g5x3w, 0, 2, S_LIGHTBULB); game_play_move(g5x3w, 2, 2, S_LIGHTBULB); game_play_move(g5x3w, 1, 1, S_LIGHTBULB); @@ -325,19 +364,18 @@ bool test_game_update_flags(void) { assert(game_has_error(g5x3w, 2, 0)); assert(game_has_error(g5x3w, 2, 1)); assert(counterF_ERROR(g5x3w) == 5); - game_delete(g2x2w); - game_delete(g3x3w); game_delete(g5x3w); - // sans wrapping + // without wrapping game g2x2 = game_new_ext(2, 2, test2x2, false); - game g3x3 = game_new_ext(3, 3, test3x3, false); - game g5x3 = game_new_ext(5, 3, test5x3, false); game_play_move(g2x2, 0, 1, S_LIGHTBULB); game_play_move(g2x2, 1, 0, S_LIGHTBULB); assert(game_is_over(g2x2)); + game g3x3 = game_new_ext(3, 3, test3x3, false); game_play_move(g3x3, 1, 0, S_LIGHTBULB); game_play_move(g3x3, 2, 2, S_LIGHTBULB); assert(game_is_over(g3x3)); + game_delete(g3x3); + game g5x3 = game_new_ext(5, 3, test5x3, false); game_play_move(g5x3, 0, 0, S_LIGHTBULB); game_play_move(g5x3, 1, 1, S_LIGHTBULB); game_play_move(g5x3, 2, 0, S_LIGHTBULB); @@ -350,6 +388,7 @@ bool test_game_update_flags(void) { assert(!game_is_over(g2x2)); assert(game_has_error(g2x2, 0, 0)); assert(counterF_ERROR(g2x2) == 1); + game_delete(g2x2); game_play_move(g5x3, 0, 2, S_LIGHTBULB); game_play_move(g5x3, 1, 1, S_LIGHTBULB); game_play_move(g5x3, 2, 0, S_LIGHTBULB); @@ -363,49 +402,67 @@ bool test_game_update_flags(void) { assert(game_has_error(g5x3, 3, 2)); assert(counterF_ERROR(g5x3) == 4); game_delete(g5x3); - game_delete(g3x3); - game_delete(g2x2); return EXIT_SUCCESS; } /* ****** game_play_move ****** */ - +/** + * @brief test if play move set square + update the flags + update history + * + * @return EXIT_SUCCESS if there is no error + */ bool test_game_play_move(void) { - game g = game_new_empty(); - game g1 = game_new_empty(); - game_play_move(g, 0, 0, S_LIGHTBULB); - assert(!game_equal(g, g1)); - game_set_square(g1, 0, 0, S_LIGHTBULB); - assert(!game_equal(g, g1)); - game_update_flags(g1); - assert(game_equal(g, g1)); - game_play_move(g, 3, 0, S_MARK); - assert(!game_equal(g, g1)); - game_set_square(g1, 3, 0, S_MARK); - assert(!game_equal(g, g1)); - game_update_flags(g1); - assert(game_equal(g, g1)); - game_play_move(g, 0, 3, S_BLANK); - assert(game_equal(g, g1)); - game_set_square(g1, 0, 3, S_BLANK); - assert(!game_equal(g, g1)); - game_update_flags(g1); - assert(game_equal(g, g1)); - game_delete(g); - game_delete(g1); + game game_play = game_new_empty(); + game game_set = game_new_empty(); + // S_LIGHTBULB + game_play_move(game_play, 0, 0, S_LIGHTBULB); + assert(!game_equal(game_play, game_set)); + game_set_square(game_set, 0, 0, S_LIGHTBULB); + assert(!game_equal(game_play, game_set)); + game_update_flags(game_set); + assert(game_equal(game_play, game_set)); + // S_BLANK + game_play_move(game_play, 0, 3, S_BLANK); + assert(game_equal(game_play, game_set)); + game_set_square(game_set, 0, 3, S_BLANK); + assert(!game_equal(game_play, game_set)); + game_update_flags(game_set); + assert(game_equal(game_play, game_set)); + // S_MARK + game_play_move(game_play, 3, 0, S_MARK); + assert(!game_equal(game_play, game_set)); + game_set_square(game_set, 3, 0, S_MARK); + assert(!game_equal(game_play, game_set)); + game_update_flags(game_set); + assert(game_equal(game_play, game_set)); + // undo / redo + game_undo(game_play); + assert(!game_equal(game_play, game_set)); + game_set_square(game_set, 3, 0, S_BLANK); + assert(!game_equal(game_play, game_set)); + game_update_flags(game_set); + assert(game_equal(game_play, game_set)); + // delete + game_delete(game_play); + game_delete(game_set); return EXIT_SUCCESS; } /* ***** game_check_move ***** */ - +/** + * @brief test if we can place usable square (here : S_BLANK, S_LIGHTBULB, S_MARK) and nothing else + if we can place something over the limits + * + * @return EXIT_SUCCESS if there is no error + */ bool test_game_check_move(void) { game g = game_new_empty(); - square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR, F_LIGHTED}; - // test if we can place something else than S_BLANK, S_LIGHTBULB, S_MARK + if we can place something over the limits - for (uint i = 0; i < 20; i++) { - for (uint j = 0; j < 20; j++) { + // put usable square at the start of the list + LIST_OF_SQUARE; + // test limits + for (uint i = 0; i < SIZE_LIMIT_GAME + 10; i++) { + for (uint j = 0; j < SIZE_LIMIT_GAME + 10; j++) { for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) { - if (i >= game_nb_rows(g) || j >= game_nb_cols(g) || index_list > 2) + if (i >= game_nb_rows(g) || j >= game_nb_cols(g) || index_list > USABLE_SQUARE) assert(!game_check_move(g, i, j, list[index_list])); else assert(game_check_move(g, i, j, list[index_list])); @@ -415,9 +472,9 @@ bool test_game_check_move(void) { // test if we can place something on a wall for (uint i = 0; i < S_BLACKU - S_BLACK0; i++) { game_set_square(g, 0, 0, S_BLACK + i); - assert(!game_check_move(g, 0, 0, S_BLANK)); - assert(!game_check_move(g, 0, 0, S_MARK)); - assert(!game_check_move(g, 0, 0, S_LIGHTBULB)); + for (uint index_list = 0; index_list < USABLE_SQUARE; index_list++) { + assert(!game_check_move(g, 0, 0, list[index_list])); + } } game_delete(g); return EXIT_SUCCESS; From c2e93a9c2b0dc6fcc3725345e51f67fa289cb000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 23 Jan 2022 23:43:48 +0100 Subject: [PATCH 274/281] finished --- game_test_thoguet.c | 77 +++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 5a108df..596e3e5 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -9,8 +9,9 @@ #include "game_ext.h" #define SIZE_LIMIT_GAME 10 -// put usable square at the start of the list -#define LIST_OF_SQUARE square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_LIGHTED, F_ERROR}; +// put usable square at the start of the list and S_BLANK at the first element +#define LIST_OF_SQUARE \ + { S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_LIGHTED, F_ERROR } #define USABLE_SQUARE 2 /* ********** DUMMY ********** */ @@ -45,7 +46,7 @@ bool test_game_new_empty_ext(void) { * @return EXIT_SUCCESS if every game has been created well and well filled */ bool test_game_new_ext(void) { - LIST_OF_SQUARE; + square list[] = LIST_OF_SQUARE; for (uint height = 1; height <= SIZE_LIMIT_GAME; height++) { for (uint width = 1; width <= SIZE_LIMIT_GAME; width++) { square tab[height * width]; @@ -71,6 +72,7 @@ bool test_game_new_ext(void) { } return EXIT_SUCCESS; } + /* ******* game_is_over ******* */ /** * @brief test if game_is_over return true with default_solution, false with one flag F_ERROR, false with one S_BLANK and false with game_default @@ -100,21 +102,24 @@ bool test_game_is_over(void) { * * @return EXIT_SUCCESS if there is no error */ + +void apply_square(game g, uint i, uint j, square s, void (*apply)(game, uint, uint, square)) { + apply(g, i, j, s); +} + bool test_game_restart(void) { game game_def = game_default(); game game_def_solution = game_default_solution(); - game_set_square(game_def, 1, 5, S_BLACK4); - game_set_square(game_def_solution, 1, 5, S_BLACK4); - game_set_square(game_def, 3, 2, S_BLACK3); - game_set_square(game_def_solution, 3, 2, S_BLACK3); - game_play_move(game_def, 0, 1, S_LIGHTBULB); - game_play_move(game_def_solution, 0, 1, S_LIGHTBULB); - game_play_move(game_def, 2, 0, S_MARK); - game_play_move(game_def_solution, 2, 0, S_MARK); - game_play_move(game_def, 1, 1, S_LIGHTBULB); - game_play_move(game_def_solution, 1, 1, S_LIGHTBULB); - game_play_move(game_def, 1, 1, S_MARK); - game_play_move(game_def_solution, 1, 1, S_MARK); + square list[] = LIST_OF_SQUARE; + for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) { + if (index_list <= USABLE_SQUARE) { + apply_square(game_def, 0, 0, list[index_list], &game_play_move); + apply_square(game_def_solution, 0, 0, list[index_list], &game_play_move); + } else { + apply_square(game_def, 0, 0, list[index_list], &game_set_square); + apply_square(game_def_solution, 0, 0, list[index_list], &game_set_square); + } + } game_undo(game_def); game_undo(game_def_solution); assert(!game_equal(game_def, game_def_solution)); @@ -138,7 +143,7 @@ bool test_game_restart(void) { */ bool test_game_new(void) { square tab[DEFAULT_SIZE * DEFAULT_SIZE]; - LIST_OF_SQUARE; + square list[] = LIST_OF_SQUARE; for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) { for (uint index_tab = 0; index_tab < DEFAULT_SIZE * DEFAULT_SIZE; index_tab++) { tab[index_tab] = list[index_list]; @@ -168,7 +173,7 @@ bool test_game_print(void) { for (int height = 1; height <= SIZE_LIMIT_GAME; height++) { for (int width = 1; width <= SIZE_LIMIT_GAME; width++) { square tab[width * height]; - LIST_OF_SQUARE; + square list[] = LIST_OF_SQUARE; game g; for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) { for (uint index_tab = 0; index_tab < width * height; index_tab++) { @@ -195,7 +200,7 @@ bool test_game_get_square(void) { for (int height = 1; height <= SIZE_LIMIT_GAME; height++) { for (int width = 1; width <= SIZE_LIMIT_GAME; width++) { square tab[width * height]; - LIST_OF_SQUARE; + square list[] = LIST_OF_SQUARE; for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) { for (uint index_tab = 0; index_tab < height * width; index_tab++) { tab[index_tab] = list[index_list]; @@ -414,32 +419,16 @@ bool test_game_update_flags(void) { bool test_game_play_move(void) { game game_play = game_new_empty(); game game_set = game_new_empty(); - // S_LIGHTBULB - game_play_move(game_play, 0, 0, S_LIGHTBULB); - assert(!game_equal(game_play, game_set)); - game_set_square(game_set, 0, 0, S_LIGHTBULB); - assert(!game_equal(game_play, game_set)); - game_update_flags(game_set); - assert(game_equal(game_play, game_set)); - // S_BLANK - game_play_move(game_play, 0, 3, S_BLANK); - assert(game_equal(game_play, game_set)); - game_set_square(game_set, 0, 3, S_BLANK); - assert(!game_equal(game_play, game_set)); - game_update_flags(game_set); - assert(game_equal(game_play, game_set)); - // S_MARK - game_play_move(game_play, 3, 0, S_MARK); - assert(!game_equal(game_play, game_set)); - game_set_square(game_set, 3, 0, S_MARK); - assert(!game_equal(game_play, game_set)); - game_update_flags(game_set); - assert(game_equal(game_play, game_set)); + square list[] = LIST_OF_SQUARE; + for (uint index_list = 0; index_list <= USABLE_SQUARE; index_list++) { + game_play_move(game_play, 0, 0, list[index_list]); + game_set_square(game_set, 0, 0, list[index_list]); + game_update_flags(game_set); + assert(game_equal(game_play, game_set)); + } // undo / redo game_undo(game_play); - assert(!game_equal(game_play, game_set)); - game_set_square(game_set, 3, 0, S_BLANK); - assert(!game_equal(game_play, game_set)); + game_set_square(game_set, 0, 0, list[USABLE_SQUARE - 1]); // take the before last usable element of list game_update_flags(game_set); assert(game_equal(game_play, game_set)); // delete @@ -457,7 +446,7 @@ bool test_game_play_move(void) { bool test_game_check_move(void) { game g = game_new_empty(); // put usable square at the start of the list - LIST_OF_SQUARE; + square list[] = LIST_OF_SQUARE; // test limits for (uint i = 0; i < SIZE_LIMIT_GAME + 10; i++) { for (uint j = 0; j < SIZE_LIMIT_GAME + 10; j++) { @@ -472,7 +461,7 @@ bool test_game_check_move(void) { // test if we can place something on a wall for (uint i = 0; i < S_BLACKU - S_BLACK0; i++) { game_set_square(g, 0, 0, S_BLACK + i); - for (uint index_list = 0; index_list < USABLE_SQUARE; index_list++) { + for (uint index_list = 0; index_list <= USABLE_SQUARE; index_list++) { assert(!game_check_move(g, 0, 0, list[index_list])); } } From bcce70dc869e954512684cc56a78a161bd790d46 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sun, 23 Jan 2022 23:46:36 +0100 Subject: [PATCH 275/281] edit test equal + edit tab_square --- game_test_thperrier.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index e9bff1d..fedad82 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -7,6 +7,9 @@ #include "game_aux.h" #include "game_ext.h" +#define TAB_SQUARE \ + { S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU } + /* ********** DUMMY ********** */ bool test_dummy() { return true; @@ -14,14 +17,19 @@ bool test_dummy() { /* ********** game_get_black_number ********** */ bool test_game_get_black_number() { - square tab_square[] = {S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4}; + square tab_square[] = TAB_SQUARE; game g = game_new_empty(); for (int i = 0; i < game_nb_rows(g); i++) { for (int j = 0; j < game_nb_cols(g); j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); - if (game_get_black_number(g, i, j) != tab_index) { + if (tab_square[tab_index] == S_BLACKU) { + if (game_get_black_number(g, i, j) != -1) { + game_delete(g); + return false; + } + } else if (tab_square[tab_index] > S_MARK && game_get_black_number(g, i, j) != tab_square[tab_index] - S_BLACK) { game_delete(g); return false; } @@ -121,10 +129,11 @@ bool test_game_delete() { /* ********** game_equal ********** */ bool test_game_equal() { square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; + bool wrap[] = {false, false, true, false, false, true, true, true}; bool equal = true; uint index_tab = 0; - for(int wrap = 0; wrap < 2 /*we only need to test two versions (with and without wrapping)*/; wrap++){ - game g1 = game_new_empty_ext(DEFAULT_SIZE, DEFAULT_SIZE, wrap); + for (int wrap_index = 0; wrap_index < sizeof(wrap) / sizeof(wrap[0]); wrap_index += 2) { + game g1 = game_new_empty_ext(DEFAULT_SIZE, DEFAULT_SIZE, wrap[wrap_index]); for (int i = 0; i < game_nb_rows(g1); i++) { for (int j = 0; j < game_nb_cols(g1); j++) { // check if index_tab reach end of tab @@ -135,11 +144,11 @@ bool test_game_equal() { index_tab++; } } - game g2 = game_copy(g1); - // check if the two games have the same height, width, and if the two have the wrapping option or not - if (game_nb_rows(g1) != game_nb_rows(g2) || game_nb_cols(g1) != game_nb_cols(g2) || game_is_wrapping(g1) != game_is_wrapping(g2)){ + game g2 = game_new_empty_ext(DEFAULT_SIZE, DEFAULT_SIZE, wrap[wrap_index + 1]); + // check if the two games have the same height, width, and if the two have the wrapping option or not + if (game_nb_rows(g1) != game_nb_rows(g2) || game_nb_cols(g1) != game_nb_cols(g2) || game_is_wrapping(g1) != game_is_wrapping(g2)) { equal = false; - } + } // check if each square is the same on each game else { for (int i = 0; i < game_nb_rows(g1); i++) { @@ -150,10 +159,10 @@ bool test_game_equal() { } } } - // check if game_equal return the expected result - equal = (equal == game_equal(g1, g2)); - game_delete(g1); - game_delete(g2); + // check if game_equal return the expected result + equal = (equal == game_equal(g1, g2)); + game_delete(g1); + game_delete(g2); } return equal; } @@ -178,7 +187,7 @@ bool test_game_new_empty() { bool test_game_copy() { square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; uint index_tab = 0; - for(int wrap = 0; wrap < 2 /*we only need to test two versions (with and without wrapping)*/; wrap++){ + for (int wrap = 0; wrap < 2 /*we only need to test two versions (with and without wrapping)*/; wrap++) { game g1 = game_new_empty_ext(DEFAULT_SIZE, DEFAULT_SIZE, wrap); for (int i = 0; i < game_nb_rows(g1); i++) { for (int j = 0; j < game_nb_cols(g1); j++) { From e0e846af470800e85be484829e5cecd22e54c7a9 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sun, 23 Jan 2022 23:47:44 +0100 Subject: [PATCH 276/281] edit test game is black --- game_test_thperrier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index fedad82..8ad596e 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -42,7 +42,7 @@ bool test_game_get_black_number() { /* ********** game_is_black ********** */ bool test_game_is_black() { - square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; + square tab_square[] = TAB_SQUARE; game g = game_new_empty(); for (int i = 0; i < game_nb_rows(g); i++) { for (int j = 0; j < game_nb_cols(g); j++) { From d6775a9e4783f4a156beb069eda1ad86b79248ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 23 Jan 2022 23:49:59 +0100 Subject: [PATCH 277/281] remove changes on game_restart --- game_test_thoguet.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index 596e3e5..fd4222c 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -102,24 +102,21 @@ bool test_game_is_over(void) { * * @return EXIT_SUCCESS if there is no error */ - -void apply_square(game g, uint i, uint j, square s, void (*apply)(game, uint, uint, square)) { - apply(g, i, j, s); -} - bool test_game_restart(void) { game game_def = game_default(); game game_def_solution = game_default_solution(); - square list[] = LIST_OF_SQUARE; - for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) { - if (index_list <= USABLE_SQUARE) { - apply_square(game_def, 0, 0, list[index_list], &game_play_move); - apply_square(game_def_solution, 0, 0, list[index_list], &game_play_move); - } else { - apply_square(game_def, 0, 0, list[index_list], &game_set_square); - apply_square(game_def_solution, 0, 0, list[index_list], &game_set_square); - } - } + game_set_square(game_def, 1, 5, S_BLACK4); + game_set_square(game_def_solution, 1, 5, S_BLACK4); + game_set_square(game_def, 3, 2, S_BLACK3); + game_set_square(game_def_solution, 3, 2, S_BLACK3); + game_play_move(game_def, 0, 1, S_LIGHTBULB); + game_play_move(game_def_solution, 0, 1, S_LIGHTBULB); + game_play_move(game_def, 2, 0, S_MARK); + game_play_move(game_def_solution, 2, 0, S_MARK); + game_play_move(game_def, 1, 1, S_LIGHTBULB); + game_play_move(game_def_solution, 1, 1, S_LIGHTBULB); + game_play_move(game_def, 1, 1, S_MARK); + game_play_move(game_def_solution, 1, 1, S_MARK); game_undo(game_def); game_undo(game_def_solution); assert(!game_equal(game_def, game_def_solution)); From d426bcf4ac24fdced853686ba72c6ab2822a12e5 Mon Sep 17 00:00:00 2001 From: thibault perrier Date: Sun, 23 Jan 2022 23:51:56 +0100 Subject: [PATCH 278/281] edit test game is lightbulb --- game_test_thperrier.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 8ad596e..16bc9b8 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -70,19 +70,19 @@ bool test_game_is_black() { /* ********** game_is_lightbulb ********** */ bool test_game_is_lightbulb() { - square tab_square[] = {S_BLANK, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; + square tab_square[] = TAB_SQUARE; game g = game_new_empty(); - game_set_square(g, 0, 0, S_LIGHTBULB); - if (!((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_lightbulb(g, 0, 0))) { - game_delete(g); - return false; - } for (int i = 0; i < game_nb_rows(g); i++) { for (int j = 0; j < game_nb_cols(g); j++) { // check for each case given in tab_square if the function return the expected result for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) { game_set_square(g, i, j, tab_square[tab_index]); - if (game_is_lightbulb(g, 0, 0)) { + if (tab_square[tab_index] == S_LIGHTBULB) { + if (!game_is_lightbulb(g, i, j)) { + game_delete(g); + return false; + } + } else if (game_is_lightbulb(g, 0, 0)) { game_delete(g); return false; } From 805e58e3605aeb4eb370df207eac8e3480d1da7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 23 Jan 2022 23:52:50 +0100 Subject: [PATCH 279/281] wrapping game_equal --- game_test_thperrier.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 8ad596e..7f0fa95 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -134,6 +134,7 @@ bool test_game_equal() { uint index_tab = 0; for (int wrap_index = 0; wrap_index < sizeof(wrap) / sizeof(wrap[0]); wrap_index += 2) { game g1 = game_new_empty_ext(DEFAULT_SIZE, DEFAULT_SIZE, wrap[wrap_index]); + game g2 = game_new_empty_ext(DEFAULT_SIZE, DEFAULT_SIZE, wrap[wrap_index + 1]); for (int i = 0; i < game_nb_rows(g1); i++) { for (int j = 0; j < game_nb_cols(g1); j++) { // check if index_tab reach end of tab @@ -141,10 +142,10 @@ bool test_game_equal() { index_tab = 0; } game_set_square(g1, i, j, tab_square[index_tab]); + game_set_square(g2, i, j, tab_square[index_tab]); index_tab++; } } - game g2 = game_new_empty_ext(DEFAULT_SIZE, DEFAULT_SIZE, wrap[wrap_index + 1]); // check if the two games have the same height, width, and if the two have the wrapping option or not if (game_nb_rows(g1) != game_nb_rows(g2) || game_nb_cols(g1) != game_nb_cols(g2) || game_is_wrapping(g1) != game_is_wrapping(g2)) { equal = false; From c3b93c14790aee3fc388054d936aa4fefe037fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Sun, 23 Jan 2022 23:56:09 +0100 Subject: [PATCH 280/281] mastercalss --- game_test_thperrier.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/game_test_thperrier.c b/game_test_thperrier.c index 4f2cd2a..62c0f0e 100644 --- a/game_test_thperrier.c +++ b/game_test_thperrier.c @@ -162,6 +162,10 @@ bool test_game_equal() { } // check if game_equal return the expected result equal = (equal == game_equal(g1, g2)); + game_set_square(g1, 0, 0, S_LIGHTBULB); + game_update_flags(g1); + game_update_flags(g2); + assert(!game_equal(g1, g2)); game_delete(g1); game_delete(g2); } From 12dd39d0a479d35a71c85235071cb4aff01e5e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Mon, 24 Jan 2022 00:14:44 +0100 Subject: [PATCH 281/281] LE CLANG PTN --- game_test_nnunes.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 55cdc0d..d6af704 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -140,10 +140,10 @@ bool test_game_has_error(void) { /* ************** game_nb_rows ************** */ bool test_game_nb_rows(void) { game g = game_new_empty(); - if (game_get_square(g, game_nb_rows(g) -1, 0) == S_BLANK) { + if (game_get_square(g, game_nb_rows(g) - 1, 0) == S_BLANK) { game_delete(g); return true; - } + } game_delete(g); return false; } @@ -159,7 +159,6 @@ bool test_game_nb_cols(void) { return false; } - /* ************** game_is_wrapping ************** */ bool test_game_is_wrapping(void) { game g = game_new_empty(); @@ -170,12 +169,12 @@ bool test_game_is_wrapping(void) { if (!(game_is_lighted(g, 0, i) && game_is_wrapping(g))) { game_delete(g); return true; - } + } if (!(game_is_lighted(g, i, 0) && game_is_wrapping(g))) { game_delete(g); return true; } - } + } game_delete(g); return false; }