get new files from ykolomie
This commit is contained in:
commit
a5988fa2ca
15 changed files with 150 additions and 114 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -35,5 +35,11 @@
|
||||||
# Vim temp
|
# Vim temp
|
||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
CMakeLists.txt
|
||||||
|
.idea/
|
||||||
|
**/cmake-build-debug/*
|
||||||
|
=======
|
||||||
# Sublime files
|
# Sublime files
|
||||||
*.sublime*
|
*.sublime*
|
||||||
|
>>>>>>> github/develop
|
||||||
|
|
6
Makefile
6
Makefile
|
@ -6,7 +6,7 @@
|
||||||
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2016/12/14 16:54:48 by gtertysh #+# #+# #
|
# Created: 2016/12/14 16:54:48 by gtertysh #+# #+# #
|
||||||
# Updated: 2016/12/20 19:05:59 by gtertysh ### ########.fr #
|
# Updated: 2016/12/20 20:05:58 by ykolomie ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
@ -46,12 +46,14 @@ LIBFOLDER = ./libft/
|
||||||
|
|
||||||
FLAGS = -Werror -Wextra -Wall
|
FLAGS = -Werror -Wextra -Wall
|
||||||
|
|
||||||
|
STACK = -Wl,-stack_size -Wl,0x10000000000
|
||||||
|
|
||||||
CC = clang
|
CC = clang
|
||||||
|
|
||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
$(NAME): $(OBJ) $(LIBFOLDER)$(LIB)
|
$(NAME): $(OBJ) $(LIBFOLDER)$(LIB)
|
||||||
$(CC) $(FLAGS) $(OBJ) $(LIBFLAGS) -o $(NAME)
|
$(CC) $(FLAGS) $(STACK) $(OBJ) $(LIBFLAGS) -o $(NAME)
|
||||||
|
|
||||||
$(OBJDIR)%.o : $(SRCDIR)%.c
|
$(OBJDIR)%.o : $(SRCDIR)%.c
|
||||||
$(CC) $(FLAGS) $(INC) -c $< -o $@
|
$(CC) $(FLAGS) $(INC) -c $< -o $@
|
||||||
|
|
|
@ -12,67 +12,71 @@
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
|
|
||||||
// t_col *add_column(t_col *root)
|
t_node *add_column(t_node *root)
|
||||||
// {
|
{
|
||||||
// t_col *new_col;
|
t_node *new_col;
|
||||||
|
|
||||||
// new_col = (t_col*)malloc(sizeof(t_col));
|
new_col = (t_node*)malloc(sizeof(t_node));
|
||||||
// new_col->down = (void*)new_col;
|
new_col->down = new_col;
|
||||||
// new_col->up = (void*)new_col;
|
new_col->up = new_col;
|
||||||
// new_col->left = root->left;
|
new_col->left = root->left;
|
||||||
// new_col->right = root;
|
new_col->right = root;
|
||||||
// return (new_col);
|
new_col->row = -1;
|
||||||
// }
|
new_col->column = NULL;
|
||||||
|
return (new_col);
|
||||||
|
}
|
||||||
|
|
||||||
// t_node *add_node(t_col *col, int row)
|
t_node *add_node(t_node *col, int row)
|
||||||
// {
|
{
|
||||||
// t_node *new_node;
|
t_node *new_node;
|
||||||
|
|
||||||
// new_node = (t_node*)malloc(sizeof(t_node));
|
new_node = (t_node*)malloc(sizeof(t_node));
|
||||||
// new_node->row = row;
|
new_node->row = row;
|
||||||
// new_node->up = (t_node*)col->up;
|
new_node->up = col->up;
|
||||||
// new_node->down = (t_node*)col;
|
new_node->down = col;
|
||||||
// col->up->down = new_node;
|
col->up->down = new_node;
|
||||||
// col->up = new_node;
|
col->up = new_node;
|
||||||
// return (new_node);
|
return (new_node);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// void cover(t_col *to_cover)
|
void cover(t_col *to_cover)
|
||||||
// {
|
{
|
||||||
// void *step_vert;
|
void *step_vert;
|
||||||
// t_node *step_horiz;
|
t_node *step_horiz;
|
||||||
|
|
||||||
// to_cover->left->right = to_cover->right;
|
to_cover->left->right = to_cover->right;
|
||||||
// to_cover->right->left = to_cover->left;
|
to_cover->right->left = to_cover->left;
|
||||||
// step_vert = to_cover->down;
|
step_vert = to_cover->down;
|
||||||
// while (step_vert != (void*)to_cover)
|
while (step_vert != to_cover)
|
||||||
// {
|
{
|
||||||
// step_horiz = (t_node*)step_vert->right;
|
step_horiz = step_vert->right;
|
||||||
// while (step_horiz != (t_node*)step_vert) {
|
while (step_horiz != step_vert) {
|
||||||
// step_horiz->down->up = step_horiz->up;
|
step_horiz->down->up = step_horiz->up;
|
||||||
// step_horiz->up->down = step_horiz->down;
|
step_horiz->up->down = step_horiz->down;
|
||||||
// step_horiz = step_horiz->right;
|
step_horiz = step_horiz->right;
|
||||||
// }
|
}
|
||||||
// step_vert = (t_node*)step_vert->down;
|
step_vert = step_vert->down;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// void uncover(t_col *to_uncover)
|
void uncover(t_col *to_uncover)
|
||||||
// {
|
{
|
||||||
// void *step_vert;
|
void *step_vert;
|
||||||
// t_node *step_horiz;
|
t_node *step_horiz;
|
||||||
|
|
||||||
// step_vert = to_uncover->up;
|
step_vert = to_uncover->up;
|
||||||
// while (step_vert != (void*)to_uncover)
|
while (step_vert != to_uncover)
|
||||||
// {
|
{
|
||||||
// step_horiz = (t_node*)step_vert->left;
|
step_horiz = step_vert->left;
|
||||||
// while (step_horiz != (t_node*)step_vert)
|
while (step_horiz != step_vert)
|
||||||
// {
|
{
|
||||||
// step_horiz->down->up = step_horiz;
|
step_horiz->down->up = step_horiz;
|
||||||
// step_horiz->up->down = step_horiz;
|
step_horiz->up->down = step_horiz;
|
||||||
// step_horiz = step_horiz->left;
|
step_horiz = step_horiz->left;
|
||||||
// }
|
}
|
||||||
// step_vert = (t_node*)step_vert->up;
|
step_vert = step_vert->up;
|
||||||
// }
|
}
|
||||||
// }
|
to_uncover->left->right = to_uncover;
|
||||||
|
to_uncover->right->left = to_uncover;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
59
src/fillit.c
59
src/fillit.c
|
@ -1,4 +1,4 @@
|
||||||
#include "fillit.h"
|
#include "../inc/fillit.h"
|
||||||
|
|
||||||
unsigned int ft_sqrt_ceil(unsigned int num)
|
unsigned int ft_sqrt_ceil(unsigned int num)
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,7 @@ void convert_tetramino(char *s, t_map *map, int index)
|
||||||
int y;
|
int y;
|
||||||
int sharp_count;
|
int sharp_count;
|
||||||
|
|
||||||
map->figure[index]->offset_y = 0;
|
map->figure[index].offset_y = 0;
|
||||||
sharp_count = 0;
|
sharp_count = 0;
|
||||||
i = 0;
|
i = 0;
|
||||||
y = 1;
|
y = 1;
|
||||||
|
@ -41,10 +41,10 @@ void convert_tetramino(char *s, t_map *map, int index)
|
||||||
|
|
||||||
}
|
}
|
||||||
temp = temp << 12;
|
temp = temp << 12;
|
||||||
map->figure[index]->line[y - 1] = temp;
|
map->figure[index].line[y - 1] = temp;
|
||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
map->figure[index]->height = y - 1;
|
map->figure[index].height = y - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void map_initialization(char **tetramino_table, t_map *map)
|
void map_initialization(char **tetramino_table, t_map *map)
|
||||||
|
@ -58,6 +58,7 @@ void map_initialization(char **tetramino_table, t_map *map)
|
||||||
map->size = ft_sqrt_ceil(i * 4);
|
map->size = ft_sqrt_ceil(i * 4);
|
||||||
map->mask = 1;
|
map->mask = 1;
|
||||||
map->mask <<= 16 - map->size;
|
map->mask <<= 16 - map->size;
|
||||||
|
map->ok = 0;
|
||||||
clear_map(map);
|
clear_map(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,32 +112,60 @@ int can_insert(t_map *map, int index)
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int shift_tetramino(t_map *map, int index)
|
int shift_tetramino(t_map *map, int index)
|
||||||
{
|
{
|
||||||
int left_shift;
|
int right_shift;
|
||||||
int i;
|
unsigned int i;
|
||||||
int k;
|
unsigned int k;
|
||||||
t_tetrominoes *temp;
|
t_tetrominoes *temp;
|
||||||
|
|
||||||
temp = &map->figure[index];
|
temp = &map->figure[index];
|
||||||
i = temp->offset_y;
|
i = temp->offset_y;
|
||||||
k = i + temp->height;
|
k = i + temp->height;
|
||||||
left_shift = 1;
|
right_shift = 1;
|
||||||
while (i < k)
|
while (i < k)
|
||||||
if (temp->line[i++] & map->mask)
|
if (temp->line[i++] & map->mask)
|
||||||
left_shift = 0;
|
right_shift = 0;
|
||||||
i = temp->offset_y;
|
i = temp->offset_y;
|
||||||
if (left_shift)
|
if (right_shift && ++(temp->offset_x))
|
||||||
while (i < k)
|
while (i < k)
|
||||||
temp->line[i++] >>= 1;
|
temp->line[i++] >>= 1;
|
||||||
else if (k < map->size)
|
else if (k < map->size && ++(temp->offset_y)) {
|
||||||
while(k-- > i)
|
while (k-- > i) {
|
||||||
{
|
temp->line[k] <<= temp->offset_x;
|
||||||
while (!(temp->line[k] & 0x8000))
|
|
||||||
temp->line[k] <<= 1;
|
|
||||||
temp->line[k + 1] = temp->line[k];
|
temp->line[k + 1] = temp->line[k];
|
||||||
|
}
|
||||||
|
temp->offset_x = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (0);
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
t_map algorithm(t_map map, unsigned int index)
|
||||||
|
{
|
||||||
|
int ins = 0;
|
||||||
|
t_map copy;
|
||||||
|
|
||||||
|
if (index == map.figure_amount) {
|
||||||
|
map.ok = 1;
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
while (!(ins = can_insert(&map, index)))
|
||||||
|
if (!shift_tetramino(&map, index))
|
||||||
|
break;
|
||||||
|
if (ins)
|
||||||
|
{
|
||||||
|
copy = map;
|
||||||
|
insert_tetramino(&map, index);
|
||||||
|
map = algorithm(map, index + 1);
|
||||||
|
if (!map.ok)
|
||||||
|
{
|
||||||
|
shift_tetramino(©, index);
|
||||||
|
map = algorithm(copy, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/14 17:12:30 by gtertysh #+# #+# */
|
/* Created: 2016/12/14 17:12:30 by gtertysh #+# #+# */
|
||||||
/* Updated: 2016/12/14 17:12:32 by gtertysh ### ########.fr */
|
/* Updated: 2016/12/20 20:06:22 by ykolomie ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "../inc/fillit.h"
|
||||||
|
|
||||||
// This function creates string table in which one line represent one figure
|
// This function creates string table in which one line represent one figure
|
||||||
// by "glueing" evry 4 strings from table
|
// by "glueing" evry 4 strings from table
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/10 16:07:25 by gtertysh #+# #+# */
|
/* Created: 2016/12/10 16:07:25 by gtertysh #+# #+# */
|
||||||
/* Updated: 2016/12/20 19:21:09 by gtertysh ### ########.fr */
|
/* Updated: 2016/12/20 20:05:29 by ykolomie ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "../inc/fillit.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** bad global variable
|
** bad global variable
|
||||||
|
@ -57,8 +57,7 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
ft_putstr("error\n");
|
ft_putstr("error\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
} //printf("string:\n\n\n%s\n", string);
|
||||||
//printf("string:\n\n\n%s\n", string);
|
|
||||||
|
|
||||||
table = to_table(&string);
|
table = to_table(&string);
|
||||||
//printf("print_table:\n\n\n");
|
//printf("print_table:\n\n\n");
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "../inc/fillit.h"
|
||||||
|
|
||||||
// Moves figures to top left corner.
|
// Moves figures to top left corner.
|
||||||
// table contains strings each represent one figure
|
// table contains strings each represent one figure
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "../inc/fillit.h"
|
||||||
|
|
||||||
// read from file. Returns string.
|
// read from file. Returns string.
|
||||||
char *read_file(char *path)
|
char *read_file(char *path)
|
||||||
|
@ -24,7 +24,7 @@ char *read_file(char *path)
|
||||||
readed = 0;
|
readed = 0;
|
||||||
string = 0;
|
string = 0;
|
||||||
old_size = 0;
|
old_size = 0;
|
||||||
if (!(fd = open(path, O_RDONLY)))
|
if ((fd = open(path, O_RDONLY)) == -1)
|
||||||
{
|
{
|
||||||
ft_putstr("error\n");
|
ft_putstr("error\n");
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "../inc/fillit.h"
|
||||||
|
|
||||||
// Split string to table by newline character.
|
// Split string to table by newline character.
|
||||||
// Each string contain one line of the file
|
// Each string contain one line of the file
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "../inc/fillit.h"
|
||||||
|
|
||||||
// Test func. Compare figures from file
|
// Test func. Compare figures from file
|
||||||
// with templates
|
// with templates
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "../inc/fillit.h"
|
||||||
|
|
||||||
// Test func. Print table but one string contain whole figure.
|
// Test func. Print table but one string contain whole figure.
|
||||||
void print_one_string(t_ttrmn ttr)
|
void print_one_string(t_ttrmn ttr)
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "../inc/fillit.h"
|
||||||
|
|
||||||
// Test func. Print string table,
|
// Test func. Print string table,
|
||||||
// each line - line of tetromino figure.
|
// each line - line of tetromino figure.
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "../inc/fillit.h"
|
||||||
|
|
||||||
// convert "#" symbols to letters
|
// convert "#" symbols to letters
|
||||||
// rewrite for new method with structures
|
// rewrite for new method with structures
|
||||||
|
|
|
@ -18,27 +18,4 @@
|
||||||
.##.
|
.##.
|
||||||
....
|
....
|
||||||
|
|
||||||
....
|
|
||||||
..#.
|
|
||||||
.##.
|
|
||||||
.#..
|
|
||||||
|
|
||||||
....
|
|
||||||
....
|
|
||||||
.##.
|
|
||||||
##..
|
|
||||||
|
|
||||||
....
|
|
||||||
....
|
|
||||||
..##
|
|
||||||
.##.
|
|
||||||
|
|
||||||
....
|
|
||||||
...#
|
|
||||||
...#
|
|
||||||
..##
|
|
||||||
|
|
||||||
....
|
|
||||||
....
|
|
||||||
...#
|
|
||||||
.###
|
|
19
tests/sample1.fillit
Normal file
19
tests/sample1.fillit
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
####
|
||||||
|
....
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
##..
|
||||||
|
.#..
|
||||||
|
.#..
|
||||||
|
|
||||||
|
..#.
|
||||||
|
###.
|
||||||
|
....
|
||||||
|
....
|
||||||
|
|
||||||
|
....
|
||||||
|
##..
|
||||||
|
##..
|
||||||
|
....
|
Loading…
Reference in a new issue