add output routines

This commit is contained in:
Gregory 2016-12-22 05:34:24 +02:00
parent 28c1cd98fd
commit 7eb11a8333
11 changed files with 278 additions and 23 deletions

1
.gitignore vendored
View file

@ -40,3 +40,4 @@
# Clion files
.idea
cmake-build-debug

View file

@ -7,7 +7,6 @@ include_directories(inc)
include_directories(libft)
set(SOURCE_FILES
inc/fillit.h
libft/ft_atoi.c
libft/ft_bzero.c
libft/ft_isalnum.c

View file

@ -21,7 +21,6 @@
#include <stdio.h> // warning!
# define BUF_S 8192
# define HOW_MUCH 10000
typedef struct s_coord
{
@ -45,7 +44,9 @@ typedef struct s_node
struct s_node *down;
struct s_node *column;
t_coord coord;
} t_node;
int type;
int size;
} t_node;
extern t_ttrmn g_templates[19];
@ -74,10 +75,7 @@ void test_check(char **ttr, t_ttrmn *tamplates);
// obsolete, rewrite for structs array
void to_letters(char **ttr);
// create array of ttr structures
int *to_strct_array(char **ttr, t_ttrmn *templates);
t_node *init_root(void);
t_node *init_root(int size);
t_node *add_column(t_node *root);
@ -85,17 +83,17 @@ t_node **add_cols(t_node *root, int number);
t_node *add_node(t_node *col);
t_node *add_node_with_coords(t_node *col, t_coord row);
t_node *add_node_with_coord(t_node *col, t_coord row, int type);
t_node **add_cols(t_node *root, int number);
void print_solution(t_list *sol);
void print_solution(t_list *sol, t_node *root, int amount);
void add_rows(int *types, int amount, int size, t_node **cols_arr);
void link_row(int *col_nums, t_node **cols_arr);
void add_row(int *col_numbers, t_node **cols_arr, t_coord coord);
void add_row(int *col_numbers, t_node **cols_arr, t_coord coord, int type);
void search(t_node* root, t_list *solution, int k, int amount);
@ -109,4 +107,6 @@ int get_amount(char **ttr);
unsigned int ft_sqrt_ceil(unsigned int num);
void fill_map(char *map, int size, t_node *ttr, int letter);
#endif

View file

@ -13,13 +13,14 @@
#include "../inc/fillit.h"
#include <stdlib.h>
t_node *init_root(void)
t_node *init_root(int size)
{
t_node *new;
new = (t_node*)malloc(sizeof(t_node));
new->left = new->right = new->down = new->up = new;
new->column = NULL;
new->size = size;
return (new);
}
@ -38,12 +39,13 @@ t_node *add_column(t_node *root)
return (new_col);
}
t_node *add_node_with_coord(t_node *col, t_coord coord)
t_node *add_node_with_coord(t_node *col, t_coord coord, int type)
{
t_node *new_node;
new_node = (t_node*)malloc(sizeof(t_node));
new_node->coord = coord;
new_node->type = type;
new_node->column = col;
new_node->up = col->up;
new_node->down = col;
@ -91,9 +93,9 @@ int *get_coords(t_coord coord, int amount, int type, int size) {
}
return (result);
}
void add_row(int *col_numbers, t_node **cols_arr, t_coord coord)
void add_row(int *col_numbers, t_node **cols_arr, t_coord coord, int type)
{
add_node_with_coord(cols_arr[col_numbers[0]], coord);
add_node_with_coord(cols_arr[col_numbers[0]], coord, type);
add_node(cols_arr[col_numbers[1]]);
add_node(cols_arr[col_numbers[2]]);
add_node(cols_arr[col_numbers[3]]);
@ -134,7 +136,7 @@ void add_rows(int *types, int amount, int size, t_node **cols_arr)
coord.y = l;
col_num = get_coords(coord, amount, types[i], size);
col_num[0] = i;
add_row(col_num, cols_arr, coord);
add_row(col_num, cols_arr, coord, types[i]);
link_row(col_num, cols_arr);
k++;
}
@ -185,10 +187,48 @@ void uncover(t_node *to_uncover)
to_uncover->right->left = to_uncover;
}
void print_solution(t_list *sol)
void fill_map(char *map, int size, t_node *ttr, int letter)
{
if (sol)
printf("as\n");
int i;
char a;
a = 'A' + letter - 1;
i = 0;
while (i < 4)
{
ft_memcpy((map + (ttr->coord.y + g_templates[ttr->type].c[i].y) * size +
ttr->coord.x + g_templates[ttr->type].c[i].x), &a, 1);
i++;
}
}
void print_solution(t_list *sol, t_node *root, int amount)
{
char *map;
int i;
int map_size;
map_size = root->size * root->size + 1;
map = malloc(sizeof(char) * map_size);
map[map_size] = 0;
while (sol)
{
fill_map(map, root->size, (*(t_node **)sol->content), amount);
sol = sol->next;
amount--;
}
i = 0;
while (i < root->size * root->size)
{
if (map[i] >= 'A' && map[i] <= 'Z')
ft_putchar(map[i]);
else
ft_putchar('.');
if ((i + 1) % root->size == 0)
ft_putchar('\n');
i++;
}
exit(0);
}
@ -199,7 +239,7 @@ void search(t_node* root, t_list *solution, int k, int amount)
t_node *j;
if (k == amount)
print_solution(solution);
print_solution(solution, root, amount);
if (root->right == root)
return ;
current_col = root->right;

View file

@ -35,7 +35,7 @@ t_ttrmn g_templates[19] =
{"##..##..........", 2, 2, {{0, 0}, {0, 1}, {1, 0}, {1, 1}}},
{"##...##.........", 3, 2, {{0, 0}, {0, 1}, {1, 1}, {1, 2}}},
{".#..##..#.......", 2, 3, {{0, 1}, {1, 0}, {1, 1}, {2, 0}}},
{".##.##..........", 3, 2, {{0, 1}, {0, 2}, {1, 0}, {1, 2}}},
{".##.##..........", 3, 2, {{0, 1}, {0, 2}, {1, 0}, {1, 1}}},
{"#...##...#......", 2, 3, {{0, 0}, {1, 0}, {1, 1}, {2, 1}}}
};
@ -76,8 +76,8 @@ int main(int argc, char **argv)
//printf("move to up left:\n\n\n");
//print_one_string(ttr);
printf("test check:\n\n");
test_check(ttr, g_templates);
//printf("test check:\n\n");
//test_check(ttr, g_templates);
@ -85,7 +85,7 @@ int main(int argc, char **argv)
amount = get_amount(ttr);
size = ft_sqrt_ceil(amount * 4);
while (1) {
r = init_root();
r = init_root(size);
cols_arr = add_cols(r, (size * size + amount));
add_rows(types, amount, size, cols_arr);
search(r, ans, 0, amount);

BIN
tests/color Executable file

Binary file not shown.

34
tests/sample2.fillit Normal file
View file

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

19
tests/sample3.fillit Normal file
View file

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

39
tests/sample4.fillit Normal file
View file

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

4
tests/sample5.fillit Normal file
View file

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

119
tests/sample6.fillit Normal file
View file

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