-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
78 lines (64 loc) · 1.82 KB
/
main.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include "ecosystem.h"
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Favor passar um arquivo de entrada!\n");
exit(1);
}
int i, j;
Ecosystem eco = ecosystem_init(argv[1]);
extern int gverbose;
for (i = 2; i < argc; i++) {
if (strcmp(argv[i], "-v") == 0 && i + 1 < argc) {
gverbose = atoi(argv[i + 1]);
break;
}
}
for(eco.current_gen = 0; eco.current_gen < eco.n_gen; eco.current_gen++){
ecosystem_print(&eco);
// Deciding movement
#pragma omp parallel for
for(j = 0; j < eco.animal_count[RABBIT]; j++){
move_rabbit(&eco, j);
}
for(j = 0; j < eco.animal_count[RABBIT]; j++){
ecosystem_resolve_conflicts(&eco, j, RABBIT, RABBIT);
}
// Updating the position.
#pragma omp parallel for
for (j = 0; j < eco.animal_count[RABBIT]; j++) {
ecosystem_update_position(&eco, j, RABBIT);
}
#pragma omp parallel for
for(j = 0; j < eco.animal_count[FOX]; j++){
move_fox(&eco, j);
}
for(j = 0; j < eco.animal_count[FOX]; j++){
ecosystem_resolve_conflicts(&eco, j, FOX, FOX);
}
for(j = 0; j < eco.animal_count[RABBIT]; j++){
ecosystem_resolve_conflicts(&eco, j, RABBIT, FOX);
}
#pragma omp parallel for
for (j = 0; j < eco.animal_count[FOX]; j++) {
ecosystem_update_position(&eco, j, FOX);
}
ecosystem_normalize(&eco, RABBIT);
ecosystem_normalize(&eco, FOX);
}
ecosystem_print(&eco);
eco.n = eco.animal_count[FOX] + eco.animal_count[RABBIT] + eco.rock_count;
printf("%d %d %d %d %d %d %d\n", eco.gen_proc_rabbits, eco.gen_proc_fox, eco.gen_food_fox, eco.n_gen, eco.l, eco.c, eco.n);
for(i = 0; i < eco.l; i++) {
for (j = 0; j < eco.c; j++) {
if (eco.matrix[i][j].type != EMPTY) {
object_print(eco.matrix[i][j].type, i, j);
}
}
}
return 0;
}