2024-09-11 16:00:35 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* check_map.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2024/09/11 11:24:13 by madumerg #+# #+# */
|
2024-09-12 13:01:04 +02:00
|
|
|
/* Updated: 2024/09/12 12:57:24 by madumerg ### ########.fr */
|
2024-09-11 16:00:35 +02:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "cub3d.h"
|
|
|
|
|
2024-09-11 22:20:37 +02:00
|
|
|
int err_not_close(char after, char before, char down, char up)
|
2024-09-11 16:00:35 +02:00
|
|
|
{
|
2024-09-11 22:20:37 +02:00
|
|
|
if (after == ' ' || after == '\0')
|
|
|
|
return (1);
|
|
|
|
else if (before == ' ' || before == '\0')
|
|
|
|
return (1);
|
|
|
|
else if (down == ' ' || down == '\0')
|
|
|
|
return (1);
|
|
|
|
else if (up == ' ' || up == '\0')
|
|
|
|
return (1);
|
2024-09-11 16:00:35 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2024-09-11 22:20:37 +02:00
|
|
|
int actual_char(char actual)
|
2024-09-11 16:00:35 +02:00
|
|
|
{
|
2024-09-11 22:20:37 +02:00
|
|
|
if (actual == '0' || actual == 'N' || actual == 'W' || \
|
|
|
|
actual == 'S' || actual == 'E')
|
|
|
|
return (0);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int check_map_close(char **map)
|
|
|
|
{
|
|
|
|
int y;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
y = 0;
|
|
|
|
while (map[y])
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
while (map[y][x])
|
|
|
|
{
|
|
|
|
if (actual_char(map[y][x]) == 0 && \
|
|
|
|
(err_not_close(map[y][x + 1], map[y][x - 1], \
|
|
|
|
map[y + 1][x], map[y - 1][x]) == 1))
|
|
|
|
return (1);
|
|
|
|
else
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int count_player(char **map)
|
|
|
|
{
|
|
|
|
int y;
|
|
|
|
int x;
|
|
|
|
int cpt;
|
|
|
|
|
|
|
|
cpt = 0;
|
|
|
|
y = 0;
|
|
|
|
while (map[y])
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
while (map[y][x])
|
|
|
|
{
|
|
|
|
if (map[y][x] == 'N' || map[y][x] == 'S' || \
|
|
|
|
map[y][x] == 'E' || map[y][x] == 'W')
|
|
|
|
cpt++;
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
if (cpt != 1)
|
2024-09-11 16:00:35 +02:00
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int check_char_map(char **map)
|
|
|
|
{
|
|
|
|
int y;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
y = 0;
|
|
|
|
while (map[y])
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
while (map[y][x])
|
|
|
|
{
|
|
|
|
if (verif_char(map[y][x]) == 1)
|
|
|
|
return (1);
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|