-
Notifications
You must be signed in to change notification settings - Fork 0
/
fill_map.c
55 lines (50 loc) · 1.49 KB
/
fill_map.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fill_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tduval <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 18:14:26 by pvandamm #+# #+# */
/* Updated: 2018/11/21 14:20:40 by pvandamm ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static int backtrack(char ***tetri, char **map, int size, int piece)
{
int i;
i = 0;
while (tetri[i])
i++;
if (piece == i)
return (1);
while (move_tetri(tetri, map, size, piece) > 0)
{
if (backtrack(tetri, map, size, piece + 1))
return (1);
}
reset(map, piece);
return (0);
}
char **fill_map(char ***tetri, char **map)
{
int size;
int pos;
int i;
pos = 0;
size = count_size(tetri);
while (backtrack(tetri, map, size, 0) == 0)
{
i = 0;
while (map[i])
{
free(map[i]);
i++;
}
free(map);
size++;
if (!(map = init_map(size)))
return (0);
}
return (map);
}