Advertisement
Guest User

pileeC2

a guest
Apr 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. int step (int next_i, int next_j)
  2. {
  3. int i=0,j=0,s=0,a=0,c=0,p=0,p0=0;
  4. if (M%2==0) p=M/2 ; else p=(M+1)/2; /*distinguo i casi in cui le colonne possano essere dispari */
  5. p0=p;
  6. for (i=0;i<N;i++) /*inizio della caduta*/
  7. {
  8. if((p==0) || (p==M)) /*distinguo i casi in cui sia agli estremi della matrice */
  9. {
  10. if (p==0)
  11. {
  12. for(j=p;j<=p+1;j++)
  13. {
  14. if(mat[i+1][j]==FULL) s++;
  15. }
  16. if ((s==2) || (mat[i][p+1]==FULL)) {next_j=p; break;} /*if che valuta se la sedimentazione è terminata*/
  17. do { c=my_rand(); next_j=p+(c%2);} while(mat[i+1][next_j]==FULL);
  18. } /*fine if caso p==0*/
  19. else
  20. {
  21. for(j=p-1;j<=p;j++)
  22. {
  23. if(mat[i+1][j]==FULL) s++;
  24. }
  25. if ((s==2) || (mat[i][p-1]==FULL)) {next_j=p; break;} /*if che valuta se la sedimentazione è terminata*/
  26. do {c=my_rand();next_j=p+(c%2)-1;} while(mat[i+1][next_j]==FULL);
  27. } /*fine if caso p==M*/
  28. }
  29. else /*caso in cui la particella non sia agli estremi*/
  30. {
  31. for (j=p-1;j<=p+1;j++)
  32. { /*ciclo che conta le possibili celle sottostanti da occupare */
  33. if (mat[i+1][j]==FULL) s++;
  34. }
  35. for (j=p-1;j<=p+1;j++)
  36. {  /*ciclo che conta le caselle occupate adiacenti */
  37. if (mat[i+1][j]==FULL) a++;
  38. }
  39. if ((s==3) || (a!=0)) {next_j=p; break;} /*if che valuta se la sedimentazione è terminata*/
  40. do {c=my_rand(); next_j=p+(c%3)-1;} while(mat[i+1][next_j]==FULL);
  41. } /*fine else*/
  42. p=next_j;
  43. }/* fine caduta particella */
  44. next_i=i;
  45. if ((next_i==0) && (next_j==p0)) return -1; else return 0;
  46. }
  47. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement