New samples added + First Try Optimisation
This commit is contained in:
13
fillit.h
13
fillit.h
@@ -6,7 +6,7 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/05/08 17:52:19 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/05/13 17:56:19 by vmanzoni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h> // for system call write
|
||||
#include <fcntl.h> // for system call open
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h> // for printf (DELETE BEFORE EVAL)
|
||||
|
||||
#include "libft/includes/libft.h"
|
||||
@@ -34,6 +35,14 @@
|
||||
#define CYN "\x1B[36m"
|
||||
#define RESET "\x1B[0m"
|
||||
|
||||
//#define RED "\e[41m"
|
||||
//#define GRN "\e[42m"
|
||||
//#define YEL "\e[43m"
|
||||
//#define BLU "\e[44m"
|
||||
//#define MAG "\e[45m"
|
||||
//#define CYN "\e[46m"
|
||||
//#define RESET "\e[49m"
|
||||
|
||||
/*
|
||||
** STRUCTURE
|
||||
*/
|
||||
@@ -45,6 +54,8 @@ typedef struct s_fillist
|
||||
int height;
|
||||
int position;
|
||||
char letter;
|
||||
uint64_t memory;
|
||||
struct s_fillist *same;
|
||||
struct s_fillist *next;
|
||||
} t_fillist;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/05/09 11:45:08 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/05/13 17:13:08 by vmanzoni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -67,6 +67,7 @@ void fill_list(char line[], t_fillist *list)
|
||||
|
||||
// transforme la ligne de . et # en un short de 0 et 1
|
||||
list->tetribit = tab_to_bin(line);
|
||||
list->memory = 0;
|
||||
// cree un mask avec des 1 sur la colonne de droite (#...#...#...#...)
|
||||
mask = (1 << 15) | (1 << 11) | (1 << 7) | (1 << 3);
|
||||
// utilise le mask pour trouver la largeur que prend le tetriminos
|
||||
|
||||
24
samples/5square
Normal file
24
samples/5square
Normal file
@@ -0,0 +1,24 @@
|
||||
##..
|
||||
##..
|
||||
....
|
||||
....
|
||||
|
||||
##..
|
||||
##..
|
||||
....
|
||||
....
|
||||
|
||||
##..
|
||||
##..
|
||||
....
|
||||
....
|
||||
|
||||
##..
|
||||
##..
|
||||
....
|
||||
....
|
||||
|
||||
##..
|
||||
##..
|
||||
....
|
||||
....
|
||||
@@ -38,11 +38,6 @@
|
||||
..##
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
#...
|
||||
###.
|
||||
....
|
||||
@@ -52,48 +47,3 @@
|
||||
.#..
|
||||
##..
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
#...
|
||||
###.
|
||||
....
|
||||
....
|
||||
|
||||
.#..
|
||||
.#..
|
||||
##..
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
#...
|
||||
###.
|
||||
....
|
||||
....
|
||||
|
||||
.#..
|
||||
.#..
|
||||
##..
|
||||
....
|
||||
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
....
|
||||
|
||||
14
samples/opti_test
Normal file
14
samples/opti_test
Normal file
@@ -0,0 +1,14 @@
|
||||
...#
|
||||
.###
|
||||
....
|
||||
....
|
||||
|
||||
....
|
||||
#...
|
||||
##..
|
||||
.#..
|
||||
|
||||
##..
|
||||
.##.
|
||||
....
|
||||
....
|
||||
19
samples/test_opti
Normal file
19
samples/test_opti
Normal file
@@ -0,0 +1,19 @@
|
||||
..#.
|
||||
..#.
|
||||
..##
|
||||
....
|
||||
|
||||
....
|
||||
.##.
|
||||
.##.
|
||||
....
|
||||
|
||||
..#.
|
||||
..#.
|
||||
..##
|
||||
....
|
||||
|
||||
..#.
|
||||
..#.
|
||||
..##
|
||||
....
|
||||
84
search_map.c
84
search_map.c
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
|
||||
/* Updated: 2019/05/08 19:38:23 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/05/13 18:24:56 by vmanzoni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -49,6 +49,7 @@ int find_place(unsigned int *tab, t_fillist *list, int size, int pos)
|
||||
return (i + 1);
|
||||
i++;
|
||||
}
|
||||
// print_final_map(list, size);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -80,12 +81,64 @@ void add_remove(unsigned int *map, t_fillist *list, int size, int pos)
|
||||
}
|
||||
|
||||
/*
|
||||
** function that recursively try to fill the map with the tetris
|
||||
** Test optimisation for not testing wrong maps when tetri are identical
|
||||
*/
|
||||
|
||||
int check_same_tetri(t_fillist *list)
|
||||
{
|
||||
t_fillist *curr_tetri;
|
||||
t_fillist *next_tetri;
|
||||
|
||||
curr_tetri = list;
|
||||
|
||||
while (curr_tetri != NULL)
|
||||
{
|
||||
next_tetri = curr_tetri->next;
|
||||
while (next_tetri != NULL)
|
||||
{
|
||||
if (curr_tetri->tetribit == next_tetri->tetribit)
|
||||
{
|
||||
if (next_tetri->same == NULL)
|
||||
next_tetri->same = curr_tetri;
|
||||
printf("%c->%c\n", next_tetri->letter, next_tetri->same->letter);
|
||||
}
|
||||
next_tetri = next_tetri->next;
|
||||
}
|
||||
curr_tetri = curr_tetri->next;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Test optimisation for not testing wrong maps when tetri are identical
|
||||
*/
|
||||
|
||||
int check_tetri_memory(t_fillist *list, int pos)
|
||||
{
|
||||
t_fillist *tetri;
|
||||
uint64_t mask;
|
||||
|
||||
tetri = list;
|
||||
if (tetri->same != NULL)
|
||||
{
|
||||
mask = 1 << (pos - 1);
|
||||
print_bits(mask, 64);
|
||||
if (tetri->same->memory & mask)
|
||||
{
|
||||
ft_putstr("test\n");
|
||||
return (pos + 1);
|
||||
}
|
||||
}
|
||||
return (pos);
|
||||
}
|
||||
|
||||
/*
|
||||
** 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 pos;
|
||||
int pos;
|
||||
|
||||
pos = 0;
|
||||
if (!list)
|
||||
@@ -93,16 +146,24 @@ int fill_map(unsigned int *map, t_fillist *list, int size, t_fillist *link) //
|
||||
// unsigned int tmp = list->tetribit << 16; print_map(&tmp, list->width, list->height, list->letter); // DEBUG
|
||||
while ((pos = find_place(map, list, size, pos)))
|
||||
{
|
||||
list->memory = (list->memory << 1) + 1;
|
||||
add_remove(map, list, size, pos);
|
||||
list->position = pos;
|
||||
// print_final_map(link, size); // DEBUG
|
||||
// ft_putnbrendl(pos);
|
||||
// print_map(map, size, size, '#'); // DEBUG
|
||||
// ft_putchar('\n');
|
||||
check_tetri_memory(list, pos);
|
||||
print_final_map(link, size); // DEBUG
|
||||
// ft_putnbrendl(pos);
|
||||
// print_map(map, size, size, '#'); // DEBUG
|
||||
ft_putchar('\n'); // DEBUG
|
||||
// if (list->same && list->position == 1)
|
||||
// {
|
||||
// list = list->next;
|
||||
// if (fill_map(map, list->next, size, link))
|
||||
// return (1);
|
||||
// }
|
||||
if (fill_map(map, list->next, size, link))
|
||||
return (1);
|
||||
add_remove(map, list, size, pos);
|
||||
// list->position = -1; // DEBUG
|
||||
list->position = -1; // DEBUG
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -155,12 +216,11 @@ void search_map(t_fillist *list)
|
||||
// imression pour tests
|
||||
print = tmp->tetribit;
|
||||
print <<= 16;
|
||||
// print_map(&print, tmp->width, tmp->height, tmp->letter); // test, imprime le tetri
|
||||
// ft_putchar('\n');
|
||||
print_map(&print, tmp->width, tmp->height, tmp->letter); // test, imprime le tetri
|
||||
ft_putchar('\n');
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
|
||||
check_same_tetri(list);
|
||||
// lance la recursive fill_map en augmentant la taille de la map tant qu'il n'y a pas de solution
|
||||
while (!fill_map(map, list, size, list))
|
||||
map = init_map(size++);
|
||||
|
||||
Reference in New Issue
Block a user