fonctionne avec une fonction nais aussi quatre fonctions pour les coordonnees

This commit is contained in:
Hugo LAMY
2019-04-15 13:41:39 +02:00
parent 1456316e42
commit f4c954829e
4 changed files with 101 additions and 37 deletions

BIN
.add_to_list.c.swp Normal file

Binary file not shown.

BIN
a.out Executable file

Binary file not shown.

View File

@@ -6,34 +6,63 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
/* Updated: 2019/04/15 00:24:25 by hulamy ### ########.fr */
/* Updated: 2019/04/15 13:41:06 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <stdio.h>
void find_start_and_end(char **square, int *x1, int *x2, int *y1, int *y2)
int start_line(char **square)
{
int i;
int x;
i = 4;
while (*x1 < 4 && i == 4 && !(i = 0) && square[++(*x1)][0] != '#')
while (i < 4 && square[*x1][i] != '#')
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;
while (*y1 < 4 && i == 4 && !(i = 0) && square[0][++(*y1)] != '#')
while (i < 4 && square[i][*y1] != '#')
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;
while (*x2 >= 0 && i == -1 && (i = 3) && square[--(*x2)][3] != '#')
while (i >= 0 && square[*x2][i] != '#')
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;
while (*y2 >= 0 && i == -1 && (i = 3) && square[3][--(*y2)] != '#')
while (i >= 0 && square[i][*y2] != '#')
i--;
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)
@@ -63,39 +92,73 @@ char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2)
return (result);
}
int add_to_list(char **square)
void find_start_and_end(char **square, int **x)
{
t_fillist *list;
int i;
x[0][0] = -1; // x1
x[0][1] = -1; // y1
x[0][2] = 4; // x2
x[0][3] = 4; // y2
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--;
}
int add_to_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];
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[1] = x2 - x1 + 1;
list->area = list->size[0] * list->size[1];
list->tetraminos = fill_tetraminos(square, x1, y1, x2, y2);
// int i; // pour imprimer
// i = -1; //
// while (++i < list->size[1]) //
// printf("%s\n", list->tetraminos[i]); //
return (0);
}
// int main(int ac, char **av)
// {
// if (ac == 5)
// {
// add_to_list(++av);
// }
// return (0);
// }
int main(int ac, char **av)
{
static t_fillist *list;
int i;
i = -1;
if (!(list = (t_fillist*)malloc(sizeof(*list))))
return (0);
if (ac > 4)
{
add_to_list(++av, list);
while (++i < list->size[1])
printf("%s\n", list->tetraminos[i]);
}
return (0);
}

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
/* Updated: 2019/04/15 00:26:08 by hulamy ### ########.fr */
/* Updated: 2019/04/15 10:43:51 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);
typedef struct s_fillist
{
@@ -49,4 +48,6 @@ typedef struct s_fillist
struct s_fillist *next;
} t_fillist;
int add_to_list(char **square, t_fillist *list);
#endif