-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
83 lines (71 loc) · 1.81 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
79
80
81
82
83
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "headers/fileHandler.h"
#include "headers/config_t.h"
#include "headers/types_t.h"
#include "headers/rules.h"
#include "headers/coord_t.h"
int main (int argc, char **argv) {
if (argc < 2) {
printf("Usage:\n%s <config_file>\n\n", argv[0]);
exit(1);
}
config_t conf;
object_t **eco, **next_eco;
coord_t p;
readFile(argv[1], &conf, &eco);
//readFile("mx/m30.txt", &conf, &eco);
next_eco = allocateMatrix(conf.L, conf.C);
deepcopy(next_eco, eco, conf.L, conf.C);
#ifdef STEP
system("clear");
printf("-------GEN:%2d-------\n", 0);
printMatrix (eco, conf.L, conf.C, conf);
getchar();
system("clear");
printf("-------GEN:%2d-------\n", 1);
#endif
for (unsigned int t = 1; t <= conf.N_GEN; t++){
conf.GEN++;
// COELHO
for (unsigned int i = 0; i < conf.L; i++){
for (unsigned int j = 0; j < conf.C; j++){
if (eco[i][j].type == RABBIT){
p = (coord_t){.x = i, .y = j};
rabbit_rules (eco, next_eco, conf, p);
}
}
}
conflict(next_eco, conf, RABBIT);
deepcopy(eco, next_eco, conf.L, conf.C);
/* #ifdef STEP
printMatrix (eco, conf.L, conf.C, conf);
getchar();
system("clear");
printf("-------GEN:%2d-------\n", t);
#endif*/
for (unsigned int i = 0; i < conf.L; i++){
for (unsigned int j = 0; j < conf.C; j++){
if (eco[i][j].type == FOX){
p = (coord_t){.x = i, .y = j};
fox_rules (eco, next_eco, conf, p);
}
}
}
conflict(next_eco, conf, FOX);
deepcopy(eco, next_eco, conf.L, conf.C);
#ifdef STEP
printMatrix (eco, conf.L, conf.C, conf);
getchar();
system("clear");
printf("-------GEN:%2d-------\n", t+1);
#endif
}
#ifdef STEP
printf("-------GEN:%2d-------\n", conf.GEN);
printMatrix (eco, conf.L, conf.C, conf);
#endif
return 0;
}