letter ajoute a la struct
This commit is contained in:
2
Makefile
2
Makefile
@@ -6,7 +6,7 @@
|
||||
# By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# #
|
||||
# Updated: 2019/04/30 14:20:52 by hulamy ### ########.fr #
|
||||
# Updated: 2019/05/03 13:50:34 by hulamy ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
||||
6
fillit.h
6
fillit.h
@@ -6,7 +6,7 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/05/02 00:39:33 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/05/03 14:22:25 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -31,6 +31,7 @@ typedef struct s_fillist
|
||||
int width;
|
||||
int height;
|
||||
int position;
|
||||
char letter;
|
||||
struct s_fillist *next;
|
||||
} t_fillist;
|
||||
|
||||
@@ -44,10 +45,11 @@ void parse_input(char *input);
|
||||
int check_file_errors(char *file);
|
||||
int check_tetri_errors(char *tetri);
|
||||
int check_tetri_errors_proxy(char *tetri);
|
||||
int add_to_list(char *square, t_fillist **list);
|
||||
int add_to_list(char *square, t_fillist **list, char letter);
|
||||
void fill_list(char line[], t_fillist *list);
|
||||
void print_bits(unsigned int bits, int size); //TO DELETE BEFORE EVAL
|
||||
void search_map(t_fillist *list);
|
||||
void print_map(unsigned int *tab, int width, int height);
|
||||
void print_final_map(t_fillist *list, int size);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/05/02 00:40:23 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/05/03 14:24:00 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -96,7 +96,7 @@ void fill_list(char line[], t_fillist *list)
|
||||
** linked each time needed
|
||||
*/
|
||||
|
||||
int add_to_list(char *line, t_fillist **list)
|
||||
int add_to_list(char *line, t_fillist **list, char letter)
|
||||
{
|
||||
t_fillist *tmp;
|
||||
t_fillist *test;
|
||||
@@ -114,6 +114,7 @@ int add_to_list(char *line, t_fillist **list)
|
||||
test->next = tmp;
|
||||
}
|
||||
fill_list(line, tmp);
|
||||
tmp->letter = letter;
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -127,8 +128,11 @@ void parse_input(char *input)
|
||||
char tetri[20];
|
||||
int i;
|
||||
int j;
|
||||
int letter;
|
||||
|
||||
i = 0;
|
||||
letter = 'A';
|
||||
--letter;
|
||||
while (input[i])
|
||||
{
|
||||
j = 0;
|
||||
@@ -137,7 +141,7 @@ void parse_input(char *input)
|
||||
tetri[19] = '\0';
|
||||
if (check_tetri_errors(tetri))
|
||||
print_error("Error: Tetrimino not valid.");
|
||||
add_to_list(tetri, &list);
|
||||
add_to_list(tetri, &list, letter++);
|
||||
while (input[i] && input[i] != '.' && input[i] != '#')
|
||||
i++;
|
||||
}
|
||||
|
||||
106
print.c
106
print.c
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */
|
||||
/* Updated: 2019/05/02 00:39:56 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/05/03 14:19:51 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,18 +17,18 @@
|
||||
** Prints a ligne of size bits
|
||||
*/
|
||||
|
||||
void print_bits(unsigned int bits, int size)
|
||||
void print_bits(unsigned int bits, int size)
|
||||
{
|
||||
unsigned int mask;
|
||||
unsigned int mask;
|
||||
|
||||
mask = 1 << (size - 1);
|
||||
while (mask)
|
||||
{
|
||||
(bits & mask) ? write(1, "#", 1) : write(1, ".", 1);
|
||||
write(1, " ", 1);
|
||||
mask >>= 1;
|
||||
}
|
||||
write(1, "\n", 1);
|
||||
mask = 1 << (size - 1);
|
||||
while (mask)
|
||||
{
|
||||
(bits & mask) ? write(1, "#", 1) : write(1, ".", 1);
|
||||
write(1, " ", 1);
|
||||
mask >>= 1;
|
||||
}
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -36,24 +36,74 @@ void print_bits(unsigned int bits, int size)
|
||||
** Print a map of height and width
|
||||
*/
|
||||
|
||||
void print_map(unsigned int *tab, int width, int height)
|
||||
void print_map(unsigned int *tab, int width, int height)
|
||||
{
|
||||
int i;
|
||||
unsigned int mask;
|
||||
int i;
|
||||
unsigned int mask;
|
||||
|
||||
i = 0;
|
||||
mask = 0;
|
||||
while (i++ < width)
|
||||
mask = (mask >> 1) | ((mask | 1) << 31);
|
||||
i = 0;
|
||||
while (i < width * height)
|
||||
{
|
||||
if (i && !(i % width))
|
||||
ft_putchar('\n');
|
||||
tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.');
|
||||
ft_putchar(' ');
|
||||
i++;
|
||||
}
|
||||
write(1, "\n", 1);
|
||||
i = 0;
|
||||
mask = 0;
|
||||
while (i++ < width)
|
||||
mask = (mask >> 1) | ((mask | 1) << 31);
|
||||
i = 0;
|
||||
while (i < width * height)
|
||||
{
|
||||
if (i && !(i % width))
|
||||
ft_putchar('\n');
|
||||
tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.');
|
||||
ft_putchar(' ');
|
||||
i++;
|
||||
}
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
** Print the final map with the letters
|
||||
*/
|
||||
|
||||
void print_final_map(t_fillist *list, int size)
|
||||
{
|
||||
// unsigned int print;
|
||||
t_fillist *tmp;
|
||||
char *map;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
map = (char *)malloc(sizeof(*map) * (size * size + 1));
|
||||
map[size*size] = '\0';
|
||||
// i = -1;
|
||||
// while (++i < size * size)
|
||||
// map[i] = '.';
|
||||
tmp = list;
|
||||
while (tmp)
|
||||
{
|
||||
j = 0;
|
||||
i = -1;
|
||||
while (++i < tmp->width * tmp->height)
|
||||
{
|
||||
// ft_putchar('\n');
|
||||
// print = tmp->tetribit << 16;
|
||||
// print_map(&print, tmp->width, tmp->height);
|
||||
// print_bits(tmp->tetribit, 16);
|
||||
// print_bits(1 << (15 - i), 16);
|
||||
// (1 >> i & tmp->tetribit) ? ft_putchar('1') : ft_putchar('.');
|
||||
if (i && i + 1 % tmp->width == 0)
|
||||
j += size;
|
||||
if (1 << (15 - i) & tmp->tetribit)
|
||||
map[tmp->position + i + j] = tmp->letter;
|
||||
else
|
||||
map[tmp->position + i + j] = '.';
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
i = -1;
|
||||
while (++i < size * size)
|
||||
{
|
||||
if (i && i % size == 0)
|
||||
ft_putchar('\n');
|
||||
ft_putchar(map[i]);
|
||||
ft_putchar(' ');
|
||||
}
|
||||
ft_putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
99
samples/test_ultra_lent
Normal file
99
samples/test_ultra_lent
Normal file
@@ -0,0 +1,99 @@
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
#...
|
||||
###.
|
||||
....
|
||||
....
|
||||
|
||||
.#..
|
||||
.#..
|
||||
##..
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
#...
|
||||
###.
|
||||
....
|
||||
....
|
||||
|
||||
.#..
|
||||
.#..
|
||||
##..
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
#...
|
||||
###.
|
||||
....
|
||||
....
|
||||
|
||||
.#..
|
||||
.#..
|
||||
##..
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
#...
|
||||
###.
|
||||
....
|
||||
....
|
||||
|
||||
.#..
|
||||
.#..
|
||||
##..
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
#...
|
||||
###.
|
||||
....
|
||||
....
|
||||
|
||||
.#..
|
||||
.#..
|
||||
##..
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
|
||||
/* Updated: 2019/05/02 16:42:47 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/05/03 14:19:42 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -139,5 +139,6 @@ void search_map(t_fillist *list)
|
||||
while (!fill_map(map, list, size))
|
||||
map = init_map(size++);
|
||||
print_map(map, size, size);
|
||||
print_final_map(list, size);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user