-
Notifications
You must be signed in to change notification settings - Fork 0
/
lem_in.h
198 lines (169 loc) · 4.17 KB
/
lem_in.h
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lem_in.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: awoimbee <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/14 17:37:38 by awoimbee #+# #+# */
/* Updated: 2019/05/11 15:00:20 by awoimbee ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LEM_IN_H
# define LEM_IN_H
# include <unistd.h>
# include <stdlib.h>
# include <limits.h>
# include <stdint.h>
# include <sys/types.h>
# include "libft.h"
# define REALLOC_COEFF 2
# define DEFMALLOCMAP 10
# define DEF_MALLOC_TSTR 10
# define UINT32_NOT_SET 4294967295U
# define LNK_VISITED 0x80000000
struct s_str;
struct s_map;
struct s_room;
struct s_graph;
typedef enum e_command
{
NONE,
UNKNOWN,
START,
END,
RED,
BLUE,
GREEN,
CYAN,
PINK,
YELLOW
} t_command;
typedef struct s_int2
{
int x;
int y;
} t_int2;
typedef struct s_str
{
char **str;
uint size;
uint used;
} t_str;
typedef struct s_map
{
struct s_room *list;
uint size;
uint used;
} t_map;
typedef struct s_room
{
char *name;
int ants;
t_int2 coords;
char *color;
uint *links;
uint nb_link;
uint mem_link;
} t_room;
typedef struct s_graph
{
uint tmp;
uint print;
uint ants;
uint start;
uint end;
t_map map;
} t_graph;
/*
** PATHFINDING
*/
void find_paths(t_graph *graph, t_str *str);
void send_ants(t_graph *g, t_vector *paths);
void edmonds_karp(t_graph *g, t_vector *path, int mx_pths,
int super_po);
int calc_ants_to_launch(t_graph *g, t_vector *vec);
void write_path(t_graph *g, uint *parents);
void graph_to_paths(t_graph *g, t_vector *paths);
void compute_paths(t_graph *g, t_vector *vec, int nb_p, int sup_po);
void destroy_paths(t_vector *paths);
/*
** /clean_graph.c
*/
void clean_graph_ants_mem(t_graph *g);
void clean_graph_links(t_graph *g);
void clean_graph_everything(t_graph *g);
void clean_graph_memlnk(t_graph *g);
/*
** EXIT
*/
void exit_lem_in(char *key);
void exit_clean(t_graph *g, int error);
/*
** PARSER
*/
void find_ants(t_graph *g, t_str **str);
void parse_input(t_graph *g, t_str **str);
/*
** DEAL_WITH_LINE
*/
long long ft_atoi_pimp(char *line);
int ft_atoi_mv_err(const char **nptr, int *err);
int is_comment(char *line);
/*
** READ_ROOMS
*/
t_room *is_room(char *line, t_graph *g);
int read_rooms(t_graph *g, t_str **str, char **tmp);
/*
** FIND_LINKS
*/
int is_link(t_graph *g, t_str **str, char *line);
void find_links(t_graph *g, t_str **str);
/*
** COMMAND_LINE
*/
t_command command_hub(char *line);
void exec_command(t_graph *g, t_command command);
void exec_room_command(t_room *room, t_command color);
int is_command(char *line);
/*
** T_STR
*/
t_str *new_t_str(void);
void free_t_str(t_str *string);
void realloc_t_str(t_str *string);
void add_t_str(t_str *string, char *add);
void display_t_str(t_str *string);
/*
** T_MAP
*/
t_map *new_t_map(void);
void free_t_map(t_map *map, int free_sub);
void realloc_t_map(t_map *map);
void add_t_map(t_map *map, t_room *add);
int is_room_here(t_map *map, t_room *room);
/*
** LINKS
*/
void realloc_links(t_room *hub);
void add_link(t_room *hub, const uint linked);
/*
** T_ROOM
*/
t_room *new_room(char *name, int ants, int x, int y);
void free_room(t_room *room);
int cmp_room(t_room *a, t_room *b);
void reset_room(t_room *tmp_room);
/*
** INIT_GRAPH
*/
t_graph *init_graph(void);
void free_t_graph(t_graph *g);
/*
** DISPLAY_GRAPH_ROOM_MAP (DEBUG)
*/
void display_links(const t_room *hub, const t_graph *g);
void display_room(const t_room *room, const t_graph *g);
void display_graph(t_graph *g);
#endif