Merge remote-tracking branch 'origin/master'
This commit is contained in:
BIN
.parse_input.c.swo
Normal file
BIN
.parse_input.c.swo
Normal file
Binary file not shown.
162
add_to_list.c
162
add_to_list.c
@@ -6,114 +6,61 @@
|
|||||||
/* 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/18 10:56:38 by hulamy ### ########.fr */
|
/* Updated: 2019/04/19 15:33:04 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "libft/includes/libft.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Function that fills the char **tetraminos section of the structure
|
** this function prints a 16 bites short
|
||||||
** with the most little rectangle that fit the tetraminos
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char **fill_tetraminos(char **square, int *tab)
|
void print_bits(short line)
|
||||||
{
|
{
|
||||||
char **result;
|
int mask;
|
||||||
int height;
|
|
||||||
int length;
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
i = 0;
|
mask = 1 << 16;
|
||||||
height = tab[2] - tab[0] + 1;
|
while (mask >>= 1)
|
||||||
length = tab[3] - tab[1] + 1;
|
(line & mask) ? ft_putnbr(1) : ft_putnbr(0);
|
||||||
if (!(result = (char**)malloc(sizeof(*result) * (height + 1))))
|
ft_putchar('\n');
|
||||||
return (NULL);
|
|
||||||
result[height] = NULL;
|
|
||||||
while (i < height)
|
|
||||||
{
|
|
||||||
if (!(result[i] = (char*)malloc(sizeof(**result) * (length + 1))))
|
|
||||||
return (NULL);
|
|
||||||
result[i][length] = '\0';
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
i = -1;
|
|
||||||
while (++i < height && (j = -1))
|
|
||||||
while (++j < length)
|
|
||||||
result[i][j] = square[tab[0] + i][tab[1] + j];
|
|
||||||
return (result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** This function calculate the line and columns where the tetraminos
|
** this function transforme a tetrminos char* into a short of 16 bites
|
||||||
** start and end, by skipping the empty lines
|
** then it fills it and its reverse into the list
|
||||||
**
|
|
||||||
** ! it has a little bug so far, i need to fix it
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void find_start_and_end(char **square, int **x)
|
int fill_list(char *line, t_fillist *list)
|
||||||
{
|
{
|
||||||
int i;
|
short tmp;
|
||||||
|
|
||||||
x[0][0] = -1;
|
while (*line)
|
||||||
x[0][1] = -1;
|
{
|
||||||
x[0][2] = 4;
|
list->tetribit <<= 1;
|
||||||
x[0][3] = 4;
|
if (*line == '\n')
|
||||||
i = 4;
|
line++;
|
||||||
while (x[0][0] < 4 && i == 4 && !(i = 0) && square[++(x[0][0])][0] != '#')
|
if (*(line++) == '#')
|
||||||
while (i < 4 && square[*(x[0])][i] != '#')
|
list->tetribit |= 1;
|
||||||
i++;
|
}
|
||||||
i = 4;
|
tmp = list->tetribit;
|
||||||
while (x[0][1] < 4 && i == 4 && !(i = 0) && square[0][++(x[0][1])] != '#')
|
while (tmp)
|
||||||
while (i < 4 && square[i][x[0][1]] != '#')
|
{
|
||||||
i++;
|
if (tmp & 1)
|
||||||
i = -1;
|
list->tibirtet |= 1;
|
||||||
while (x[0][2] >= 0 && i == -1 && (i = 3) && square[--(x[0][2])][3] != '#')
|
list->tibirtet <<= 1;
|
||||||
while (i >= 0 && square[x[0][2]][i] != '#')
|
tmp >>= 1;
|
||||||
i--;
|
}
|
||||||
i = -1;
|
return (0);
|
||||||
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
|
** this function create the linked list and add a new structure linked each time needed
|
||||||
** 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 add_to_list(char *line, t_fillist **list)
|
||||||
{
|
|
||||||
int *tab;
|
|
||||||
|
|
||||||
tab = (int*)malloc(sizeof(int) * 4);
|
|
||||||
find_start_and_end(square, &tab);
|
|
||||||
list->size[0] = tab[3] - tab[1] + 1;
|
|
||||||
list->size[1] = tab[2] - tab[0] + 1;
|
|
||||||
list->area = list->size[0] * list->size[1];
|
|
||||||
list->tetraminos = fill_tetraminos(square, tab);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** 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;
|
t_fillist *tmp;
|
||||||
|
|
||||||
@@ -124,30 +71,27 @@ int add_to_list(char **square, t_fillist **list)
|
|||||||
else
|
else
|
||||||
tmp->next = *list;
|
tmp->next = *list;
|
||||||
*list = tmp;
|
*list = tmp;
|
||||||
fill_list(square, *list);
|
fill_list(line, *list);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
int main(int ac, char **av)
|
||||||
**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
|
||||||
** static t_fillist *list = NULL; // avant d'appeller add_to_list il faut declarer un pointeur static vers la structure
|
int i;
|
||||||
** int i;
|
|
||||||
**
|
if (ac > 1)
|
||||||
** if (ac > 1)
|
{
|
||||||
** {
|
add_to_list(*(++av), &list);
|
||||||
** 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
|
while (list && (i = -1))
|
||||||
** if (ac == 9)
|
{
|
||||||
** add_to_list(av += 4, &list);
|
printf("%d\n", list->tetribit);
|
||||||
** while (list && (i = -1))
|
print_bits(list->tetribit);
|
||||||
** {
|
print_bits(list->tibirtet);
|
||||||
** while (++i < list->size[1])
|
list = list->next;
|
||||||
** printf("%s\n", list->tetraminos[i]);
|
}
|
||||||
** printf("\n");
|
}
|
||||||
** list = list->next;
|
|
||||||
** }
|
return (0);
|
||||||
** }
|
}
|
||||||
**
|
|
||||||
** return (0);
|
|
||||||
**}
|
|
||||||
*/
|
|
||||||
|
|||||||
12
fillit.h
12
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/18 11:46:51 by vmanzoni ### ########.fr */
|
/* Updated: 2019/04/19 14:52:10 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -28,11 +28,9 @@
|
|||||||
|
|
||||||
typedef struct s_fillist
|
typedef struct s_fillist
|
||||||
{
|
{
|
||||||
int id;
|
short tetribit;
|
||||||
char **tetraminos;
|
short tibirtet;
|
||||||
int position[2];
|
int position;
|
||||||
int size[2];
|
|
||||||
int area;
|
|
||||||
struct s_fillist *next;
|
struct s_fillist *next;
|
||||||
} t_fillist;
|
} t_fillist;
|
||||||
|
|
||||||
@@ -46,6 +44,6 @@ void parse_input(char *input);
|
|||||||
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, t_fillist **list);
|
int add_to_list(char *square, t_fillist **list);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,7 +6,11 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
|
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
|
||||||
|
<<<<<<< HEAD
|
||||||
/* Updated: 2019/04/18 16:09:24 by vmanzoni ### ########.fr */
|
/* Updated: 2019/04/18 16:09:24 by vmanzoni ### ########.fr */
|
||||||
|
=======
|
||||||
|
/* Updated: 2019/04/19 12:53:40 by hulamy ### ########.fr */
|
||||||
|
>>>>>>> master
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -84,6 +88,8 @@ void parse_input(char *input)
|
|||||||
short test; //DELETE BEFORE EVAL
|
short test; //DELETE BEFORE EVAL
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
printf("input: %s\n", input);
|
||||||
|
printf("end\n");
|
||||||
while (input[i])
|
while (input[i])
|
||||||
{
|
{
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
|
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/04/15 14:48:36 by vmanzoni ### ########.fr */
|
/* Updated: 2019/04/19 12:50:32 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user