This is my code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
int main(){
FILE *f = fopen("result.txt","w");
int i, j, run=0 ,counter=0, random_i, random_j;
double matrix[20][40];
srand(time(NULL));
for(i=0; i<20; i++){
for(j=0; j<40; j++){
matrix[0][j] = 2;
matrix[19][j] = 2;
}
matrix[i][0] = 2;
matrix[i][39] = 2;
}
for(i=1; i<19; i++){
for(j=1; j<39; j++){
matrix[i][j] = 1;
counter++;
}
}
for(i=8; i<12; i++){
for(j=0; j<1; j++){
matrix[i][j] = 3;
}
for(j=39; j<40; j++){
matrix[i][j] = 3;
}
}
fprintf(f,"\n\ncounter: %d\n run: %d\n",counter,run);
do{
run++;
}while(counter != 0)
for(i=0; i<20; i++){
for(j=0; j<40; j++){
fprintf(f,"%.f;\t",matrix[i][j]);
}
fprintf(f,"\n");
}
fprintf(f,"\n\ncounter: %d\n run: %d\n",counter,run);
fclose(f);
return 0;
}
Where '2' means a wall, '3' means a door and '1' means a human ('0' would be a plance where no human is standing).
The task is to pick a human randomly and in case this human is standing nexto a door, the place can be '0' and this means -1 human from the rectangle. In case a human is not standing nexto a door, but there is a '0' around him, he can move.
The main object is to empty this rectangle and to calculate how many times ran the program.
Could you please help me with that? Unfortunately I'm not able to write the part where I can get the rectangle empty.
Thank you very much!
Aucun commentaire:
Enregistrer un commentaire