-
Notifications
You must be signed in to change notification settings - Fork 0
/
fillit.c
134 lines (124 loc) · 3.14 KB
/
fillit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* ************************************************************************** */
/* */
/* :::::::: */
/* fillit.c :+: :+: */
/* +:+ */
/* By: ravan-de <marvin@codam.nl> +#+ */
/* +#+ */
/* Created: 2019/05/31 14:38:43 by ravan-de #+# #+# */
/* Updated: 2019/06/19 20:10:57 by ravan-de ######## odam.nl */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include "libft.h"
#include "fillit.h"
int print_usage(int argc)
{
if (argc != 2)
{
write(1, "usage: ./fillit source_file\n", 28);
return (0);
}
return (1);
}
uint64_t *lst2arr(t_list *lst)
{
uint64_t *tets;
int tetcount;
tets = (uint64_t *)malloc(sizeof(uint64_t) * 26);
tetcount = 0;
while (lst->next != NULL)
{
tets[tetcount] = *(uint64_t *)(lst->content);
lst = lst->next;
tetcount++;
}
tets[tetcount] = *(uint64_t *)(lst->content);
tets[tetcount + 1] = 0;
return (tets);
}
int ft_lstlen(t_list *lst)
{
int len;
len = 1;
while (lst->next != NULL)
{
len++;
lst = lst->next;
}
return (len);
}
void ft_create_board(t_board *board)
{
t_board strip_1;
t_board strip_2;
t_board strip_3;
t_board strip_4;
strip_1.state = 0;
strip_1.tet = 0;
strip_2.state = 0;
strip_2.tet = 0;
strip_3.state = 0;
strip_3.tet = 0;
strip_4.state = 0;
strip_4.tet = 0;
board[0] = strip_1;
board[1] = strip_2;
board[2] = strip_3;
board[3] = strip_4;
}
int main(int argc, char **argv)
{
uint16_t *board;
// int strip_index;
int fd;
t_list *tetr_lst;
int output;
// int map_size;
// unsigned short square;
size_t size;
//strip_index = 0;
//board = (t_board *)malloc(4 * sizeof(t_board));
//ft_create_board(board);
//ft_putnbr(board[3].tet);
//square = 0;
//map_size = 2;
board = NULL;
if (print_usage(argc) == 0)
return (0);
else
{
fd = open(argv[1], O_RDONLY);
if (fd < 0)
return (0);
tetr_lst = NULL;
output = read_file(fd, &tetr_lst);
if (output == -1)
{
write(1, "error\n", 6);
return (0);
}
else
print_list(&tetr_lst);
size = initial_boardsize(tetr_lst);
printf(ANSI_COLOR_CYAN "\n ========= Initial Board State ========= \n" ANSI_COLOR_RESET);
initialize_board(&board);
print_board(board);
solver(tetr_lst, &board, size);
printf(ANSI_COLOR_CYAN "=== Final Board State === \n" ANSI_COLOR_RESET);
print_board(board);
// while (map_size * map_size < 4 * ft_lstlen(tetr_lst))
// map_size++;
// while (square == 0 && map_size < 16)
// {
// ft_putnbr(map_size);
// ft_putendl(" map_size");
// square = ft_recursive(board, map_size, lst2arr(tetr_lst), 0);
// map_size++;
// }
close(fd);
}
return (0);
}