clean les comments
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* 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 #+# #+# */
|
||||||
/* Updated: 2019/05/17 18:40:30 by hulamy ### ########.fr */
|
/* Updated: 2019/05/18 14:17:14 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -58,6 +58,14 @@ unsigned short reduce_tetri(unsigned short tetri, int width)
|
|||||||
/*
|
/*
|
||||||
** Function that transforme a tetriminos char* into a short of 16 bites
|
** Function that transforme a tetriminos char* into a short of 16 bites
|
||||||
** and then fills it and its reversed into the list
|
** and then fills it and its reversed into the list
|
||||||
|
**
|
||||||
|
** 1) transforme la ligne de . et # en un short de 0 et 1
|
||||||
|
** 2) cree un mask avec des 1 sur la colonne de droite (#...#...#...#...)
|
||||||
|
** 3) utilise le mask pour trouver la largeur que prend le tetriminos
|
||||||
|
** 4) deplace le tetriminos tout en haut a gauche
|
||||||
|
** (i - list->width = le nombre de colonne vide a gauche)
|
||||||
|
** 5) trouve la hauteur du tetri
|
||||||
|
** 6) fabrique la ligne pour le tetriminos de la bonne largeur
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fill_list(char line[], t_fillist *list)
|
void fill_list(char line[], t_fillist *list)
|
||||||
@@ -65,12 +73,9 @@ void fill_list(char line[], t_fillist *list)
|
|||||||
unsigned int mask;
|
unsigned int mask;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// transforme la ligne de . et # en un short de 0 et 1
|
|
||||||
list->tetribit = tab_to_bin(line);
|
list->tetribit = tab_to_bin(line);
|
||||||
list->memory = 0;
|
list->memory = 0;
|
||||||
// cree un mask avec des 1 sur la colonne de droite (#...#...#...#...)
|
|
||||||
mask = (1 << 15) | (1 << 11) | (1 << 7) | (1 << 3);
|
mask = (1 << 15) | (1 << 11) | (1 << 7) | (1 << 3);
|
||||||
// utilise le mask pour trouver la largeur que prend le tetriminos
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (!(mask & list->tetribit) && i++ < 4)
|
while (!(mask & list->tetribit) && i++ < 4)
|
||||||
mask >>= 1;
|
mask >>= 1;
|
||||||
@@ -78,19 +83,14 @@ void fill_list(char line[], t_fillist *list)
|
|||||||
while (mask & list->tetribit && ++i < 4)
|
while (mask & list->tetribit && ++i < 4)
|
||||||
mask >>= 1;
|
mask >>= 1;
|
||||||
list->width = i - list->width;
|
list->width = i - list->width;
|
||||||
// deplace le tetriminos tout en haut a gauche
|
|
||||||
//(i - list->width = le nombre de colonne vide a gauche)
|
|
||||||
list->tetribit <<= (i - list->width);
|
list->tetribit <<= (i - list->width);
|
||||||
while (!(list->tetribit & (~0u << 12)))
|
while (!(list->tetribit & (~0u << 12)))
|
||||||
list->tetribit <<= 4;
|
list->tetribit <<= 4;
|
||||||
// trouve la hauteur du tetri
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < 4 && list->tetribit & (~0u << 28 >> (i * 4 + 16)))
|
while (i < 4 && list->tetribit & (~0u << 28 >> (i * 4 + 16)))
|
||||||
i++;
|
i++;
|
||||||
list->height = i;
|
list->height = i;
|
||||||
// fabrique la ligne pour le tetriminos de la bonne largeur
|
|
||||||
list->tetribit = reduce_tetri(list->tetribit, list->width);
|
list->tetribit = reduce_tetri(list->tetribit, list->width);
|
||||||
list->position = 0;
|
|
||||||
list->test = 0; // DEBUG pour que print_final_map puisse imprimer correctement au fur et a mesure
|
list->test = 0; // DEBUG pour que print_final_map puisse imprimer correctement au fur et a mesure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
40
search_map.c
40
search_map.c
@@ -6,12 +6,49 @@
|
|||||||
/* 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/17 18:31:44 by hulamy ### ########.fr */
|
/* Updated: 2019/05/18 15:16:26 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** OLD VERSION of find_place and fit_in_place all in one but with a lot of divisions and modulo
|
||||||
|
**
|
||||||
|
** int find_place(unsigned int *tab, t_fillist *list, int size, int pos)
|
||||||
|
** {
|
||||||
|
** int i;
|
||||||
|
** int j;
|
||||||
|
** unsigned int mask;
|
||||||
|
** unsigned int tmp;
|
||||||
|
**
|
||||||
|
** mask = ~0u << (32 - list->width);
|
||||||
|
** tmp = mask;
|
||||||
|
** i = pos;
|
||||||
|
** while (i < (size - list->height + 1) * size)
|
||||||
|
** {
|
||||||
|
** if (i % size == size - list->width + 1)
|
||||||
|
** i += list->width - 1;
|
||||||
|
** else
|
||||||
|
** {
|
||||||
|
** tmp = 0;
|
||||||
|
** j = (list->height - 1) * size + i;
|
||||||
|
** while (j >= i)
|
||||||
|
** {
|
||||||
|
** tmp >>= list->width;
|
||||||
|
** tmp |= (mask & (tab[j / 32] << j));
|
||||||
|
** tmp |= (mask & (tab[(j + list->width) / 32] >> (32 - j)));
|
||||||
|
** j -= size;
|
||||||
|
** }
|
||||||
|
** if (!((tmp >> 16) & list->tetribit))
|
||||||
|
** return (i + 1);
|
||||||
|
** i++;
|
||||||
|
** }
|
||||||
|
** }
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** function that look if a tretri fit in a place
|
** function that look if a tretri fit in a place
|
||||||
*/
|
*/
|
||||||
@@ -91,7 +128,6 @@ void add_remove(unsigned int *map, t_fillist *list, int size)
|
|||||||
mask = ~0u << (32 - list->width);
|
mask = ~0u << (32 - list->width);
|
||||||
i = (list->height - 1) * list->width;
|
i = (list->height - 1) * list->width;
|
||||||
j = (list->height - 1) * size + list->position;
|
j = (list->height - 1) * size + list->position;
|
||||||
// change les bits du tetri sur la map a la position donnee
|
|
||||||
while (j >= list->position)
|
while (j >= list->position)
|
||||||
{
|
{
|
||||||
map[(j - 1) / 32] ^= (mask & tetri << (16 + i)) >> (j - 1);
|
map[(j - 1) / 32] ^= (mask & tetri << (16 + i)) >> (j - 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user