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.
172
add_to_list.c
172
add_to_list.c
@@ -6,114 +6,61 @@
|
||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdio.h>
|
||||
#include "libft/includes/libft.h"
|
||||
|
||||
/*
|
||||
** Function that fills the char **tetraminos section of the structure
|
||||
** with the most little rectangle that fit the tetraminos
|
||||
** this function prints a 16 bites short
|
||||
*/
|
||||
|
||||
char **fill_tetraminos(char **square, int *tab)
|
||||
void print_bits(short line)
|
||||
{
|
||||
char **result;
|
||||
int height;
|
||||
int length;
|
||||
int i;
|
||||
int j;
|
||||
int mask;
|
||||
|
||||
i = 0;
|
||||
height = tab[2] - tab[0] + 1;
|
||||
length = tab[3] - tab[1] + 1;
|
||||
if (!(result = (char**)malloc(sizeof(*result) * (height + 1))))
|
||||
return (NULL);
|
||||
result[height] = NULL;
|
||||
while (i < height)
|
||||
mask = 1 << 16;
|
||||
while (mask >>= 1)
|
||||
(line & mask) ? ft_putnbr(1) : ft_putnbr(0);
|
||||
ft_putchar('\n');
|
||||
}
|
||||
|
||||
/*
|
||||
** this function transforme a tetrminos char* into a short of 16 bites
|
||||
** then it fills it and its reverse into the list
|
||||
*/
|
||||
|
||||
int fill_list(char *line, t_fillist *list)
|
||||
{
|
||||
short tmp;
|
||||
|
||||
while (*line)
|
||||
{
|
||||
if (!(result[i] = (char*)malloc(sizeof(**result) * (length + 1))))
|
||||
return (NULL);
|
||||
result[i][length] = '\0';
|
||||
i++;
|
||||
list->tetribit <<= 1;
|
||||
if (*line == '\n')
|
||||
line++;
|
||||
if (*(line++) == '#')
|
||||
list->tetribit |= 1;
|
||||
}
|
||||
i = -1;
|
||||
while (++i < height && (j = -1))
|
||||
while (++j < length)
|
||||
result[i][j] = square[tab[0] + i][tab[1] + j];
|
||||
return (result);
|
||||
tmp = list->tetribit;
|
||||
while (tmp)
|
||||
{
|
||||
if (tmp & 1)
|
||||
list->tibirtet |= 1;
|
||||
list->tibirtet <<= 1;
|
||||
tmp >>= 1;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
** 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
|
||||
** this function create the linked list and add a new structure linked each time needed
|
||||
*/
|
||||
|
||||
void find_start_and_end(char **square, int **x)
|
||||
{
|
||||
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;
|
||||
|
||||
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)
|
||||
int add_to_list(char *line, t_fillist **list)
|
||||
{
|
||||
t_fillist *tmp;
|
||||
|
||||
@@ -124,30 +71,27 @@ int add_to_list(char **square, t_fillist **list)
|
||||
else
|
||||
tmp->next = *list;
|
||||
*list = tmp;
|
||||
fill_list(square, *list);
|
||||
fill_list(line, *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 > 1)
|
||||
** {
|
||||
** 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);
|
||||
**}
|
||||
*/
|
||||
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 > 1)
|
||||
{
|
||||
add_to_list(*(++av), &list);
|
||||
while (list && (i = -1))
|
||||
{
|
||||
printf("%d\n", list->tetribit);
|
||||
print_bits(list->tetribit);
|
||||
print_bits(list->tibirtet);
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
12
fillit.h
12
fillit.h
@@ -6,7 +6,7 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
{
|
||||
int id;
|
||||
char **tetraminos;
|
||||
int position[2];
|
||||
int size[2];
|
||||
int area;
|
||||
short tetribit;
|
||||
short tibirtet;
|
||||
int position;
|
||||
struct s_fillist *next;
|
||||
} t_fillist;
|
||||
|
||||
@@ -46,6 +44,6 @@ void parse_input(char *input);
|
||||
int check_file_errors(char *file);
|
||||
int check_tetri_errors(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
|
||||
|
||||
@@ -6,7 +6,11 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* 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
|
||||
|
||||
i = 0;
|
||||
printf("input: %s\n", input);
|
||||
printf("end\n");
|
||||
while (input[i])
|
||||
{
|
||||
j = 0;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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