Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define L 300
- #define t_max 11000
- int main(){
- int c[L][L];
- int ant[L][L];
- int ant1[L][L];
- int i, j, n, somm, t;
- FILE *fp, *fd;
- fp=fopen("ant.dat","w");
- fd=fopen("ant.gnu","w");
- fprintf(fd, "splot 'ant.dat' \n");
- fclose(fd);
- for(i=0;i<L;i++){ //azzero array ant e ant1 e metto tutta bianca la scacchiera
- for(j=0;j<L;j++){
- c[i][j]=0;
- ant[i][j]=0;
- ant1[i][j]=0;
- }
- }
- ant1[L/2][L/2]=1; //creo una ant al centro della scacchiera
- ant[L/2][L/2-1]=1;
- for(t=0;t<t_max;t++){
- for(i=1;i<L;i++){
- for(j=1;j<L;j++){
- if(ant1[i][j]==1){
- if(c[i][j]==1){
- if(ant[i-1][j]==1){ant1[i][j+1]=1;ant1[i][j]=0;ant[i][j]=1;ant[i-1][j]=0;c[i][j]=0;}
- if(ant[i][j-1]==1){ant1[i-1][j]=1;ant1[i][j]=0;ant[i][j]=1;ant[i][j-1]=0;c[i][j]=0;}
- if(ant[i+1][j]==1){ant1[i][j-1]=1;ant1[i][j]=0;ant[i][j]=1;ant[i+1][j]=0;c[i][j]=0;}
- if(ant[i][j+1]==1){ant1[i+1][j]=1;ant1[i][j]=0;ant[i][j]=1;ant[i][j+1]=0;c[i][j]=0;}
- fprintf(fp,"%d %d %d\n",i,j,t);
- }
- else if(c[i][j]==0){
- if(ant[i-1][j]==1){ant1[i][j-1]=1;ant1[i][j]=0;ant[i][j]=1;ant[i-1][j]=0;c[i][j]=1;}
- if(ant[i][j-1]==1){ant1[i+1][j]=1;ant1[i][j]=0;ant[i][j]=1;ant[i][j-1]=0;c[i][j]=1;}
- if(ant[i+1][j]==1){ant1[i][j+1]=1;ant1[i][j]=0;ant[i][j]=1;ant[i+1][j]=0;c[i][j]=1;}
- if(ant[i][j+1]==1){ant1[i-1][j]=1;ant1[i][j]=0;ant[i][j]=1;ant[i][j+1]=0;c[i][j]=1;}
- fprintf(fp,"%d %d %d\n",i,j,t);
- }
- }
- }
- }
- }
- fclose(fp);
- system("gnuplot ant.gnu");
- }
Advertisement
Add Comment
Please, Sign In to add comment