-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchoice.c
76 lines (68 loc) · 1.2 KB
/
choice.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
#include "lem_in.h"
void fill_count_routes(t_lemin **lemin)
{
t_pack_routes *prs;
t_routes *rs;
prs = (*lemin)->pack_routes;
while (prs)
{
if (prs->routes->route->room)
{
rs = prs->routes;
while (rs)
{
prs->count_routes++;
rs = rs->next;
}
}
prs = prs->next;
}
}
void routes_choice_if(int *moves, int *tmp,
t_pack_routes **choice, t_pack_routes **prs)
{
if (*moves && *tmp < *moves)
{
*moves = *tmp;
*choice = *prs;
}
if (!(*moves))
{
*moves = *tmp;
*choice = *prs;
}
}
t_pack_routes *routes_choice(t_lemin **lemin, int moves, int tmp)
{
t_pack_routes *choice;
t_routes *rs;
t_pack_routes *prs;
choice = NULL;
moves = 0;
tmp = 0;
prs = (*lemin)->pack_routes;
while (prs)
{
if (prs->routes->route->room)
{
rs = prs->routes;
while (rs)
{
tmp += ((*lemin)->ants / prs->count_routes) * rs->len_route;
rs = rs->next;
}
tmp = tmp / prs->count_routes;
routes_choice_if(&moves, &tmp, &choice, &prs);
tmp = 0;
}
prs = prs->next;
}
return (choice);
}
void make_a_choice(t_lemin **lemin)
{
t_pack_routes *choice;
fill_count_routes(lemin);
choice = routes_choice(lemin, 0, 0);
print_lemin(&(choice->routes), lemin, 1);
}