-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_valid.c
94 lines (85 loc) · 2.3 KB
/
check_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_valid.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sonkang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/19 14:58:39 by sonkang #+# #+# */
/* Updated: 2021/08/23 00:26:28 by sonkang ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int check_extention(char *argv)
{
int len;
int ret;
len = ft_strlen(argv);
if (len >= 5)
ret = ft_strncmp(&(argv[len - 4]), ".ber", 4);
else
return (-1);
if (ret != 0)
return (-1);
return (0);
}
int check_map_valid(t_map *m_info)
{
int row;
int col;
row = 0;
col = -1;
while (++col < m_info->col)
{
if (m_info->map[0][col] != '1')
return (-1);
if (m_info->map[m_info->row - 1][col] != '1')
return (-1);
}
while (++row < m_info->row - 1)
{
if (m_info->map[row][0] != '1')
return (-1);
if (m_info->map[row][m_info->col - 1] != '1')
return (-1);
}
return (0);
}
void get_player_position(int *count, t_map *map, int row, int col)
{
*count += 1;
map->player_x = row;
map->player_y = col;
}
void get_collect_ea(int *count, t_map *map)
{
*count += 1;
map->collect = *count;
}
int check_comp_valid(t_map *m_info)
{
int row;
int col;
static int count[3];
row = -1;
while (m_info->map[++row])
{
col = -1;
while (m_info->map[row][++col])
{
if (m_info->map[row][col] == '0' || m_info->map[row][col] == '1')
continue ;
else if (m_info->map[row][col] == 'C')
get_collect_ea(&count[0], m_info);
else if (m_info->map[row][col] == 'E')
count[1]++;
else if (m_info->map[row][col] == 'P')
get_player_position(&count[2], m_info, row, col);
else
return (-1);
}
}
if (count[0] < 1 || count[1] != 1 || count[2] != 1)
return (-1);
return (0);
}