version clean sans modulos et divisions pour find_place

This commit is contained in:
Hugo LAMY
2019-05-15 18:05:37 +02:00
parent 2e53b04a9a
commit 6705bf9133

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */ /* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ /* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
/* Updated: 2019/05/15 17:46:55 by hulamy ### ########.fr */ /* Updated: 2019/05/15 18:03:41 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -16,15 +16,12 @@
** function that look if a tretri fit in a place ** function that look if a tretri fit in a place
*/ */
//unsigned int fit_in_place(unsigned int *map, t_fillist *list, int size, int pos) unsigned int fit_in_place(unsigned int *map, t_fillist *list, int size, int n, int r)
unsigned int fit_in_place(unsigned int *map, t_fillist *list, int size, int pos, int number, int place)
{ {
unsigned int tmp; unsigned int tmp;
unsigned int mask; unsigned int mask;
int i; int i;
// /*
(void)pos;
unsigned int tetri; unsigned int tetri;
i = list->height; i = list->height;
tetri = list->tetribit << 16 >> list->width; tetri = list->tetribit << 16 >> list->width;
@@ -34,29 +31,13 @@ unsigned int fit_in_place(unsigned int *map, t_fillist *list, int size, int pos,
{ {
if (tmp & tetri) if (tmp & tetri)
return (0); return (0);
if (place >= 32 && ++number) if (r >= 32 && ++n)
place -= 32; r -= 32;
tmp = (mask & (map[number] << place)) | (mask & (map[number + 1] >> (32 - place))); tmp = (mask & (map[n] << r)) | (mask & (map[n + 1] >> (32 - r)));
tetri <<= list->width; tetri <<= list->width;
place += size; r += size;
} }
return (!(tmp & tetri)); return (!(tmp & tetri));
// */
/*
(void)place;
(void)number;
mask = ~0u << (32 - list->width);
i = (list->height - 1) * size + pos;
tmp = 0;
while (i >= pos)
{
tmp >>= list->width;
tmp |= (mask & (map[i / 32] << i)) | (mask & (map[(i / 32) + 1] >> (32 - i)));
i -= size;
}
return (!((tmp >> 16) & list->tetribit));
*/
} }
/* /*
@@ -65,48 +46,30 @@ unsigned int fit_in_place(unsigned int *map, t_fillist *list, int size, int pos,
int find_place(unsigned int *tab, t_fillist *list, int size, int pos) int find_place(unsigned int *tab, t_fillist *list, int size, int pos)
{ {
// /* int place; // designe la position sur la ligne du tableau de size*size
int row; // designe la position de size*size sur la ligne du tableau int r; // designe la position de pos dans l'int du tableau
int number; // designe la position de pos dans l'int du tableau int n; // designe dans quel int tu tableau pos se trouve
int place; // designe dans quel int tu tableau pos se trouve
int limit; // limit en hauteur du tableau a chercher pour la position du tetri int limit; // limit en hauteur du tableau a chercher pour la position du tetri
row = pos % size; place = pos % size;
place = pos % 32; r = pos % 32;
number = pos / 32; n = pos / 32;
limit = (size - list->height + 1) * size; limit = (size - list->height + 1) * size;
while (pos < limit) while (pos < limit)
{ {
if (place >= 32 && ++number) if (r >= 32 && ++n)
place -= 32; r -= 32;
// if (place != (pos % 32) || number != (pos / 32)) // pour verifier que place et number sont bien implementes if (place > size - list->width && (place = -1))
// ft_putendl("error");
if (row > size - list->width && (row = -1))
{ {
pos += list->width - 2; pos += list->width - 2;
place += list->width - 2; r += list->width - 2;
} }
else if (fit_in_place(tab, list, size, pos, number, place)) else if (fit_in_place(tab, list, size, n, r))
return (pos + 1); return (pos + 1);
pos++; pos++;
row++;
place++; place++;
r++;
} }
// */
/*
// boucle jusqu'a la dernier place pour le tetri dans la map ou qu'il entre dans un trou
while (pos < (size - list->height + 1) * size)
{
// pour ne pas deborder a droite de la map
if (pos % size > size - list->width)
pos += list->width - 2;
else if (fit_in_place(tab, list, size, pos))
return (pos + 1);
pos++;
}
*/
return (0); return (0);
} }