-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility_functions.c
More file actions
81 lines (71 loc) · 2.06 KB
/
utility_functions.c
File metadata and controls
81 lines (71 loc) · 2.06 KB
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
/* ************************************************************************** */
/* */
/* :::::::: */
/* utility_functions.c :+: :+: */
/* +:+ */
/* By: lvan-vlo <lvan-vlo@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2019/09/20 12:48:17 by lvan-vlo #+# #+# */
/* Updated: 2019/09/23 10:58:27 by rcorke ######## odam.nl */
/* */
/* ************************************************************************** */
#include "lem_in.h"
char *get_room_name(char *str)
{
int x;
x = 0;
while (str[x] && str[x] != ' ')
x++;
return (ft_strsub(str, 0, x));
}
void print_movement(int which_ant, char *str)
{
ft_printf("L%d-%s ", which_ant + 1, str);
}
int return_shortest_path_index(t_table *lem)
{
int x;
int rtn;
x = 0;
rtn = 0;
while (x < lem->num_real_paths)
{
if (lem->rp[x]->temp_size < lem->rp[rtn]->temp_size)
rtn = x;
x++;
}
return (rtn);
}
void reset_visited(t_table *lem, int first_or_second)
{
int i;
i = 0;
while (i < lem->rooms)
{
if (first_or_second != 3)
lem->link_table[i]->bfs_visited = 0;
else if (first_or_second == 3)
{
if (lem->link_table[i]->bfs_visited != 2)
lem->link_table[i]->bfs_visited = 0;
}
lem->link_table[i]->distance = -1;
i++;
}
lem->link_table[lem->end_index]->trav_visited = 0;
lem->link_table[lem->start_index]->trav_visited = 0;
}
int can_backtrack(t_table *lem, t_links *node)
{
t_links *iter;
iter = node->next;
while (iter)
{
if (iter->in == 0 && iter->out == 1 && \
lem->link_table[iter->index]->trav_visited == 1 && \
lem->link_table[iter->index]->bfs_visited == 0)
return (1);
iter = iter->next;
}
return (0);
}