Merge remote-tracking branch 'origin/master'

This commit is contained in:
Manzovince
2019-05-28 13:23:15 +02:00
67 changed files with 4641 additions and 93 deletions

BIN
.DS_Store vendored

Binary file not shown.

84
f_bonus_opti.c Normal file
View File

@@ -0,0 +1,84 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */
/* Updated: 2019/05/28 13:03:46 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** Test optimisation for not testing wrong maps when tetri are identical
*/
int check_tetri_memory(t_fillist *list, int pos)
{
t_fillist *tetri;
unsigned int mask;
tetri = list;
mask = 1 << ((pos % 32) - 1);
if (tetri->same)
{
if (!(tetri->same->memory[pos / 32] & mask))
return (tetri->same->memory[pos / 32] |= mask);
}
else
{
if (!(tetri->memory[pos / 32] & mask))
return (tetri->memory[pos / 32] |= mask);
}
return (0);
}
/*
** Test optimisation for not testing wrong maps when tetri are identical
*/
int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b)
{
if (tetri_a->tetribit != tetri_b->tetribit)
return (0);
if (tetri_a->width != tetri_b->width)
return (0);
if (tetri_a->height != tetri_b->height)
return (0);
return (1);
}
/*
** Test optimisation for not testing wrong maps when tetri are identical
*/
int check_same_tetri(t_fillist *list, int num)
{
t_fillist *curr_tetri;
t_fillist *next_tetri;
int i;
curr_tetri = list;
while (curr_tetri != NULL/* && list->dope[1]*/)
{
i = 0;
if (!(curr_tetri->memory =
(unsigned int *)malloc(sizeof(*curr_tetri->memory) * num)))
return (0);
while (i < num)
curr_tetri->memory[i++] = 0;
next_tetri = curr_tetri->next;
while (next_tetri != NULL)
{
if (compare_tetri(curr_tetri, next_tetri))
if (next_tetri->same == NULL)
next_tetri->same = curr_tetri;
next_tetri = next_tetri->next;
}
curr_tetri = curr_tetri->next;
}
return (0);
}

77
f_bonus_print.c Normal file
View File

