From aee16c5d4424b9a812952c6b4252c3f1a9bf677b Mon Sep 17 00:00:00 2001 From: Elvis H Ribeiro Date: Wed, 11 Dec 2019 16:13:30 -0300 Subject: [PATCH] Testing version: Commented printfs to test --- fileHandler.c | 38 -------------------------------------- main.c | 33 +++++++++++++++++---------------- rules.c | 4 ++-- 3 files changed, 19 insertions(+), 56 deletions(-) delete mode 100644 fileHandler.c diff --git a/fileHandler.c b/fileHandler.c deleted file mode 100644 index 65973af..0000000 --- a/fileHandler.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "headers/fileHandler.h" - - -/*Reads the file passed by the string filename returning a configuration struct and the ecosystem matrix*/ -int readFile (char *filename, config_t *conf, object_t ***eco) { - FILE *fp; - unsigned int N; - char object_type[7]; - coord_t p; - object_t **matrix; - - fp = fopen(filename, "r"); - if (fp == NULL) { - perror(filename); - exit(1); - } - - /*TODO -- file checking*/ - fscanf(fp, "%u %u %u %u %u %u %u\n",&(conf->GEN_PROC_COELHOS), - &(conf->GEN_PROC_RAPOSAS), - &(conf->GEN_COMIDA_RAPOSAS), - &(conf->N_GEN), - &(conf->L), - &(conf->C), - &N); - conf->GEN = 0; - - matrix = allocateMatrix(conf->L, conf->C); - - for (int i = 0; i < N; i++) { - fscanf(fp, "%s %d %d\n", object_type, &(p.x), &(p.y)); - insert_into_matrix(matrix, object_type, p); - } - - *eco = matrix; - - return 1; -} \ No newline at end of file diff --git a/main.c b/main.c index 7d61e4a..7862715 100644 --- a/main.c +++ b/main.c @@ -22,41 +22,41 @@ int main (int argc, char **argv) { readFile(argv[1], &conf, &eco); - int matrix_size = conf.L*conf.C*sizeof(object_t); - next_eco = allocateMatrix(conf.L, conf.C); deepcopy(next_eco, eco, conf.L, conf.C); - system("clear"); + //system("clear"); printf("-------GEN:%2d-------\n", 0); printMatrix (eco, conf.L, conf.C, conf); //usleep(500000); - getchar(); - system("clear"); - printf("-------GEN:%2d-------\n", 1); + //getchar(); + //system("clear"); + //printf("-------GEN:%2d-------\n", 1); 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++){ - p = (coord_t){.x = i, .y = 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); - printMatrix (eco, conf.L, conf.C, conf); + + //printMatrix (eco, conf.L, conf.C, conf); //usleep(500000); - getchar(); - system("clear"); - printf("-------GEN:%2d-------\n", t); + //getchar(); + //system("clear"); + //printf("-------GEN:%2d-------\n", t); for (unsigned int i = 0; i < conf.L; i++){ for (unsigned int j = 0; j < conf.C; j++){ - p = (coord_t){.x = i, .y = j}; if (eco[i][j].type == FOX){ + p = (coord_t){.x = i, .y = j}; fox_rules (eco, next_eco, conf, p); } } @@ -64,13 +64,14 @@ int main (int argc, char **argv) { conflict(next_eco, conf, FOX); deepcopy(eco, next_eco, conf.L, conf.C); - printMatrix (eco, conf.L, conf.C, conf); + //printMatrix (eco, conf.L, conf.C, conf); //usleep(500000); - getchar(); - system("clear"); - printf("-------GEN:%2d-------\n", t+1); + //getchar(); + //system("clear"); + //printf("-------GEN:%2d-------\n", t+1); } + printf("-------GEN:%2d-------\n", conf.GEN); printMatrix (eco, conf.L, conf.C, conf); return 0; diff --git a/rules.c b/rules.c index 4728bac..9e22792 100644 --- a/rules.c +++ b/rules.c @@ -130,8 +130,8 @@ void fox_rules (object_t **eco, object_t **next_eco, config_t conf, coord_t p) { /* Movement */ if (!predation(eco, next_eco, conf, p)) { eco[p.x][p.y].animal.hunger++; - if(eco[p.x][p.y].animal.hunger >= conf.GEN_COMIDA_RAPOSAS){ - next_eco[p.x][p.y].type = EMPTY; + if(eco[p.x][p.y].animal.hunger >= conf.GEN_COMIDA_RAPOSAS){ //death + clear_position(&(next_eco[p.x][p.y])); } else fox_move(eco, next_eco, conf, p);