-
Notifications
You must be signed in to change notification settings - Fork 0
/
muravei_idi.c
executable file
·82 lines (75 loc) · 2.17 KB
/
muravei_idi.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* muravei_idi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ioleksiu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/15 21:22:13 by ioleksiu #+# #+# */
/* Updated: 2017/08/15 21:22:15 by ioleksiu ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
void muravei_alloc(t_rooms *temp, t_lemin *lem)
{
int i;
while (temp)
{
temp->ant_num = -1;
temp = temp->next;
}
lem->is_ant_finished = (int*)malloc(sizeof(int) * lem->n_ants);
i = -1;
while (++i < lem->n_ants)
lem->is_ant_finished[i] = 1;
}
void muravei_idi1(t_lemin *lem, t_ways *ways, t_rooms *room,
t_rooms *rooms)
{
int pos;
t_rooms *next_room;
while (ways)
{
pos = ft_room_position(ways->way, lem->room_num, room->id);
if (pos != -1)
{
next_room = find_room_by_id(rooms, ways->way[pos + 1]);
if (next_room->ant_num == -1)
{
room->ant_num = -1;
if (next_room->id == lem->room_num - 1)
{
lem->n_ants--;
lem->is_ant_finished[lem->i] = 0;
}
else
next_room->ant_num = lem->i + 1;
print_results(lem->i + 1, next_room->r_name);
break ;
}
}
ways = ways->next;
}
}
void muravei_idi(t_lemin *lem, t_rooms *rooms)
{
int ant_num;
t_rooms *room;
t_ways *ways;
t_rooms *temp;
temp = rooms;
muravei_alloc(temp, lem);
ant_num = lem->n_ants;
while (lem->n_ants != 0)
{
lem->i = -1;
while (++lem->i < ant_num)
if (lem->is_ant_finished[lem->i] == 1)
{
ways = lem->ways;
room = get_room_by_ant_id(rooms, lem->i + 1);
muravei_idi1(lem, ways, room, rooms);
}
write(1, "\n", 1);
}
}