@@ -0,0 +1,77 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* f_bonus_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/27 13:46:29 by hulamy #+# #+# */
/* Updated: 2019/05/28 09:57:40 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** function that print the given tetris if flag p is present
*/
t_fillist *print_tetri(t_fillist *list)
{
unsigned int print;
t_fillist *tmp;
tmp = list;
if (list->dope[2])
{
while (tmp)
{
check_same_tetri(list, 1);
print = tmp->tetribit;
print <<= 16;
print_sized_map(&print, tmp->width, tmp->height, tmp->letter);
if (tmp->same)
{
print = tmp->same->tetribit;
print <<= 16;
ft_putstr("same --> ");
ft_put_tetri_color(tmp->same->letter);
ft_putchar('\n');
}
ft_putchar('\n');
tmp = tmp->next;
}
}
return (list);
}
/*
** function that print the map in binary if flag p is present
** it returns anyway the size of the map for main to print it
*/
int print_binary_map(unsigned int *map, int size, int *dope)
{
size--;
if (dope[2])
{
ft_putendl("result in binary :");
print_sized_map(map, size, size, '#');
ft_putchar('\n');
}
return (size);
}
/*
** function that print the flags usage
*/
int print_flags_usage(void)
{
ft_putendl("flags usage :");
ft_putendl("d : debug print (print the map during the backtracking)");
ft_putendl("o : optimisation ultra fast but with some errors still");
ft_putendl("p : print the tetri and the map in different formats");
ft_putendl("e : error msgs more precise AND no error for too much tetri\n");
return (0);
}

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
/* Updated: 2019/05/20 13:42:07 by vmanzoni ### ########.fr */
/* Updated: 2019/05/28 11:26:25 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,32 +19,36 @@
void print_error(char *str)
{
write(1, str, ft_strlen(str));
exit(1);
// exit(1);
}
/*
** UPGRADE VERSION
** Function that display error message *s on fd
** with more informations
** and exit program
**
**void print_error_extended(int error)
**{
** if (error == 1)
** ft_putstr("error: File contains char other than '.','#' and '\\n'.\n");
** if (error == 2)
** ft_putstr("error: File contains more than 2 '\\n' in a row.\n");
** if (error == 3)
** ft_putstr("error: File contains less than 1 tetrimino "
** "or more than 26.\n");
** if (error == 4)
** ft_putstr("error: Tetrimino has more or less than 4 #.\n");
** if (error == 5)
** ft_putstr("error: Tetrimino # are not all connected.\n");
** exit(1);
**}
*/
void print_error_extended(int error, int *dope)
{
if (!dope[3])
{
print_error("error\n");
exit(0);
}
if (error == 1)
ft_putstr("error: File contains char other than '.','#' and '\\n'.\n");
if (error == 2)
ft_putstr("error: File contains more than 2 '\\n' in a row.\n");
if (error == 3)
ft_putstr("error: File contains less than 1 tetrimino "
"or more than 26.\n");
if (error == 4)
ft_putstr("error: Tetrimino has more or less than 4 #.\n");
if (error == 5)
ft_putstr("error: Tetrimino # are not all connected.\n");
// exit(1);
}
/*
** Function to see if there if an error if the file
** - less than 4 lines
@@ -52,7 +56,7 @@ void print_error(char *str)
** - two \n in a row
*/
int check_file_errors(char *file)
void check_file_errors(char *file, int *dope)
{
int i;
int line_nbr;
@@ -62,19 +66,19 @@ int check_file_errors(char *file)
while (file[i])
{
if (file[i] != '.' && file[i] != '#' && file[i] != '\n')
return (1);
print_error_extended(1, dope);
else if (file[i] == '\n')
line_nbr++;
// le if suivant verifie quoi
if (file[i] == '\n' && line_nbr % 5 == 0 && file[i-1] != '\n')
print_error("error\n");
if (file[i] == '\n' && file[i+1] != '\0' && \
file[i+2] != '.' && file[i+2] != '#')
return (2);
print_error_extended(2, dope);
i++;
}
if (line_nbr < 4 || line_nbr > 129)
return (3);
return (0);
print_error_extended(3, dope);
}
/*

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
/* Updated: 2019/05/18 14:17:14 by hulamy ### ########.fr */
/* Updated: 2019/05/28 10:44:43 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -45,7 +45,6 @@ unsigned short reduce_tetri(unsigned short tetri, int width)
unsigned int tmp;
mask = ~0u << (32 - width) >> 16;
tmp = tetri;
tmp = (mask & tetri);
tmp |= ((mask & tetri << 4) >> width);
tmp |= ((mask & tetri << 8) >> (2 * width));
@@ -64,9 +63,12 @@ unsigned short reduce_tetri(unsigned short tetri, int width)
** (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
**
** list->test is used to debug the backtracking, allowing to print the
** map each time without the previous tries
*/
void fill_list(char line[], t_fillist *list)
void fill_list(char line[], t_fillist *list)
{
unsigned int mask;
int i;
@@ -89,7 +91,8 @@ void fill_list(char line[], t_fillist *list)
i++;
list->height = i;
list->tetribit = reduce_tetri(list->tetribit, list->width);
list->test = 0; // DEBUG pour que print_final_map puisse imprimer correctement au fur et a mesure
list->same = NULL;
list->test = 0;
}
/*
@@ -97,7 +100,7 @@ void fill_list(char line[], t_fillist *list)
** linked each time needed
*/
int add_to_list(char *line, t_fillist **list, char letter)
int add_to_list(char *line, t_fillist **lst, char letter, int *dope)
{
t_fillist *tmp;
t_fillist *test;
@@ -105,17 +108,19 @@ int add_to_list(char *line, t_fillist **list, char letter)
if (!(tmp = (t_fillist*)malloc(sizeof(*tmp))))
return (0);
tmp->next = NULL;
test = *list;
test = *lst;
if (!test)
*list = tmp;
*lst = tmp;
else
{
while(test->next)
while (test->next)
test = test->next;
test->next = tmp;
}
fill_list(line, tmp);
tmp->letter = letter;
tmp->dope = dope;
tmp->start = *lst;
return (1);
}
@@ -123,12 +128,13 @@ int add_to_list(char *line, t_fillist **list, char letter)
** Function that parse a file and put each tetrimino in a linked list
*/
int parse_input(char *input, t_fillist **list)
int parse_input(char *input, t_fillist **list, int *dope)
{
char tetri[20];
int i;
int j;
int letter;
int size;
i = 0;
letter = 'A';
@@ -138,12 +144,15 @@ int parse_input(char *input, t_fillist **list)
while (j < 19)
tetri[j++] = input[i++];
tetri[19] = '\0';
// "wrong tetrimino" utile ?
if (check_tetri_errors(tetri))
print_error("error\n");
add_to_list(tetri, list, letter++);
// print_error("error\n");
// print_error("error: Wrong tetrimino.\n");
print_error_extended(check_tetri_errors(tetri), dope);
add_to_list(tetri, list, letter++, dope);
while (input[i] && input[i] != '.' && input[i] != '#')
i++;
}
int size = search_map(*list);
size = search_map(*list);
return (size);
}

