diff --git a/game_private.c b/game_private.c index e436499..3f4526f 100644 --- a/game_private.c +++ b/game_private.c @@ -7,6 +7,12 @@ unsigned int max(unsigned int a, unsigned int b) { return b; } +unsigned int min(unsigned int a, unsigned int b) { + if (a < b) + return a; + return b; +} + void checkPointer(void* p, char* errMessage) { if (!p) { fprintf(stderr, "%s", errMessage); diff --git a/game_private.h b/game_private.h index 19cd631..3348f18 100644 --- a/game_private.h +++ b/game_private.h @@ -21,6 +21,15 @@ struct game_s { */ unsigned int max(unsigned int a, unsigned int b); +/** + * @brief return the min between a and b + * + * @param a uint to test + * @param b uint to test + * @return the min between a and b + */ +unsigned int min(unsigned int a, unsigned int b); + /** * @brief check if the pointer is NULL fprinf and exit else nothing * diff --git a/game_tools.c b/game_tools.c index 14eb5cc..08dce64 100644 --- a/game_tools.c +++ b/game_tools.c @@ -502,7 +502,7 @@ uint game_nb_solutions(cgame g) { uint nb_blank_cases = total_number_of_blank_cases(copy_g); uint alreadyDone[nb_blank_cases * 2]; // else try brutforce with deepness going from 1 to the total number of blank cases on the game - for (uint deep = 1; deep < nb_blank_cases; deep++) { + for (uint deep = min(game_nb_rows(copy_g), game_nb_cols(copy_g)); deep < nb_blank_cases; deep++) { aux_game_solve(copy_g, deep, &move_played, alreadyDone, 0, nb_blank_cases * 2, true, &nb_solutions, &t_games, &size); } for (uint i = 0; i < nb_solutions; i++) {