conflict solved
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -5,3 +5,11 @@ objs/
|
|||||||
a\.out\.dSYM/
|
a\.out\.dSYM/
|
||||||
|
|
||||||
a\.out
|
a\.out
|
||||||
|
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
*.swp
|
||||||
|
|
||||||
|
fillit
|
||||||
|
|
||||||
|
test_fillit\.c
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
BIN
.test_mask.c.swp
BIN
.test_mask.c.swp
Binary file not shown.
10
Makefile
10
Makefile
@@ -6,22 +6,24 @@
|
|||||||
# By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ #
|
# By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# #
|
# Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# #
|
||||||
# Updated: 2019/04/18 12:27:12 by vmanzoni ### ########.fr #
|
# Updated: 2019/04/23 15:16:05 by vmanzoni ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
NAME = fillit
|
NAME = fillit
|
||||||
|
|
||||||
OBJ_DIR = objs./
|
OBJ_DIR = ./objs
|
||||||
HEADER = fillit.h
|
HEADER = fillit.h
|
||||||
|
|
||||||
SRCS = main.c \
|
SRCS = main.c \
|
||||||
read_file.c \
|
read_file.c \
|
||||||
handle_errors.c \
|
handle_errors.c \
|
||||||
parse_input.c \
|
parse_input.c \
|
||||||
get_smallest_square.c \
|
add_to_list.c \
|
||||||
|
# get_smallest_square.c \
|
||||||
print_fillit.c
|
print_fillit.c
|
||||||
|
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
LIB = libft/
|
LIB = libft/
|
||||||
|
|
||||||
@@ -33,7 +35,7 @@ RM = rm -rf
|
|||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
$(NAME):
|
$(NAME):
|
||||||
make -C libft/
|
make -C $(LIB)
|
||||||
$(CC) $(CFLAGS) -I$(HEADER) -c $(SRCS)
|
$(CC) $(CFLAGS) -I$(HEADER) -c $(SRCS)
|
||||||
$(CC) -o $(NAME) $(OBJS) -L $(LIB) -lft
|
$(CC) -o $(NAME) $(OBJS) -L $(LIB) -lft
|
||||||
mkdir $(OBJ_DIR)
|
mkdir $(OBJ_DIR)
|
||||||
|
|||||||
@@ -6,16 +6,17 @@
|
|||||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
|
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/04/22 15:10:14 by hulamy ### ########.fr */
|
/* Updated: 2019/04/24 12:15:47 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "libft/includes/libft.h"
|
//#include "libft/includes/libft.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** this function prints a 16 bites short
|
** DELETE BEFORE EVAL - TEST FUNCTION
|
||||||
|
** Function that prints a 16 bites short
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void print_bits(short line)
|
void print_bits(short line)
|
||||||
@@ -24,45 +25,44 @@ void print_bits(short line)
|
|||||||
|
|
||||||
mask = 1 << 27;
|
mask = 1 << 27;
|
||||||
while (mask >>= 1)
|
while (mask >>= 1)
|
||||||
(line & mask) ? ft_putnbr(1) : ft_putnbr(0);
|
(line & mask) ? write(1, "1", 1) : write(1, "0", 1);
|
||||||
ft_putchar('\n');
|
write(1, "\n", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** this function transforme a tetrminos char* into a short of 16 bites
|
** Function that transforme a tetrminos char* into a short of 16 bites
|
||||||
** then it fills it and its reverse into the list
|
** then it fills it and its reverse into the list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int fill_list(char *line, t_fillist *list)
|
int fill_list(char line[], t_fillist *list)
|
||||||
{
|
{
|
||||||
short tmp;
|
// short tmp;
|
||||||
int test;
|
int i;
|
||||||
|
|
||||||
while (*line)
|
i = 0;
|
||||||
|
while (line[i])
|
||||||
{
|
{
|
||||||
list->tetribit <<= 1;
|
list->tetribit <<= 1;
|
||||||
if (*line == '\n')
|
if (line[i] == '\n')
|
||||||
line++;
|
i++;
|
||||||
if (*(line++) == '#')
|
if (line[i++] == '#')
|
||||||
list->tetribit |= 1;
|
list->tetribit |= 1;
|
||||||
}
|
}
|
||||||
tmp = list->tetribit;
|
// tmp = list->tetribit;
|
||||||
while (tmp)
|
// while (tmp)
|
||||||
{
|
// {
|
||||||
if (tmp & 1)
|
// if (tmp & 1)
|
||||||
list->tibirtet |= 1;
|
// list->tibirtet |= 1;
|
||||||
list->tibirtet <<= 1;
|
// list->tibirtet <<= 1;
|
||||||
tmp >>= 1;
|
// tmp >>= 1;
|
||||||
}
|
// }
|
||||||
test = list->tibirtet;
|
print_bits(list->tetribit);
|
||||||
print_bits(test);
|
|
||||||
while (test <<= 1)
|
|
||||||
print_bits(test);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** this function create the linked list and add a new structure linked each time needed
|
** Function that create the linked list and add a new structure
|
||||||
|
** linked each time needed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int add_to_list(char *line, t_fillist **list)
|
int add_to_list(char *line, t_fillist **list)
|
||||||
@@ -80,6 +80,11 @@ int add_to_list(char *line, t_fillist **list)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** DELETE BEFORE EVAL - TEST FUNCTION
|
||||||
|
** Print octet
|
||||||
|
*/
|
||||||
|
|
||||||
void print_test(int octet)
|
void print_test(int octet)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
@@ -92,6 +97,11 @@ void print_test(int octet)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** DELETE BEFORE EVAL - TEST FUNCTION
|
||||||
|
** Test for big map
|
||||||
|
*/
|
||||||
|
|
||||||
void test(unsigned int map[])
|
void test(unsigned int map[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -121,6 +131,11 @@ void test(unsigned int map[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** DELETE BEFORE EVAL - MAIN FOR TEST
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
static t_fillist *list = NULL; // avant d'appeller add_to_list il faut declarer un pointeur static vers la structure
|
static t_fillist *list = NULL; // avant d'appeller add_to_list il faut declarer un pointeur static vers la structure
|
||||||
@@ -142,4 +157,4 @@ int main(int ac, char **av)
|
|||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|||||||
11
fillit.h
11
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/04/19 14:52:10 by hulamy ### ########.fr */
|
/* Updated: 2019/04/23 16:19:19 by vmanzoni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -16,11 +16,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h> // for system call write
|
#include <unistd.h> // for system call write
|
||||||
#include <fcntl.h> // for system call open
|
#include <fcntl.h> // for system call open
|
||||||
#include <string.h> // for memmove and strlen
|
#include <stdio.h> // for printf (DELETE BEFORE EVAL)
|
||||||
#include <stdio.h> // for debug printf
|
|
||||||
#include <stdbool.h> // to use bool type
|
|
||||||
|
|
||||||
# define BUFF_SIZE 1024
|
#include "libft/includes/libft.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** STRUCTURE
|
** STRUCTURE
|
||||||
@@ -43,7 +41,8 @@ void print_error(char *s);
|
|||||||
void parse_input(char *input);
|
void parse_input(char *input);
|
||||||
int check_file_errors(char *file);
|
int check_file_errors(char *file);
|
||||||
int check_tetri_errors(char *tetri);
|
int check_tetri_errors(char *tetri);
|
||||||
int check_tetri_errors2(char *tetri);
|
int check_tetri_errors_proxy(char *tetri);
|
||||||
int add_to_list(char *square, t_fillist **list);
|
int add_to_list(char *square, t_fillist **list);
|
||||||
|
int fill_list(char *line, t_fillist *list);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,15 +6,43 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/12 22:29:45 by vmanzoni #+# #+# */
|
/* Created: 2019/04/12 22:29:45 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/04/14 21:37:19 by vmanzoni ### ########.fr */
|
/* Updated: 2019/04/23 21:42:35 by vmanzoni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
char *get_smallest_square()
|
** Function that initialize a int map equivalent to a square size*size
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
unsigned int *initialize_map(int size)
|
||||||
|
{
|
||||||
|
unsigned int *map[0];
|
||||||
|
|
||||||
|
while (size--)
|
||||||
|
map[size] = 0;
|
||||||
|
return (map);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that bruteforce with backtracking for smallest square
|
||||||
|
*/
|
||||||
|
|
||||||
|
int *get_smallest_square(t_fillist list, int size, unsigned int map[])
|
||||||
|
{
|
||||||
|
unsigned int mask;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
mask = map[size];
|
||||||
|
while (list.tetribit != NULL)
|
||||||
|
{
|
||||||
|
mask = (mask >> 1) | (((1 << (i % 32)) & map[j]) << (31 - (i % 32)));
|
||||||
|
if (!(tetri & mask))
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
|
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/04/15 14:41:19 by vmanzoni ### ########.fr */
|
/* Updated: 2019/04/23 14:05:16 by vmanzoni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ int check_tetri_errors(char *tetri)
|
|||||||
dot++;
|
dot++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (htg != 4 || dot != 12 || check_tetri_errors2(tetri))
|
if (htg != 4 || dot != 12 || check_tetri_errors_proxy(tetri))
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ int check_tetri_errors(char *tetri)
|
|||||||
** Function that check if tetrimino parts are linked
|
** Function that check if tetrimino parts are linked
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int check_tetri_errors2(char *tetri)
|
int check_tetri_errors_proxy(char *tetri)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|||||||
2
main.c
2
main.c
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
|
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/04/16 16:41:28 by vmanzoni ### ########.fr */
|
/* Updated: 2019/04/23 21:39:42 by vmanzoni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@@ -6,29 +6,49 @@
|
|||||||
/* 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/04/18 16:09:24 by vmanzoni ### ########.fr */
|
/* Updated: 2019/04/23 21:23:47 by vmanzoni ### ########.fr */
|
||||||
/* Updated: 2019/04/19 12:53:40 by hulamy ### ########.fr */
|
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** !!! DELETE PRINT_BITS BEFORE EVAL !!!
|
** Function that parse a file and put each tetrimino in a linked list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void print_bits(short octet)
|
void parse_input(char *input)
|
||||||
{
|
{
|
||||||
|
static t_fillist *list = NULL;
|
||||||
|
char tetri[20];
|
||||||
int i;
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
i = 1 << 16;
|
i = 0;
|
||||||
while (i >>= 1)
|
printf("%s", input);
|
||||||
(octet & i) ? write(1, "1", 1) : write(1, "0", 1);
|
while (input[i])
|
||||||
printf("\n");
|
{
|
||||||
|
j = 0;
|
||||||
|
while (j < 19)
|
||||||
|
tetri[j++] = input[i++];
|
||||||
|
tetri[19] = '\0';
|
||||||
|
if (check_tetri_errors(tetri))
|
||||||
|
print_error("Error: Tetrimino not valid.");
|
||||||
|
add_to_list(tetri, &list);
|
||||||
|
printf("added to list !!\n");
|
||||||
|
while (input[i] && input[i] != '.' && input[i] != '#')
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
/*DEBUG PART - Print each tetribit*/
|
||||||
|
// while (list != NULL)
|
||||||
|
// {
|
||||||
|
// printf("%i\n", list->tetribit);
|
||||||
|
// printf("\n");
|
||||||
|
// list = list->next;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
** DELETE BEFORE EVAL - NOT USED ANYMORE
|
||||||
** Function that parse a file and put each tetrimino in a linked list
|
** Function that parse a file and put each tetrimino in a linked list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -55,63 +75,3 @@ char **create_square(char *tetri)
|
|||||||
}
|
}
|
||||||
return (square);
|
return (square);
|
||||||
}
|
}
|
||||||
|
|
||||||
short create_tetribit(char *tetri)
|
|
||||||
{
|
|
||||||
short tetribit;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
tetribit = 0;
|
|
||||||
while (tetri[i])
|
|
||||||
{
|
|
||||||
if (tetri[i] != '\n') // Pour comparer avec le tetri en char
|
|
||||||
printf("%c", tetri[i]);
|
|
||||||
if (tetri[i] == '#')
|
|
||||||
tetribit = tetribit | 1;
|
|
||||||
else
|
|
||||||
tetribit <<= 1;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (tetribit);
|
|
||||||
}
|
|
||||||
|
|
||||||
void parse_input(char *input)
|
|
||||||
{
|
|
||||||
static t_fillist *list = NULL;
|
|
||||||
char tetri[20];
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
short test; //DELETE BEFORE EVAL
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
printf("input: %s\n", input);
|
|
||||||
printf("end\n");
|
|
||||||
while (input[i])
|
|
||||||
{
|
|
||||||
j = 0;
|
|
||||||
while (j < 19)
|
|
||||||
tetri[j++] = input[i++];
|
|
||||||
tetri[19] = '\0';
|
|
||||||
if (check_tetri_errors(tetri))
|
|
||||||
print_error("Error: Tetrimino not valid.");
|
|
||||||
test = create_tetribit(tetri);
|
|
||||||
printf("\n");
|
|
||||||
print_bits(test);
|
|
||||||
//test = create_square(tetri);
|
|
||||||
//add_to_list(test, &list);
|
|
||||||
while (input[i] == '\n')
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
** ce qui suit sert juste a afficher le contenu de tous les tetraminos de la liste chainee
|
|
||||||
** pour debug, a effacer au rendu
|
|
||||||
*/
|
|
||||||
while (list && (i = -1))
|
|
||||||
{
|
|
||||||
while (++i < list->size[1])
|
|
||||||
printf("%s\n", list->tetraminos[i]);
|
|
||||||
printf("\n");
|
|
||||||
list = list->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
|
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/04/19 12:50:32 by hulamy ### ########.fr */
|
/* Updated: 2019/04/22 15:16:18 by vmanzoni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -29,12 +29,9 @@ char *read_file(char *file)
|
|||||||
|| !(result = malloc(sizeof(char) * rv)))
|
|| !(result = malloc(sizeof(char) * rv)))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
buf[rv] = '\0';
|
buf[rv] = '\0';
|
||||||
i = 0;
|
i = -1;
|
||||||
while (buf[i])
|
while (buf[++i])
|
||||||
{
|
|
||||||
result[i] = buf[i];
|
result[i] = buf[i];
|
||||||
i++;
|
|
||||||
}
|
|
||||||
result[i] = '\0';
|
result[i] = '\0';
|
||||||
close(fd);
|
close(fd);
|
||||||
return (result);
|
return (result);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
...#
|
#...
|
||||||
...#
|
#...
|
||||||
...#
|
#...
|
||||||
...#
|
#...
|
||||||
|
|||||||
9
samples/2tetri
Normal file
9
samples/2tetri
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
....
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
14
samples/3tetri
Normal file
14
samples/3tetri
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
....
|
||||||
|
##..
|
||||||
|
.##.
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
###.
|
||||||
|
.#..
|
||||||
|
....
|
||||||
19
samples/4tetri
Normal file
19
samples/4tetri
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
|
...#
|
||||||
@@ -111,4 +111,4 @@
|
|||||||
....
|
....
|
||||||
....
|
....
|
||||||
####
|
####
|
||||||
....iskjdslkfsljklfdjk
|
....i
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
#...
|
||||||
|
###.
|
||||||
....
|
....
|
||||||
....
|
....
|
||||||
....
|
|
||||||
####
|
|
||||||
@@ -98,13 +98,8 @@ int main()
|
|||||||
unsigned int map[10] = {1568713153, 817645681, 654186132, 538171355, 1718453135, 551286515, 1631843343, 3413834313, 1155555555, 999999999};
|
unsigned int map[10] = {1568713153, 817645681, 654186132, 538171355, 1718453135, 551286515, 1631843343, 3413834313, 1155555555, 999999999};
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = -1;
|
//while (i < 10)
|
||||||
while (++i < 10)
|
// printf("%d\n", map[i++]);
|
||||||
{
|
|
||||||
print_bits(map[i]);
|
|
||||||
printf(" ");
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
test(map);
|
test(map);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
272
test_fillit.c
Normal file
272
test_fillit.c
Normal file
@@ -0,0 +1,272 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* test_fillit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/04/22 16:05:59 by vmanzoni #+# #+# */
|
||||||
|
/* Updated: 2019/04/23 13:57:22 by vmanzoni ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h> // for system call write
|
||||||
|
#include <fcntl.h> // for system call open
|
||||||
|
#include <string.h> // for memmove and strlen
|
||||||
|
#include <stdio.h> // for debug printf
|
||||||
|
#include <stdbool.h> // to use bool type
|
||||||
|
|
||||||
|
#include "libft/includes/libft.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** STRUCTURE
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct s_fillist
|
||||||
|
{
|
||||||
|
int tetribit;
|
||||||
|
int position;
|
||||||
|
struct s_fillist *next;
|
||||||
|
} t_fillist;
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that display error message *s on fd and exit program
|
||||||
|
*/
|
||||||
|
|
||||||
|
void print_error(char *s)
|
||||||
|
{
|
||||||
|
write(2, s, strlen(s));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that read file
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *read_file(char *file)
|
||||||
|
{
|
||||||
|
char buf[BUFF_SIZE];
|
||||||
|
int fd;
|
||||||
|
int rv;
|
||||||
|
int i;
|
||||||
|
char *result;
|
||||||
|
|
||||||
|
if (((fd = open(file, O_RDONLY)) < 0) \
|
||||||
|
|| ((rv = read(fd, &buf, BUFF_SIZE)) < 0) \
|
||||||
|
|| !(result = malloc(sizeof(char) * rv)))
|
||||||
|
return (NULL);
|
||||||
|
buf[rv] = '\0';
|
||||||
|
i = -1;
|
||||||
|
while (buf[++i])
|
||||||
|
result[i] = buf[i];
|
||||||
|
result[i] = '\0';
|
||||||
|
close(fd);
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function to see if there if an error if the file
|
||||||
|
** - less than 4 lines
|
||||||
|
** - more than 104 (26 tetri) + 25 (\n) = 129 lines
|
||||||
|
** - two \n in a row
|
||||||
|
*/
|
||||||
|
|
||||||
|
int check_file_errors(char *file)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int line_nbr;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
line_nbr = 0;
|
||||||
|
while (file[i])
|
||||||
|
{
|
||||||
|
if (file[i] != '.' && file[i] != '#' && file[i] != '\n')
|
||||||
|
return (1);
|
||||||
|
if (file[i] == '\n')
|
||||||
|
line_nbr++;
|
||||||
|
if (file[i] == '\n' && file[i+1] != '\0' && \
|
||||||
|
file[i+2] != '.' && file[i+2] != '#')
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (line_nbr < 4 || line_nbr > 129)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that check if tetrimino parts are linked
|
||||||
|
*/
|
||||||
|
|
||||||
|
int check_tetri_errors2(char *tetri)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (tetri[i])
|
||||||
|
{
|
||||||
|
if (tetri[i] == '.' || tetri[i] == '\n')
|
||||||
|
i++;
|
||||||
|
else if (tetri[i] == '#' && (tetri[i + 1] == '#' || tetri[i - 1] == '#'
|
||||||
|
|| tetri[i + 5] == '#' || tetri[i - 5] == '#'))
|
||||||
|
i++;
|
||||||
|
else
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that check if tetrimino square contains:
|
||||||
|
** - 4 '#'
|
||||||
|
** - 12 '.'
|
||||||
|
*/
|
||||||
|
|
||||||
|
int check_tetri_errors(char *tetri)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int htg;
|
||||||
|
int dot;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
htg = 0;
|
||||||
|
dot = 0;
|
||||||
|
while (tetri[i])
|
||||||
|
{
|
||||||
|
if (tetri[i] == '#')
|
||||||
|
htg++;
|
||||||
|
else if (tetri[i] == '.')
|
||||||
|
dot++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (htg != 4 || dot != 12 || check_tetri_errors2(tetri))
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that take char * tetri and convert to short and put it in a list
|
||||||
|
*/
|
||||||
|
|
||||||
|
int fill_list(char *line, t_fillist *list)
|
||||||
|
{
|
||||||
|
short tmp;
|
||||||
|
short tet;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
tet = 0;
|
||||||
|
while (line[++i])
|
||||||
|
{
|
||||||
|
tet <<= 1;
|
||||||
|
if (line[i] == '\n')
|
||||||
|
i++;
|
||||||
|
if (line[i] == '#')
|
||||||
|
tet |= 1;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** this function create the linked list and add a new structure linked each time needed
|
||||||
|
*/
|
||||||
|
|
||||||
|
int add_to_list(char *line, t_fillist **list)
|
||||||
|
{
|
||||||
|
t_fillist *tmp;
|
||||||
|
|
||||||
|
if (!(tmp = (t_fillist*)malloc(sizeof(*tmp))))
|
||||||
|
return (0);
|
||||||
|
if (!(*list))
|
||||||
|
tmp->next = NULL;
|
||||||
|
else
|
||||||
|
tmp->next = *list;
|
||||||
|
*list = tmp;
|
||||||
|
fill_list(line, *list);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that parse a file and put each tetrimino in a linked list
|
||||||
|
*/
|
||||||
|
|
||||||
|
int parse_input(char *input, t_fillist list)
|
||||||
|
{
|
||||||
|
//static t_fillist *list = NULL;
|
||||||
|
static int size;
|
||||||
|
char tetri[20];
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
size = 0;
|
||||||
|
while (input[i])
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (j < 19)
|
||||||
|
tetri[j++] = input[i++];
|
||||||
|
tetri[19] = '\0';
|
||||||
|
if (check_tetri_errors(tetri))
|
||||||
|
print_error("Error: Tetrimino not valid.");
|
||||||
|
add_to_list(tetri, &list);
|
||||||
|
while (input[i] == '\n')
|
||||||
|
i++;
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
printf("%i\n", size);
|
||||||
|
return (size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *****************************************************************************
|
||||||
|
** Function that brute force with backtracking for smallest square with tetris
|
||||||
|
***************************************************************************** */
|
||||||
|
|
||||||
|
int get_smallest_square(t_fillist list, int size, unsigned int map[])
|
||||||
|
{
|
||||||
|
unsigned int mask;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
mask = map[size];
|
||||||
|
while (list.next != NULL)
|
||||||
|
{
|
||||||
|
mask = (mask >> 1) | (((1 << (i % 32)) & map[j]) << (31 - (i % 32)));
|
||||||
|
if (!(list.tetribit & mask))
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *****************************************************************************
|
||||||
|
** MAIN
|
||||||
|
***************************************************************************** */
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *input;
|
||||||
|
int map;
|
||||||
|
int size;
|
||||||
|
t_fillist list;
|
||||||
|
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
if (!(input = read_file(argv[1])))
|
||||||
|
print_error("Error: Could not read file.\n");
|
||||||
|
if (check_file_errors(input))
|
||||||
|
print_error("Error: Invalid file.\n");
|
||||||
|
size = parse_input(input, list);
|
||||||
|
get_smallest_square(list, size, map);
|
||||||
|
/*
|
||||||
|
Backtracking for smallest square
|
||||||
|
Transform tetriminos with letters
|
||||||
|
Print result
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
print_error("Usage: Please submit a file.\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
50
test_mask.c
50
test_mask.c
@@ -40,16 +40,16 @@ void compare(int initial, int compare)
|
|||||||
!(initial & compare) ? ft_putendl("&: fit") : ft_putendl("&: not fit");
|
!(initial & compare) ? ft_putendl("&: fit") : ft_putendl("&: not fit");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// j = 1 << 12;
|
j = 1 << 12;
|
||||||
// while (j >>= 1)
|
while (j >>= 1)
|
||||||
// (initial | compare) & j ? ft_putnbr(1) : ft_putnbr(0);
|
(initial | compare) & j ? ft_putnbr(1) : ft_putnbr(0);
|
||||||
// ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
// (initial | compare) ? ft_putendl("|: fit") : ft_putendl("|: not fit");
|
(initial | compare) ? ft_putendl("|: fit") : ft_putendl("|: not fit");
|
||||||
// j = 1 << 12;
|
j = 1 << 12;
|
||||||
// while (j >>= 1)
|
while (j >>= 1)
|
||||||
// (initial ^ compare) & j ? ft_putnbr(1) : ft_putnbr(0);
|
(initial ^ compare) & j ? ft_putnbr(1) : ft_putnbr(0);
|
||||||
// ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
// (initial ^ compare) ? ft_putendl("^: fit") : ft_putendl("^: not fit");
|
(initial ^ compare) ? ft_putendl("^: fit") : ft_putendl("^: not fit");
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,19 +74,19 @@ int main(int ac, char **av)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
**{
|
{
|
||||||
** int init;
|
int init;
|
||||||
** int mask;
|
int mask;
|
||||||
**
|
|
||||||
** mask = (1 << 4);
|
mask = (1 << 4);
|
||||||
** if (ac == 4)
|
if (ac == 4)
|
||||||
** {
|
{
|
||||||
** ft_putendl(ft_convertbase(av[1], av[2], av[3]));
|
ft_putendl(ft_convertbase(av[1], av[2], av[3]));
|
||||||
** ft_putnbrendl(init);
|
ft_putnbrendl(init);
|
||||||
** init |= mask;
|
init |= mask;
|
||||||
** ft_putnbrendl(init);
|
ft_putnbrendl(init);
|
||||||
** }
|
}
|
||||||
** return (0);
|
return (0);
|
||||||
**}
|
}
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user