norm and no more submodule
This commit is contained in:
parent
a7bb8aa364
commit
7edaabc3a1
11 changed files with 131 additions and 98 deletions
3
fillit/.gitmodules
vendored
3
fillit/.gitmodules
vendored
|
|
@ -1,3 +0,0 @@
|
|||
[submodule "libft"]
|
||||
path = libft
|
||||
url = https://github.com/jzck/libft.git
|
||||
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fillit.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:38:16 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:39:41 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FILLIT_H
|
||||
# define FILLIT_H
|
||||
# define BUF_SIZE 32
|
||||
|
|
@ -9,18 +21,21 @@ extern int g_target;
|
|||
extern int g_ttmn;
|
||||
extern char **g_sol;
|
||||
|
||||
typedef struct s_stack
|
||||
struct s_stack
|
||||
{
|
||||
char id;
|
||||
int num;
|
||||
} t_stack;
|
||||
};
|
||||
|
||||
typedef struct s_ttmn
|
||||
struct s_ttmn
|
||||
{
|
||||
char id;
|
||||
int placed;
|
||||
int pos[4][2];
|
||||
} t_ttmn;
|
||||
};
|
||||
|
||||
typedef struct s_stack t_stack;
|
||||
typedef struct s_ttmn t_ttmn;
|
||||
|
||||
t_list *ft_parse(char *filename);
|
||||
int ft_parse_line(char *line, int linenumber, t_list **list);
|
||||
|
|
@ -31,7 +46,8 @@ int ft_solver(char **board, t_list *lttmn, int space, int size);
|
|||
int ft_solved(char **board);
|
||||
|
||||
int ft_check_waste(char **board, t_list *lttmn, int space, int size);
|
||||
int ft_fit_blob(char **board, t_list *lttmn, int space, int size, int blob_size, int i);
|
||||
int ft_fit_blob(
|
||||
char **board, t_list *lttmn, int space, int size, int blob_size, int i);
|
||||
int ft_floodfill_recursive(char **board, int size, int i, char c);
|
||||
int ft_floodfill_stack(char **board, int size, int i, char c);
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 70af533db4c5a53646e2ea2e371d611cc9959f48
|
||||
|
|
@ -1,6 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fillit_fit_blob.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:39:49 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:42:03 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
|
||||
int ft_fit_blob(char **board, t_list *lttmn, int space, int size, int blob_size, int y)
|
||||
int ft_fit_blob(
|
||||
char **board, t_list *lttmn, int space, int size, int blob_size, int y)
|
||||
{
|
||||
t_ttmn *ttmn;
|
||||
t_list *list;
|
||||
|
|
@ -22,7 +35,6 @@ int ft_fit_blob(char **board, t_list *lttmn, int space, int size, int blob_size
|
|||
if (ttmn->placed || ft_board_add(board, *ttmn, i, size))
|
||||
continue ;
|
||||
ttmn->placed = 1;
|
||||
/* ft_board_print(board); */
|
||||
if (ft_solver(board, lttmn, space, size))
|
||||
return (1);
|
||||
ft_board_replace(board, ttmn->id, '*');
|
||||
|
|
|
|||
|
|
@ -1,4 +1,17 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fillit_parser.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:29:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:31:00 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
|
||||
int g_target = 0;
|
||||
int g_ttmn = 0;
|
||||
|
||||
|
|
@ -22,7 +35,6 @@ int ft_parse_line(char *line, int linenumber, t_list **list)
|
|||
i = -1;
|
||||
while (line[++i])
|
||||
{
|
||||
/* ft_printf("%i,%i,%i: %c\n", i, j, k, line[i]); */
|
||||
if (!ft_strchr(".#", line[i]))
|
||||
return (1);
|
||||
else if (line[i] == '#' && ft_parse_sharp(&j, &k, &ttmn))
|
||||
|
|
@ -40,7 +52,6 @@ int ft_parse_sharp(int *j, int *k, t_ttmn *ttmn)
|
|||
{
|
||||
ref[0] = *j / 4;
|
||||
ref[1] = *j % 4;
|
||||
/* ft_printf("refs: %i,%i\n", ref[0], ref[1]); */
|
||||
ttmn->pos[0][0] = 0;
|
||||
ttmn->pos[0][1] = 0;
|
||||
}
|
||||
|
|
@ -48,7 +59,6 @@ int ft_parse_sharp(int *j, int *k, t_ttmn *ttmn)
|
|||
{
|
||||
ttmn->pos[*k][0] = (*j) / 4 - ref[0];
|
||||
ttmn->pos[*k][1] = (*j) % 4 - ref[1];
|
||||
/* ft_printf("pos: %i,%i\n", ttmn->pos[*k][0], ttmn->pos[*k][1]); */
|
||||
}
|
||||
else
|
||||
return (1);
|
||||
|
|
@ -62,7 +72,6 @@ int ft_parse_addttmn(int *j, int *k, t_ttmn ttmn, t_list **list)
|
|||
t_list *tmp;
|
||||
|
||||
ttmn.id = id++;
|
||||
/* ft_printf("%i,%i\n", *j, *k); */
|
||||
if (*j != 16 || *k != 4)
|
||||
return (1);
|
||||
if (ft_ttmn_validate(ttmn))
|
||||
|
|
@ -88,7 +97,6 @@ t_list *ft_parse(char *filename)
|
|||
linenumber = 0;
|
||||
while ((ret = get_next_line(fd, &line)))
|
||||
{
|
||||
/* ft_printf("parsing line:%s\n", line); */
|
||||
if (ft_parse_line(line, linenumber++, &list))
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fillit_solver.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:36:27 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:38:05 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
|
||||
int ft_solved(char **board)
|
||||
{
|
||||
ft_putendl("found solution:");
|
||||
|
||||
ft_board_remove(board, '^');
|
||||
ft_board_remove(board, '*');
|
||||
g_sol = ft_board_copy(board);
|
||||
ft_board_print(board);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
|
@ -21,17 +30,13 @@ int ft_solver(char **board, t_list *lttmn, int space, int size)
|
|||
ttmn = (t_ttmn *)lttmn->content;
|
||||
if (ttmn->placed)
|
||||
return (ft_solver(board, lttmn->next, space, size));
|
||||
/* ft_board_print(board); */
|
||||
i = -1;
|
||||
while (++i < size * size)
|
||||
{
|
||||
if (ft_board_add(board, *ttmn, i, size))
|
||||
continue ;
|
||||
/* if (ft_solver(board, lttmn->next, space, size)) */
|
||||
/* return (1); */
|
||||
if (ft_check_waste(board, lttmn->next, space, size))
|
||||
return (1);
|
||||
|
||||
ft_board_remove(board, ttmn->id);
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* floodfill.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:26:42 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:29:36 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
|
||||
int ft_floodfill_recursive(char **board, int size, int i, char c)
|
||||
|
|
@ -9,58 +21,14 @@ int ft_floodfill_recursive(char **board, int size, int i, char c)
|
|||
{
|
||||
board[i / size][i % size] = c;
|
||||
n++;
|
||||
n += i % size < size - 1 ? ft_floodfill_recursive(board, size, i + 1, c) : 0;
|
||||
n += i / size > 0 ? ft_floodfill_recursive(board, size, i - size, c) : 0;
|
||||
n += i % size > 0 ? ft_floodfill_recursive(board, size, i - 1, c) : 0;
|
||||
n += i / size < size - 1 ? ft_floodfill_recursive(board, size, i + size, c) : 0;
|
||||
}
|
||||
/* printf("list at %i: ", i); */
|
||||
/* fflush(stdout); */
|
||||
/* ft_lst_print(blob, &ft_putnbr); */
|
||||
return (n);
|
||||
}
|
||||
|
||||
int ft_floodfill_stack(char **board, int size, int i, char c)
|
||||
{
|
||||
static const int dx[4] = {1, -1, 0, 0};
|
||||
static const int dy[4] = {0, 0, 1, -1};
|
||||
int x;
|
||||
int y;
|
||||
int nx;
|
||||
int ny;
|
||||
int n;
|
||||
t_list *top;
|
||||
t_list *stack;
|
||||
t_list *stack2;
|
||||
|
||||
stack = NULL;
|
||||
stack2 = NULL;
|
||||
n = 0;
|
||||
ft_lstadd(&stack, ft_lstnew(&i, sizeof(int)));
|
||||
while (stack || stack2)
|
||||
{
|
||||
if (stack2)
|
||||
stack = stack2;
|
||||
stack2 = NULL;
|
||||
/* ft_board_print(board); */
|
||||
while((top = ft_lstpop(&stack)))
|
||||
{
|
||||
i = *(int *)top->content;
|
||||
x = i % size;
|
||||
y = i / size;
|
||||
board[y][x] = c;
|
||||
for(int j = 0; j < 4; j++) {
|
||||
nx = x + dx[j];
|
||||
ny = y + dy[j];
|
||||
i = nx + size * ny;
|
||||
if(nx >= 0 && nx < size && ny >= 0 && ny < size
|
||||
&& board[ny][nx] == '.')
|
||||
{
|
||||
ft_lstadd(&stack2, ft_lstnew(&i, sizeof(int)));
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
n += i % size < size - 1 ?
|
||||
ft_floodfill_recursive(board, size, i + 1, c) : 0;
|
||||
n += i / size > 0 ?
|
||||
ft_floodfill_recursive(board, size, i - size, c) : 0;
|
||||
n += i % size > 0 ?
|
||||
ft_floodfill_recursive(board, size, i - 1, c) : 0;
|
||||
n += i / size < size - 1 ?
|
||||
ft_floodfill_recursive(board, size, i + size, c) : 0;
|
||||
}
|
||||
return (n);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* lib_board.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:34:39 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:35:39 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
|
||||
void ft_board_print(char **board)
|
||||
{
|
||||
/* ft_putendl("-s-"); */
|
||||
while (*board)
|
||||
ft_putendl(*board++);
|
||||
ft_putendl("");
|
||||
|
|
@ -55,4 +66,3 @@ void ft_board_fill(char **dst, char **src)
|
|||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* lib_board2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:31:46 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:31:51 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
|
||||
int ft_board_add(char **board, t_ttmn ttmn, int i, int size)
|
||||
|
|
@ -11,8 +23,6 @@ int ft_board_add(char **board, t_ttmn ttmn, int i, int size)
|
|||
{
|
||||
x = i % size + ttmn.pos[k][1];
|
||||
y = i / size + ttmn.pos[k][0];
|
||||
/* printf("adding %c to %i,%i\n", block.id, y, x); */
|
||||
/* fflush(stdout); */
|
||||
if (x > size - 1 || y > size - 1 || x < 0 || y < 0)
|
||||
return (1);
|
||||
if (board[y][x] != '.' && board[y][x] != '*')
|
||||
|
|
@ -25,7 +35,6 @@ int ft_board_add(char **board, t_ttmn ttmn, int i, int size)
|
|||
x = i % size + ttmn.pos[k][1];
|
||||
y = i / size + ttmn.pos[k][0];
|
||||
board[y][x] = ttmn.id;
|
||||
/* ft_show_board(board); */
|
||||
k++;
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* lib_ttmn.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:32:01 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:34:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
|
||||
int ft_ttmn_validate(t_ttmn ttmn)
|
||||
|
|
@ -28,22 +40,6 @@ int ft_ttmn_validate(t_ttmn ttmn)
|
|||
return (1);
|
||||
}
|
||||
|
||||
void ft_ttmn_print(t_ttmn ttmn)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!ttmn.id)
|
||||
{
|
||||
ft_putendl("end of ttmn\n");
|
||||
return ;
|
||||
}
|
||||
printf("%c,%i", ttmn.id, ttmn.placed);
|
||||
for (i=1; i < 4; i++)
|
||||
printf("\t%d,%d\n", ttmn.pos[i][0], ttmn.pos[i][1]);
|
||||
fflush(stdout);
|
||||
ft_putendl("");
|
||||
}
|
||||
|
||||
void ft_ttmn_reset(t_list *ttmn)
|
||||
{
|
||||
((t_ttmn *)ttmn->content)->placed = 0;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 17:31:13 by jhalford #+# #+# */
|
||||
/* Updated: 2016/11/03 17:37:59 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
|
||||
char **g_sol = NULL;
|
||||
|
|
@ -26,5 +38,6 @@ int main(int ac, char **av)
|
|||
ft_solver(board, lttmn, size * size - 4 * g_ttmn, size);
|
||||
size--;
|
||||
}
|
||||
ft_board_print(g_sol);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue