recherche de la position du tetri dans la map fonctionne
This commit is contained in:
4
fillit.h
4
fillit.h
@@ -6,7 +6,7 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/27 00:34:44 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/04/27 21:00:53 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -44,5 +44,7 @@ void parse_input(char *input);
|
||||
int check_file_errors(char *file);
|
||||
int check_tetri_errors(char *tetri);
|
||||
int check_tetri_errors_proxy(char *tetri);
|
||||
void search_map(t_fillist *list);
|
||||
void print_map(unsigned int *tab, int width, int height);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,57 +6,12 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/27 02:00:45 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/04/27 22:55:32 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
|
||||
/*
|
||||
** DELETE BEFORE EVAL - TEST FUNCTION
|
||||
** prints a ligne of size bits
|
||||
*/
|
||||
|
||||
void print_bits(unsigned int bits, int size)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
** DELETE BEFORE EVAL - TEST FUNCTION
|
||||
** print a map of height and width
|
||||
*/
|
||||
|
||||
void print_map(unsigned int *tab, int width, int height)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
** function that transform a tab of . and # into a binary tab of int
|
||||
*/
|
||||
@@ -106,7 +61,7 @@ unsigned short reduce_tetri(unsigned short tetri, int width)
|
||||
|
||||
void fill_list(char line[], t_fillist *list)
|
||||
{
|
||||
unsigned int tmp;
|
||||
// unsigned int tmp;
|
||||
unsigned int mask;
|
||||
int i;
|
||||
|
||||
@@ -133,13 +88,6 @@ void fill_list(char line[], t_fillist *list)
|
||||
list->height = i;
|
||||
// fabrique la ligne pour le tetriminos de la bonne largeur
|
||||
list->tetribit = reduce_tetri(list->tetribit, list->width);
|
||||
|
||||
// imression pour tests
|
||||
ft_putchar('\n');
|
||||
tmp = list->tetribit;
|
||||
tmp <<= 16;
|
||||
print_map(&tmp, list->width, list->height);
|
||||
tmp >>= 16;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -150,15 +98,21 @@ void fill_list(char line[], t_fillist *list)
|
||||
int add_to_list(char *line, t_fillist **list)
|
||||
{
|
||||
t_fillist *tmp;
|
||||
t_fillist *test;
|
||||
|
||||
if (!(tmp = (t_fillist*)malloc(sizeof(*tmp))))
|
||||
return (0);
|
||||
if (!(*list))
|
||||
tmp->next = NULL;
|
||||
tmp->next = NULL;
|
||||
test = *list;
|
||||
if (!test)
|
||||
*list = tmp;
|
||||
else
|
||||
tmp->next = *list;
|
||||
*list = tmp;
|
||||
fill_list(line, *list);
|
||||
{
|
||||
while(test->next)
|
||||
test = test->next;
|
||||
test->next = tmp;
|
||||
}
|
||||
fill_list(line, tmp);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -186,5 +140,6 @@ void parse_input(char *input)
|
||||
while (input[i] && input[i] != '.' && input[i] != '#')
|
||||
i++;
|
||||
}
|
||||
search_map(list);
|
||||
}
|
||||
|
||||
|
||||
115
search_map.c
Normal file
115
search_map.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* search_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
|
||||
/* Updated: 2019/04/28 01:08:55 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
|
||||
void print_bits(unsigned int bits, int size)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** DELETE BEFORE EVAL - TEST FUNCTION
|
||||
** print a map of height and width
|
||||
*/
|
||||
|
||||
void print_map(unsigned int *tab, int width, int height)
|
||||
{
|
||||
int i;
|
||||
unsigned int mask;
|
||||
|
||||
i = 0;
|
||||
mask = ~0u << (32 - width);
|
||||
while (i < width * height)
|
||||
{
|
||||
if (i && !(i % width))
|
||||
ft_putnbrendl(i); // pour imprimer les tailles du tableaux pour faciliter sa verification
|
||||
tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.');
|
||||
ft_putchar(' ');
|
||||
i++;
|
||||
}
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
|
||||
void find_place(unsigned int *tab, t_fillist *list, int size)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
unsigned int mask;
|
||||
unsigned int tmp;
|
||||
|
||||
// creer un mask avec les size bits de gauche a 1 (ex: 11111110000000000000000000000000)
|
||||
mask = ~0u << (32 - list->width);
|
||||
tmp = mask;
|
||||
i = 0;
|
||||
// boucle jusqu'a la dernier place pour le tetri dans la map ou qu'il fit dans un trou
|
||||
while (i < (size - list->height + 1) * size && (tmp >> 16) & list->tetribit)
|
||||
{
|
||||
tmp = 0;
|
||||
j = list->height * size + i;
|
||||
while (j >= i)
|
||||
{
|
||||
tmp >>= list->width;
|
||||
tmp |= (mask & (tab[j / 32] << j));
|
||||
tmp |= (mask & (tab[(j + size) / 32] >> (32 - j)));
|
||||
j -= size;
|
||||
}
|
||||
// test pour imprimer la "photo de la map"
|
||||
print_bits(tmp >> 16, 32);
|
||||
if (i % size == size - list->width)
|
||||
i += list->width - 1;
|
||||
i++;
|
||||
}
|
||||
// ligne de test pour imprimer la position a laquelle le tetri a trouve une place
|
||||
ft_putnbrendl(((i - list->width) % size == size - list->width) ? i - list->width : i);
|
||||
}
|
||||
|
||||
void search_map(t_fillist *list)
|
||||
{
|
||||
unsigned int tmp;
|
||||
unsigned int tab[8];
|
||||
t_fillist *print;
|
||||
|
||||
// ce tableau permet de monter jusqu'a une map de 16*16
|
||||
tab[0] = 2656554334;
|
||||
tab[1] = 1394456818;
|
||||
tab[2] = 1494256918;
|
||||
tab[3] = 2656554334;
|
||||
tab[4] = 1592453883;
|
||||
tab[5] = 1444352908;
|
||||
tab[6] = 2154339230;
|
||||
tab[7] = 1576493154;
|
||||
print_map(tab, 10, 10);
|
||||
print = list;
|
||||
while (print)
|
||||
{
|
||||
// imression pour tests
|
||||
tmp = print->tetribit;
|
||||
tmp <<= 16;
|
||||
print_map(&tmp, print->width, print->height);
|
||||
ft_putchar('\n');
|
||||
find_place(tab, print, 10);
|
||||
print = print->next;
|
||||
}
|
||||
// find_place(tab, list, 10);
|
||||
}
|
||||
|
||||
37
test_right.c
37
test_right.c
@@ -14,21 +14,17 @@ void print_bits(unsigned int bits, int size)
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
|
||||
void print_map(unsigned int *tab, int size)
|
||||
void print_map(unsigned int *tab, int width, int height)
|
||||
{
|
||||
int i;
|
||||
unsigned int mask;
|
||||
unsigned int tmp;
|
||||
|
||||
i = 0;
|
||||
mask = 0;
|
||||
// creer un mask avec les size bits de gauche a 1 (ex: 11111110000000000000000000000000)
|
||||
while (i++ < size)
|
||||
mask = (mask >> 1) | ((mask | 1) << 31);
|
||||
i = 0;
|
||||
while (i < size * size)
|
||||
mask = ~0u << (32 - width);
|
||||
while (i < width * height)
|
||||
{
|
||||
if (!(i % size))
|
||||
if (!(i % width))
|
||||
ft_putchar('\n');
|
||||
tab[i / 32] & (1 << (31 - i % 32)) ? ft_putchar('#') : ft_putchar('.');
|
||||
ft_putchar(' ');
|
||||
@@ -44,13 +40,14 @@ void find_place(unsigned int *tab, char *line, int size)
|
||||
int j;
|
||||
unsigned int mask;
|
||||
unsigned int tmp;
|
||||
int large;
|
||||
int width;
|
||||
int height;
|
||||
|
||||
// ft_putendl("# . . # # # # T T # . # . # # # # # . . # # . # T # . # # # # . . # . # . . # # T . . # # # . # # . # # # . . . # # # # . . # . . # . # # . . # . . . # . . . . # . . . # # . # . . . # . # # .");
|
||||
/////////////// create tetri ///////////////
|
||||
i = 0;
|
||||
tmp = 0;
|
||||
large = 3;
|
||||
width = 3;
|
||||
height = 2;
|
||||
while (line[i])
|
||||
{
|
||||
tetri <<= 1;
|
||||
@@ -63,31 +60,31 @@ void find_place(unsigned int *tab, char *line, int size)
|
||||
tetri <<= 1;
|
||||
print_bits(tetri, 16);
|
||||
tmp = (tetri | tmp) << 16;
|
||||
print_map(&tmp, large);
|
||||
print_map(&tmp, width, height);
|
||||
/////////////// create tetri ///////////////
|
||||
|
||||
mask = ~0;
|
||||
mask <<= 32 - large;
|
||||
mask <<= 32 - width;
|
||||
ft_putendl("mask: ");
|
||||
print_bits(mask, 32);
|
||||
i = 0;
|
||||
while (i < 20)
|
||||
while (i < (size - height + 1) * size)
|
||||
{
|
||||
tmp = 0;
|
||||
j = 3 * size + i;
|
||||
j = height * size + i;
|
||||
while (j >= i)
|
||||
{
|
||||
tmp >>= large;
|
||||
tmp >>= width;
|
||||
tmp |= (mask & (tab[j / 32] << j));
|
||||
tmp |= (mask & (tab[(j + size) / 32] >> (32 - j)));
|
||||
j -= size;
|
||||
}
|
||||
print_map(&tmp, large);
|
||||
print_map(&tmp, width, height);
|
||||
print_bits(tmp >> 16, 32);
|
||||
print_bits(tetri, 32);
|
||||
print_bits((tmp >> 16) & tetri, 32);
|
||||
if (i % size == size - large)
|
||||
i += large - 1;
|
||||
if (i % size == size - width)
|
||||
i += width - 1;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -119,7 +116,7 @@ int main(int ac, char **av)
|
||||
// mettre l'option "b" pour afficher la troisieme argument en binaire
|
||||
if (av[0][0] == 'b' && ac > 2)
|
||||
ft_putendl(ft_convertbase(av[1], "01", "0123456789"));
|
||||
print_map(tab, 10);
|
||||
print_map(tab, 10, 10);
|
||||
write(1, "\n", 1);
|
||||
if (av[0][0] == 't' && ac > 2)
|
||||
find_place(tab, av[1], 10);
|
||||
|
||||
Reference in New Issue
Block a user