Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int step (int next_i, int next_j)
- {
- int i=0,j=0,s=0,a=0,c=0,p=0,p0=0;
- if (M%2==0) p=M/2 ; else p=(M+1)/2; /*distinguo i casi in cui le colonne possano essere dispari */
- p0=p;
- for (i=0;i<N;i++) /*inizio della caduta*/
- {
- if((p==0) || (p==M)) /*distinguo i casi in cui sia agli estremi della matrice */
- {
- if (p==0)
- {
- for(j=p;j<=p+1;j++)
- {
- if(mat[i+1][j]==FULL) s++;
- }
- if ((s==2) || (mat[i][p+1]==FULL)) {next_j=p; break;} /*if che valuta se la sedimentazione è terminata*/
- do { c=my_rand(); next_j=p+(c%2);} while(mat[i+1][next_j]==FULL);
- } /*fine if caso p==0*/
- else
- {
- for(j=p-1;j<=p;j++)
- {
- if(mat[i+1][j]==FULL) s++;
- }
- if ((s==2) || (mat[i][p-1]==FULL)) {next_j=p; break;} /*if che valuta se la sedimentazione è terminata*/
- do {c=my_rand();next_j=p+(c%2)-1;} while(mat[i+1][next_j]==FULL);
- } /*fine if caso p==M*/
- }
- else /*caso in cui la particella non sia agli estremi*/
- {
- for (j=p-1;j<=p+1;j++)
- { /*ciclo che conta le possibili celle sottostanti da occupare */
- if (mat[i+1][j]==FULL) s++;
- }
- for (j=p-1;j<=p+1;j++)
- { /*ciclo che conta le caselle occupate adiacenti */
- if (mat[i+1][j]==FULL) a++;
- }
- if ((s==3) || (a!=0)) {next_j=p; break;} /*if che valuta se la sedimentazione è terminata*/
- do {c=my_rand(); next_j=p+(c%3)-1;} while(mat[i+1][next_j]==FULL);
- } /*fine else*/
- p=next_j;
- }/* fine caduta particella */
- next_i=i;
- if ((next_i==0) && (next_j==p0)) return -1; else return 0;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement