add_to_list fonctionne et creer une liste chainee coherente, mais encore quelques bugs si la liste comporte une erreur
This commit is contained in:
Binary file not shown.
BIN
.fillit.h.swp
Normal file
BIN
.fillit.h.swp
Normal file
Binary file not shown.
106
add_to_list.c
106
add_to_list.c
@@ -6,65 +6,13 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
|
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/04/15 13:41:06 by hulamy ### ########.fr */
|
/* Updated: 2019/04/15 16:06:37 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int start_line(char **square)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int x;
|
|
||||||
|
|
||||||
i = 4;
|
|
||||||
x = -1;
|
|
||||||
while (x < 4 && i == 4 && !(i = 0) && square[++x][0] != '#')
|
|
||||||
while (i < 4 && square[x][i] != '#')
|
|
||||||
i++;
|
|
||||||
return (x);
|
|
||||||
}
|
|
||||||
|
|
||||||
int start_column(char **square)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int x;
|
|
||||||
|
|
||||||
i = 4;
|
|
||||||
x = -1;
|
|
||||||
while (x < 4 && i == 4 && !(i = 0) && square[0][++x] != '#')
|
|
||||||
while (i < 4 && square[i][x] != '#')
|
|
||||||
i++;
|
|
||||||
return (x);
|
|
||||||
}
|
|
||||||
|
|
||||||
int end_line(char **square)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int x;
|
|
||||||
|
|
||||||
i = -1;
|
|
||||||
x = 4;
|
|
||||||
while (x >= 0 && i == -1 && (i = 3) && square[--x][3] != '#')
|
|
||||||
while (i >= 0 && square[x][i] != '#')
|
|
||||||
i--;
|
|
||||||
return (x);
|
|
||||||
}
|
|
||||||
|
|
||||||
int end_column(char **square)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int x;
|
|
||||||
|
|
||||||
i = -1;
|
|
||||||
x = 4;
|
|
||||||
while (x < 4 && i == 4 && !(i = 0) && square[++x][0] != '#')
|
|
||||||
while (i < 4 && square[x][i] != '#')
|
|
||||||
i++;
|
|
||||||
return (x);
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
char **result;
|
char **result;
|
||||||
@@ -96,10 +44,10 @@ void find_start_and_end(char **square, int **x)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
x[0][0] = -1; // x1
|
x[0][0] = -1;
|
||||||
x[0][1] = -1; // y1
|
x[0][1] = -1;
|
||||||
x[0][2] = 4; // x2
|
x[0][2] = 4;
|
||||||
x[0][3] = 4; // y2
|
x[0][3] = 4;
|
||||||
i = 4;
|
i = 4;
|
||||||
while (x[0][0] < 4 && i == 4 && !(i = 0) && square[++(x[0][0])][0] != '#')
|
while (x[0][0] < 4 && i == 4 && !(i = 0) && square[++(x[0][0])][0] != '#')
|
||||||
while (i < 4 && square[*(x[0])][i] != '#')
|
while (i < 4 && square[*(x[0])][i] != '#')
|
||||||
@@ -118,7 +66,7 @@ void find_start_and_end(char **square, int **x)
|
|||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
|
|
||||||
int add_to_list(char **square, t_fillist *list)
|
int fill_list(char **square, t_fillist *list)
|
||||||
{
|
{
|
||||||
int *tab;
|
int *tab;
|
||||||
int x1;
|
int x1;
|
||||||
@@ -132,32 +80,52 @@ int add_to_list(char **square, t_fillist *list)
|
|||||||
y1 = tab[1];
|
y1 = tab[1];
|
||||||
x2 = tab[2];
|
x2 = tab[2];
|
||||||
y2 = tab[3];
|
y2 = tab[3];
|
||||||
printf("%d %d %d %d\n", x1, y1, x2, y2);
|
|
||||||
|
|
||||||
// x1 = start_line(square);
|
|
||||||
// y1 = start_column(square);
|
|
||||||
// x2 = end_line(square);
|
|
||||||
// y2 = end_column(square);
|
|
||||||
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 push_to_end(t_fillist **list)
|
||||||
|
{
|
||||||
|
t_fillist *tmp;
|
||||||
|
|
||||||
|
if (!(tmp = (t_fillist*)malloc(sizeof(*tmp))))
|
||||||
return (0);
|
return (0);
|
||||||
|
if (!(*list))
|
||||||
|
tmp->next = NULL;
|
||||||
|
else
|
||||||
|
tmp->next = *list;
|
||||||
|
*list = tmp;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int add_to_list(char **square, t_fillist **list)
|
||||||
|
{
|
||||||
|
if (!(push_to_end(list)))
|
||||||
|
return (0);
|
||||||
|
fill_list(square, *list);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
static t_fillist *list;
|
static t_fillist *list = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = -1;
|
|
||||||
if (!(list = (t_fillist*)malloc(sizeof(*list))))
|
|
||||||
return (0);
|
|
||||||
if (ac > 4)
|
if (ac > 4)
|
||||||
{
|
{
|
||||||
add_to_list(++av, list);
|
add_to_list(++av, &list);
|
||||||
|
if (ac == 9)
|
||||||
|
add_to_list(av += 4, &list);
|
||||||
|
while (list && (i = -1))
|
||||||
|
{
|
||||||
while (++i < list->size[1])
|
while (++i < list->size[1])
|
||||||
printf("%s\n", list->tetraminos[i]);
|
printf("%s\n", list->tetraminos[i]);
|
||||||
|
printf("\n");
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
4
fillit.h
4
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 10:43:51 by hulamy ### ########.fr */
|
/* Updated: 2019/04/15 15:51:03 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -48,6 +48,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);
|
int add_to_list(char **square, t_fillist **list);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user