-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvalid.c
121 lines (112 loc) · 2.68 KB
/
valid.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* valid.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sinlee <sinlee@student42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 11:56:35 by sinlee #+# #+# */
/* Updated: 2023/04/02 17:17:03 by sinlee ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int row_leftright(int check, int *attr, int grid[4][4], int arr[4][4])
{
int i;
int highest;
int count;
i = -1;
highest = 0;
count = 0;
while (++i < 4)
{
if (attr[2] == grid[attr[0]][i] && i != attr[1])
return (1);
if (grid[attr[0]][i] > highest)
{
highest = grid[attr[0]][i];
count++;
}
if (grid[attr[0]][i] == -1)
check = 1;
}
if (count > arr[2][attr[0]] && check == 0)
return (1);
if (check == 0 && count != arr[2][attr[0]])
return (1);
return (0);
}
int col_updown(int check, int *attr, int grid[4][4], int arr[4][4])
{
int i;
int highest;
int count;
count = 0;
i = -1;
highest = 0;
while (++i < 4)
{
if (attr[2] == grid[i][attr[1]] && i != attr[0])
return (1);
if (grid[i][attr[1]] > highest)
{
highest = grid[i][attr[1]];
count++;
}
if (grid[i][attr[1]] == -1)
check = 1;
}
if (count > arr[0][attr[1]] && check == 0)
return (1);
if (check == 0 && count != arr[0][attr[1]])
return (1);
return (0);
}
int rightleft(int check, int *attr, int grid[4][4], int arr[4][4])
{
int count;
int highest;
int i;
count = 0;
highest = 0;
i = 4;
while (--i > -1)
{
if (grid[attr[0]][i] > highest)
{
highest = grid[attr[0]][i];
count++;
}
if (grid[attr[0]][i] == -1)
check = 1;
}
if (count > arr[3][attr[0]] && check == 0)
return (1);
if (check == 0 && count != arr[3][attr[0]])
return (1);
return (0);
}
int downup(int check, int *attr, int grid[4][4], int arr[4][4])
{
int count;
int highest;
int i;
count = 0;
highest = 0;
i = 4;
while (--i > -1)
{
if (grid[i][attr[1]] > highest)
{
highest = grid[i][attr[1]];
count++;
}
if (grid[i][attr[1]] == -1)
check = 1;
}
if (count > arr[1][attr[1]] && check == 0)
return (1);
if (check == 0 && count != arr[1][attr[1]])
return (1);
return (0);
}