View File

@@ -6,37 +6,18 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */
/* Updated: 2019/05/17 17:24:54 by hulamy ### ########.fr */
/* Updated: 2019/05/27 19:47:11 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** DELETE BEFORE EVAL - TEST FUNCTION
** Prints a ligne of size bits
** function that print a map of height and width
** usefull to print tetris
*/
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, char letter)
void print_sized_map(unsigned int *tab, int width, int height, char letter)
{
int i;
unsigned int mask;
@@ -50,7 +31,10 @@ void print_map(unsigned int *tab, int width, int height, char letter)
{
if (i && !(i % width))
ft_putchar('\n');
tab[i / 32] & (1 << (31 - i % 32)) ? ft_put_tetri_color(letter) : ft_putchar('.');
if (tab[i / 32] & (1 << (31 - i % 32)))
ft_put_tetri_color(letter);
else
ft_putchar('.');
ft_putchar(' ');
i++;
}
@@ -59,42 +43,56 @@ void print_map(unsigned int *tab, int width, int height, char letter)
/*
** Print the final map with the letters
** if flag value is 0 -> print moulinette version
** if flag value is 0 -> print in color
*/
void print_final_map(t_fillist *list, int size, int flag) // DEBUG flag vaut 0 pour imprimer comme rendu et 1 pour imprimer en couleur
char *init_print_map(t_fillist *list, int size)
{
t_fillist *tmp;
char *map;
int i;
int j;
map = (char *)malloc(sizeof(*map) * (size * size + 1));
map[size*size] = '\0';
map[size * size] = '\0';
i = -1;
while (++i < size * size)
map[i] = '.';
tmp = list;
while (tmp)
while (list)
{
j = 0;
i = -1;
while (++i < tmp->width * tmp->height)
while (++i < list->width * list->height)
{
if (i && i % tmp->width == 0)
j += size - tmp->width;
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;
if (i && i % list->width == 0)
j += size - list->width;
if (1 << (15 - i) & list->tetribit && list->test == 1)
map[list->position + i + j - 1] = list->letter;
}
tmp = tmp->next;
list = list->next;
}
return (map);
}
/*
** Function that print the map with color if flag = 1
** or for moulinette if flag = 0;
*/
void print_letter_map(t_fillist *list, int size, int flag)
{
int i;
char *map;
map = init_print_map(list, size);
i = -1;
while (++i < size * size)
{
if (i && i % size == 0)
ft_putchar('\n');
if (flag == 0) // DEBUG imprim comme rendu
if (flag == 0)
ft_putchar(map[i]);
else // DEBUG imprim avec couleurs
else
{
ft_put_tetri_color(map[i]);
ft_putchar(' ');
@@ -102,3 +100,21 @@ void print_final_map(t_fillist *list, int size, int flag) // DEBUG flag vaut 0 p
}
ft_putchar('\n');
}
/*
** Function that print the map
*/
void print_final_map(t_fillist *list, int size)
{
if (list->dope[2])
{
ft_putendl("result for humans :");
print_letter_map(list, size, 1);
ft_putchar('\n');
ft_putendl("result for moulinette :");
}
print_letter_map(list, size, 0);
if (list->dope[2])
ft_putchar('\n');
}

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
/* Updated: 2019/04/22 15:16:18 by vmanzoni ### ########.fr */
/* Updated: 2019/05/27 19:46:54 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,7 +26,7 @@ char *read_file(char *file)
if (((fd = open(file, O_RDONLY)) < 0) \
|| ((rv = read(fd, &buf, BUFF_SIZE)) < 0) \
|| !(result = malloc(sizeof(char) * rv)))
|| !(result = malloc(sizeof(char) * rv)))
return (NULL);
buf[rv] = '\0';
i = -1;

167
f_search_map.c Normal file
View File

@@ -0,0 +1,167 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* search_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
/* Updated: 2019/05/28 11:56:18 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** function that look if a tretri fit in a place
*/
unsigned int fit_in_place(unsigned int *map, t_fillist *lst, int size, int i)
{
unsigned int tmp;
unsigned int mask;
unsigned int tetri;
int n;
int r;
n = lst->num;
r = lst->rank;
i = lst->height;
tetri = lst->tetribit << 16 >> lst->width;
tmp = 0;
mask = ~0u << (32 - lst->width);
while (i--)
{
if (tmp & tetri)
return (0);
if (r >= 32 && ++n)
r -= 32;
tmp = (mask & (map[n] << r)) | (mask & (map[n + 1] >> (32 - r)));
tetri <<= lst->width;
r += size;
}
return (!(tmp & tetri));
}
/*
** function that look for the first place in the map for a tetri
*/
int find_place(unsigned int *map, t_fillist *list, int size)
{
int limit;
int pos;
pos = list->position;
list->place = pos % size;
list->rank = pos % 32;
list->num = pos / 32;
limit = (size - list->height + 1) * size;
while (pos < limit)
{
if (list->rank >= 32 && ++list->num)
list->rank -= 32;
if (list->place > size - list->width)
{
list->place = -1;
pos += list->width - 2;
list->rank += list->width - 2;
}
else if (fit_in_place(map, list, size, 0))
return ((list->position = pos + 1));
pos++;
list->place++;
list->rank++;
}
return (0);
}
/*
** function that add or remove a tetri on the map
*/
void add_remove(unsigned int *map, t_fillist *list, int size)
{
unsigned int mask;
unsigned short tetri;
int i;
int j;
tetri = list->tetribit;
mask = ~0u << (32 - list->width);
i = (list->height - 1) * list->width;
j = (list->height - 1) * size + list->position;
while (j >= list->position)
{
map[(j - 1) / 32] ^= (mask & tetri << (16 + i)) >> (j - 1);
if (map[(j - 1) / 32 + 1])
map[(j - 1) / 32 + 1] ^= (mask & tetri << (16 + i)) << (32 - j) << 1;
j -= size;
i -= list->width;
}
}
/*
** Function that recursively try to fill the map with the tetris
*/
int fill_map(unsigned int *map, t_fillist *list, int size)
{
if (!list)
return (1);
list->position = 0;
while (find_place(map, list, size))
{
add_remove(map, list, size);
list->test = 1;
if (list->dope[0])
{
print_letter_map(list->start, size, 1);
ft_putchar('\n');
}
if (list->dope[1])
if (check_tetri_memory(list, list->position))
if (fill_map(map, list->next, size))
return (1);
if (!list->dope[1])
if (fill_map(map, list->next, size))
return (1);
add_remove(map, list, size);
list->test = 0;
}
return (0);
}
/*
** function that send to "fill_map" a map of a certain size
** and increment its size untill it's solved
*/
int search_map(t_fillist *list)
{
t_fillist *tmp;
unsigned int *map;
int size;
int num;
int i;
size = 2;
num = 1;
tmp = print_tetri(list);
while ((tmp = tmp->next))
num++;
while (size * size < num * 4)
size++;
i = 0;
while (!i)
{
num = (size * size) / 32 + 1;
if (!(map = (unsigned int *)malloc(sizeof(*map) * num)))
return (0);
check_same_tetri(list, num);
while (num)
map[num--] = 0;
i = fill_map(map, list, size++);
}
return (print_binary_map(map, size, list->dope));
}

View 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>

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
/* Updated: 2019/05/20 15:18:43 by hulamy ### ########.fr */
/* Updated: 2019/05/28 12:15:39 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -44,8 +44,22 @@
/*
** STRUCTURE
** tetribit : tetri ecrit en binaire dans un short de 16 bits
** width : largeur du tetri
** height : hauteur du tetri
** position : memorise la position d tetri bit a bit
** place : position sur l'axe des abscisses de la map (position % size)
** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32)
** num : memorise dans quel int du tableau on se trouve (position / 32)
** total_num : le nombre d'int dans le tableau d'int
** test :
** letter :
** dope :
** memory :
** same :
** next :
** start :
*/
typedef struct s_fillist
{
unsigned short tetribit;
@@ -57,15 +71,75 @@ typedef struct s_fillist
int num;
int test;
char letter;
int *dope;
unsigned int *memory;
struct s_fillist *same;
struct s_fillist *next;
struct s_fillist *start;
} t_fillist;
/*
** FUNCTIONS
** bonus_print.c
*/
t_fillist *print_tetri(t_fillist *list);
int print_binary_map(unsigned int *map, int size, int *dope);
int print_flags_usage(void);
/*
** bonus_opti.c
*/
int check_same_tetri(t_fillist *list, int num);
int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b);
int check_tetri_memory(t_fillist *list, int pos);
/*
** main.c
*/
int main(int argc, char **argv);
int *create_dope(char *av, int mdp);
int is_mdp(int ac, char **av);
/*
** read_file.c
*/
char *read_file(char *file);
/*
** handle_errors.c
*/
void print_error(char *s);
void print_error_extended(int error, int *dope);
void check_file_errors(char *file, int *dope);
int check_tetri_errors(char *tetri);
int check_tetri_errors_proxy(char *tetri);
/*
** parse_input.c
*/
int parse_input(char *input, t_fillist **list, int *dope);
int add_to_list(char *sqr, t_fillist **lst, char lett, int *dope);
void fill_list(char line[], t_fillist *list);
unsigned short reduce_tetri(unsigned short tetri, int width);
unsigned short tab_to_bin(char line[]);
/*
** search_map.c
*/
unsigned int fit_in_place(unsigned int *map, t_fillist *lst, int siz, int i);
int find_place(unsigned int *map, t_fillist *list, int size);
void add_remove(unsigned int *map, t_fillist *list, int size);
int fill_map(unsigned int *map, t_fillist *list, int size);
int search_map(t_fillist *list);
/*
** print.c
*/
void print_sized_map(unsigned int *tab, int width, int height, char letter);
char *init_print_map(t_fillist *list, int size);
void print_letter_map(t_fillist *list, int size, int flag);
void print_final_map(t_fillist *list, int size);
<<<<<<< HEAD
char *read_file(char *file);
void print_error(char *s);
void print_error_extended(int error);
@@ -80,6 +154,8 @@ void print_tetri(unsigned int bits, int size);
int search_map(t_fillist *list);
void print_map(unsigned int *tab, int width, int height, char letter);
void print_final_map(t_fillist *list, int size, int flag);
=======
>>>>>>> master
void ft_put_tetri_color(char c);
#endif

82
main.c
View File

@@ -6,21 +6,87 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
<<<<<<< HEAD
/* Updated: 2019/05/20 13:41:00 by vmanzoni ### ########.fr */
=======
/* Updated: 2019/05/27 18:21:58 by hulamy ### ########.fr */
>>>>>>> master
/* */
/* ************************************************************************** */
#include "fillit.h"
int main(int argc, char **argv)
/*
** function that put the flags for bonus into a tab of int
**
** d : debug print (print the map during the backtracking)
** o : optimisation ultra fast but with some errors still
** p : print extended (print the tetri and the map in different formats)
** e : error extended (error message more precise AND no error for too much tetri)
*/
int *create_dope(char *av, int mdp)
{
char *comp;
int *dope;
int i;
int j;
comp = "dope";
if (!(dope = (int*)malloc(sizeof(*dope) * 4)))
return (NULL);
i = 0;
while (i < 4)
dope[i++] = 0;
if (!mdp)
return (dope);
i = -1;
while (++i < 4 && (j = -1))
while (av[++j])
if (comp[i] == av[j])
dope[i] = 1;
return (dope);
}
/*
** function that check if the password is good to unlock the flags
*/
int is_mdp(int ac, char **av)
{
char *mdp;
int i;
if (ac < 3 || ac > 4)
return (0);
mdp = "trompette";
i = 0;
while (av[2][i] && mdp[i] && mdp[i] == av[2][i])
i++;
if (av[2][i] || mdp[i])
return (0);
if (ac == 3)
return (print_flags_usage());
return (1);
}
/*
** main function
*/
int main(int ac, char **av)
{
t_fillist *list;
char *input;
int *dope;
int size;
int mdp;
list = NULL;
if (argc == 2)
dope = create_dope(av[3], (mdp = is_mdp(ac, av)));
if (ac == 2 || mdp)
{
<<<<<<< HEAD
if (!(input = read_file(argv[1])))
print_error("error\n");
if (check_file_errors(input))
@@ -29,6 +95,18 @@ int main(int argc, char **argv)
ft_putnbrendl(size);
print_final_map(list, size, 1); // DEBUG
print_final_map(list, size, 0); // DEBUG
=======
if (!(input = read_file(av[1])))
{
if (dope[3])
print_error("error: Could not read file.\n");
else
print_error("error\n");
}
check_file_errors(input, dope);
size = parse_input(input, &list, dope);
print_final_map(list, size);
>>>>>>> master
}
else
print_error("usage: Please submit a file.\n> ./fillit file.fillit\n");

89
samples/debug/jdugoudr Normal file
View File

@@ -0,0 +1,89 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr1 Normal file
View File

@@ -0,0 +1,84 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr10 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr11 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr12 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr13 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr14 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr15 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr16 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr17 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
....
###.
#...
....

79
samples/debug/jdugoudr18 Normal file
View File

@@ -0,0 +1,79 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#

View File

@@ -0,0 +1,79 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#

View File

@@ -0,0 +1,74 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....

View File

@@ -0,0 +1,69 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....

View File

@@ -0,0 +1,64 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....

View File

@@ -0,0 +1,59 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,54 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....

View File

@@ -0,0 +1,49 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#

View File

@@ -0,0 +1,44 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
....
###.
#...
....

View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....

79
samples/debug/jdugoudr1_2 Normal file
View File

@@ -0,0 +1,79 @@
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,74 @@
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,69 @@
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,64 @@
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,59 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,54 @@
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,49 @@
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,44 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

View File

@@ -0,0 +1,39 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

79
samples/debug/jdugoudr1_3 Normal file
View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

79
samples/debug/jdugoudr1_4 Normal file
View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

79
samples/debug/jdugoudr1_5 Normal file
View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

79
samples/debug/jdugoudr1_6 Normal file
View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

79
samples/debug/jdugoudr1_7 Normal file
View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

79
samples/debug/jdugoudr1_8 Normal file
View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

79
samples/debug/jdugoudr1_9 Normal file
View File

@@ -0,0 +1,79 @@
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr2 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr3 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr4 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr5 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr6 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr7 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
#...
##..
.#..
....
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr8 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
....
###.
#...
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

84
samples/debug/jdugoudr9 Normal file
View File

@@ -0,0 +1,84 @@
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....
####
....
....
....
.##.
##..
....
....
##..
.##.
....
....
...#
...#
...#
...#
#...
##..
.#..
....
....
###.
#...
....

99
samples/map_slack Normal file
View File

@@ -0,0 +1,99 @@
...#
...#
..##
....
#...
###.
....
....
.#..
.#..
##..
....
...#
...#
..##
....
...#
...#
..##
....
#...
###.
....
....
.#..
.#..
##..
....
...#
...#
..##
....
...#
...#
..##
....
#...
###.
....
....
.#..
.#..
##..
....
...#
...#
..##
....
...#
...#
..##
....
#...
###.
....
....
.#..
.#..
##..
....
...#
...#
..##
....
...#
...#
..##
....
#...
###.
....
....
.#..
.#..
##..
....
...#
...#
..##
....

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
/* Updated: 2019/05/20 15:41:59 by hulamy ### ########.fr */
/* Updated: 2019/05/24 14:41:08 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -215,27 +215,43 @@ int check_tetri_memory(t_fillist *list, int pos)
tetri = list;
mask = 1 << ((pos % 32) - 1);
if (tetri->same != NULL)
if (tetri->same)
{
if (!(tetri->same->memory[pos / 32] & mask))
{
tetri->same->memory[pos / 32] |= mask;
return (1);
}
return (tetri->same->memory[pos / 32] |= mask);
}
else
{
tetri->memory[pos / 32] |= mask;
return (1);
// if (!(tetri->memory[pos / 32] & mask))
return (tetri->memory[pos / 32] |= mask);
}
return (0);
}
void remove_tetri_memory(t_fillist *list, int pos)
{
t_fillist *tetri;
unsigned int mask;
tetri = list;
mask = 1 << ((pos % 32) - 1);
if (tetri->same != NULL)
{
if ((tetri->same->memory[pos / 32] & mask))
tetri->same->memory[pos / 32] ^= mask;
}
else
{
if ((tetri->memory[pos / 32] & mask))
tetri->memory[pos / 32] ^= mask;
}
}
/*
** Function that recursively try to fill the map with the tetris
*/
int fill_map(unsigned int *map, t_fillist *list, int size)
int fill_map(unsigned int *map, t_fillist *list, int size, t_fillist *link)
{
if (!list)
return (1);
@@ -243,10 +259,19 @@ int fill_map(unsigned int *map, t_fillist *list, int size)
while (find_place(map, list, size))
{
add_remove(map, list, size);
if (check_tetri_memory(list, list->position))
if (fill_map(map, list->next, size))
list->test = 1; // DEBUG
// print_final_map(link, size, 1); // DEBUG
// ft_putchar('\n'); // DEBUG
// if (check_tetri_memory(list, list->position))
if (fill_map(map, list->next, size, link))
return (1);
add_remove(map, list, size);
// remove_tetri_memory(list, list->position);
list->test = 0; // DEBUG
}
return (0);
}
@@ -279,7 +304,6 @@ int check_same_tetri(t_fillist *list, int num)
curr_tetri = list;
while (curr_tetri != NULL)
{
curr_tetri->same = NULL;
i = 0;
if (!(curr_tetri->memory = (unsigned int *)malloc(sizeof(*curr_tetri->memory) * num)))
return (0);
@@ -316,9 +340,18 @@ int search_map(t_fillist *list)
while (tmp)
{
// imression pour tests
check_same_tetri(list, 1);
print = tmp->tetribit;
print <<= 16;
print_map(&print, tmp->width, tmp->height, tmp->letter);
if (tmp->same)
{
print = tmp->same->tetribit;
print <<= 16;
ft_putstr("same --> ");
ft_putchar(tmp->same->letter);
ft_putchar('\n');
}
ft_putchar('\n');
tmp = tmp->next;
}
@@ -334,14 +367,16 @@ int search_map(t_fillist *list)
i = 0;
while (!i)
{
ft_putnbrendl(size);
num = (size * size) / 32 + 1;
if (!(map = (unsigned int *)malloc(sizeof(*map) * num)))
return (0);
check_same_tetri(list, num);
while (num)
map[num--] = 0;
i = fill_map(map, list, size++);
i = fill_map(map, list, size++, list);
}
ft_putendl("result in binary :"); // DEBUG (pas dans le main car besoin de map)
print_map(map, size - 1, size - 1, '#'); // DEBUG
return (--size);
}

BIN
testmap

Binary file not shown.