backtracking fonctionne avec list->position directement
This commit is contained in:
20
fillit.dSYM/Contents/Info.plist
Normal file
20
fillit.dSYM/Contents/Info.plist
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
|
<string>English</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>com.apple.xcode.dsym.fillit</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>dSYM</string>
|
||||||
|
<key>CFBundleSignature</key>
|
||||||
|
<string>????</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>1</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
3
fillit.h
3
fillit.h
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
|
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/05/08 17:52:19 by hulamy ### ########.fr */
|
/* Updated: 2019/05/16 15:31:15 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -44,6 +44,7 @@ typedef struct s_fillist
|
|||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int position;
|
int position;
|
||||||
|
int test;
|
||||||
char letter;
|
char letter;
|
||||||
struct s_fillist *next;
|
struct s_fillist *next;
|
||||||
} t_fillist;
|
} t_fillist;
|
||||||
|
|||||||
@@ -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/06 16:30:45 by hulamy ### ########.fr */
|
/* Updated: 2019/05/16 15:30:57 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -89,7 +89,8 @@ void fill_list(char line[], t_fillist *list)
|
|||||||
list->height = i;
|
list->height = i;
|
||||||
// fabrique la ligne pour le tetriminos de la bonne largeur
|
// 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 = -1; // DEBUG pour que print_final_map puisse imprimer correctement au fur et a mesure
|
list->position = 0;
|
||||||
|
list->test = 0; // DEBUG pour que print_final_map puisse imprimer correctement au fur et a mesure
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
4
print.c
4
print.c
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */
|
/* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/05/08 17:52:14 by hulamy ### ########.fr */
|
/* Updated: 2019/05/16 15:52:52 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ void print_final_map(t_fillist *list, int size)
|
|||||||
{
|
{
|
||||||
if (i && i % tmp->width == 0)
|
if (i && i % tmp->width == 0)
|
||||||
j += size - tmp->width;
|
j += size - tmp->width;
|
||||||
if (1 << (15 - i) & tmp->tetribit && tmp->position != -1) // DEBUG "&& tmp->position != -1" pour imprimer les bonnes lettres au coours du debug
|
if (1 << (15 - i) & tmp->tetribit/* && tmp->test == 1*/) // DEBUG "&& tmp->position != -1" pour imprimer les bonnes lettres au coours du debug
|
||||||
map[tmp->position + i + j - 1] = tmp->letter;
|
map[tmp->position + i + j - 1] = tmp->letter;
|
||||||
}
|
}
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
|
|||||||
46
search_map.c
46
search_map.c
@@ -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 18:03:41 by hulamy ### ########.fr */
|
/* Updated: 2019/05/16 16:50:29 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -44,13 +44,15 @@ unsigned int fit_in_place(unsigned int *map, t_fillist *list, int size, int n, i
|
|||||||
** function that look for the first place in the map for a tetri
|
** function that look for the first place in the map for a tetri
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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 place; // designe la position sur la ligne du tableau de size*size
|
int place; // designe la position sur la ligne du tableau de size*size
|
||||||
int r; // designe la position de pos dans l'int du tableau
|
int r; // designe la position de pos dans l'int du tableau
|
||||||
int n; // designe dans quel int tu tableau pos se trouve
|
int n; // 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
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
pos = list->position;
|
||||||
place = pos % size;
|
place = pos % size;
|
||||||
r = pos % 32;
|
r = pos % 32;
|
||||||
n = pos / 32;
|
n = pos / 32;
|
||||||
@@ -65,7 +67,8 @@ int find_place(unsigned int *tab, t_fillist *list, int size, int pos)
|
|||||||
r += list->width - 2;
|
r += list->width - 2;
|
||||||
}
|
}
|
||||||
else if (fit_in_place(tab, list, size, n, r))
|
else if (fit_in_place(tab, list, size, n, r))
|
||||||
return (pos + 1);
|
return ((list->position = pos + 1));
|
||||||
|
// return (pos + 1);
|
||||||
pos++;
|
pos++;
|
||||||
place++;
|
place++;
|
||||||
r++;
|
r++;
|
||||||
@@ -77,7 +80,7 @@ int find_place(unsigned int *tab, t_fillist *list, int size, int pos)
|
|||||||
** function that add or remove a tetri on the map
|
** function that add or remove a tetri on the map
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void add_remove(unsigned int *map, t_fillist *list, int size, int pos)
|
void add_remove(unsigned int *map, t_fillist *list, int size)
|
||||||
{
|
{
|
||||||
unsigned int mask;
|
unsigned int mask;
|
||||||
unsigned short tetri;
|
unsigned short tetri;
|
||||||
@@ -87,9 +90,9 @@ void add_remove(unsigned int *map, t_fillist *list, int size, int pos)
|
|||||||
tetri = list->tetribit;
|
tetri = list->tetribit;
|
||||||
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 + pos;
|
j = (list->height - 1) * size + list->position;
|
||||||
// change les bits du tetri sur la map a la position donnee
|
// change les bits du tetri sur la map a la position donnee
|
||||||
while (j >= pos)
|
while (j >= list->position)
|
||||||
{
|
{
|
||||||
map[(j - 1) / 32] ^= (mask & tetri << (16 + i)) >> (j - 1);
|
map[(j - 1) / 32] ^= (mask & tetri << (16 + i)) >> (j - 1);
|
||||||
map[(j - 1) / 32 + 1] ^= (mask & tetri << (16 + i)) << (32 - j) << 1;
|
map[(j - 1) / 32 + 1] ^= (mask & tetri << (16 + i)) << (32 - j) << 1;
|
||||||
@@ -102,24 +105,47 @@ void add_remove(unsigned int *map, t_fillist *list, int size, int pos)
|
|||||||
** function that recursively try to fill the map with the tetris
|
** function that recursively try to fill the map with the tetris
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int fill_map(unsigned int *map, t_fillist *list, int size, t_fillist *link) // DEBUG "link"
|
int fill_map(unsigned int *map, t_fillist *list, int size, t_fillist *link) // DEBUG link sert uniquement pour afficher le debug
|
||||||
{
|
{
|
||||||
|
// /*
|
||||||
|
// int posx;
|
||||||
|
// int posy;
|
||||||
|
|
||||||
|
// posx = list->posx;
|
||||||
|
// posy = list->posy;
|
||||||
|
if (!list)
|
||||||
|
return (1);
|
||||||
|
list->position = 0; // comme les positions sont marquees en dure dans la liste et non plus dans une petite variable
|
||||||
|
// au sein de la fonction, il faut remettre a zero la position a chaque nouveau tour de map
|
||||||
|
while (find_place(map, list, size))
|
||||||
|
{
|
||||||
|
// pos = list->position;
|
||||||
|
// list->test = 1; // DEBUG pour afficher la map a chaque etape
|
||||||
|
add_remove(map, list, size);
|
||||||
|
// print_final_map(link, size); ft_putnbrendl(pos); print_map(map, size, size, '#'); ft_putchar('\n'); // DEBUG
|
||||||
|
if (fill_map(map, list->next, size, link))
|
||||||
|
return (1);
|
||||||
|
add_remove(map, list, size);
|
||||||
|
// list->test = 0; // DEBUG pour afficher la map a chaque etape
|
||||||
|
}
|
||||||
|
// */
|
||||||
|
|
||||||
|
/*
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
if (!list)
|
if (!list)
|
||||||
return (1);
|
return (1);
|
||||||
// unsigned int tmp = list->tetribit << 16; print_map(&tmp, list->width, list->height, list->letter); // DEBUG
|
|
||||||
while ((pos = find_place(map, list, size, pos)))
|
while ((pos = find_place(map, list, size, pos)))
|
||||||
{
|
{
|
||||||
add_remove(map, list, size, pos);
|
add_remove(map, list, size, pos);
|
||||||
list->position = pos;
|
list->position = pos;
|
||||||
// print_final_map(link, size); ft_putnbrendl(pos); print_map(map, size, size, '#'); ft_putchar('\n'); // DEBUG
|
|
||||||
if (fill_map(map, list->next, size, link))
|
if (fill_map(map, list->next, size, link))
|
||||||
return (1);
|
return (1);
|
||||||
add_remove(map, list, size, pos);
|
add_remove(map, list, size, pos);
|
||||||
// list->position = -1; // DEBUG
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user