Compare commits
22 Commits
a8b2e31701
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
94a1cdaffc | ||
|
c672ca1205 | ||
|
ca1abc4990 | ||
|
ea99e7b1fc | ||
|
94145d3d17 | ||
|
f44cda2833 | ||
|
a21860983e | ||
|
5894c0cdd0 | ||
|
3156bddf27 | ||
|
a40b6b00e7 | ||
|
8552cf8a32 | ||
|
4bb3b45781 | ||
|
ee59b79e75 | ||
|
b22a1a5af7 | ||
|
a51c8ad81d | ||
|
6ad8cd2d95 | ||
|
9a386b315b | ||
|
ba1cea020d | ||
|
0b4c310374 | ||
|
5b4e0c0150 | ||
|
fe1c85371f | ||
|
c35deace58 |
6
Makefile
6
Makefile
@@ -6,7 +6,7 @@
|
|||||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2019/03/27 16:51:02 by tmaze #+# #+# #
|
# Created: 2019/03/27 16:51:02 by tmaze #+# #+# #
|
||||||
# Updated: 2019/04/22 09:44:46 by tmaze ### ########.fr #
|
# Updated: 2019/05/09 18:39:33 by tmaze ### ########.fr #
|
||||||
# #
|
# #
|
||||||
#******************************************************************************#
|
#******************************************************************************#
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ endif
|
|||||||
|
|
||||||
# Compilator
|
# Compilator
|
||||||
CC = gcc
|
CC = gcc
|
||||||
FLAGS = -Wall -Wextra -Werror -g
|
FLAGS = -Wall -Wextra -Werror
|
||||||
|
|
||||||
# Folders
|
# Folders
|
||||||
LIBDIR = libft
|
LIBDIR = libft
|
||||||
@@ -45,12 +45,14 @@ SRC = lm_parser.c \
|
|||||||
lm_graph_utils.c \
|
lm_graph_utils.c \
|
||||||
lm_parser_error_check.c \
|
lm_parser_error_check.c \
|
||||||
lm_utils_parser.c \
|
lm_utils_parser.c \
|
||||||
|
lm_utils_algo.c \
|
||||||
bfs.c \
|
bfs.c \
|
||||||
lst_ind.c \
|
lst_ind.c \
|
||||||
edmonds_karp.c \
|
edmonds_karp.c \
|
||||||
push_ants.c \
|
push_ants.c \
|
||||||
push_ants_utils.c \
|
push_ants_utils.c \
|
||||||
score_utils.c \
|
score_utils.c \
|
||||||
|
print_map.c \
|
||||||
lem_in.c
|
lem_in.c
|
||||||
|
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/23 17:31:19 by tmaze #+# #+# */
|
/* Created: 2019/03/23 17:31:19 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/04/22 10:01:33 by tmaze ### ########.fr */
|
/* Updated: 2019/05/09 17:39:33 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -32,15 +32,6 @@ typedef struct s_ind
|
|||||||
struct s_ind *next;
|
struct s_ind *next;
|
||||||
} t_ind;
|
} t_ind;
|
||||||
|
|
||||||
typedef struct s_lmdata
|
|
||||||
{
|
|
||||||
int nbants;
|
|
||||||
int nb_nodes;
|
|
||||||
int nb_paths_max;
|
|
||||||
t_node *nodes_data;
|
|
||||||
t_ind **adj;
|
|
||||||
} t_lmdata;
|
|
||||||
|
|
||||||
typedef struct s_bfs
|
typedef struct s_bfs
|
||||||
{
|
{
|
||||||
int parent;
|
int parent;
|
||||||
@@ -58,24 +49,6 @@ typedef struct s_ants
|
|||||||
struct s_ants *next;
|
struct s_ants *next;
|
||||||
} t_ants;
|
} t_ants;
|
||||||
|
|
||||||
typedef struct s_syntax
|
|
||||||
{
|
|
||||||
int nb_state;
|
|
||||||
int s_cmd;
|
|
||||||
int s_pos;
|
|
||||||
int error;
|
|
||||||
int s_error;
|
|
||||||
int e_error;
|
|
||||||
int v_error;
|
|
||||||
int l_error;
|
|
||||||
int gr_status;
|
|
||||||
int s_vert;
|
|
||||||
int e_vert;
|
|
||||||
int e_cmd;
|
|
||||||
int e_pos;
|
|
||||||
int v_flag;
|
|
||||||
} t_syntax;
|
|
||||||
|
|
||||||
typedef struct s_temp
|
typedef struct s_temp
|
||||||
{
|
{
|
||||||
int src_ind;
|
int src_ind;
|
||||||
@@ -86,6 +59,21 @@ typedef struct s_temp
|
|||||||
typedef struct s_holder
|
typedef struct s_holder
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
|
int nb_state;
|
||||||
|
int s_cmd;
|
||||||
|
int s_pos;
|
||||||
|
int error;
|
||||||
|
int s_error;
|
||||||
|
int state;
|
||||||
|
int e_error;
|
||||||
|
int v_error;
|
||||||
|
int l_error;
|
||||||
|
int gr_status;
|
||||||
|
int s_vert;
|
||||||
|
int e_vert;
|
||||||
|
int e_cmd;
|
||||||
|
int e_pos;
|
||||||
|
int v_flag;
|
||||||
t_temp *data;
|
t_temp *data;
|
||||||
} t_holder;
|
} t_holder;
|
||||||
|
|
||||||
@@ -95,31 +83,44 @@ typedef struct s_rdata
|
|||||||
struct s_rdata *next;
|
struct s_rdata *next;
|
||||||
} t_rdata;
|
} t_rdata;
|
||||||
|
|
||||||
int lm_error_exit(void);
|
typedef struct s_lmdata
|
||||||
int lm_validate(t_syntax *synt, t_lmdata *lmdata);
|
{
|
||||||
int lm_parser(t_syntax *synt, t_lmdata *ldata
|
int nbants;
|
||||||
|
int nb_nodes;
|
||||||
|
int nb_paths_max;
|
||||||
|
t_node *nodes_data;
|
||||||
|
t_ind **adj;
|
||||||
|
t_rdata *map;
|
||||||
|
} t_lmdata;
|
||||||
|
|
||||||
|
int lm_parser(t_lmdata *ldata
|
||||||
, t_holder *holder);
|
, t_holder *holder);
|
||||||
int lm_check_room_before(char **tab, t_syntax *synt);
|
int lm_check_room_before(char **tab, t_holder *holder
|
||||||
|
, char **name);
|
||||||
void lm_clear_unv(t_holder *holder);
|
void lm_clear_unv(t_holder *holder);
|
||||||
int lm_add_vertex(t_lmdata *ldata, char *raw, char flag
|
int lm_add_vertex(t_lmdata *ldata, char *raw, char flag
|
||||||
, t_syntax *synt);
|
, t_holder *holder);
|
||||||
int lm_ext_conn(t_holder *holder, t_lmdata *data
|
int lm_ext_conn(t_holder *holder, t_lmdata *data
|
||||||
, char *raw);
|
, char *raw);
|
||||||
|
void lm_ext_conn_sub(t_holder *holder, t_temp *new_data);
|
||||||
|
int lm_init_src_dest(int *src, int *dest, t_lmdata *data
|
||||||
|
, char *raw);
|
||||||
int lm_find_index(t_lmdata *data, char *str);
|
int lm_find_index(t_lmdata *data, char *str);
|
||||||
|
void lm_get_cmd_vertices(int count, t_holder *holder
|
||||||
int lm_get_value(char *line);
|
|
||||||
void lm_get_cmd_vert(int count, t_syntax *synt
|
|
||||||
, t_lmdata *ldata, char *line);
|
, t_lmdata *ldata, char *line);
|
||||||
void lm_get_vert_link(int count, t_syntax *synt
|
int lm_get_value(char *line);
|
||||||
, t_lmdata *ldata, t_holder *holder
|
void lm_check_start_vert(int count, t_holder *hol
|
||||||
, char *line);
|
, t_lmdata *ldata, char *line);
|
||||||
|
void lm_check_end_vert(int count, t_holder *hol
|
||||||
|
, t_lmdata *ldata, char *line);
|
||||||
|
void lm_get_vert_link(int count, t_lmdata *ldata
|
||||||
|
, t_holder *holder, char *line);
|
||||||
int lm_validate_rooms(char *name, char *x, char *y);
|
int lm_validate_rooms(char *name, char *x, char *y);
|
||||||
int lm_adj_parser(t_lmdata *lmdata, t_holder *holder);
|
int lm_adj_parser(t_lmdata *lmdata, t_holder *holder);
|
||||||
void lm_init_data(t_syntax *synt, t_holder *holder
|
void lm_init_data(t_holder *holder, t_lmdata *ldata);
|
||||||
, t_lmdata *ldata);
|
int lm_verify_cmd(t_holder *holder, t_lmdata *data);
|
||||||
int lm_verify_cmd(t_syntax *synt, t_holder *holder
|
|
||||||
, t_lmdata *data);
|
|
||||||
void lm_initdata(t_lmdata *data);
|
void lm_initdata(t_lmdata *data);
|
||||||
|
int lm_error_nbr(char *raw);
|
||||||
int lm_getparams(t_lmdata *data);
|
int lm_getparams(t_lmdata *data);
|
||||||
void lm_clean_data(t_lmdata *data);
|
void lm_clean_data(t_lmdata *data);
|
||||||
int lm_check_forbiden_chars(char *line, int flag);
|
int lm_check_forbiden_chars(char *line, int flag);
|
||||||
@@ -142,5 +143,14 @@ int get_score(t_lmdata *data, t_ind **ret, int nb_paths);
|
|||||||
void print_paths(t_lmdata *data, t_ind **ret);
|
void print_paths(t_lmdata *data, t_ind **ret);
|
||||||
int push_ants(t_lmdata *data, t_ind **paths
|
int push_ants(t_lmdata *data, t_ind **paths
|
||||||
, int nb_paths);
|
, int nb_paths);
|
||||||
|
void push_ants_end(t_lmdata *data, char *e_name);
|
||||||
|
|
||||||
|
void del_map(t_lmdata *data);
|
||||||
|
int add_line_map(t_lmdata *data, char *line);
|
||||||
|
void print_map(t_lmdata *data);
|
||||||
|
|
||||||
|
t_node *get_node_role(t_lmdata *data, char role);
|
||||||
|
int get_nb_paths(t_ind **ret);
|
||||||
|
void get_nb_paths_max(t_lmdata *data, int start, int end);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2018/04/07 12:47:06 by tmaze #+# #+# #
|
# Created: 2018/04/07 12:47:06 by tmaze #+# #+# #
|
||||||
# Updated: 2019/04/18 09:18:00 by tmaze ### ########.fr #
|
# Updated: 2019/05/09 18:39:42 by tmaze ### ########.fr #
|
||||||
# #
|
# #
|
||||||
#******************************************************************************#
|
#******************************************************************************#
|
||||||
|
|
||||||
@@ -32,6 +32,7 @@ SRCS = ft_memalloc.c \
|
|||||||
ft_isascii.c \
|
ft_isascii.c \
|
||||||
ft_isprint.c \
|
ft_isprint.c \
|
||||||
ft_toupper.c \
|
ft_toupper.c \
|
||||||
|
ft_isnumeric.c \
|
||||||
ft_tolower.c \
|
ft_tolower.c \
|
||||||
ft_isupper.c \
|
ft_isupper.c \
|
||||||
ft_islower.c \
|
ft_islower.c \
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */
|
/* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/20 16:46:41 by tmaze ### ########.fr */
|
/* Updated: 2019/04/26 10:36:51 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -266,6 +266,7 @@ int ft_strncmp(const char *s1, const char *s2, size_t n);
|
|||||||
int ft_atoi(const char *str);
|
int ft_atoi(const char *str);
|
||||||
int ft_isalpha(int c);
|
int ft_isalpha(int c);
|
||||||
int ft_isdigit(int c);
|
int ft_isdigit(int c);
|
||||||
|
int ft_isnumeric(char *str);
|
||||||
int ft_isalnum(int c);
|
int ft_isalnum(int c);
|
||||||
int ft_isascii(int c);
|
int ft_isascii(int c);
|
||||||
int ft_isprint(int c);
|
int ft_isprint(int c);
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/04 11:33:35 by tmaze #+# #+# */
|
/* Created: 2018/04/04 11:33:35 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/04 11:34:10 by tmaze ### ########.fr */
|
/* Updated: 2019/04/29 11:16:40 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
29
libft/srcs/ft_isnumeric.c
Normal file
29
libft/srcs/ft_isnumeric.c
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isnumeric.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/04/26 10:17:04 by mndhlovu #+# #+# */
|
||||||
|
/* Updated: 2019/04/29 11:20:54 by mndhlovu ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isnumeric(char *str)
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
|
||||||
|
index = 0;
|
||||||
|
if (str[index] == '-' || str[index] == '+')
|
||||||
|
index++;
|
||||||
|
while (str[index] != '\0')
|
||||||
|
{
|
||||||
|
if (!ft_isdigit(str[index]))
|
||||||
|
return (0);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
@@ -3,26 +3,22 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ft_strcmp.c :+: :+: :+: */
|
/* ft_strcmp.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/03 15:38:27 by tmaze #+# #+# */
|
/* Created: 2018/11/07 17:33:42 by mndhlovu #+# #+# */
|
||||||
/* Updated: 2018/04/08 15:30:24 by tmaze ### ########.fr */
|
/* Updated: 2018/11/09 17:56:30 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int ft_strcmp(const char *s1, const char *s2)
|
int ft_strcmp(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
int i;
|
size_t len;
|
||||||
int diff;
|
|
||||||
|
|
||||||
i = 1;
|
len = 0;
|
||||||
diff = (unsigned char)s1[0] - (unsigned char)s2[0];
|
while (s1[len] && s2[len] && s1[len] == s2[len])
|
||||||
while (diff == 0 && s1[i - 1] && s2[i - 1])
|
len++;
|
||||||
{
|
return ((unsigned char)s1[len] - (unsigned char)s2[len]);
|
||||||
diff = (unsigned char)s1[i] - (unsigned char)s2[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (diff);
|
|
||||||
}
|
}
|
||||||
|
BIN
maps/.DS_Store
vendored
BIN
maps/.DS_Store
vendored
Binary file not shown.
@@ -1,11 +0,0 @@
|
|||||||
3
|
|
||||||
#you
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
#lost
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
#the
|
|
||||||
#game
|
|
||||||
start-end
|
|
||||||
#!!
|
|
@@ -1,7 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 0 0
|
|
||||||
start-end
|
|
||||||
end-start
|
|
@@ -1,7 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 0 0
|
|
||||||
start-end
|
|
||||||
start-end
|
|
@@ -1,7 +0,0 @@
|
|||||||
3
|
|
||||||
Lillegalname 2 2
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
start-end
|
|
@@ -1,7 +0,0 @@
|
|||||||
3
|
|
||||||
ill-egalname 2 2
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
start-end
|
|
25
maps/in0
25
maps/in0
@@ -1,25 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
1 23 3
|
|
||||||
2 16 7
|
|
||||||
#commentaire
|
|
||||||
3 16 3
|
|
||||||
4 16 5
|
|
||||||
5 9 3
|
|
||||||
6 1 5
|
|
||||||
7 4 8
|
|
||||||
##end
|
|
||||||
0 9 5
|
|
||||||
0-4
|
|
||||||
0-6
|
|
||||||
1-3
|
|
||||||
4-3
|
|
||||||
5-2
|
|
||||||
3-5
|
|
||||||
#autre commentaire
|
|
||||||
4-2
|
|
||||||
2-1
|
|
||||||
7-6
|
|
||||||
7-2
|
|
||||||
7-4
|
|
||||||
6-5
|
|
@@ -1,8 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
##invalidcommand
|
|
||||||
room 2 2
|
|
||||||
start-end
|
|
@@ -1,6 +0,0 @@
|
|||||||
3
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
##start
|
|
||||||
start-end
|
|
11
maps/loop
11
maps/loop
@@ -1,11 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
mid0 2 2
|
|
||||||
mid1 3 3
|
|
||||||
start-mid0
|
|
||||||
mid0-mid1
|
|
||||||
mid1-start
|
|
||||||
start-end
|
|
10
maps/loop1
10
maps/loop1
@@ -1,10 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
mid0 2 2
|
|
||||||
mid1 3 3
|
|
||||||
start-mid0
|
|
||||||
mid0-mid1
|
|
||||||
mid1-start
|
|
@@ -1,5 +0,0 @@
|
|||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
start-end
|
|
@@ -1,5 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
end 1 1
|
|
||||||
start-end
|
|
@@ -1,5 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
@@ -1,5 +0,0 @@
|
|||||||
3
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
start-end
|
|
@@ -1,6 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 999999999999999999999 9999999999999999999999999999
|
|
||||||
start-end
|
|
@@ -1,20 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
long0 2 2
|
|
||||||
long1 3 3
|
|
||||||
short 4 4
|
|
||||||
longer0 5 5
|
|
||||||
longer1 6 6
|
|
||||||
longer2 7 7
|
|
||||||
start-long0
|
|
||||||
long0-long1
|
|
||||||
long1-end
|
|
||||||
start-short
|
|
||||||
short-end
|
|
||||||
start-longer0
|
|
||||||
longer0-longer1
|
|
||||||
longer1-longer2
|
|
||||||
longer2-end
|
|
@@ -1,6 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
start-end
|
|
10
maps/simple1
10
maps/simple1
@@ -1,10 +0,0 @@
|
|||||||
4
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
dead0 2 2
|
|
||||||
dead1 3 3
|
|
||||||
start-dead0
|
|
||||||
start-dead1
|
|
||||||
start-end
|
|
16
maps/simple2
16
maps/simple2
@@ -1,16 +0,0 @@
|
|||||||
4
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
dead0 2 2
|
|
||||||
dead1 3 3
|
|
||||||
mid0 4 4
|
|
||||||
mid1 5 5
|
|
||||||
mid2 6 6
|
|
||||||
start-dead0
|
|
||||||
start-mid0
|
|
||||||
mid0-dead0
|
|
||||||
start-mid1
|
|
||||||
mid1-mid2
|
|
||||||
mid2-end
|
|
@@ -1,4 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
##end
|
|
||||||
startend 0 0
|
|
@@ -1,13 +0,0 @@
|
|||||||
3
|
|
||||||
1 0 2
|
|
||||||
##start
|
|
||||||
0 2 0
|
|
||||||
##end
|
|
||||||
4 2 6
|
|
||||||
2 4 2
|
|
||||||
3 4 4
|
|
||||||
0-1
|
|
||||||
0-2
|
|
||||||
2-3
|
|
||||||
3-4
|
|
||||||
4-1
|
|
@@ -1,6 +0,0 @@
|
|||||||
3
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 -9999999999999999999999999
|
|
||||||
start-end
|
|
@@ -1,7 +0,0 @@
|
|||||||
3
|
|
||||||
# #end
|
|
||||||
##start
|
|
||||||
start 0 0
|
|
||||||
##end
|
|
||||||
end 1 1
|
|
||||||
start-end
|
|
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/18 09:25:05 by tmaze #+# #+# */
|
/* Created: 2019/04/18 09:25:05 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/04/21 14:42:08 by tmaze ### ########.fr */
|
/* Updated: 2019/04/30 07:08:31 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/18 09:59:11 by tmaze #+# #+# */
|
/* Created: 2019/04/18 09:59:11 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/04/21 16:11:56 by tmaze ### ########.fr */
|
/* Updated: 2019/04/30 07:14:04 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@@ -1,165 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* edmunds_karp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2019/03/28 16:21:19 by tmaze #+# #+# */
|
|
||||||
/* Updated: 2019/04/14 14:03:45 by tmaze ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "lem_in.h"
|
|
||||||
|
|
||||||
static void update_weights(t_lmdata *data, t_bfs *tab, int end_ind)
|
|
||||||
{
|
|
||||||
t_ind *it;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = end_ind;
|
|
||||||
while (i != -1)
|
|
||||||
{
|
|
||||||
if (tab[i].parent != -1)
|
|
||||||
{
|
|
||||||
it = data->adj[tab[i].parent];
|
|
||||||
while (it && it->index != i)
|
|
||||||
it = it->next;
|
|
||||||
if (it && it->index == i)
|
|
||||||
it->weight--;
|
|
||||||
it = data->adj[i];
|
|
||||||
while (it && it->index != tab[i].parent)
|
|
||||||
it = it->next;
|
|
||||||
if (it && it->index == tab[i].parent)
|
|
||||||
it->weight++;
|
|
||||||
}
|
|
||||||
i = tab[i].parent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int get_score(t_lmdata *data, t_ind **ret)
|
|
||||||
{
|
|
||||||
int tot;
|
|
||||||
int score;
|
|
||||||
int nb_paths;
|
|
||||||
int i;
|
|
||||||
t_ind *it;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
tot = 0;
|
|
||||||
score = 0;
|
|
||||||
while (ret && ret[i])
|
|
||||||
i++;
|
|
||||||
nb_paths = i;
|
|
||||||
ft_printf("nb_paths: %d\n", nb_paths);
|
|
||||||
i = 0;
|
|
||||||
while (ret && ret[i] && (it = ret[i]))
|
|
||||||
{
|
|
||||||
while (it && ++tot)
|
|
||||||
it = it->next;
|
|
||||||
tot = tot + (data->nbants / nb_paths) - 1;
|
|
||||||
if (score == 0 || tot > score)
|
|
||||||
score = tot;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (score);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static int reset_weights(t_lmdata *data, int node) */
|
|
||||||
/* { */
|
|
||||||
/* t_ind *it; */
|
|
||||||
/* t_ind *it2; */
|
|
||||||
|
|
||||||
/* it = data->adj[node]; */
|
|
||||||
/* it2 = NULL; */
|
|
||||||
/* while (it && it->weight != 2) */
|
|
||||||
/* it = it->next; */
|
|
||||||
/* if (it && it->weight == 2) */
|
|
||||||
/* it->weight = 1; */
|
|
||||||
/* if (it && it->index) */
|
|
||||||
/* it2 = data->adj[it->index]; */
|
|
||||||
/* while (it2 && it2->index != node) */
|
|
||||||
/* it2 = it2->next; */
|
|
||||||
/* if (it2 && it2->index == node) */
|
|
||||||
/* it2->weight = 1; */
|
|
||||||
/* return ((it != NULL) ? it->index : -1); */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
static t_ind **clean_ret(t_ind **ret)
|
|
||||||
{
|
|
||||||
tablst_inddel(ret);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static t_ind **resolve_path(t_lmdata *data, int s_ind, int e_ind, t_bfs *tab)
|
|
||||||
{
|
|
||||||
t_ind **ret;
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
t_ind *it;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
ret = NULL;
|
|
||||||
if ((ret = (t_ind**)ft_memalloc(sizeof(t_ind*) * (data->nb_paths_max + 1))) != NULL)
|
|
||||||
{
|
|
||||||
it = data->adj[e_ind];
|
|
||||||
while (it && i < data->nb_paths_max && (j = e_ind) == e_ind)
|
|
||||||
{
|
|
||||||
if (it->weight == 2 && (j = it->index))
|
|
||||||
{
|
|
||||||
if (lst_indadd(&(ret[i]), e_ind) == NULL)
|
|
||||||
return (clean_ret(ret));
|
|
||||||
while (j != s_ind)
|
|
||||||
{
|
|
||||||
if (lst_indadd(&(ret[i]), j) == NULL)
|
|
||||||
return (clean_ret(ret));
|
|
||||||
j = tab[j].parent;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
it = it->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
t_ind **edmunds_karp(t_lmdata *data, int start_ind, int end_ind)
|
|
||||||
{
|
|
||||||
t_bfs tab[data->nb_nodes];
|
|
||||||
t_ind **ret[2];
|
|
||||||
int score[2];
|
|
||||||
|
|
||||||
ret[0] = NULL;
|
|
||||||
ret[1] = NULL;
|
|
||||||
score[0] = 0;
|
|
||||||
score[1] = 0;
|
|
||||||
ft_printf("nb paths max: %d\n", data->nb_paths_max);
|
|
||||||
if (data && data->adj)
|
|
||||||
{
|
|
||||||
bfs(data, tab, start_ind, end_ind);
|
|
||||||
while (tab[end_ind].parent != -1)
|
|
||||||
{
|
|
||||||
update_weights(data, tab, end_ind);
|
|
||||||
if (tab[end_ind].parent != -1)
|
|
||||||
ret[1] = resolve_path(data, start_ind, end_ind, tab);
|
|
||||||
ft_printf("ret 0: %p\n", ret[0]);
|
|
||||||
ft_printf("score 0: %d\nscore 1: %d\n", score[0], get_score(data, ret[1]));
|
|
||||||
score[1] = get_score(data, ret[1]);
|
|
||||||
if (ret[0] == NULL || score[0] > score[1])
|
|
||||||
{
|
|
||||||
score[0] = score[1];
|
|
||||||
if (ret[0] != NULL)
|
|
||||||
clean_ret(ret[0]);
|
|
||||||
ret[0] = ret[1];
|
|
||||||
bfs(data, tab, start_ind, end_ind);
|
|
||||||
}
|
|
||||||
else if (score[0] <= score[1])
|
|
||||||
{
|
|
||||||
clean_ret(ret[1]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (ret[0]);
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
@@ -6,77 +6,64 @@
|
|||||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */
|
/* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */
|
||||||
/* Updated: 2019/04/22 10:02:05 by tmaze ### ########.fr */
|
/* Updated: 2019/05/09 17:38:50 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lem_in.h"
|
#include "lem_in.h"
|
||||||
|
|
||||||
static t_node *get_node_role(t_lmdata *data, char role)
|
static int start_end_link(t_lmdata *data, int s_ind, int e_ind)
|
||||||
{
|
{
|
||||||
t_node *it;
|
|
||||||
|
|
||||||
it = data->nodes_data;
|
|
||||||
while (it)
|
|
||||||
{
|
|
||||||
if (it->role == role)
|
|
||||||
return (it);
|
|
||||||
it = it->next;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int get_nb_paths(t_ind **ret)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (ret[i])
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void get_nb_paths_max(t_lmdata *data, int start, int end)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
t_ind *it;
|
t_ind *it;
|
||||||
|
|
||||||
i = 0;
|
it = data->adj[s_ind];
|
||||||
j = 0;
|
while (it)
|
||||||
it = data->adj[start];
|
{
|
||||||
while (it && ++i)
|
if (it->index == e_ind)
|
||||||
|
return (1);
|
||||||
it = it->next;
|
it = it->next;
|
||||||
it = data->adj[end];
|
}
|
||||||
while (it && ++j)
|
return (0);
|
||||||
it= it->next;
|
|
||||||
data->nb_paths_max = (i > j) ? j : i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lem_in(t_syntax *synt, t_holder *holder,
|
static int do_algorithm(t_lmdata *lmdata, t_ind ***ret)
|
||||||
t_lmdata *lmdata, t_ind ***ret)
|
|
||||||
{
|
{
|
||||||
if (!(lm_parser(synt, lmdata, holder)))
|
|
||||||
return (0);
|
|
||||||
if (!(lm_verify_cmd(synt, holder, lmdata)))
|
|
||||||
return (0);
|
|
||||||
if (!lst_indinit(lmdata))
|
|
||||||
return (0);
|
|
||||||
if (!(lm_adj_parser(lmdata, holder)))
|
|
||||||
return (0);
|
|
||||||
lm_clear_unv(holder);
|
|
||||||
get_nb_paths_max(lmdata, get_node_role(lmdata, 's')->ind
|
get_nb_paths_max(lmdata, get_node_role(lmdata, 's')->ind
|
||||||
, get_node_role(lmdata, 'e')->ind);
|
, get_node_role(lmdata, 'e')->ind);
|
||||||
if ((*ret = edmonds_karp(lmdata, get_node_role(lmdata, 's')->ind
|
if ((*ret = edmonds_karp(lmdata, get_node_role(lmdata, 's')->ind
|
||||||
, get_node_role(lmdata, 'e')->ind)) == NULL)
|
, get_node_role(lmdata, 'e')->ind)) == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
|
print_map(lmdata);
|
||||||
if (!push_ants(lmdata, *ret, get_nb_paths(*ret)))
|
if (!push_ants(lmdata, *ret, get_nb_paths(*ret)))
|
||||||
return (0);
|
return (0);
|
||||||
tablst_inddel(*ret);
|
tablst_inddel(*ret);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lm_error_exit(void)
|
static int lem_in(t_holder *holder,
|
||||||
|
t_lmdata *lmdata, t_ind ***ret)
|
||||||
|
{
|
||||||
|
lm_parser(lmdata, holder);
|
||||||
|
if (!lm_verify_cmd(holder, lmdata))
|
||||||
|
return (0);
|
||||||
|
if (!lst_indinit(lmdata))
|
||||||
|
return (0);
|
||||||
|
if ((lm_adj_parser(lmdata, holder) == 0))
|
||||||
|
return (0);
|
||||||
|
lm_clear_unv(holder);
|
||||||
|
if (start_end_link(lmdata, get_node_role(lmdata, 's')->ind
|
||||||
|
, get_node_role(lmdata, 'e')->ind))
|
||||||
|
{
|
||||||
|
print_map(lmdata);
|
||||||
|
push_ants_end(lmdata, get_node_role(lmdata, 'e')->name);
|
||||||
|
}
|
||||||
|
else if (!do_algorithm(lmdata, ret))
|
||||||
|
return (0);
|
||||||
|
del_map(lmdata);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lm_error_exit(void)
|
||||||
{
|
{
|
||||||
ft_putendl_fd("ERROR", 2);
|
ft_putendl_fd("ERROR", 2);
|
||||||
return (1);
|
return (1);
|
||||||
@@ -84,7 +71,6 @@ int lm_error_exit(void)
|
|||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
t_syntax synt;
|
|
||||||
t_lmdata ldata;
|
t_lmdata ldata;
|
||||||
t_holder holder;
|
t_holder holder;
|
||||||
t_ind **ret;
|
t_ind **ret;
|
||||||
@@ -92,9 +78,14 @@ int main(int ac, char **av)
|
|||||||
(void)av;
|
(void)av;
|
||||||
if (ac == 1)
|
if (ac == 1)
|
||||||
{
|
{
|
||||||
lm_init_data(&synt, &holder, &ldata);
|
lm_init_data(&holder, &ldata);
|
||||||
if (!(lem_in(&synt, &holder, &ldata, &ret)))
|
if (!(lem_in(&holder, &ldata, &ret)))
|
||||||
|
{
|
||||||
|
lm_clean_data(&ldata);
|
||||||
|
del_map(&ldata);
|
||||||
return (lm_error_exit());
|
return (lm_error_exit());
|
||||||
|
}
|
||||||
|
del_map(&ldata);
|
||||||
lm_clean_data(&ldata);
|
lm_clean_data(&ldata);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@@ -6,47 +6,54 @@
|
|||||||
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/22 08:55:30 by mndhlovu #+# #+# */
|
/* Created: 2019/04/22 08:55:30 by mndhlovu #+# #+# */
|
||||||
/* Updated: 2019/04/22 09:55:46 by mndhlovu ### ########.fr */
|
/* Updated: 2019/05/09 17:37:23 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lem_in.h"
|
#include "lem_in.h"
|
||||||
|
|
||||||
int lm_check_room_before(char **tab, t_syntax *synt)
|
int lm_check_room_before(char **tab, t_holder *holder
|
||||||
|
, char **name)
|
||||||
{
|
{
|
||||||
if (tab[0] != NULL && tab[1] != NULL && tab[2] != NULL)
|
if (tab[0] != NULL && tab[1] != NULL && tab[2] != NULL)
|
||||||
{
|
{
|
||||||
if (!lm_validate_rooms(tab[0], tab[1], tab[2]))
|
if (lm_validate_rooms(tab[0], tab[1], tab[2]) && !holder->state)
|
||||||
{
|
{
|
||||||
synt->v_error = 1;
|
if (!(*name = ft_strdup(tab[0])))
|
||||||
return (0);
|
return (0);
|
||||||
}
|
return (1);
|
||||||
}
|
}
|
||||||
return (1);
|
}
|
||||||
}
|
holder->v_error = 1;
|
||||||
|
|
||||||
int lm_check_forbiden_chars(char *line, int flag)
|
|
||||||
{
|
|
||||||
char *hash;
|
|
||||||
char *dash;
|
|
||||||
|
|
||||||
dash = ft_strchr(line, '-');
|
|
||||||
hash = ft_strchr(line, '#');
|
|
||||||
if (flag == 0 && dash == NULL && hash == NULL)
|
|
||||||
return (1);
|
|
||||||
if (flag == 1 && dash == NULL && hash != NULL)
|
|
||||||
return (1);
|
|
||||||
if (flag == 2 && dash == NULL && (hash == NULL || (hash != NULL && line[1] != '#')))
|
|
||||||
return (1);
|
|
||||||
if (flag == 3 && dash != NULL && (hash == NULL || (hash != NULL && line[1] != '#')))
|
|
||||||
return (1);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_clear_unv(t_holder *holder)
|
int lm_check_forbiden_chars(char *line, int flag)
|
||||||
{
|
{
|
||||||
t_temp *data;
|
char *hash;
|
||||||
t_temp *flush;
|
char *dash;
|
||||||
|
|
||||||
|
if (line != NULL)
|
||||||
|
{
|
||||||
|
dash = ft_strchr(line, '-');
|
||||||
|
hash = ft_strchr(line, '#');
|
||||||
|
if (flag == 0 && dash == NULL && hash == NULL)
|
||||||
|
return (1);
|
||||||
|
if (flag == 1 && dash == NULL && hash != NULL)
|
||||||
|
return (1);
|
||||||
|
if (flag == 2 && dash == NULL
|
||||||
|
&& (hash == NULL || (hash != NULL && line[1] != '#')))
|
||||||
|
return (1);
|
||||||
|
if (flag == 3 && (dash != NULL && hash == NULL))
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lm_clear_unv(t_holder *holder)
|
||||||
|
{
|
||||||
|
t_temp *data;
|
||||||
|
t_temp *flush;
|
||||||
|
|
||||||
data = holder->data;
|
data = holder->data;
|
||||||
while (data)
|
while (data)
|
||||||
@@ -59,12 +66,26 @@ void lm_clear_unv(t_holder *holder)
|
|||||||
holder->data = NULL;
|
holder->data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lm_verify_cmd(t_syntax *synt, t_holder *holder, t_lmdata *data)
|
int lm_verify_links(t_holder *data, t_holder *hold)
|
||||||
{
|
{
|
||||||
if (synt->s_cmd && synt->e_cmd && !synt->v_error
|
if (!hold->l_error
|
||||||
&& !synt->l_error && !synt->e_error && !synt->s_error
|
|| (hold->l_error
|
||||||
&& synt->nb_state && (holder->count > 0)
|
&& data->count > 0))
|
||||||
&& (data->nb_nodes > 0))
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lm_verify_cmd(t_holder *holder
|
||||||
|
, t_lmdata *data)
|
||||||
|
{
|
||||||
|
if (holder->s_cmd && holder->e_cmd
|
||||||
|
&& !holder->e_error && !holder->s_error
|
||||||
|
&& !holder->v_error
|
||||||
|
&& holder->s_vert
|
||||||
|
&& holder->e_vert
|
||||||
|
&& holder->nb_state
|
||||||
|
&& lm_verify_links(holder, holder)
|
||||||
|
&& (data->nb_nodes > 0))
|
||||||
return (1);
|
return (1);
|
||||||
lm_clear_unv(holder);
|
lm_clear_unv(holder);
|
||||||
return (0);
|
return (0);
|
||||||
|
@@ -6,40 +6,40 @@
|
|||||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/05 06:35:40 by mndhlovu #+# #+# */
|
/* Created: 2019/04/05 06:35:40 by mndhlovu #+# #+# */
|
||||||
/* Updated: 2019/04/11 11:32:32 by tmaze ### ########.fr */
|
/* Updated: 2019/05/09 17:35:34 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lem_in.h"
|
#include "lem_in.h"
|
||||||
|
|
||||||
t_rdata *lm_new_raw_line(char *raw)
|
t_rdata *lm_new_raw_line(char *raw)
|
||||||
{
|
{
|
||||||
t_rdata *line;
|
t_rdata *line;
|
||||||
|
|
||||||
if (!(line = (t_rdata *)malloc(sizeof(t_rdata))))
|
if (!(line = (t_rdata *)malloc(sizeof(t_rdata))))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
line->line = ft_strdup(raw);
|
line->line = ft_strdup(raw);
|
||||||
line->next = NULL;
|
line->next = NULL;
|
||||||
return (line);
|
return (line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_append_line(t_rdata **line, char *raw)
|
void lm_append_line(t_rdata **line, char *raw)
|
||||||
{
|
{
|
||||||
if (*line)
|
if (*line)
|
||||||
{
|
{
|
||||||
if((*line)->next)
|
if ((*line)->next)
|
||||||
lm_append_line(&(*line)->next, raw);
|
lm_append_line(&(*line)->next, raw);
|
||||||
else
|
else
|
||||||
(*line)->next = lm_new_raw_line(raw);
|
(*line)->next = lm_new_raw_line(raw);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*line = lm_new_raw_line(raw);
|
*line = lm_new_raw_line(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_clean_data(t_lmdata *data)
|
void lm_clean_data(t_lmdata *data)
|
||||||
{
|
{
|
||||||
t_node *tmp;
|
t_node *tmp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
while (data->nodes_data)
|
while (data->nodes_data)
|
||||||
{
|
{
|
||||||
@@ -51,7 +51,8 @@ void lm_clean_data(t_lmdata *data)
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (i < data->nb_nodes)
|
while (i < data->nb_nodes)
|
||||||
{
|
{
|
||||||
lst_inddel(&(data->adj[i]));
|
if (data->adj && data->adj[i])
|
||||||
|
lst_inddel(&(data->adj[i]));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
ft_memdel((void**)&(data->adj));
|
ft_memdel((void**)&(data->adj));
|
||||||
|
@@ -6,15 +6,16 @@
|
|||||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/29 07:17:06 by mndhlovu #+# #+# */
|
/* Created: 2019/03/29 07:17:06 by mndhlovu #+# #+# */
|
||||||
/* Updated: 2019/04/11 20:34:58 by tmaze ### ########.fr */
|
/* Updated: 2019/05/09 17:26:36 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lem_in.h"
|
#include "lem_in.h"
|
||||||
|
|
||||||
static int is_link_in(t_lmdata *data, int src, int dest)
|
static int is_link_in(t_lmdata *data, int src, int dest)
|
||||||
{
|
{
|
||||||
t_ind *it;
|
t_ind *it;
|
||||||
|
|
||||||
if (src < data->nb_nodes)
|
if (src < data->nb_nodes)
|
||||||
{
|
{
|
||||||
it = data->adj[src];
|
it = data->adj[src];
|
||||||
@@ -28,9 +29,19 @@ static int is_link_in(t_lmdata *data, int src, int dest)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lm_adj_parser(t_lmdata *lmdata, t_holder *holder)
|
void lm_ext_conn_sub(t_holder *holder, t_temp *new_data)
|
||||||
{
|
{
|
||||||
t_temp *data;
|
t_temp *temp;
|
||||||
|
|
||||||
|
temp = holder->data;
|
||||||
|
while (temp->next)
|
||||||
|
temp = temp->next;
|
||||||
|
temp->next = new_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lm_adj_parser(t_lmdata *lmdata, t_holder *holder)
|
||||||
|
{
|
||||||
|
t_temp *data;
|
||||||
|
|
||||||
if (holder != NULL)
|
if (holder != NULL)
|
||||||
{
|
{
|
||||||
|
@@ -6,15 +6,100 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/23 17:43:34 by tmaze #+# #+# */
|
/* Created: 2019/03/23 17:43:34 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/04/08 18:26:13 by tmaze ### ########.fr */
|
/* Updated: 2019/05/09 17:35:50 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lem_in.h"
|
#include "lem_in.h"
|
||||||
|
|
||||||
void lm_initdata(t_lmdata *data)
|
void lm_initdata(t_lmdata *data)
|
||||||
{
|
{
|
||||||
data->nbants = 0;
|
data->nbants = 0;
|
||||||
data->nodes_data = NULL;
|
data->nodes_data = NULL;
|
||||||
data->adj = NULL;
|
data->adj = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lm_check_start_vert(int count, t_holder *hol
|
||||||
|
, t_lmdata *ldata, char *line)
|
||||||
|
{
|
||||||
|
if ((hol->s_pos < hol->e_pos)
|
||||||
|
&& lm_check_forbiden_chars(line, 0))
|
||||||
|
{
|
||||||
|
if ((count > hol->s_pos && count < hol->e_pos)
|
||||||
|
&& (!hol->s_vert))
|
||||||
|
{
|
||||||
|
if ((lm_add_vertex(ldata, line, 's', hol)))
|
||||||
|
hol->s_vert = count;
|
||||||
|
else
|
||||||
|
hol->s_error = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((hol->s_pos > hol->e_pos)
|
||||||
|
&& lm_check_forbiden_chars(line, 0))
|
||||||
|
{
|
||||||
|
if (!hol->s_vert)
|
||||||
|
{
|
||||||
|
if ((lm_add_vertex(ldata, line, 's', hol)))
|
||||||
|
hol->s_vert = count;
|
||||||
|
else
|
||||||
|
hol->s_error = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void lm_check_end_vert(int count, t_holder *hol
|
||||||
|
, t_lmdata *ldata, char *line)
|
||||||
|
{
|
||||||
|
if ((hol->e_pos < hol->s_pos)
|
||||||
|
&& lm_check_forbiden_chars(line, 0))
|
||||||
|
{
|
||||||
|
if ((count > hol->e_pos && count < hol->s_pos)
|
||||||
|
&& (!hol->e_vert))
|
||||||
|
{
|
||||||
|
if ((lm_add_vertex(ldata, line, 'e', hol)))
|
||||||
|
hol->e_vert = count;
|
||||||
|
else
|
||||||
|
hol->e_error = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((hol->e_pos > hol->s_pos)
|
||||||
|
&& lm_check_forbiden_chars(line, 0))
|
||||||
|
{
|
||||||
|
if (!hol->e_vert)
|
||||||
|
{
|
||||||
|
if ((lm_add_vertex(ldata, line, 'e', hol)))
|
||||||
|
hol->e_vert = count;
|
||||||
|
else
|
||||||
|
hol->e_error = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int lm_init_src_dest(int *src, int *dest, t_lmdata *data
|
||||||
|
, char *raw)
|
||||||
|
{
|
||||||
|
int s;
|
||||||
|
int d;
|
||||||
|
char **tab;
|
||||||
|
|
||||||
|
if (raw != NULL)
|
||||||
|
{
|
||||||
|
tab = ft_strsplit(raw, '-');
|
||||||
|
if (tab != NULL)
|
||||||
|
{
|
||||||
|
s = lm_find_index(data, tab[0]);
|
||||||
|
d = lm_find_index(data, tab[1]);
|
||||||
|
if (s == -1 || d == -1)
|
||||||
|
{
|
||||||
|
ft_del_words_tables(&tab);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
*src = s;
|
||||||
|
*dest = d;
|
||||||
|
ft_del_words_tables(&tab);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ft_del_words_tables(&tab);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
@@ -6,121 +6,116 @@
|
|||||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/25 06:31:37 by mndhlovu #+# #+# */
|
/* Created: 2019/03/25 06:31:37 by mndhlovu #+# #+# */
|
||||||
/* Updated: 2019/04/11 11:39:06 by tmaze ### ########.fr */
|
/* Updated: 2019/05/09 17:33:39 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lem_in.h"
|
#include "lem_in.h"
|
||||||
|
|
||||||
void lm_init_data(t_syntax *synt, t_holder *holder, t_lmdata *ldata)
|
void lm_init_data(t_holder *holder, t_lmdata *ldata)
|
||||||
{
|
{
|
||||||
synt->nb_state = 0;
|
holder->nb_state = 0;
|
||||||
synt->s_cmd = 0;
|
holder->s_cmd = 0;
|
||||||
synt->e_cmd = 0;
|
holder->e_cmd = 0;
|
||||||
synt->s_error = 0;
|
holder->s_error = 0;
|
||||||
synt->e_error = 0;
|
holder->e_error = 0;
|
||||||
synt->v_error = 0;
|
holder->v_error = 0;
|
||||||
synt->l_error = 0;
|
holder->l_error = 0;
|
||||||
synt->s_vert = 0;
|
holder->s_vert = 0;
|
||||||
synt->e_vert = 0;
|
holder->e_vert = 0;
|
||||||
synt->gr_status = 0;
|
holder->state = 0;
|
||||||
synt->s_pos = 0;
|
holder->s_pos = 0;
|
||||||
synt->e_pos = 0;
|
holder->e_pos = 0;
|
||||||
synt->v_flag = 0;
|
holder->v_flag = 0;
|
||||||
holder->count = 0;
|
holder->count = 0;
|
||||||
holder->data = NULL;
|
holder->data = NULL;
|
||||||
ldata->nbants = 0;
|
ldata->nbants = 0;
|
||||||
ldata->nb_nodes = 0;
|
ldata->nb_nodes = 0;
|
||||||
ldata->nodes_data = NULL;
|
ldata->nodes_data = NULL;
|
||||||
ldata->adj = NULL;
|
ldata->adj = NULL;
|
||||||
|
ldata->map = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lm_add_vertex_sub(t_lmdata *ldata, t_node *new)
|
static void lm_add_vertex_sub(t_lmdata *ldata, t_node *new)
|
||||||
{
|
{
|
||||||
t_node *tmp;
|
t_node *tmp;
|
||||||
|
|
||||||
if (ldata->nodes_data == NULL)
|
if (ldata->nodes_data == NULL)
|
||||||
ldata->nodes_data = new;
|
ldata->nodes_data = new;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tmp = ldata->nodes_data;
|
tmp = ldata->nodes_data;
|
||||||
while (tmp->next)
|
while (tmp->next)
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
tmp->next = new;
|
tmp->next = new;
|
||||||
}
|
}
|
||||||
(ldata->nb_nodes)++;
|
(ldata->nb_nodes)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lm_add_vertex(t_lmdata *ldata, char *raw, char flag,
|
int lm_add_vertex(t_lmdata *ldata, char *raw, char flag,
|
||||||
t_syntax *synt)
|
t_holder *holder)
|
||||||
{
|
{
|
||||||
char **tab;
|
char **tab;
|
||||||
t_node *new;
|
t_node *new;
|
||||||
|
char *str;
|
||||||
|
|
||||||
if (!(new = (t_node *)ft_memalloc(sizeof(t_node))))
|
if (!(new = (t_node *)ft_memalloc(sizeof(t_node))))
|
||||||
return (0);
|
return (0);
|
||||||
tab = ft_strsplit(raw, ' ');
|
if ((tab = ft_strsplit(raw, ' ')) != NULL)
|
||||||
if (tab != NULL)
|
{
|
||||||
{
|
if (lm_check_room_before(tab, holder, &str))
|
||||||
if (lm_check_room_before(tab, synt))
|
{
|
||||||
{
|
new->name = str;
|
||||||
if ((new->name = ft_strdup(tab[0])) == NULL)
|
new->x = ft_atoi(tab[1]);
|
||||||
ft_del_words_tables(&tab);
|
new->y = ft_atoi(tab[2]);
|
||||||
if (new->name == NULL)
|
new->role = flag;
|
||||||
return (0);
|
new->ind = ldata->nb_nodes;
|
||||||
new->x = ft_atoi(tab[1]);
|
new->next = NULL;
|
||||||
new->y = ft_atoi(tab[2]);
|
lm_add_vertex_sub(ldata, new);
|
||||||
new->role = flag;
|
|
||||||
new->ind = ldata->nb_nodes;
|
|
||||||
new->next = NULL;
|
|
||||||
lm_add_vertex_sub(ldata, new);
|
|
||||||
ft_del_words_tables(&tab);
|
ft_del_words_tables(&tab);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int lm_find_index(t_lmdata *data, char *str)
|
|
||||||
{
|
|
||||||
t_node *nodes;
|
|
||||||
|
|
||||||
nodes = data->nodes_data;
|
|
||||||
while (nodes)
|
|
||||||
{
|
|
||||||
if (ft_strcmp(nodes->name, str) == 0)
|
|
||||||
return (nodes->ind);
|
|
||||||
nodes = nodes->next;
|
|
||||||
}
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int lm_ext_conn(t_holder *holder, t_lmdata *data, char *raw)
|
|
||||||
{
|
|
||||||
char **tab;
|
|
||||||
t_temp *temp;
|
|
||||||
t_temp *new;
|
|
||||||
|
|
||||||
if (!(new = (t_temp *)ft_memalloc(sizeof(t_temp))))
|
|
||||||
return (0);
|
|
||||||
tab = ft_strsplit(raw, '-');
|
|
||||||
if (tab != NULL)
|
|
||||||
{
|
|
||||||
new->src_ind = lm_find_index(data, tab[0]);
|
|
||||||
new->dest_ind = lm_find_index(data, tab[1]);
|
|
||||||
new->next = NULL;
|
|
||||||
if (holder->data == NULL)
|
|
||||||
holder->data = new;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
temp = holder->data;
|
|
||||||
while (temp->next)
|
|
||||||
temp = temp->next;
|
|
||||||
temp->next = new;
|
|
||||||
}
|
|
||||||
(holder->count)++;
|
|
||||||
ft_del_words_tables(&tab);
|
ft_del_words_tables(&tab);
|
||||||
return (1);
|
free(new);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lm_find_index(t_lmdata *data, char *str)
|
||||||
|
{
|
||||||
|
t_node *nodes;
|
||||||
|
|
||||||
|
nodes = data->nodes_data;
|
||||||
|
while (nodes)
|
||||||
|
{
|
||||||
|
if (ft_strequ(nodes->name, str))
|
||||||
|
return (nodes->ind);
|
||||||
|
nodes = nodes->next;
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lm_ext_conn(t_holder *holder, t_lmdata *data, char *raw)
|
||||||
|
{
|
||||||
|
t_temp *new;
|
||||||
|
int src;
|
||||||
|
int dest;
|
||||||
|
|
||||||
|
if (!(new = (t_temp *)ft_memalloc(sizeof(t_temp))))
|
||||||
|
return (0);
|
||||||
|
if (lm_init_src_dest(&src, &dest, data, raw))
|
||||||
|
{
|
||||||
|
new->src_ind = src;
|
||||||
|
new->dest_ind = dest;
|
||||||
|
new->next = NULL;
|
||||||
|
if (holder->data == NULL)
|
||||||
|
holder->data = new;
|
||||||
|
else
|
||||||
|
lm_ext_conn_sub(holder, new);
|
||||||
|
(holder->count)++;
|
||||||
|
holder->state = 1;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
free(new);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
152
srcs/lm_parser.c
152
srcs/lm_parser.c
@@ -3,99 +3,91 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* lm_parser.c :+: :+: :+: */
|
/* lm_parser.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/25 06:30:51 by mndhlovu #+# #+# */
|
/* Created: 2019/04/20 15:24:51 by mndhlovu #+# #+# */
|
||||||
/* Updated: 2019/04/20 13:08:01 by mndhlovu ### ########.fr */
|
/* Updated: 2019/05/09 16:55:53 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lem_in.h"
|
#include "lem_in.h"
|
||||||
|
|
||||||
void lm_locate_cd(int index, t_syntax *synt, char *line)
|
static void lm_locate_cd(int index, t_holder *holder, char *line)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
tmp = ft_strchr(line, '#');
|
tmp = ft_strchr(line, '#');
|
||||||
if ((!synt->s_cmd || !synt->e_cmd)
|
if ((!holder->s_cmd || !holder->e_cmd)
|
||||||
&& (tmp != NULL && line[1] == '#'
|
&& (tmp != NULL && line[1] == '#'
|
||||||
&& lm_check_forbiden_chars(line, 1)))
|
&& lm_check_forbiden_chars(line, 1)))
|
||||||
{
|
{
|
||||||
if (!synt->s_cmd)
|
if (!holder->s_cmd)
|
||||||
{
|
|
||||||
if (ft_strcmp(tmp, "##start") == 0)
|
|
||||||
{
|
|
||||||
synt->s_cmd = 1;
|
|
||||||
synt->s_pos = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!synt->e_cmd)
|
|
||||||
{
|
|
||||||
if (ft_strcmp(tmp, "##end") == 0)
|
|
||||||
{
|
|
||||||
synt->e_cmd = 1;
|
|
||||||
synt->e_pos = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int lm_get_ant_(int counter, t_lmdata *ldata, t_syntax *synt, char *line)
|
|
||||||
{
|
|
||||||
int value;
|
|
||||||
|
|
||||||
if (counter == 0 && lm_check_forbiden_chars(line, 0))
|
|
||||||
{
|
|
||||||
value = lm_get_value(line);
|
|
||||||
if (value != -1)
|
|
||||||
{
|
|
||||||
ldata->nbants = value;
|
|
||||||
synt->nb_state = 1;
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lm_get_vertices(int count, t_syntax *synt,
|
|
||||||
t_lmdata *data, t_holder *holder, char *line)
|
|
||||||
{
|
|
||||||
lm_get_cmd_vert(count, synt, data, line);
|
|
||||||
if (!synt->s_error && !synt->e_error)
|
|
||||||
{
|
|
||||||
lm_get_vert_link(count, synt, data, holder, line);
|
|
||||||
if (!synt->v_error && !synt->l_error)
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int lm_parser(t_syntax *synt, t_lmdata *ldata,
|
|
||||||
t_holder *holder)
|
|
||||||
{
|
|
||||||
char *raw;
|
|
||||||
int index;
|
|
||||||
|
|
||||||
index = 0;
|
|
||||||
while (ft_getline(&raw) > 0)
|
|
||||||
{
|
|
||||||
ft_printf("%s\n", raw);
|
|
||||||
if (!(lm_get_ant_(index, ldata, synt, raw)) && index == 0)
|
|
||||||
{
|
{
|
||||||
ft_strdel(&raw);
|
if (ft_strcmp(line, "##start") == 0)
|
||||||
return (0);
|
{
|
||||||
|
holder->s_cmd = 1;
|
||||||
|
holder->s_pos = index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lm_locate_cd(index, synt, raw);
|
if (!holder->e_cmd)
|
||||||
if (!(lm_get_vertices(index, synt, ldata, holder, raw)))
|
|
||||||
{
|
{
|
||||||
ft_strdel(&raw);
|
if (ft_strcmp(line, "##end") == 0)
|
||||||
|
{
|
||||||
|
holder->e_cmd = 1;
|
||||||
|
holder->e_pos = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lm_get_ant_(int counter, t_lmdata *ldata
|
||||||
|
, t_holder *holder, char *line)
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
|
||||||
|
if (counter == 0 && lm_check_forbiden_chars(line, 0))
|
||||||
|
{
|
||||||
|
value = lm_get_value(line);
|
||||||
|
if (value > 0)
|
||||||
|
{
|
||||||
|
ldata->nbants = value;
|
||||||
|
holder->nb_state = 1;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lm_get_vertices(int count, t_lmdata *data
|
||||||
|
, t_holder *holder, char *line)
|
||||||
|
{
|
||||||
|
lm_get_cmd_vertices(count, holder, data, line);
|
||||||
|
if (!holder->s_error && !holder->e_error)
|
||||||
|
{
|
||||||
|
lm_get_vert_link(count, data, holder, line);
|
||||||
|
if (!holder->v_error && !holder->l_error)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lm_parser(t_lmdata *ldata, t_holder *holder)
|
||||||
|
{
|
||||||
|
char *raw;
|
||||||
|
int index;
|
||||||
|
|
||||||
|
index = 0;
|
||||||
|
while (ft_getline(&raw) > 0 && raw[0] != '\0')
|
||||||
|
{
|
||||||
|
if ((add_line_map(ldata, raw)))
|
||||||
return (0);
|
return (0);
|
||||||
}
|
if (!(lm_get_ant_(index, ldata, holder, raw)) && index == 0)
|
||||||
ft_strdel(&raw);
|
return (0);
|
||||||
index++;
|
lm_locate_cd(index, holder, raw);
|
||||||
}
|
if (!(lm_get_vertices(index, ldata, holder, raw)))
|
||||||
|
return (0);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
ft_strdel(&raw);
|
ft_strdel(&raw);
|
||||||
ft_putchar('\n');
|
return (1);
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
@@ -6,13 +6,13 @@
|
|||||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/08 06:42:37 by mndhlovu #+# #+# */
|
/* Created: 2019/04/08 06:42:37 by mndhlovu #+# #+# */
|
||||||
/* Updated: 2019/04/20 13:29:12 by mndhlovu ### ########.fr */
|
/* Updated: 2019/05/06 07:24:46 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lem_in.h"
|
#include "lem_in.h"
|
||||||
|
|
||||||
int lm_chk_format_nbr(char *raw)
|
static int lm_chk_format_nbr(char *raw)
|
||||||
{
|
{
|
||||||
while (*raw)
|
while (*raw)
|
||||||
{
|
{
|
||||||
@@ -25,16 +25,16 @@ int lm_chk_format_nbr(char *raw)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lm_check_max(char *raw)
|
static int lm_check_max(char *raw)
|
||||||
{
|
{
|
||||||
if (ft_atoi(raw) < INT_MIN || ft_atoi(raw) > INT_MAX)
|
if (ft_atoi(raw) < INT_MIN || ft_atoi(raw) > INT_MAX)
|
||||||
return (-1);
|
return (-1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lm_validate_name(char *name)
|
static int lm_validate_name(char *name)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
if (name[0] == 'L')
|
if (name[0] == 'L')
|
||||||
@@ -48,28 +48,29 @@ int lm_validate_name(char *name)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lm_validate_rooms(char *name, char *x, char *y)
|
int lm_validate_rooms(char *name, char *x, char *y)
|
||||||
{
|
{
|
||||||
if (lm_validate_name(name) == -1)
|
if (lm_validate_name(name) == -1)
|
||||||
return (-1);
|
|
||||||
if (lm_chk_format_nbr(x) == -1 ||
|
|
||||||
lm_check_max(x) == -1 || (ft_atoi(x) > 0 &&
|
|
||||||
(ft_atoi(x) == 0)) ||
|
|
||||||
ft_strlen(x) > 19)
|
|
||||||
return (0);
|
return (0);
|
||||||
if (lm_chk_format_nbr(y) == -1 ||
|
if (lm_chk_format_nbr(x) == -1
|
||||||
lm_check_max(y) == -1 || (ft_atoi(y) > 0 &&
|
|| lm_check_max(x) == -1
|
||||||
(ft_atoi(y) == 0)) ||
|
|| (ft_atoi(x) > 0 && (ft_atoi(x) == 0))
|
||||||
ft_strlen(y) > 19)
|
|| ft_strlen(x) > 19)
|
||||||
|
return (0);
|
||||||
|
if (lm_chk_format_nbr(y) == -1
|
||||||
|
|| lm_check_max(y) == -1
|
||||||
|
|| (ft_atoi(y) > 0 && (ft_atoi(y) == 0))
|
||||||
|
|| ft_strlen(y) > 19)
|
||||||
return (0);
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lm_error_nbr(char *raw)
|
int lm_error_nbr(char *raw)
|
||||||
{
|
{
|
||||||
if (lm_chk_format_nbr(raw) == -1 || lm_check_max(raw) == -1 ||
|
if (lm_chk_format_nbr(raw) == -1
|
||||||
(ft_atoi(raw) > 0 && (ft_atoi(raw) == 0)) ||
|
|| lm_check_max(raw) == -1
|
||||||
ft_strlen(raw) > 19)
|
|| (ft_atoi(raw) > 0 && (ft_atoi(raw) == 0))
|
||||||
return (-1);
|
|| ft_strlen(raw) > 19)
|
||||||
return (0);
|
return (0);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
54
srcs/lm_utils_algo.c
Normal file
54
srcs/lm_utils_algo.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lm_utils_algo.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/04/29 11:50:04 by mndhlovu #+# #+# */
|
||||||
|
/* Updated: 2019/04/30 07:19:29 by mndhlovu ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "lem_in.h"
|
||||||
|
|
||||||
|
t_node *get_node_role(t_lmdata *data, char role)
|
||||||
|
{
|
||||||
|
t_node *it;
|
||||||
|
|
||||||
|
it = data->nodes_data;
|
||||||
|
while (it)
|
||||||
|
{
|
||||||
|
if (it->role == role)
|
||||||
|
return (it);
|
||||||
|
it = it->next;
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_nb_paths(t_ind **ret)
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
|
||||||
|
index = 0;
|
||||||
|
while (ret[index])
|
||||||
|
index++;
|
||||||
|
return (index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_nb_paths_max(t_lmdata *data, int start, int end)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
t_ind *it;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
it = data->adj[start];
|
||||||
|
while (it && ++i)
|
||||||
|
it = it->next;
|
||||||
|
it = data->adj[end];
|
||||||
|
while (it && ++j)
|
||||||
|
it = it->next;
|
||||||
|
data->nb_paths_max = (i > j) ? j : i;
|
||||||
|
}
|
@@ -6,79 +6,61 @@
|
|||||||
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/04 09:24:45 by mndhlovu #+# #+# */
|
/* Created: 2019/04/04 09:24:45 by mndhlovu #+# #+# */
|
||||||
/* Updated: 2019/04/20 13:25:57 by mndhlovu ### ########.fr */
|
/* Updated: 2019/05/09 17:40:24 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lem_in.h"
|
#include "lem_in.h"
|
||||||
|
|
||||||
int lm_get_value(char *line)
|
static int lm_check_ant_no(char *line)
|
||||||
{
|
{
|
||||||
int index;
|
int len;
|
||||||
|
|
||||||
if (line != NULL)
|
len = ft_strlen(line);
|
||||||
{
|
if (len > 0)
|
||||||
index = ft_atoi(line);
|
{
|
||||||
if (index > INT_MIN && index < INT_MAX)
|
if (len == 1 && ft_isdigit(*line))
|
||||||
{
|
return (*line - '0');
|
||||||
if (index > 0)
|
else if (len > 1 && lm_error_nbr(line) && ft_isnumeric(line))
|
||||||
return (index);
|
return (ft_atoi(line));
|
||||||
else
|
}
|
||||||
{
|
return (0);
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_get_cmd_vert(int count, t_syntax *synt
|
int lm_get_value(char *line)
|
||||||
, t_lmdata *ldata, char *line)
|
|
||||||
{
|
{
|
||||||
char *tmp;
|
if (line != NULL)
|
||||||
|
return (lm_check_ant_no(line));
|
||||||
if (synt->s_pos == count - 1)
|
return (0);
|
||||||
{
|
|
||||||
tmp = ft_strchr(line, '#');
|
|
||||||
if (tmp == NULL && count != synt->e_vert)
|
|
||||||
{
|
|
||||||
synt->s_vert = count;
|
|
||||||
if (!(lm_add_vertex(ldata, line, 's', synt)))
|
|
||||||
synt->e_error = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (synt->e_pos == count - 1)
|
|
||||||
{
|
|
||||||
tmp = ft_strchr(line, '#');
|
|
||||||
if (tmp == NULL && count != synt->s_vert)
|
|
||||||
{
|
|
||||||
synt->e_vert = count;
|
|
||||||
if (!(lm_add_vertex(ldata, line, 'e', synt)))
|
|
||||||
synt->s_error = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_get_vert_link(int count, t_syntax *synt, t_lmdata *ldata
|
void lm_get_cmd_vertices(int count, t_holder *holder
|
||||||
, t_holder *holder, char *line)
|
, t_lmdata *ldata, char *line)
|
||||||
{
|
{
|
||||||
if (count > 0 && (count != synt->s_vert && count != synt->e_vert)
|
if (count > 0 && line != NULL)
|
||||||
&& (count != synt->s_pos && count != synt->e_pos))
|
{
|
||||||
{
|
lm_check_start_vert(count, holder, ldata, line);
|
||||||
if (lm_check_forbiden_chars(line, 0))
|
lm_check_end_vert(count, holder, ldata, line);
|
||||||
{
|
}
|
||||||
if (!(lm_add_vertex(ldata, line, 'v', synt)))
|
}
|
||||||
{
|
|
||||||
synt->v_error = 1;
|
void lm_get_vert_link(int count, t_lmdata *ldata
|
||||||
}
|
, t_holder *holder, char *line)
|
||||||
}
|
{
|
||||||
if (lm_check_forbiden_chars(line, 0))
|
if (count > 0 && (count != holder->s_vert
|
||||||
{
|
&& count != holder->e_vert)
|
||||||
if (!(lm_ext_conn(holder, ldata, line)))
|
&& (count != holder->s_pos
|
||||||
{
|
&& count != holder->e_pos && line != NULL))
|
||||||
synt->l_error = 1;
|
{
|
||||||
return ;
|
if (lm_check_forbiden_chars(line, 0))
|
||||||
}
|
{
|
||||||
}
|
if (!(lm_add_vertex(ldata, line, 'v', holder)))
|
||||||
}
|
holder->v_error = 1;
|
||||||
|
}
|
||||||
|
if (lm_check_forbiden_chars(line, 3))
|
||||||
|
{
|
||||||
|
if (!(lm_ext_conn(holder, ldata, line)))
|
||||||
|
holder->l_error = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/27 14:56:55 by tmaze #+# #+# */
|
/* Created: 2019/03/27 14:56:55 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/04/09 19:04:33 by tmaze ### ########.fr */
|
/* Updated: 2019/04/30 07:19:43 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
64
srcs/print_map.c
Normal file
64
srcs/print_map.c
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* print_map.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/04/24 17:35:29 by tmaze #+# #+# */
|
||||||
|
/* Updated: 2019/05/09 16:35:02 by tmaze ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "lem_in.h"
|
||||||
|
|
||||||
|
void del_map(t_lmdata *data)
|
||||||
|
{
|
||||||
|
t_rdata *tmp;
|
||||||
|
|
||||||
|
if (data != NULL)
|
||||||
|
{
|
||||||
|
while (data->map)
|
||||||
|
{
|
||||||
|
tmp = data->map;
|
||||||
|
data->map = data->map->next;
|
||||||
|
ft_strdel(&(tmp->line));
|
||||||
|
ft_memdel((void**)&tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_map(t_lmdata *data)
|
||||||
|
{
|
||||||
|
t_rdata *it;
|
||||||
|
|
||||||
|
it = data->map;
|
||||||
|
while (it)
|
||||||
|
{
|
||||||
|
ft_printf("%s\n", it->line);
|
||||||
|
it = it->next;
|
||||||
|
}
|
||||||
|
del_map(data);
|
||||||
|
ft_printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int add_line_map(t_lmdata *data, char *line)
|
||||||
|
{
|
||||||
|
t_rdata *it;
|
||||||
|
t_rdata *new;
|
||||||
|
|
||||||
|
if ((new = (t_rdata*)ft_memalloc(sizeof(t_rdata))) == NULL)
|
||||||
|
return (1);
|
||||||
|
new->line = line;
|
||||||
|
new->next = NULL;
|
||||||
|
if (data->map == NULL)
|
||||||
|
data->map = new;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
it = data->map;
|
||||||
|
while (it->next)
|
||||||
|
it = it->next;
|
||||||
|
it->next = new;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/06 11:37:56 by tmaze #+# #+# */
|
/* Created: 2019/04/06 11:37:56 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/04/21 16:14:45 by tmaze ### ########.fr */
|
/* Updated: 2019/04/30 07:05:43 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/10 11:23:36 by tmaze #+# #+# */
|
/* Created: 2019/04/10 11:23:36 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/04/18 19:04:49 by tmaze ### ########.fr */
|
/* Updated: 2019/05/02 14:33:30 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -69,3 +69,18 @@ t_ind *get_node_path(t_ind *lst, int index)
|
|||||||
it = it->next;
|
it = it->next;
|
||||||
return (it);
|
return (it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void push_ants_end(t_lmdata *data, char *e_name)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
while (i <= data->nbants)
|
||||||
|
{
|
||||||
|
ft_printf("L%d-%s", i, e_name);
|
||||||
|
if (i != data->nbants)
|
||||||
|
ft_putchar(' ');
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
ft_printf("\n");
|
||||||
|
}
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/18 18:05:06 by tmaze #+# #+# */
|
/* Created: 2019/04/18 18:05:06 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/04/21 16:53:11 by tmaze ### ########.fr */
|
/* Updated: 2019/04/30 07:05:10 by mndhlovu ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user