Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define L 10
- #define N 4
- #define Vo 1
- typedef struct
- {
- double vitesse;
- int *direction;//tableau de 4 booleens , [top bot left right]
- } Particule;
- Particule **plan;
- //Fonction pour afficher le plan
- void afficherPlan()
- {
- for (int row = 0; row < L; row++)
- {
- for (int column = 0; column < L; column++)
- {
- if (plan[row][column].vitesse != -1)
- printf("+ ");
- }
- printf("\n");
- }
- }
- //Fonction pour vérifier si le plan contient toujours des particules de vitesse non nulle
- int etatFinal()
- {
- for (int row = 0; row < L; row++)
- {
- for (int column = 0; column < L; column++)
- {
- if (plan[row][column].vitesse != -1)
- return 0;
- }
- }
- return 1;
- }
- //Main function
- int main()
- {
- //Construction du plan (matrice carrée)
- plan = calloc(L, sizeof(Particule *) + 1);
- for (int i = 0; i < L; i++)
- {
- plan[i] = calloc(L, sizeof(Particule));
- }
- for (int i = 0; i < L; i++)
- {
- for (int j = 0; j < L; j++)
- {
- plan[i][j].direction = calloc(4, sizeof(int));
- plan[i][j].vitesse = -1;
- }
- }
- //Initialisation de la particule du milieu (agregat)
- plan[(int)(L / 2)][(int)(L / 2)].direction;
- plan[(int)(L / 2)][(int)(L / 2)].vitesse = 0;
- //Initialisation des autres particules
- int compteur = N;
- for (int i = 0; i < L; i++)
- {
- for (int j = 0; j < L; j++)
- {
- if (plan[i][j].vitesse != -1)
- {
- plan[i][j].vitesse = Vo;
- plan[i][j].direction = calloc(4,sizeof(int));
- for(int k = 0;k<4;k++)
- plan[i][j].direction[k] = rand() % 2;
- compteur--;
- }
- }
- }
- //Début de la boucle de simulation
- while (!etatFinal())
- {
- for (int i = 0; i < L; i++)
- {
- for (int j = 0; j < L; j++)
- {
- if (plan[i][j].vitesse != -1)
- {
- //On déplace la particule
- int newRow = i;
- newRow -= plan[i][j].direction[0];
- newRow += plan[i][j].direction[1];
- int newCol = j;
- newCol -= plan[i][j].direction[2];
- newRow += plan[i][j].direction[3];
- plan[newCol][newRow] = plan[i][j];
- plan[i][j].vitesse = -1;
- }
- }
- }
- afficherPlan();
- system("pause");
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement