Map printing
This commit is contained in:
parent
ccba521158
commit
a2e313a22a
5
Makefile
5
Makefile
|
@ -3,9 +3,12 @@ SRC = main.c \
|
|||
parsing.c \
|
||||
parsing_simple.c \
|
||||
solution.c \
|
||||
printing.c \
|
||||
mem.c \
|
||||
|
||||
HEADERS = parsing.h \
|
||||
printing.h \
|
||||
solution.h \
|
||||
|
||||
OBJDIR = obj
|
||||
SRCDIR = srcs
|
||||
|
@ -74,7 +77,7 @@ CYN = : [36m;
|
|||
CLR_RST = && : [m
|
||||
|
||||
run:
|
||||
@clear
|
||||
@#clear
|
||||
$(YLW) ./$(NAME) $(CLR_RST) $(SUCCESS)
|
||||
|
||||
valgrind: re
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
...............................o..................................o.............................................o.....................................o............................................o..............o.......o.......o................
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* printing.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/05 04:11:08 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/05 04:16:35 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PRINTING_H
|
||||
# define PRINTING_H
|
||||
# include "parsing.h"
|
||||
# include <limits.h>
|
||||
# include <unistd.h>
|
||||
|
||||
void ft_putchar(char c);
|
||||
void ft_putnbr(int nb);
|
||||
size_t ft_strlen(char const *str);
|
||||
void print_map(t_map *map);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* solution.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/05 04:02:35 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/05 04:03:37 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SOLUTION_H
|
||||
# define SOLUTION_H
|
||||
# include "parsing.h"
|
||||
|
||||
void solve(t_map *map);
|
||||
|
||||
#endif
|
24
srcs/main.c
24
srcs/main.c
|
@ -6,12 +6,13 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/04 21:50:50 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/04 22:57:12 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/05 04:27:43 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "parsing.h"
|
||||
#include "solution.h"
|
||||
#include "printing.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
@ -21,12 +22,23 @@ int main(int argc, char **argv)
|
|||
(void)argc;
|
||||
(void)argv;
|
||||
ret = read_fname("./assets/map2", &map);
|
||||
map.data = \
|
||||
"..........................." "....o......................"
|
||||
"............o.............." "..........................."
|
||||
"....o......................" "...............o..........."
|
||||
"..........................." "......o..............o....."
|
||||
"..o.......o................";
|
||||
printf("Reading file ret val: %d\n", ret);
|
||||
printf("Empty: '%c'\n", map.meta.empty);
|
||||
printf("Obstacle: '%c'\n", map.meta.obstacle);
|
||||
printf("Full: '%c'\n", map.meta.full);
|
||||
printf("Height: %d\n", map.meta.height);
|
||||
printf("Width: %d\n", map.meta.width);
|
||||
printf("Map:\n%s\n", map.data);
|
||||
printf("Map len: %zu\n", ft_strlen(map.data));
|
||||
printf("Map 1d:\n\"%s\"\n", map.data);
|
||||
fflush(stdout);
|
||||
print_map(&map);
|
||||
printf("######## STARTED SOLVE ########\n");
|
||||
solve(&map);
|
||||
printf("######## FINISHED SOLVE ########\n");
|
||||
fflush(stdout);
|
||||
print_map(&map);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* printing.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/05 04:09:39 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/05 04:23:45 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "printing.h"
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
while (*str)
|
||||
ft_putchar(*str++);
|
||||
}
|
||||
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
ft_putchar(nb % 10 + '0');
|
||||
}
|
||||
else if (nb == INT_MIN)
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
ft_putnbr(-(nb % 10));
|
||||
}
|
||||
else if (nb < 0)
|
||||
{
|
||||
ft_putchar('-');
|
||||
ft_putnbr(-nb);
|
||||
}
|
||||
else
|
||||
ft_putchar(nb % 10 + '0');
|
||||
}
|
||||
|
||||
size_t ft_strlen(char const *str)
|
||||
{
|
||||
size_t size;
|
||||
|
||||
size = 0;
|
||||
while (*str++)
|
||||
++size;
|
||||
return (size);
|
||||
}
|
||||
|
||||
void print_map(t_map *map)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
ft_putstr("Map Meta:\n\tEmpty char: ");
|
||||
ft_putchar(map->meta.empty);
|
||||
ft_putchar('\n');
|
||||
ft_putstr("\tObstacle char: ");
|
||||
ft_putchar(map->meta.obstacle);
|
||||
ft_putchar('\n');
|
||||
ft_putstr("\tFull char: ");
|
||||
ft_putchar(map->meta.full);
|
||||
ft_putstr("\nMap:\n");
|
||||
i = 0;
|
||||
while (i < map->meta.height)
|
||||
{
|
||||
j = 0;
|
||||
while (j < map->meta.width)
|
||||
{
|
||||
ft_putchar(map->data[i * map->meta.width + j]);
|
||||
j++;
|
||||
}
|
||||
ft_putchar('\n');
|
||||
i++;
|
||||
}
|
||||
ft_putchar('\n');
|
||||
}
|
|
@ -6,8 +6,13 @@
|
|||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/04 21:46:57 by tischmid #+# #+# */
|
||||
/* Updated: 2023/04/04 21:50:48 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/04/05 04:04:28 by tischmid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "solution.h"
|
||||
|
||||
void solve(t_map *map)
|
||||
{
|
||||
(void)map;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue