diff --git a/a.out b/a.out new file mode 100755 index 0000000..9683d80 Binary files /dev/null and b/a.out differ diff --git a/a.out.dSYM/Contents/Info.plist b/a.out.dSYM/Contents/Info.plist new file mode 100644 index 0000000..3679a65 --- /dev/null +++ b/a.out.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.a.out + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/a.out.dSYM/Contents/Resources/DWARF/a.out b/a.out.dSYM/Contents/Resources/DWARF/a.out new file mode 100644 index 0000000..307a6b6 Binary files /dev/null and b/a.out.dSYM/Contents/Resources/DWARF/a.out differ diff --git a/add_to_list.c b/add_to_list.c index 4b69176..5a8dc83 100644 --- a/add_to_list.c +++ b/add_to_list.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/15 14:38:43 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/15 16:41:09 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,33 +14,8 @@ #include /* -** Function that ... -*/ - -void find_start_and_end(char **square, int *x1, int *x2, int *y1, int *y2) -{ - int i; - - i = 4; - while (*x1 < 4 && i == 4 && !(i = 0) && square[++(*x1)][0] != '#') - while (i < 4 && square[*x1][i] != '#') - i++; - i = 4; - while (*y1 < 4 && i == 4 && !(i = 0) && square[0][++(*y1)] != '#') - while (i < 4 && square[i][*y1] != '#') - i++; - i = -1; - while (*x2 >= 0 && i == -1 && (i = 3) && square[--(*x2)][3] != '#') - while (i >= 0 && square[*x2][i] != '#') - i--; - i = -1; - while (*y2 >= 0 && i == -1 && (i = 3) && square[3][--(*y2)] != '#') - while (i >= 0 && square[i][*y2] != '#') - i--; -} - -/* -** Function that ... +** Function that fills the char **tetraminos section of the structure +** with the most little rectangle that fit the tetraminos */ char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2) @@ -71,42 +46,113 @@ char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2) } /* -** Function that ... +** this function calculate the line and columns where the tetraminos +** start and end, by skipping the empty lines +** +** ! it has a little bug so far, i need to fix it */ -int add_to_list(char **square) +void find_start_and_end(char **square, int **x) { - t_fillist *list; + int i; + + x[0][0] = -1; + x[0][1] = -1; + x[0][2] = 4; + x[0][3] = 4; + i = 4; + while (x[0][0] < 4 && i == 4 && !(i = 0) && square[++(x[0][0])][0] != '#') + while (i < 4 && square[*(x[0])][i] != '#') + i++; + i = 4; + while (x[0][1] < 4 && i == 4 && !(i = 0) && square[0][++(x[0][1])] != '#') + while (i < 4 && square[i][x[0][1]] != '#') + i++; + i = -1; + while (x[0][2] >= 0 && i == -1 && (i = 3) && square[--(x[0][2])][3] != '#') + while (i >= 0 && square[x[0][2]][i] != '#') + i--; + i = -1; + while (x[0][3] >= 0 && i == -1 && (i = 3) && square[3][--(x[0][3])] != '#') + while (i >= 0 && square[i][x[0][3]] != '#') + i--; +} + +/* +** this function first call find_start_and_end to find the coordinates +** of start en end of the most little rectangle that fit the tetraminos +** +** it allows it to fill the structure with the size information +** (for instance : +** "##" ".#" ".#" +** is a tatraminos of 2 by 3) +** then it fills also the area information (2 * 3 = 6) +** +** and finally it calls fill_tetraminos to fill the char **tetraminos +*/ + +int fill_list(char **square, t_fillist *list) +{ + int *tab; int x1; int x2; int y1; int y2; - x1 = -1; - y1 = -1; - x2 = 4; - y2 = 4; - if (!(list = (t_fillist*)malloc(sizeof(*list)))) - return (0); - find_start_and_end(square, &x1, &x2, &y1, &y2); + tab = (int*)malloc(sizeof(int) * 4); + find_start_and_end(square, &tab); + x1 = tab[0]; + y1 = tab[1]; + x2 = tab[2]; + y2 = tab[3]; list->size[0] = y2 - y1 + 1; list->size[1] = x2 - x1 + 1; list->area = list->size[0] * list->size[1]; list->tetraminos = fill_tetraminos(square, x1, y1, x2, y2); + return (1); +} -// int i; // pour imprimer -// i = -1; // -// while (++i < list->size[1]) // -// printf("%s\n", list->tetraminos[i]); // +/* +** this function first checks if the structure has been created +** if not, it creates the first element, else it adds an element +** and modifies the initial pointer to link to the new first element +** +** then it calls fill_list to fill the data of the structure +*/ + +int add_to_list(char **square, t_fillist **list) +{ + t_fillist *tmp; + + if (!(tmp = (t_fillist*)malloc(sizeof(*tmp)))) + return (0); + if (!(*list)) + tmp->next = NULL; + else + tmp->next = *list; + *list = tmp; + fill_list(square, *list); + return (1); +} + +int main(int ac, char **av) +{ + static t_fillist *list = NULL; // avant d'appeller add_to_list il faut declarer un pointeur static vers la structure + int i; + + if (ac > 4) + { + add_to_list(++av, &list); // l'appel de la fonction se fait avec un carre valide de 4*4 et l'adresse du pointeur vers la liste + if (ac == 9) + add_to_list(av += 4, &list); + while (list && (i = -1)) + { + while (++i < list->size[1]) + printf("%s\n", list->tetraminos[i]); + printf("\n"); + list = list->next; + } + } return (0); } - -// int main(int ac, char **av) -// { -// if (ac == 5) -// { -// add_to_list(++av); -// } -// return (0); -// } diff --git a/fillit.h b/fillit.h index a7a5912..d033553 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/15 13:39:50 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/15 16:23:18 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,6 @@ void print_error(char *s); int check_file_errors(char *file); int check_tetri_errors(char *tetri); int check_tetri_errors2(char *tetri); -int add_to_list(char **square); /* ** STRUCTURE @@ -53,4 +52,6 @@ typedef struct s_fillist struct s_fillist *next; } t_fillist; +int add_to_list(char **square, t_fillist **list); + #endif