-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_board.c
110 lines (102 loc) · 2.54 KB
/
check_board.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_board.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rgiraud <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/13 18:44:48 by rgiraud #+# #+# */
/* Updated: 2023/08/13 19:08:56 by rgiraud ### ########.fr */
/* */
/* ************************************************************************** */
int ft_check_board_duplicate(int **tab_solution, int num, int i, int j)
{
int k;
k = 0;
while (k < 4)
{
if (tab_solution[j][k] == num)
{
return (0);
}
k++;
}
k = 0;
while (k < 4)
{
if (tab_solution[k][i] == num)
{
return (0);
}
k++;
}
return (1);
}
void initialize_variables(int *count_top, int *count_bottom, int *max_top,
int *max_bottom)
{
*count_top = 0;
*count_bottom = 0;
*max_top = 0;
*max_bottom = 0;
}
int ft_check_col(int tab_config[4][4], int **tab_solution, int i, int j)
{
int count_top;
int count_bottom;
int max_top;
int max_bottom;
initialize_variables(&count_top, &count_bottom, &max_top, &max_bottom);
while (j < 4)
{
if (tab_solution[j][i] > max_top)
{
max_top = tab_solution[j][i];
count_top++;
}
if (tab_solution[3 - j][i] > max_bottom)
{
max_bottom = tab_solution[3 - j][i];
count_bottom++;
}
j++;
}
if (tab_config[0][i] == count_top && tab_config[1][i] == count_bottom)
return (1);
else
return (0);
}
void ft_init_variable1(int *count_start, int *count_end, int *max_start,
int *max_end)
{
*count_start = 0;
*count_end = 0;
*max_start = 0;
*max_end = 0;
}
int ft_check_line(int tab_config[4][4], int **tab_solution, int j, int i)
{
int count_start;
int count_end;
int max_start;
int max_end;
ft_init_variable1(&count_start, &count_end, &max_start, &max_end);
while (i < 4)
{
if (tab_solution[j][i] > max_start)
{
max_start = tab_solution[j][i];
count_start++;
}
if (tab_solution[j][3 - i] > max_end)
{
max_end = tab_solution[j][3 - i];
count_end++;
}
i++;
}
if (tab_config[2][j] == count_start && tab_config[3][j] == count_end)
return (1);
else
return (0);
}