Skip to content

Commit

Permalink
Testing version
Browse files Browse the repository at this point in the history
  • Loading branch information
elvishribeiro committed Dec 14, 2019
1 parent a1feeb6 commit fd53701
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 55 deletions.
22 changes: 5 additions & 17 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ int main (int argc, char **argv) {
object_t **eco;
coord_t p;


printf("Lendo arquivo");
readFile(argv[1], &conf, &eco);
//readFile("mx/m20.txt", &conf, &eco);
//readFile("config.ini", &conf, &eco);
//next_eco = allocateMatrix(conf.L, conf.C);
//deepcopy(next_eco, eco, conf.L, conf.C);

#ifdef STEP
system("clear");
Expand All @@ -46,9 +42,6 @@ int main (int argc, char **argv) {
#endif

// REGRAS DO COELHO
#ifdef PARALELO
#pragma omp parallel for //paralelo
#endif
for (unsigned int i = 0; i < conf.L; i++){
for (unsigned int j = 0; j < conf.C; j++){
if (eco[i][j].animal.type == RABBIT){
Expand All @@ -57,7 +50,6 @@ int main (int argc, char **argv) {
}
}
}
//conflict(eco, conf, RABBIT);

//CONFLITOS DO COELHO
#ifdef PARALELO
Expand All @@ -68,7 +60,6 @@ int main (int argc, char **argv) {
eco[i][j].animal = choose_rabbit(eco[i][j]);
}
}
//deepcopy(eco, next_eco, conf.L, conf.C);

#ifdef STEP2
printMatrix (eco, conf.L, conf.C, conf);
Expand All @@ -78,9 +69,6 @@ int main (int argc, char **argv) {
#endif

//REGRAS DA RAPOSA
#ifdef PARALELO
#pragma omp parallel for //paralelo
#endif
for (unsigned int i = 0; i < conf.L; i++){
for (unsigned int j = 0; j < conf.C; j++){
if (eco[i][j].animal.type == FOX){
Expand All @@ -91,7 +79,6 @@ int main (int argc, char **argv) {
}

//CONFLITOS DA RAPOSA
//conflict(eco, conf, FOX);
#ifdef PARALELO
#pragma omp parallel for //paralelo
#endif
Expand All @@ -100,8 +87,9 @@ int main (int argc, char **argv) {
eco[i][j].animal = choose_fox(eco[i][j]);
}
}
//deepcopy(eco, next_eco, conf.L, conf.C);

printf("\rGeração %d/%d", t, conf.N_GEN);
fflush(stdout);
#ifdef STEP
printMatrix (eco, conf.L, conf.C, conf);
#endif
Expand All @@ -112,7 +100,7 @@ int main (int argc, char **argv) {
}


/*void printResult (object_t **eco, config_t conf) {
void printResult (object_t **eco, config_t conf) {
int N = 0;
for (unsigned int i = 0; i < conf.L; i++)
for (unsigned int j = 0; j < conf.C; j++)
Expand All @@ -139,4 +127,4 @@ int main (int argc, char **argv) {
printf("ROCHA %d %d\n", i, j);
}
}
}*/
}
57 changes: 19 additions & 38 deletions rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,34 @@ coord_t neighbour(object_t **eco, config_t conf, coord_t p, int type) {

// Inserts a rabbit and resolve possible conflicts
void rabbit_insert (object_t **eco, animal_t r, coord_t old, coord_t new) {
int candidate_id;

if (old.y + 1 == new.y)
candidate_id = LEFT;
else if (old.x - 1 == new.x)
candidate_id = DOWN;
else if (old.y - 1 == new.y)
candidate_id = RIGHT;
else if (old.x + 1 == new.x)
candidate_id = UP;
else if (old.x == new.x && old.y == new.y)
candidate_id = CENTER;

eco[new.x][new.y].candidates[candidate_id] = r;
int candidate_id;

if (old.y + 1 == new.y)
candidate_id = LEFT;
else if (old.x - 1 == new.x)
candidate_id = DOWN;
else if (old.y - 1 == new.y)
candidate_id = RIGHT;
else if (old.x + 1 == new.x)
candidate_id = UP;
else if (old.x == new.x && old.y == new.y)
candidate_id = CENTER;

eco[new.x][new.y].candidates[candidate_id] = r;
}

// Make a move if a available slot is found and returns the new position
int rabbit_move (object_t **eco, config_t conf, coord_t p) {
coord_t new = neighbour(eco, conf, p, EMPTY);
coord_t new = neighbour(eco, conf, p, EMPTY);

if (new.x >= 0 && new.y >= 0){
if (conf.GEN - eco[p.x][p.y].animal.gen_nascimento > conf.GEN_PROC_COELHOS) { // Reproduction
rabbit_insert(eco, NEWANIMAL(RABBIT, conf.GEN, -1), p, p);
rabbit_insert(eco, NEWANIMAL(RABBIT, conf.GEN, -1), p, new);
}
else { // Move without reproducing
rabbit_insert(eco, eco[p.x][p.y].animal, p, new);
//rabbit_insert(eco, eco[p.x][p.y].animal, p, new);
rabbit_insert(eco, NEWANIMAL(RABBIT, eco[p.x][p.y].animal.gen_nascimento, -1), p, new);
}
return 1;
} //No neighbours, returns false
Expand Down Expand Up @@ -212,25 +214,4 @@ animal_t choose_fox (object_t object) {
return old_animal;
else
return NEWANIMAL(EMPTY, -1, -1);
}

/*void conflict (object_t **eco, config_t conf, int type) {
if (type == RABBIT) {
//#ifdef PARALELO
#pragma omp parallel for //paralelo#endif
for (unsigned int i = 0; i < conf.L; i++){
for (unsigned int j = 0; j < conf.C; j++){
eco[i][j].animal = choose_rabbit(eco[i][j]);
}
}
}
else if (type == FOX) {
//#ifdef PARALELO
#pragma omp parallel for //paralelo#endif
for (unsigned int i = 0; i < conf.L; i++){
for (unsigned int j = 0; j < conf.C; j++){
eco[i][j].animal = choose_fox(eco[i][j]);
}
}
}
}*/
}

0 comments on commit fd53701

Please sign in to comment.