ajout de commentaires a add_to_list et resolution de conflits pour merge
This commit is contained in:
20
a.out.dSYM/Contents/Info.plist
Normal file
20
a.out.dSYM/Contents/Info.plist
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
|
<string>English</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>com.apple.xcode.dsym.a.out</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>dSYM</string>
|
||||||
|
<key>CFBundleSignature</key>
|
||||||
|
<string>????</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>1</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
BIN
a.out.dSYM/Contents/Resources/DWARF/a.out
Normal file
BIN
a.out.dSYM/Contents/Resources/DWARF/a.out
Normal file
Binary file not shown.
148
add_to_list.c
148
add_to_list.c
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/14 15:20:53 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 <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Function that ...
|
** Function that fills the char **tetraminos section of the structure
|
||||||
*/
|
** with the most little rectangle that fit the tetraminos
|
||||||
|
|
||||||
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 ...
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2)
|
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 x1;
|
||||||
int x2;
|
int x2;
|
||||||
int y1;
|
int y1;
|
||||||
int y2;
|
int y2;
|
||||||
|
|
||||||
x1 = -1;
|
tab = (int*)malloc(sizeof(int) * 4);
|
||||||
y1 = -1;
|
find_start_and_end(square, &tab);
|
||||||
x2 = 4;
|
x1 = tab[0];
|
||||||
y2 = 4;
|
y1 = tab[1];
|
||||||
if (!(list = (t_fillist*)malloc(sizeof(*list))))
|
x2 = tab[2];
|
||||||
return (0);
|
y2 = tab[3];
|
||||||
find_start_and_end(square, &x1, &x2, &y1, &y2);
|
|
||||||
list->size[0] = y2 - y1 + 1;
|
list->size[0] = y2 - y1 + 1;
|
||||||
list->size[1] = x2 - x1 + 1;
|
list->size[1] = x2 - x1 + 1;
|
||||||
list->area = list->size[0] * list->size[1];
|
list->area = list->size[0] * list->size[1];
|
||||||
list->tetraminos = fill_tetraminos(square, x1, y1, x2, y2);
|
list->tetraminos = fill_tetraminos(square, x1, y1, x2, y2);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
// int i; // pour imprimer
|
/*
|
||||||
// i = -1; //
|
** this function first checks if the structure has been created
|
||||||
// while (++i < list->size[1]) //
|
** if not, it creates the first element, else it adds an element
|
||||||
// printf("%s\n", list->tetraminos[i]); //
|
** 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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// int main(int ac, char **av)
|
|
||||||
// {
|
|
||||||
// if (ac == 5)
|
|
||||||
// {
|
|
||||||
// add_to_list(++av);
|
|
||||||
// }
|
|
||||||
// return (0);
|
|
||||||
// }
|
|
||||||
|
|||||||
5
fillit.h
5
fillit.h
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/01 13:34:46 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_file_errors(char *file);
|
||||||
int check_tetri_errors(char *tetri);
|
int check_tetri_errors(char *tetri);
|
||||||
int check_tetri_errors2(char *tetri);
|
int check_tetri_errors2(char *tetri);
|
||||||
int add_to_list(char **square);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** STRUCTURE
|
** STRUCTURE
|
||||||
@@ -53,4 +52,6 @@ typedef struct s_fillist
|
|||||||
struct s_fillist *next;
|
struct s_fillist *next;
|
||||||
} t_fillist;
|
} t_fillist;
|
||||||
|
|
||||||
|
int add_to_list(char **square, t_fillist **list);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user