fonctionne avec une fonction nais aussi quatre fonctions pour les coordonnees
This commit is contained in:
BIN
.add_to_list.c.swp
Normal file
BIN
.add_to_list.c.swp
Normal file
Binary file not shown.
133
add_to_list.c
133
add_to_list.c
@@ -6,34 +6,63 @@
|
|||||||
/* 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 00:24:25 by hulamy ### ########.fr */
|
/* Updated: 2019/04/15 13:41:06 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int start_line(char **square)
|
||||||
void find_start_and_end(char **square, int *x1, int *x2, int *y1, int *y2)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int x;
|
||||||
|
|
||||||
i = 4;
|
i = 4;
|
||||||
while (*x1 < 4 && i == 4 && !(i = 0) && square[++(*x1)][0] != '#')
|
x = -1;
|
||||||
while (i < 4 && square[*x1][i] != '#')
|
while (x < 4 && i == 4 && !(i = 0) && square[++x][0] != '#')
|
||||||
|
while (i < 4 && square[x][i] != '#')
|
||||||
i++;
|
i++;
|
||||||
|
return (x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int start_column(char **square)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int x;
|
||||||
|
|
||||||
i = 4;
|
i = 4;
|
||||||
while (*y1 < 4 && i == 4 && !(i = 0) && square[0][++(*y1)] != '#')
|
x = -1;
|
||||||
while (i < 4 && square[i][*y1] != '#')
|
while (x < 4 && i == 4 && !(i = 0) && square[0][++x] != '#')
|
||||||
|
while (i < 4 && square[i][x] != '#')
|
||||||
i++;
|
i++;
|
||||||
|
return (x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int end_line(char **square)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int x;
|
||||||
|
|
||||||
i = -1;
|
i = -1;
|
||||||
while (*x2 >= 0 && i == -1 && (i = 3) && square[--(*x2)][3] != '#')
|
x = 4;
|
||||||
while (i >= 0 && square[*x2][i] != '#')
|
while (x >= 0 && i == -1 && (i = 3) && square[--x][3] != '#')
|
||||||
|
while (i >= 0 && square[x][i] != '#')
|
||||||
i--;
|
i--;
|
||||||
|
return (x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int end_column(char **square)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int x;
|
||||||
|
|
||||||
i = -1;
|
i = -1;
|
||||||
while (*y2 >= 0 && i == -1 && (i = 3) && square[3][--(*y2)] != '#')
|
x = 4;
|
||||||
while (i >= 0 && square[i][*y2] != '#')
|
while (x < 4 && i == 4 && !(i = 0) && square[++x][0] != '#')
|
||||||
i--;
|
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)
|
||||||
@@ -63,39 +92,73 @@ char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2)
|
|||||||
return (result);
|
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 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);
|
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);
|
||||||
|
|
||||||
// int i; // pour imprimer
|
|
||||||
// i = -1; //
|
|
||||||
// while (++i < list->size[1]) //
|
|
||||||
// printf("%s\n", list->tetraminos[i]); //
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
// {
|
{
|
||||||
// if (ac == 5)
|
static t_fillist *list;
|
||||||
// {
|
int i;
|
||||||
// add_to_list(++av);
|
|
||||||
// }
|
i = -1;
|
||||||
// return (0);
|
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);
|
||||||
|
}
|
||||||
|
|||||||
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 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_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);
|
|
||||||
|
|
||||||
typedef struct s_fillist
|
typedef struct s_fillist
|
||||||
{
|
{
|
||||||
@@ -49,4 +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);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user