-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckers.c
119 lines (108 loc) · 2.84 KB
/
checkers.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* checkers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vsimeono <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/17 13:44:38 by vsimeono #+# #+# */
/* Updated: 2022/03/21 18:50:47 by vsimeono ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
/* Checking if P, E, C is in Map */
int check_p_e_c_in_map(t_long *arch, t_list **lines)
{
t_list *temp;
int i;
temp = *lines;
while (temp->next != NULL)
{
i = 0;
while (temp->line[i] && temp->line[i] != '\n')
{
if (temp->line[i] == 'P')
arch->player++;
else if (temp->line[i] == 'E')
arch->exit++;
else if (temp->line[i] == 'C')
arch->collect++;
i++;
}
temp = temp->next;
}
if (arch->player == 0 || arch->exit == 0 || arch->collect == 0)
return (0);
return (1);
}
/* Check that there are not any other Characters except P,C,E, 1 and 0 */
int is_p_c_e_1_0(t_list **lines)
{
t_list *temp;
int i;
int len_line;
temp = (*lines);
len_line = ft_strlen_line(lines);
while (temp->next != NULL)
{
i = 0;
while (i < len_line)
{
if (temp->line[i] != '0' && temp->line[i] != '1' && \
temp->line[i] != 'P' && temp->line[i] != 'E' && \
temp->line[i] != 'C' && temp->line[i] != '\n')
return (0);
i++;
}
temp = temp->next;
}
return (1);
}
/* Checking the Length of the Lines are the Same */
int is_length(t_list **lines)
{
t_list *temp;
int len_line;
temp = (*lines);
len_line = ft_strlen_line(lines);
while (temp->next != NULL)
{
temp = temp->next;
if (len_line != ft_strlen_line_1(temp->line))
return (0);
}
return (1);
}
/* Checking if first Line and Last Line is Made from 1s */
int is_first_last_line(t_list **lines)
{
t_list *temp;
temp = (*lines);
if (!ft_strchr_first_line(temp->line, '1'))
return (0);
while (temp->next != NULL)
temp = temp->next;
if (!ft_strchr_second_line(temp->line, '1'))
return (0);
return (1);
}
/* Check if First Char and Last Char is 1 */
int is_first_last_char(t_list **lines)
{
t_list *temp;
int len_line;
int j;
temp = (*lines);
len_line = ft_strlen_line(lines);
while (temp->next != NULL)
{
j = 0;
if (temp->line[j] != 49)
return (0);
j = len_line - 1;
if (temp->line[j] != 49)
return (0);
temp = temp->next;
}
return (1);
}