-
Notifications
You must be signed in to change notification settings - Fork 0
/
solve.c
executable file
·93 lines (84 loc) · 1.97 KB
/
solve.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* solve.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vportell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/09 21:00:29 by stati #+# #+# */
/* Updated: 2016/11/12 22:36:06 by vportell ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int spotchecker(int row, int col, char **board, t_piece *lst)
{
int i;
int x;
int y;
i = 3;
while (i >= 0)
{
x = lst->x[i];
y = lst->y[i];
if (board[row + y][col + x] != '.')
return (0);
i--;
}
return (1);
}
t_piece **store_piece(int row, int col, char **board, t_piece *lst)
{
int i;
int x;
int y;
i = 3;
while (i >= 0)
{
x = lst->x[i];
y = lst->y[i];
board[row + y][col + x] = lst->type;
i--;
}
return (&lst->next);
}
void ft_free(int row, int col, t_piece *lst, char **board)
{
int i;
int x;
int y;
i = 3;
while (i >= 0)
{
x = lst->x[i];
y = lst->y[i];
board[row + y][col + x] = '.';
i--;
}
}
int solve(int n, int row, char **board, t_piece **bgnlst)
{
t_piece *lst;
int found;
int col;
lst = *bgnlst;
if (!lst)
return (1);
while (row < n - lst->h)
{
col = 0;
while (col < n - lst->w)
{
found = spotchecker(row, col, board, lst);
if (found)
{
if (solve(n, 0, board,
store_piece(row, col, board, lst)))
return (1);
ft_free(row, col, lst, board);
}
col++;
}
row++;
}
return (0);
}