Ejemplo n.º 1
0
/*
 * Vérification visuelle de la fonction d'affichage.
 * Affichage d'une matrice complète, puis d'un sous-bloc.
 * Vérification du scatter/gather
 */
int main(){

  double* global_mat;
  double* global_verif;

  MPI_Init(NULL, NULL);
  int size, rank, i;
  MPI_Comm_size(MPI_COMM_WORLD,&size);
  MPI_Comm_rank(MPI_COMM_WORLD,&rank);
  if (rank == 0){
    double* mat = matrix_rand(4,6);
    printf("Matrice entière de taille (4,6) : \n");
    affiche(4, 6, mat, 4, stdout);
    printf("Sous-bloc [3,2] de taille (2,3) : \n");
    affiche(2, 3, mat+2+4, 4, stdout);
    free(mat);
    printf("Test scatter/gather...\t");
    global_verif = matrix_rand(100, 100);
    global_mat = matrix_rand(100, 100);
    memcpy(global_verif, global_mat, 100*100*sizeof(double));
  }
  int bsize = 3;
  int nb_cols = nb_col(size, bsize, 100, rank);
  double* local_mat = matrix_rand(100, nb_cols*bsize);
  split_matrix(100, 100, global_mat, local_mat, bsize, SCATTER);
  split_matrix(100, 100, global_mat, local_mat, bsize, GATHER);
  if (rank == 0){
    for(i=0;i<100*100;++i)
      ASSERT_EQ(global_mat[i],global_verif[i]);
    printf("ok\n");
    free(global_verif);
    free(global_mat);
  }
  free(local_mat);

  MPI_Finalize();
  return 0;
}
ResumeConfiguration::ResumeConfiguration(QWidget *parent,
                                         int iC, int iP,
                                         Produit *produit,
                                         Data *d) :
    QWidget(parent),
    ui(new Ui::ResumeConfiguration),
    PageInterface(parent,iC,iP)
{
    ui->setupUi(this);
    currentProduit = produit;
    database = d;
    signalAndSlot();
    affiche();
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
	srand((time)NULL);
	
	
	printf("Taille structure = %u\n", sizeof(Tableau)); // (taille du tableau * taille int) + (taille du champs 'taille') = 100*4 + 1 = 404
	

/*	int a = 0; // On initialise arbitrairement la variable a
	printf("%d\n", alea(a));	
*/
	
	Tableau T = initialise(T);
	
	affiche(T);
	printf("Elément minimum du tableau : %d\n", minimum(T));
	if (produit(T) < 0) printf("Produit trop grand"); // Evite d'afficher un produit négatif sur des entiers non signés
	else printf("Produit des éléments du tableau : %d\n", produit(T));
	
	
	// Décalage //
	T = decalage(T); 
	putchar('\n'); 
	printf("Tableau après décalage : \n"); 
	affiche(T);	
	printf("Taille du tableau après le décalage = %d\n\n", T.taille);
	
	
	// Trie //
	printf("Après trie du tableau : \n");
	T = trie(T);
	affiche(T);	
	
	
	return 0;
}
Ejemplo n.º 4
0
void main(int argc, char *argv[]) {
	int tab[10][20][30][40], i, j, k, l, dim4 = 2, plan = 2, ligne = 2, colonne = 4, cpt = 1;
	
	for(i = 0; i < dim4; i++) {
		for(j = 0; j < plan; j++) {
			for(k = 0; k < ligne; k ++) {
				for(l = 0; l < colonne; l++) {
					tab[i][j][k][l] = cpt++;
				}
			}
		}
	}
	affiche(tab,dim4,plan,ligne,colonne);
	sommeMat4Dim(tab,dim4,plan,ligne,colonne);
	exit(0);
}
Ejemplo n.º 5
0
void* cell(void* data)
{
  coord * xy = (coord*) data;
  char c;
  while (1)
  {
    c = etat_suivant(xy->x, xy->y);
    next();
    tab[xy->x][xy->y] = c;
    if (next())
    {
      sleep(1);
      affiche();
    }
  }
  return NULL;
}
Ejemplo n.º 6
0
void connecteur_programme::choisir_graphe()
{
    QUrl url_file = QFileDialog::getOpenFileName(0,"Selectionner un graphe");
    file_url->setText(url_file.path());

    affichage_programme->setText("");
    matrice_text->setText("");
    QString nomProg = "./bin/prog.exe affichage ";

    affichage_programme->clear();
    caracteristique_graphe->setText("Caractéristiques du graphe");
    matrice_text->clear();
    proc->start(nomProg+file_url->toPlainText());

    affiche();

}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
    int tableau[4] = {150, 5, 55, 7};
    int tableauoriginal[4];
    int i;
    for (i = 0 ; i < 4 ; i++)
    {
        tableauoriginal[i] = tableau[i];
    }

    affiche(tableau, 4);
    sommeTableau(tableau, 4);
    moyenneTableau(tableau, 4);
    ordonnerTableau(tableau, 4);
    copie(tableau, tableau, 4); //does not work right now
    return 0;
}
Ejemplo n.º 8
0
int main(int argc, char* argv[])
{
    int encore;

    encore = 1;
    cpt = 1;
    indice_prod =0;
    indice_consom = 0;
    nb_val = 0;
    nb_thread_bloque = 0;

    while(encore)
    {
	char action;
	printf("Bonjour, que voulez vous faire ? Taper \"c\" pour consommer, \"p\" pour produire, \"a\" pour afficher l'état courant, ou \"q\" pour quitter :\n");
	scanf(" %c", &action);
	if (action  == 'c') {
	    pthread_t p_thread;
	    pthread_attr_t attr;
	    int a = cpt;

	    pthread_attr_init(&attr);
	    pthread_create(&p_thread,&attr, consommer, (void*) &a);
	}

	if (action  == 'p') {
	    pthread_t p_thread;
	    pthread_attr_t attr;
	    int a = cpt;

	    pthread_attr_init(&attr);
	    pthread_create(&p_thread,&attr, produire, (void*) &a);
	}

	if (action  == 'a') {
	    affiche();
	}

	if (action  == 'q') {
	    encore=0;
	}
    }

    return 0;
}
Ejemplo n.º 9
0
int main(void)
{
    float valeur = 0, chiffre;
    int i;

    printf("Nombre de valeurs : %d\n", NBREVALEUR);

    for (i = 0; i < NBREVALEUR; i++) {
	/* saisie() a définir dans entree.c */
	chiffre = saisie();

	/* total()  a définir dans calcul.c */
	valeur = total(valeur, chiffre);
    }

    /* affiche() a définir dans affichage.c */
    affiche(valeur);
    exit(0);
}
Ejemplo n.º 10
0
int main()
{
  init();
  int i;
  count = 0;
  // initialize counter mutex;
  if (pthread_mutex_init(&mutex, NULL) != 0)
  {
    perror("pthread_mutex_init");
    exit(-1);
  }
  // initialize counter condition;
  if (pthread_cond_init(&cond, NULL) != 0)
  {
    perror("pthread_cond_init");
    exit(-2);
  }
  affiche();
  // create a thread for each cell in the 2d array
  for (i = 0; i < NB_LIGNES*NB_COLONNES; i++)
  {
    data[i].x = i / NB_COLONNES;
    data[i].y = i % NB_COLONNES;
    // creation of a thread without parameters and with the thread's coordinates
    if (pthread_create(threads+i, NULL, cell, data+i) != 0)
    {
      perror("pthread_create");
      exit(-3);
    }
    //printf("Thread created outer[%d,%d]\n", data[i].x, data[i].y);
  }
  // wait for all threads to be terminated to terminate the main process
  for (i = 0; i < NB_LIGNES*NB_COLONNES; i++)
  {
    if (pthread_join(threads[i], NULL) != 0)
    {
      perror("pthread_join");
      exit(-4);
    }
  }
  return 0;
}
Ejemplo n.º 11
0
int main(int argc, char *argv[]) {
    Image<byte> I;
    Image<float> Vx, Vy;
    if (!load(I, argc > 1 ? argv[1] : srcPath("salon.png"))) {
        cout << "Echec de lecture d'image" << endl;
        return 1;
    }

    openWindow(I.width(), I.height());
    display(I);
    click();
    cout << "Contraste simple" << endl;
    affiche(I);
    gradient(I, Vx, Vy);
    click();
    cout << "Dérivée selon x par la fonction gradient" <<endl;
    affiche(Vx);
    click();
    cout << "Dérivée selon y par la fonction gradient" <<endl;
    affiche(Vy);

    click();

    Image<float> F = dx(I);

    cout << "Dérivée selon x par la fonction dx" <<endl;

    affiche(F);

    click();

    Image<float> U= dy(I);
    cout << "Dérivée selon y par la fonction dy" <<endl;

    affiche(U);

    click();

    masque(I,F,U);

    Image<float> z = poisson(F,U);
    cout << "Image reconstruite par poisson" <<endl;

    affiche(z);

    endGraphics();
    return 0;
}
Ejemplo n.º 12
0
int main(int argc, char** argv) { char s[512];
    double xmin=-5, xmax=5;
    ARBRE r=NULL;
    int dx=400,dy=200;
    SDL_Surface* f1;

    /* 
       Creation d'une fenetre graphique
       */
    f1=newfenetregraphique(dx,dy);
    Draw_Line(f1,0, 10, 200, 50,0xFFFFFFFF);
    /*
       Lecture d'une expression prefixe au clavier 
       */
    puts("Entrer une expression en notation prefixee"); gets(s);
    r=lire(s);

    /*
       Affichage de cette expression en notation classique
       */
    puts("Expression :"); affiche(r); puts("");


    puts("Entrer les bornes du trace (xmin et xmax): attention au domaine de definition");
    scanf("%lf %lf",&xmin,&xmax);

    /*
       Recherche du min et du max des ordonnees du graphe de la fonction 
       */
    trace1courbe(f1,r,dx,xmin,xmax);
    getchar(); getchar();

    /*
       Liberation de la memoire de l'arbre
       */
    r=libere(r);
    return 0;
}
Ejemplo n.º 13
0
int main()
{
    int i,j;
    int **carre;
    carre=malloc(TAILLE*sizeof(int*));
    for (i=0;i<TAILLE;i++){
        carre[i]=malloc(TAILLE*sizeof(int));
    }

    casejeton jeton;
    casejeton *pjeton=&jeton;

    init(carre,pjeton);

    for (i=0;i<(TAILLE)*(TAILLE);i++){
        if (i==0){ //Si c'est le premier remplissage, on cherche la case au dessus du milieu...
            remplircase(carre,pjeton,i+1); //...et on y place 1
        }else{ //Si ce n'est pas le premier remplissage...
            case_hd(pjeton);

            //la case est vide, on la remplit
            if (casevide(carre,pjeton)){
                remplircase(carre,pjeton,i+1);
            }else{
                //Sinon on cherche la premiere case en haut a gauche de libre...
                case_hg(carre,pjeton);
                //... et on y met place la valeur
                remplircase(carre,pjeton,i+1);
            }
        }
    }
    affiche(carre);

    free(carre);
    free(pjeton);
    return 0;
}
Ejemplo n.º 14
0
int main(void) {
	Complexe a = {1,0};
	Complexe b = {1,1};
	Complexe c = {0,1};
	Complexe d = {0,2};
	Complexe e = {2, -3};
	Complexe f = {-1, 0};
	Complexe p = {0,0};
	Complexe r = {3, -2};
	Complexe s = {-5, 1};
	affiche2(resoudre_second_degre(p, a));
	affiche2(resoudre_second_degre(r, s));
	affiche(sqrt(f));
	affiche(addition(a, c));
	affiche(multiplication(c, c));
	affiche(multiplication(b, b));
	affiche(division(d, c));
	affiche(division(e, b));
}
Ejemplo n.º 15
0
void pacman::avance(terrain& T,NativeBitmap rien, NativeBitmap pacman_debut, NativeBitmap pacman_normal, NativeBitmap pacman_vitamine, int nb_w, int nb_h) {
	switch (dir) {
		case droite :
			if (i==7 && j==20) {
				putNativeBitmap(nb_w*j, nb_h*i, rien);
				T(i,j)=0;
				j=0;
				if (T(7,0)==1)
					gomme=true;
				affiche(pacman_debut, pacman_normal, pacman_vitamine, nb_w, nb_h);
			} // passage secret

			else if (T(i,j+1)!=3) {
				putNativeBitmap(nb_w*j, nb_h*i, rien);
				T(i,j)=0;
				j+=1;
				if (T(i,j)==1)
					gomme=true;
				affiche(pacman_debut, pacman_normal, pacman_vitamine, nb_w, nb_h);
			}
			break;

		case haut : 
			if (T(i-1,j)!=3) {
				putNativeBitmap(nb_w*j, nb_h*i, rien);
				T(i,j)=0;
				i-=1;
				if (T(i,j)==1)
					gomme=true;
				affiche(pacman_debut, pacman_normal, pacman_vitamine, nb_w, nb_h);
			}
			break;

		case gauche :
			if ( i == 7 && j == 0 ) {
				putNativeBitmap(nb_w*j, nb_h*i, rien);
				T(i,j)=0;
				j=20;
				if (T(7,20)==1)
					gomme=true;
				affiche(pacman_debut, pacman_normal, pacman_vitamine, nb_w, nb_h);
			} //passage secret

			else if (T(i,j-1)!=3) {
				putNativeBitmap(nb_w*j, nb_h*i, rien);
				T(i,j)=0;
				j-=1;
				if (T(i,j)==1)
					gomme=true;
				affiche(pacman_debut, pacman_normal, pacman_vitamine, nb_w, nb_h);
			}
			break;

		case bas :
			if (T(i+1,j)!= 3 && T(i+1,j)!=4) {
				putNativeBitmap(nb_w*j, nb_h*i, rien);
				T(i,j)=0;
				i+=1;
				if (T(i,j)==1)
					gomme=true;
				affiche(pacman_debut, pacman_normal, pacman_vitamine, nb_w, nb_h);
			}
			break;
	}
	
}
Ejemplo n.º 16
0
void boucle_niv_3(arene table, int x, int y, char nom_j[50], char go){

    time_t t = time(NULL);
    char temp; /*<-----------------Permet de garder une valeur temporairement */
    char orientation_perso ; /*<---Orientation du personnage en x,y */
    char bonus_1 = 0x3; /*<--------Bonus 1 de N_bonus points */
    char bonus_2 = 0x6; /*<--------Bonus 2 de N_bonus points */
    int score = 0 ; /*<------------Score du Joueur */
    int s;  /*<--------------------Rand de s pour le déplacement "Aléatoir" du(des) fantôme(s) */
    int ok; /*<--------------------ok=1 le fantôme bouge */
    int yfant1 = 9;  /*<-----------Postion verticale   du fantôme 1 */
    int xfant1 = 13; /*<-----------Postion horizontale du fantôme 1 */
    int yfant2 = 5;  /*<-----------Postion verticale   du fantôme 2 */
    int xfant2 = 18; /*<-----------Postion horizontale du fantôme 2 */
    int yfant3 = 14; /*<-----------Postion verticale   du fantôme 3 */
    int xfant3 = 36; /*<-----------Postion horizontale du fantôme 3 */
    int yfant4 = 13; /*<-----------Postion verticale   du fantôme 4 */
    int xfant4 = 20; /*<-----------Postion horizontale du fantôme 4 */
    int yfant5 = 18; /*<-----------Postion verticale   du fantôme 5 */
    int xfant5 = 2;  /*<-----------Postion horizontale du fantôme 5 */
    int yfant6 = 9;  /*<-----------Postion verticale   du fantôme 6 */
    int xfant6 = 25; /*<-----------Postion horizontale du fantôme 6 */
    int yfant7 = 8;  /*<-----------Postion verticale   du fantôme 7 */
    int xfant7 = 5;  /*<-----------Postion horizontale du fantôme 7 */
    int yfant8 = 2;  /*<-----------Postion verticale   du fantôme 8 */
    int xfant8 = 37; /*<-----------Postion horizontale du fantôme 8 */
    int yfant9 = 8;  /*<-----------Postion verticale   du fantôme 9 */
    int xfant9 = 37; /*<-----------Postion horizontale du fantôme 9 */
    int yfant10 = 12;/*<-----------Postion verticale   du fantôme 10 */
    int xfant10 = 3; /*<-----------Postion horizontale du fantôme 10 */
    int yfant11 = 18;/*<-----------Postion verticale   du fantôme 11 */
    int xfant11 = 24;/*<-----------Postion horizontale du fantôme 11 */
    int yfant12 = 18;/*<-----------Postion verticale   du fantôme 12 */
    int xfant12 = 14;/*<-----------Postion horizontale du fantôme 12 */
    int nb_point_max = 0;/*<-------Nombre de points présents dans le jeux au démarrage */
    int nb_point = 0; /*<----------Nombre de points restants dans le jeux en cours */
    int i,j;

    while(i!=60){   /* On compte le nombre de points présent dans l'arène en début de jeu */
        for(i=0; i<60; i++){
            for(j=0; j<20; j++){
                if(table[j][i] == '.'){
                    nb_point_max++;
                }
            }
        }
    }

    nb_point = nb_point_max + 13; /* On ajoute 9 (Personnage + 8 fantômes qui cachent les points en début de jeux */

    while (1){

        if(nb_point == 0){        /* Si il ne reste plus de point donc nb_point vaut 0, alors on termine le jeu et on lance la page de fin */
            game_over(nom_j,score);
        }

        affichage_foot(nom_j,score,nb_point);   /* On affiche le pied de page */

        orientation_perso = _getch(); /* Selection de l'orientation sans appuyer sur "Entrer" */

        switch (orientation_perso){   /* Switch qui gère le déplacement du personnage (haut, bas, gauche et droite) */

            case 's' :      /* Deplacement vers le bas */
                if(table[y+1][x] == '.' || table[y+1][x] == ' ' || table[y+1][x] == 0x6 || table[y+1][x] == 0x3){ /* Si le prochain char est un point, un vide ou un bonus */
                    y++;    /* Alors on avance */
                    if(table[y][x] == '.'){
                        score = score + 10; /* Et on augmente le score si on mange un point */
                        nb_point--;         /* On diminue de 1 le nombre de points restants */
                    }
                    if(table[y][x] == ' '){
                        score = score - 5;  /* Puis on diminue le score si on ne mange pas de point (bond dans le vide */
                    }
                    if(table[y][x] == bonus_1){
                        score = score + N_bonus; bonus_1 = vide;        /* Puis on augmente le score si on mange un bonus 1, le bonus lui, disparait et devient un vide */
                        if(table[1][57] == 0x3 && table[1][58] == 0x6){ /* Si le bonus pique est encore là, on enlève le bonus coeur en haut à droite et on met le pique a sa place */
                             table[1][57] = 0x6;
                             table[1][58] = ' ';
                        }
                        if(table[1][57] == 0x3 && table[1][58] == ' '){ /* Si le bonus pique n'est plus là, on enlève juste le bonus coeur en haut à droite */
                             table[1][57] = ' ';
                        }
                    }
                    if(table[y][x] == 0x6){
                        score = score + N_bonus; bonus_2 = vide; /* Puis on augmente le score si on mange un bonus 2, le bonus lui, disparait et devient un vide */
                        if(table[1][58] == 0x6){ /* On enlève juste le bonus pique en haut à droite */
                             table[1][58] = ' ';
                        }
                        if(table[y][x] == ' '){
                        score = score - 5;       /* Et on diminue le score si on mange pas de point */
                        }
                    }
                    table[y-1][x] = ' ';
                    if(table[7][46] == blanc_p){ /* On fait bouger l'oeil gauche du phantôme (de droite à gauche) */
                        table[7][46]  = blanc_p2;
                        table[7][48]  = blanc_p;}
                    if(table[7][51] == blanc_p){ /* On fait bouger l'oeil droit du phantôme (de droite à gauche) */
                        table[7][51]  = blanc_p2;
                        table[7][53]  = blanc_p;}
                }
                break;

            case 'z' :   /* Deplacment vers le haut */
                if(table[y-1][x] == '.' || table[y-1][x] == ' '){
                    y--; /* Alors on avance */
                    if(table[y][x] == '.'){
                        score = score + 10;
                        nb_point--;
                    }
                    if(table[y][x] == ' '){
                        score = score - 5;  /* Et on diminue le score si on mange pas de point */
                    }
                    table[y+1][x] = ' ';
                    if(table[7][46] == blanc_p2){ /* On fait bouger l'oeil gauche du fantôme (de gauche à droite) */
                        table[7][46]  = blanc_p;
                        table[7][48]  = blanc_p2;}
                    if(table[7][51] == blanc_p2){ /* On fait bouger l'oeil droit du fantôme (de gauche à droite) */
                        table[7][51]  = blanc_p;
                        table[7][53]  = blanc_p2;}
                }
                break;

            case 'q' :   /* Deplacmeent vers la gauche */
                if(table[y][x-1] == '.' || table[y][x-1] == ' '){
                    x--; /* Alors on avance */
                    if(table[y][x] == '.'){
                        score = score + 10; /* Et on augmente le score si on mange un point */
                        nb_point--;
                    }
                    if(table[y][x] == ' '){
                        score = score - 5;  /* Et on diminue le score si on mange pas de point */
                    }
                    table[y][x+1] = ' ';
                    if(table[7][46] == blanc_p){ /* On fait bouger l'oeil gauche du fantôme (de droite à gauche) */
                        table[7][46]  = blanc_p2;
                        table[7][48]  = blanc_p;}
                    if(table[7][51] == blanc_p){ /* On fait bouger l'oeil droit du fantôme (de droite à gauche) */
                        table[7][51]  = blanc_p2;
                        table[7][53]  = blanc_p;}
                }
                break;

            case 'd' :   /* Deplacement vers la droite */
                if(table[y][x+1] == '.' || table[y][x+1] == ' '){
                    x++; /* Alors on avance */
                    if(table[y][x] == '.'){
                        score = score + 10; /* Et on augmente le score si on mange un point */
                        nb_point--;
                    }
                    if(table[y][x] == ' '){
                        score = score - 5;  /* Et on diminue le score si on mange pas de point */
                    }
                    table[y][x-1] = ' ';
                    if(table[7][46] == blanc_p2){ /* On fait bouger l'oeil gauche du fantôme (de gauche à droite) */
                        table[7][46]  = blanc_p;
                        table[7][48]  = blanc_p2;}
                    if(table[7][51] == blanc_p2){ /* On fait bouger l'oeil droit du fantôme (de gauche à droite) */
                        table[7][51]  = blanc_p;
                        table[7][53]  = blanc_p2;}
                }
                break;

            case 'Q' : /* Changer de difficulter ou quitter */
                return 0;
                break;

            case 'A' : /* Aide */
                MessageBox(0,"Touches : \n\n   - Avancer : 'z'\n   - Reculer : 's'\n   - Aller à gauche : 'q'\n   - Aller à droite : 'd'\n\nRègles du jeux :\n\n   - Vous devez \"manger\" les points en vous déplaçant tout en évitant\n      les fantômes. Le but étant d'obtenir le score le plus élevé possible.\n   - 1 point attrapé vaut 10 points.\n   - 1 mouvement dans le vide retire 5 points.","PAC-MAN Aide",MB_OK|MB_ICONQUESTION);
                break;

            default : /* Erreur */
                printf("Erreur de selection\n" );
                break;
        }   /* End of Switch */

        do{ /* Deplacement Aléatoir du fantôme 1 */
            s=rand()%4; /* Random de le résultat entre 0 et 3 */
            switch (s){
                case 0: /* deplacement vers la droite */    /* Si la case suivant vaut un point, un vide ou le personnage */
                    if(table[yfant1][xfant1+1] == '.' || table[yfant1][xfant1+1] == ' ' || table[yfant1][xfant1+1] == 0xF){
                        temp = table[yfant1][xfant1+1];     /* On met la valeur de la case suivante dans une variable temporaire (temp) */
                        xfant1++;                           /* Puis le fantôme ce déplace */
                        if(temp == 0xF){
                            table[yfant1][xfant1-1] = '.';
                        }
                        else{
                            table[yfant1][xfant1-1] = temp; /* Si la case suivante valait un vide alors, on remet le vide, si c'était un point, on remet le point... */
                        }
                        ok=1;                               /* Alors ok=1 donc on sort de la boucle */
                    }
                    else{
                        ok=0;                               /* Si ok=0 alors on reste dans la boucle et on relance un rand jusqu'à ce que le fantôme bouge */
                    }
                    break;
                case 1: /* deplacement vers la gauche */
                    if(table[yfant1][xfant1-1] == '.' || table[yfant1][xfant1-1] == ' ' || table[yfant1][xfant1-1] == 0xF){
                        temp = table[yfant1][xfant1-1];
                        xfant1--;
                        if(temp == 0xF){
                            table[yfant1][xfant1+1] = '.';
                        }
                        else{
                            table[yfant1][xfant1+1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 2: /* deplacement vers le bas */
                    if(table[yfant1+1][xfant1] == '.' || table[yfant1+1][xfant1] == ' ' || table[yfant1+1][xfant1] == 0xF){
                        temp = table[yfant1+1][xfant1];
                        yfant1++;
                        if(temp == 0xF){
                            table[yfant1-1][xfant1] = '.';
                        }
                        else{
                            table[yfant1-1][xfant1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 3: /* deplacement vers le haut */
                    if(table[yfant1-1][xfant1] == '.' || table[yfant1-1][xfant1] == ' ' || table[yfant1-1][xfant1] == 0xF){
                        temp = table[yfant1-1][xfant1];
                        yfant1--;
                        if(temp == 0xF){
                            table[yfant1+1][xfant1] = '.';
                        }
                        else{
                            table[yfant1+1][xfant1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
            } /* End of switch */
        }while(ok!=1);

        do{ /* Deplacement Aléatoir du fantôme 2 */
            s=rand()%4;
            switch (s){
                case 0: /* deplacement vers la droite */
                    if(table[yfant2][xfant2+1] == '.' || table[yfant2][xfant2+1] == ' ' || table[yfant2][xfant2+1] == 0xF){
                        temp = table[yfant2][xfant2+1];
                        xfant2++;
                        if(temp == 0xF){
                            table[yfant2][xfant2-1] = '.';
                        }
                        else{
                            table[yfant2][xfant2-1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 1: /* deplacement vers la gauche */
                    if(table[yfant2][xfant2-1] == '.' || table[yfant2][xfant2-1] == ' ' || table[yfant2][xfant2-1] == 0xF){
                        temp = table[yfant2][xfant2-1];
                        xfant2--;
                        if(temp == 0xF){
                            table[yfant2][xfant2+1] = '.';
                        }
                        else{
                            table[yfant2][xfant2+1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 2: /* deplacement vers le bas */
                    if(table[yfant2+1][xfant2] == '.' || table[yfant2+1][xfant2] == ' ' || table[yfant2+1][xfant2] == 0xF){
                        temp = table[yfant2+1][xfant2];
                        yfant2++;
                        if(temp == 0xF){
                            table[yfant2-1][xfant2] = '.';
                        }
                        else{
                            table[yfant2-1][xfant2] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 3: /* deplacement vers le haut */
                    if(table[yfant2-1][xfant2] == '.' || table[yfant2-1][xfant2] == ' ' || table[yfant2-1][xfant2] == 0xF){
                        temp = table[yfant2-1][xfant2];
                        yfant2--;
                        if(temp == 0xF){
                            table[yfant2+1][xfant2] = '.';
                        }
                        else{
                            table[yfant2+1][xfant2] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
            } /* End of switch */
        }while(ok!=1);

        do{ /* Deplacement Aléatoir du fantôme 3 */
            s=rand()%4;
            switch (s){
                case 0: /* deplacement vers la droite */
                    if(table[yfant3][xfant3+1] == '.' || table[yfant3][xfant3+1] == ' ' || table[yfant3][xfant3+1] == 0xF){
                        temp = table[yfant3][xfant3+1];
                        xfant3++;
                        if(temp == 0xF){
                            table[yfant3][xfant3-1] = '.';
                        }
                        else{
                            table[yfant3][xfant3-1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 1: /* deplacement vers la gauche */
                    if(table[yfant3][xfant3-1] == '.' || table[yfant3][xfant3-1] == ' ' || table[yfant3][xfant3-1] == 0xF){
                        temp = table[yfant3][xfant3-1];
                        xfant3--;
                        if(temp == 0xF){
                            table[yfant3][xfant3+1] = '.';
                        }
                        else{
                            table[yfant3][xfant3+1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 2: /* deplacement vers le bas */
                    if(table[yfant3+1][xfant3] == '.' || table[yfant3+1][xfant3] == ' ' || table[yfant3+1][xfant3] == 0xF){
                        temp = table[yfant3+1][xfant3];
                        yfant3++;
                        if(temp == 0xF){
                            table[yfant3-1][xfant3] = '.';
                        }
                        else{
                            table[yfant3-1][xfant3] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 3: /* deplacement vers le haut */
                    if(table[yfant3-1][xfant3] == '.' || table[yfant3-1][xfant3] == ' ' || table[yfant3-1][xfant3] == 0xF){
                        temp = table[yfant3-1][xfant3];
                        yfant3--;
                        if(temp == 0xF){
                            table[yfant3+1][xfant3] = '.';
                        }
                        else{
                            table[yfant3+1][xfant3] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
            } /* End of switch */
        }while(ok!=1);

        do{ /* Deplacement Aléatoir du fantôme 4 */
            s=rand()%4;
            switch (s){
                case 0: /* deplacement vers la droite */
                    if(table[yfant4][xfant4+1] == '.' || table[yfant4][xfant4+1] == ' ' || table[yfant4][xfant4+1] == 0xF){
                        temp = table[yfant4][xfant4+1];
                        xfant4++;
                        if(temp == 0xF){
                            table[yfant4][xfant4-1] = '.';
                        }
                        else{
                            table[yfant4][xfant4-1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 1: /* deplacement vers la gauche */
                    if(table[yfant4][xfant4-1] == '.' || table[yfant4][xfant4-1] == ' ' || table[yfant4][xfant4-1] == 0xF){
                        temp = table[yfant4][xfant4-1];
                        xfant4--;
                        if(temp == 0xF){
                            table[yfant4][xfant4+1] = '.';
                        }
                        else{
                            table[yfant4][xfant4+1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 2: /* deplacement vers le bas */
                    if(table[yfant4+1][xfant4] == '.' || table[yfant4+1][xfant4] == ' ' || table[yfant4+1][xfant4] == 0xF){
                        temp = table[yfant4+1][xfant4];
                        yfant4++;
                        if(temp == 0xF){
                            table[yfant4-1][xfant4] = '.';
                        }
                        else{
                            table[yfant4-1][xfant4] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 3: /* deplacement vers le haut */
                    if(table[yfant4-1][xfant4] == '.' || table[yfant4-1][xfant4] == ' ' || table[yfant4-1][xfant4] == 0xF){
                        temp = table[yfant4-1][xfant4];
                        yfant4--;
                        if(temp == 0xF){
                            table[yfant4+1][xfant4] = '.';
                        }
                        else{
                            table[yfant4+1][xfant4] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
            } /* End of switch */
        }while(ok!=1);

        do{ /* Deplacement Aléatoir du fantôme 5 */
            s=rand()%4;
            switch (s){
                case 0: /* deplacement vers la droite */
                    if(table[yfant5][xfant5+1] == '.' || table[yfant5][xfant5+1] == ' ' || table[yfant5][xfant5+1] == 0xF){
                        temp = table[yfant5][xfant5+1];
                        xfant5++;
                        if(temp == 0xF){
                            table[yfant5][xfant5-1] = '.';
                        }
                        else{
                            table[yfant5][xfant5-1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 1: /* deplacement vers la gauche */
                    if(table[yfant5][xfant5-1] == '.' || table[yfant5][xfant5-1] == ' ' || table[yfant5][xfant5-1] == 0xF){
                        temp = table[yfant5][xfant5-1];
                        xfant5--;
                        if(temp == 0xF){
                            table[yfant5][xfant5+1] = '.';
                        }
                        else{
                            table[yfant5][xfant5+1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 2: /* deplacement vers le bas */
                    if(table[yfant5+1][xfant5] == '.' || table[yfant5+1][xfant5] == ' ' || table[yfant5+1][xfant5] == 0xF){
                        temp = table[yfant5+1][xfant5];
                        yfant5++;
                        if(temp == 0xF){
                            table[yfant5-1][xfant5] = '.';
                        }
                        else{
                            table[yfant5-1][xfant5] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 3: /* deplacement vers le haut */
                    if(table[yfant5-1][xfant5] == '.' || table[yfant5-1][xfant5] == ' ' || table[yfant5-1][xfant5] == 0xF){
                        temp = table[yfant5-1][xfant5];
                        yfant5--;
                        if(temp == 0xF){
                            table[yfant5+1][xfant5] = '.';
                        }
                        else{
                            table[yfant5+1][xfant5] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
            } /* End of switch */
        }while(ok!=1);

        do{ /* Deplacement Aléatoir du fantôme 6 */
            s=rand()%4;
            switch (s){
                case 0: /* deplacement vers la droite */
                    if(table[yfant6][xfant6+1] == '.' || table[yfant6][xfant6+1] == ' ' || table[yfant6][xfant6+1] == 0xF){
                        temp = table[yfant6][xfant6+1];
                        xfant6++;
                        if(temp == 0xF){
                            table[yfant6][xfant6-1] = '.';
                        }
                        else{
                            table[yfant6][xfant6-1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 1: /* deplacement vers la gauche */
                    if(table[yfant6][xfant6-1] == '.' || table[yfant6][xfant6-1] == ' ' || table[yfant6][xfant6-1] == 0xF){
                        temp = table[yfant6][xfant6-1];
                        xfant6--;
                        if(temp == 0xF){
                            table[yfant6][xfant6+1] = '.';
                        }
                        else{
                            table[yfant6][xfant6+1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 2: /* deplacement vers le bas */
                    if(table[yfant6+1][xfant6] == '.' || table[yfant6+1][xfant6] == ' ' || table[yfant6+1][xfant6] == 0xF){
                        temp = table[yfant6+1][xfant6];
                        yfant6++;
                        if(temp == 0xF){
                            table[yfant6-1][xfant6] = '.';
                        }
                        else{
                            table[yfant6-1][xfant6] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 3: /* deplacement vers le haut */
                    if(table[yfant6-1][xfant6] == '.' || table[yfant6-1][xfant6] == ' ' || table[yfant6-1][xfant6] == 0xF){
                        temp = table[yfant6-1][xfant6];
                        yfant6--;
                        if(temp == 0xF){
                            table[yfant6+1][xfant6] = '.';
                        }
                        else{
                            table[yfant6+1][xfant6] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
            } /* End of switch */
        }while(ok!=1);

        do{ /* Deplacement Aléatoir du fantôme 7 */
            s=rand()%4;
            switch (s){
                case 0: /* deplacement vers la droite */
                    if(table[yfant7][xfant7+1] == '.' || table[yfant7][xfant7+1] == ' ' || table[yfant7][xfant7+1] == 0xF){
                        temp = table[yfant7][xfant7+1];
                        xfant7++;
                        if(temp == 0xF){
                            table[yfant7][xfant7-1] = '.';
                        }
                        else{
                            table[yfant7][xfant7-1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 1: /* deplacement vers la gauche */
                    if(table[yfant7][xfant7-1] == '.' || table[yfant7][xfant7-1] == ' ' || table[yfant7][xfant7-1] == 0xF){
                        temp = table[yfant7][xfant7-1];
                        xfant7--;
                        if(temp == 0xF){
                            table[yfant7][xfant7+1] = '.';
                        }
                        else{
                            table[yfant7][xfant7+1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 2: /* deplacement vers le bas */
                    if(table[yfant7+1][xfant7] == '.' || table[yfant7+1][xfant7] == ' ' || table[yfant7+1][xfant7] == 0xF){
                        temp = table[yfant7+1][xfant7];
                        yfant7++;
                        if(temp == 0xF){
                            table[yfant7-1][xfant7] = '.';
                        }
                        else{
                            table[yfant7-1][xfant7] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 3: /* deplacement vers le haut */
                    if(table[yfant7-1][xfant7] == '.' || table[yfant7-1][xfant7] == ' ' || table[yfant7-1][xfant7] == 0xF){
                        temp = table[yfant7-1][xfant7];
                        yfant7--;
                        if(temp == 0xF){
                            table[yfant7+1][xfant7] = '.';
                        }
                        else{
                            table[yfant7+1][xfant7] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
            } /* End of switch */
        }while(ok!=1);

        do{ /* Deplacement Aléatoir du fantôme 8 */
            s=rand()%4;
            switch (s){
                case 0: /* deplacement vers la droite */
                    if(table[yfant8][xfant8+1] == '.' || table[yfant8][xfant8+1] == ' ' || table[yfant8][xfant8+1] == 0xF){
                        temp = table[yfant8][xfant8+1];
                        xfant8++;
                        if(temp == 0xF){
                            table[yfant8][xfant8-1] = '.';
                        }
                        else{
                            table[yfant8][xfant8-1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 1: /* deplacement vers la gauche */
                    if(table[yfant8][xfant8-1] == '.' || table[yfant8][xfant8-1] == ' ' || table[yfant8][xfant8-1] == 0xF){
                        temp = table[yfant8][xfant8-1];
                        xfant8--;
                        if(temp == 0xF){
                            table[yfant8][xfant8+1] = '.';
                        }
                        else{
                            table[yfant8][xfant8+1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 2: /* deplacement vers le bas */
                    if(table[yfant8+1][xfant8] == '.' || table[yfant8+1][xfant8] == ' ' || table[yfant8+1][xfant8] == 0xF){
                        temp = table[yfant8+1][xfant8];
                        yfant8++;
                        if(temp == 0xF){
                            table[yfant8-1][xfant8] = '.';
                        }
                        else{
                            table[yfant8-1][xfant8] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 3: /* deplacement vers le haut */
                    if(table[yfant8-1][xfant8] == '.' || table[yfant8-1][xfant8] == ' ' || table[yfant8-1][xfant8] == 0xF){
                        temp = table[yfant8-1][xfant8];
                        yfant8--;
                        if(temp == 0xF){
                            table[yfant8+1][xfant8] = '.';
                        }
                        else{
                            table[yfant8+1][xfant8] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
            } /* End of switch */
        }while(ok!=1);


        do{ /* Deplacement Aléatoir du fantôme 9 */
            s=rand()%4;
            switch (s){
                case 0: /* deplacement vers la droite */
                    if(table[yfant9][xfant9+1] == '.' || table[yfant9][xfant9+1] == ' ' || table[yfant9][xfant9+1] == 0xF){
                        temp = table[yfant9][xfant9+1];
                        xfant9++;
                        if(temp == 0xF){
                            table[yfant9][xfant9-1] = '.';
                        }
                        else{
                            table[yfant9][xfant9-1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 1: /* deplacement vers la gauche */
                    if(table[yfant9][xfant9-1] == '.' || table[yfant9][xfant9-1] == ' ' || table[yfant9][xfant9-1] == 0xF){
                        temp = table[yfant9][xfant9-1];
                        xfant9--;
                        if(temp == 0xF){
                            table[yfant9][xfant9+1] = '.';
                        }
                        else{
                            table[yfant9][xfant9+1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 2: /* deplacement vers le bas */
                    if(table[yfant9+1][xfant9] == '.' || table[yfant9+1][xfant9] == ' ' || table[yfant9+1][xfant9] == 0xF){
                        temp = table[yfant9+1][xfant9];
                        yfant9++;
                        if(temp == 0xF){
                            table[yfant9-1][xfant9] = '.';
                        }
                        else{
                            table[yfant9-1][xfant9] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 3: /* deplacement vers le haut */
                    if(table[yfant9-1][xfant9] == '.' || table[yfant9-1][xfant9] == ' ' || table[yfant9-1][xfant9] == 0xF){
                        temp = table[yfant9-1][xfant9];
                        yfant9--;
                        if(temp == 0xF){
                            table[yfant9+1][xfant9] = '.';
                        }
                        else{
                            table[yfant9+1][xfant9] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
            } /* End of switch */
        }while(ok!=1);

        do{ /* Deplacement Aléatoir du fantôme 10 */
            s=rand()%4;
            switch (s){
                case 0: /* deplacement vers la droite */
                    if(table[yfant10][xfant10+1] == '.' || table[yfant10][xfant10+1] == ' ' || table[yfant10][xfant10+1] == 0xF){
                        temp = table[yfant10][xfant10+1];
                        xfant10++;
                        if(temp == 0xF){
                            table[yfant10][xfant10-1] = '.';
                        }
                        else{
                            table[yfant10][xfant10-1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 1: /* deplacement vers la gauche */
                    if(table[yfant10][xfant10-1] == '.' || table[yfant10][xfant10-1] == ' ' || table[yfant10][xfant10-1] == 0xF){
                        temp = table[yfant10][xfant10-1];
                        xfant10--;
                        if(temp == 0xF){
                            table[yfant10][xfant10+1] = '.';
                        }
                        else{
                            table[yfant10][xfant10+1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 2: /* deplacement vers le bas */
                    if(table[yfant10+1][xfant10] == '.' || table[yfant10+1][xfant10] == ' ' || table[yfant10+1][xfant10] == 0xF){
                        temp = table[yfant10+1][xfant10];
                        yfant10++;
                        if(temp == 0xF){
                            table[yfant10-1][xfant10] = '.';
                        }
                        else{
                            table[yfant10-1][xfant10] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 3: /* deplacement vers le haut */
                    if(table[yfant10-1][xfant10] == '.' || table[yfant10-1][xfant10] == ' ' || table[yfant10-1][xfant10] == 0xF){
                        temp = table[yfant10-1][xfant10];
                        yfant10--;
                        if(temp == 0xF){
                            table[yfant10+1][xfant10] = '.';
                        }
                        else{
                            table[yfant10+1][xfant10] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
            } /* End of switch */
        }while(ok!=1);

        do{ /* Deplacement Aléatoir du fantôme 11 */
            s=rand()%4;
            switch (s){
                case 0: /* deplacement vers la droite */
                    if(table[yfant11][xfant11+1] == '.' || table[yfant11][xfant11+1] == ' ' || table[yfant11][xfant11+1] == 0xF){
                        temp = table[yfant11][xfant11+1];
                        xfant11++;
                        if(temp == 0xF){
                            table[yfant11][xfant11-1] = '.';
                        }
                        else{
                            table[yfant11][xfant11-1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 1: /* deplacement vers la gauche */
                    if(table[yfant11][xfant11-1] == '.' || table[yfant11][xfant11-1] == ' ' || table[yfant11][xfant11-1] == 0xF){
                        temp = table[yfant11][xfant11-1];
                        xfant11--;
                        if(temp == 0xF){
                            table[yfant11][xfant11+1] = '.';
                        }
                        else{
                            table[yfant11][xfant11+1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 2: /* deplacement vers le bas */
                    if(table[yfant11+1][xfant11] == '.' || table[yfant11+1][xfant11] == ' ' || table[yfant11+1][xfant11] == 0xF){
                        temp = table[yfant11+1][xfant11];
                        yfant11++;
                        if(temp == 0xF){
                            table[yfant11-1][xfant11] = '.';
                        }
                        else{
                            table[yfant11-1][xfant11] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 3: /* deplacement vers le haut */
                    if(table[yfant11-1][xfant11] == '.' || table[yfant11-1][xfant11] == ' ' || table[yfant11-1][xfant11] == 0xF){
                        temp = table[yfant11-1][xfant11];
                        yfant11--;
                        if(temp == 0xF){
                            table[yfant11+1][xfant11] = '.';
                        }
                        else{
                            table[yfant11+1][xfant11] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
            } /* End of switch */
        }while(ok!=1);

        do{ /* Deplacement Aléatoir du fantôme 12 */
            s=rand()%4;
            switch (s){
                case 0: /* deplacement vers la droite */
                    if(table[yfant12][xfant12+1] == '.' || table[yfant12][xfant12+1] == ' ' || table[yfant12][xfant12+1] == 0xF){
                        temp = table[yfant12][xfant12+1];
                        xfant12++;
                        if(temp == 0xF){
                            table[yfant12][xfant12-1] = '.';
                        }
                        else{
                            table[yfant12][xfant12-1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 1: /* deplacement vers la gauche */
                    if(table[yfant12][xfant12-1] == '.' || table[yfant12][xfant12-1] == ' ' || table[yfant12][xfant12-1] == 0xF){
                        temp = table[yfant12][xfant12-1];
                        xfant12--;
                        if(temp == 0xF){
                            table[yfant12][xfant12+1] = '.';
                        }
                        else{
                            table[yfant12][xfant12+1] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 2: /* deplacement vers le bas */
                    if(table[yfant12+1][xfant12] == '.' || table[yfant12+1][xfant12] == ' ' || table[yfant12+1][xfant12] == 0xF){
                        temp = table[yfant12+1][xfant12];
                        yfant12++;
                        if(temp == 0xF){
                            table[yfant12-1][xfant12] = '.';
                        }
                        else{
                            table[yfant12-1][xfant12] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
                case 3: /* deplacement vers le haut */
                    if(table[yfant12-1][xfant12] == '.' || table[yfant12-1][xfant12] == ' ' || table[yfant12-1][xfant12] == 0xF){
                        temp = table[yfant12-1][xfant12];
                        yfant12--;
                        if(temp == 0xF){
                            table[yfant12+1][xfant12] = '.';
                        }
                        else{
                            table[yfant12+1][xfant12] = temp;
                        }
                        ok=1;
                    }
                    else{
                        ok=0;
                    }
                    break;
            } /* End of switch */
        }while(ok!=1);

        table[y][x] = perso;           /* Positionnement du perso */
        table[yfant1][xfant1] = fant1; /* Positionnement des fantômes 1,2,3,4,5,6,7,8,9,10,11 et 12 */
        table[yfant2][xfant2] = fant2;
        table[yfant3][xfant3] = fant3;
        table[yfant4][xfant4] = fant4;
        table[yfant5][xfant5] = fant5;
        table[yfant6][xfant6] = fant6;
        table[yfant7][xfant7] = fant7;
        table[yfant8][xfant8] = fant8;
        table[yfant9][xfant9] = fant9;
        table[yfant10][xfant10] = fant10;
        table[yfant11][xfant11] = fant11;
        table[yfant12][xfant12] = fant12;
        table[ybonus_1][xbonus_1] = bonus_1; /* Positionnement des bonus 1 et 2*/
        table[ybonus_2][xbonus_2] = bonus_2;

        /* Fin du Jeux si le perso rencontre un fantôme avec enregistrement du score dans le fichier score.txt */
        if(table[y][x] == table[yfant1][xfant1] || table[y][x] == table[yfant2][xfant2] || table[y][x] == table[yfant3][xfant3] || table[y][x] == table[yfant4][xfant4] || table[y][x] == table[yfant5][xfant5] || table[y][x] == table[yfant6][xfant6] || table[y][x] == table[yfant7][xfant7] || table[y][x] == table[yfant8][xfant8] || table[y][x] == table[yfant9][xfant9] || table[y][x] == table[yfant10][xfant10] || table[y][x] == table[yfant11][xfant11] || table[y][x] == table[yfant12][xfant12]){
            enregistrement_du_score(nom_j,score,go,t,nb_point);
            game_over(nom_j,score);
        }

        system("CLS"); /* Rafraichissement de la page */
        affiche(table);

  } /* End of while */
  return 0;
}
Ejemplo n.º 17
0
int  Simplex::solve(int ineq1, int ineq2, int eq, int n, bool debug) {
    try {
		const int ntmp = n;
		const int BORNEMAX = 1024;
		int i,j,k;
		int m=ineq1+ineq2+eq;
		int res ;
		
		// MODIFICATION POUR GERER DES VARIABLES NEGATIVES
		for (i=0 ; i <= m ; i++) {
			for (j=1 ; j<=n ; j++) {	
				a[i][j+n] = -a[i][j];
				// cout << "a[" << i <<"][" << j << "]=" << a[i][j];
				// cout << "a[" << i << "][" << j+n << "]=" << a[i][j+n];
			}
			// cout << endl;
		}
		n *= 2;
		// FIN DE LA MODIFICATION
		
		// MODIFICATION POUR EVITER UN BUG DE PRECISION ; on borne
		// toutes les variables
		k = ineq1 + ineq2 + 1;
		for (i=0 ; i<eq ; i++) {
			for (j=0 ; j<=n ; j++) {
				a[k+i+n]=a[k+i];
			}
		}
		for (i=0 ; i<n ; i++) {
			for (j=1 ; j<=n ; j++) {
				a[k+i][j]=0;
			}
			a[k+i][0]=-BORNEMAX;
			a[k+i][i+1]=-1;
		}
		ineq2 = ineq2 + n;
		// FIN DE LA MODIFICATION ANTIBUG DE PRECISION.
	
		if (debug) {
			affiche(ineq1,ineq2,eq,n);
		}

		res = simplexe_dual(ineq1,ineq2,eq,n);
		if (res != 1) {		
			for (i=1 ; i<=ntmp ; i++)
				sol[i] -= sol[i+ntmp];
		
			// // --------- AFfICHAGE DEBUG SOLUTION -------
			// char lettre = 'X';
			// cout << "\nn=" << n << ", m=" << m << endl;
			// cout << "\nSOLUTION : ";
			// for (i=1 ; i<=n ; i++) {
			// 	cout << lettre++ << "=" << sol[i]<< ", ";
			// }
			// cout << endl;
			// // --------- FIN AFFICHAGE DEBUG SOLUTION ------
		}
		return (res);
	}
	catch (int erreur) {
		if (PFA_VERBOSE)
		{
			cerr << "ERREUR : Simplex::solve" << endl;
			switch (erreur)
			{
				default :
					cerr << "Erreur n°" << erreur << endl;
			}
		}
		return erreur;
	}
}
Ejemplo n.º 18
0
int main(int argc, char *argv[]) {
    int opt, parallelism = 1;
    int taille, i, temps = 0, ressources = 0;
    int *tableau;
    struct timeval debut, fin;
    struct rusage rusage;
    time_t system, user;
    char *arg=NULL;

    struct option longopts[] = {
        { "help", required_argument, NULL, 'h' },
        { "parallelism", required_argument, NULL, 'p' },
        { "quiet", no_argument, NULL, 'q' },
        { "time", no_argument, NULL, 't' },
        { "rusage", no_argument, NULL, 'r' },
        { "arg", required_argument, NULL, 'a' },
        { NULL, 0, NULL, 0 }
    };

    while ((opt = getopt_long(argc, argv, "hp:qrta:", longopts, NULL)) != -1) {
        switch (opt) {
          case 'p':
            parallelism = atoi(optarg);
            break;
          case 'q':
            quiet = 1;
            break;
          case 'r':
            ressources = 1;
            break;
          case 't':
            temps = 1;
            break;
          case 'a':
            arg = optarg;
            break;
          case 'h':
          default:
            usage(argv[0]);
        }
    }
    argc -= optind;
    argv += optind;

    affiche("Saisissez la taille du vecteur\n");
    scanf(" %d", &taille);
    tableau = (int *) malloc(taille*sizeof(int));
    if (tableau == NULL) {
        fprintf(stderr,"Erreur de malloc\n");
        exit(3);
    }
    affiche("Saisissez tous les elements du vecteur\n");
    for (i=0; i<taille; i++)
        scanf(" %d", &tableau[i]);

    /* Recuperation du temps systeme */
    gettimeofday(&debut, NULL);

    /* Recuperation des ressources utilisees jusqu'alors */
    getrusage(RUSAGE_SELF, &rusage);
    user = to_usec(rusage.ru_utime);
    system = to_usec(rusage.ru_stime);

    /* Algo */
    algo_principal(parallelism, tableau, taille, arg);

    /* Calcul des resources utilisees par l'algo */
    getrusage(RUSAGE_SELF, &rusage);
    user = to_usec(rusage.ru_utime) - user;
    system = to_usec(rusage.ru_stime) - system;

    /* Recuperation du temps systeme */
    gettimeofday(&fin, NULL);

    if (temps) {
        affiche("Temps ecoule en microsecondes : ");
        printf("%lld\n", to_usec(fin) - to_usec(debut));
    }

    if (ressources) {
        affiche("Utilisation ressources : ");
        printf("%ld ", user+system);
        affiche("(");
        printf("%ld ", user);
        affiche("User, ");
        printf("%ld", system);
        affiche(" System)");
        printf("\n");
    }
    return 0;
}
void SstCarac::read_data_user(int index, Metil::DataUser& data_user){
    const DataUser::Json_materials &new_material = data_user.materials_vec[index];
    id = new_material.id_in_calcul;
    type_num = new_material.type_num;
    type = new_material.mtype;
    type_plast = new_material.type_plast;
    type_endo = new_material.type_endo;
    comp = new_material.comp;
    std::cout << "id : " << id << "    type : " << type << "    comp : " << comp << std::endl;
    if(data_user.dim == 2){/*   2D EN STAND-BY
        if (new_material.resolution =="CP"){
            resolution=1;
        } else if (new_material.resolution =="DP"){
            resolution=0;
        } else {
            std::cout << "type de resolution non implemente : choix contrainte_plane ou deformation_plane" << std::endl;
            assert(0);
        }*/
    }else{
        resolution=0;
    }
    
    density.setExpression(new_material.rho);
    
    if(type.find("isotrope")<type.size()) {/// comportement thermo-elastique isotrope
            elastic_modulus = new_material.E_1;         /// E
            poisson_ratio   = new_material.nu_12;       /// nu
            alpha           = new_material.alpha_1;     /// alpha
            deltaT          = 0;                        /// deltaT
    } else if (type.find("orthotrope")<type.size()) {/// comportement thermo-elastique orthotrope
            /// coefficients d'elasticite
            elastic_modulus_1 = new_material.E_1;      /// E1
            elastic_modulus_2 = new_material.E_2;      /// E2
            elastic_modulus_3 = new_material.E_3;      /// E3
            
            poisson_ratio_12 = new_material.nu_12;     /// nu12
            poisson_ratio_13 = new_material.nu_13;     /// nu13
            poisson_ratio_23 = new_material.nu_23;     /// nu23
            
            shear_modulus_12.setExpression(new_material.cis_1);    /// G12
            shear_modulus_13.setExpression(new_material.cis_2);    /// G13
            shear_modulus_23.setExpression(new_material.cis_3);    /// G23
            
            /// directions d'orthotropie TODO version parametrique
            v1[0]=new_material.dir_1_x;
            v2[0]=new_material.dir_2_x;
            v1[1]=new_material.dir_1_y;
            v2[1]=new_material.dir_2_y;
            if(DIM == 3){
                v1[2]=new_material.dir_1_z;
                v2[2]=new_material.dir_2_z;
            }
            v1=v1/norm_2(v1);
            v2=v2/norm_2(v2);
            
            /// coefficients thermiques
            alpha_1.setExpression(new_material.alpha_1);           ///alpha_1
            alpha_2.setExpression(new_material.alpha_2);           ///alpha_2
            alpha_3.setExpression(new_material.alpha_3);           ///alpha_3
            deltaT  = 0;                                           /// deltaT
    }
    
    if(comp.find("visqueux")<comp.size()){/// Comportement visqueux
            viscosite.setExpression(new_material.viscosite);   /// viscosite
    }
    if (comp.find("pl")<comp.size() or comp.find("mesomodele")<comp.size()) {
        /// parametres de plasticite
        plast_ecrouissage_init.setExpression(new_material.R0);                         /// R0
        plast_ecrouissage_mult.setExpression(new_material.k_p);                        /// k_p
        plast_ecrouissage_expo.setExpression(new_material.m_p);                        /// m_p
        plast_cinematique_coef.setExpression(new_material.coeff_plast_cinematique);    /// couplage
    }
    if (comp.find("en")<comp.size()){
        /// parametres d'endommagement
        Yo.setExpression(new_material.Yo);  /// Yo (limite initiale d'endommagement)
        dmax = new_material.dmax;           /// dmax (valeur maximale de l'endommagement - pour eviter les divisions par 0)
        b_c  = new_material.b_c;            /// b_c (voir endommagement.cpp::calcul_endommagement)
    }
    if (comp.find("mesomodele")<comp.size()) {
        /// parametres du mesomodele
        Yo.setExpression(new_material.Yo);         /// Yo
        Yc.setExpression(new_material.Yc);         /// Yc
        Ycf.setExpression(new_material.Ycf);       /// Ycf
        dmax         = new_material.dmax;           /// dmax
        b_c          = new_material.b_c;            /// b_c
        effet_retard = new_material.effet_retard;   /// effet_retard
        a            = new_material.a;              /// a
        tau_c        = new_material.tau_c;          /// tau_c
    }//*/
    
    
    affiche();
}
Ejemplo n.º 20
0
GLvoid randomArbre(int delai){
	usleep(delai);

	//variables de constructions
	GLfloat h_troncR=10.0f;
	GLfloat lL_troncR=5.0f;	
	GLfloat t_feuillageR=10.0f;
	GLfloat h_racineR=3.0f;
	GLfloat lL_racineR=1.0f;	
	GLfloat l_brasR=5.0f;
	GLfloat L_brasR=1.0f;
	GLfloat h_brasR=1.0f;
	GLfloat t_arbreR=(t_feuillageR>lL_troncR) ? t_feuillageR : lL_troncR;

	//variables de mouvements
	int orientationR=(rand()%4);

  // Entre glPushMatrix et glPopMatrix s'écrit la description de la scène.
  glPushMatrix();

		if(dep)
			glTranslatef(0.0f,h_racineR,0.0f);
		glTranslatef(posxR,0.0f,poszR);

		glRotatef(90.0f*orientationR,0.0f,1.0f,0.0f);	

		//tronc
		glPushMatrix();
			pave *troncR=creer_pave(lL_troncR,h_troncR,lL_troncR,0.36f,0.25f,0.20f);
			affiche(troncR);		
		glPopMatrix();

		//bras			
		glPushMatrix();
			glTranslatef(lL_troncR/2,0.0f,0.0f);
			if(!dep){
				glRotatef(90.0f,0.0f,0.0f,-1.0f);
			}else{
				glRotatef(rand()%201-100,0.0f,1.0f,0.0f);
				glRotatef(rand()%201-100,0.0f,0.0f,1.0f);
			}
			glTranslatef(l_brasR/2,0.0f,0.0f);			
			pave *bras_unR=creer_pave(l_brasR,h_brasR,L_brasR,0.36f,0.25f,0.20f);
			affiche(bras_unR);		
		glPopMatrix();

		glPushMatrix();
			glTranslatef(-lL_troncR/2,0.0f,0.0f);
			if(!dep){
				glRotatef(90.0f,0.0f,0.0f,1.0f);
			}else{
				glRotatef(rand()%201-100,0.0f,-1.0f,0.0f);
				glRotatef(rand()%201-100,0.0f,0.0f,-1.0f);
			}
			glTranslatef(-l_brasR/2,0.0f,0.0f);			
			pave *bras_deuxR=creer_pave(l_brasR,h_brasR,L_brasR,0.36f,0.25f,0.20f);
			affiche(bras_deuxR);		
		glPopMatrix();				

		//visage
		glPushMatrix();
			glTranslatef(-lL_troncR/4,h_troncR/2,lL_troncR/2);
			pave* oeil_unR=creer_pave(lL_troncR/5,h_troncR/10,1.0f,0.91f,0.76f,0.65f);
			affiche(oeil_unR);
			glTranslatef(lL_troncR/2,0.0f,0.0f);
			pave* oeil_deuxR=creer_pave(lL_troncR/5,h_troncR/10,1.0f,0.91f,0.76f,0.65f);
			affiche(oeil_deuxR);
			glTranslatef(-lL_troncR/4,-lL_troncR/4-0.5f,0.0f);
			pave* nezR=creer_pave(lL_troncR/5,lL_troncR/5,3.0f,0.91f,0.76f,0.65f);
			affiche(nezR);
			glTranslatef(0.0f,-lL_troncR/5-0.5f,0.0f);
			pave* boucheR=creer_pave((lL_troncR/4)*3,h_troncR/10,1.0f,0.91f,0.76f,0.65f);
			affiche(boucheR);
			if(dep){
				//sourire
				glTranslatef(-((lL_troncR/4)*3)/2,h_troncR/20,0.0f);
				pave* sourire_unR=creer_pave(lL_troncR/8,h_troncR/10,1.0f,0.91f,0.76f,0.65f);
				affiche(sourire_unR);
				glTranslatef((lL_troncR/4)*3,0.0f,0.0f);
				pave* sourire_deuxR=creer_pave(lL_troncR/8,h_troncR/10,1.0f,0.91f,0.76f,0.65f);
				affiche(sourire_deuxR);							
			}
		glPopMatrix();	

		//feuillage
		glPushMatrix();
			glTranslatef(0.0f,(h_troncR+t_feuillageR)/2,0.0f);
			pave *feuillageR=creer_pave(t_feuillageR,t_feuillageR,t_feuillageR,0.2f,0.3f,0.2f);
			affiche(feuillageR);
		glPopMatrix();

		int actionR=rand()%2;
		if(actionR)
				switch(orientationR){
					case 0:
						if((dep)&&((t_arbreR/2+poszR)<t_monde/2))
							poszR++;
					break;

					case 1:
						if((dep)&&((t_arbreR/2+posxR)<t_monde/2))
							posxR++;  
					break;

					case 2:
						if((dep)&&((-t_arbreR/2+poszR)>-t_monde/2)) 
							poszR--;
					break;

					case 3:
						if((dep)&&((-t_arbreR/2+posxR)>-t_monde/2)) 
							posxR--;
					break;
			}
		else
				switch(orientationR){
					case 0:
						if((dep)&&((-t_arbreR/2+poszR)>-t_monde/2)) 
							poszR--;  
					break;

					case 1:
						if((dep)&&((-t_arbreR/2+posxR)>-t_monde/2)) 
							posxR--;  
					break;

					case 2:
						if((dep)&&((t_arbreR/2+poszR)<t_monde/2)) 
							poszR++;
					break;

					case 3:
						if((dep)&&((t_arbreR/2+posxR)<t_monde/2)) 
							posxR++;
					break;
			}	

		//racines
		glPushMatrix();
			glTranslatef(-lL_troncR/2,-h_troncR/2,-lL_troncR/2);
			if((dep)&&(!(poszR % 2))&&((t_arbreR/2+poszR)<t_monde/2)&&((-t_arbreR/2+poszR)>-t_monde/2))
				glRotatef(30.0f,-1.0f,0.0f,0.0f);
			else if((dep)&&(!(posxR % 2))&&((t_arbreR/2+posxR)<t_monde/2)&&((-t_arbreR/2+posxR)>-t_monde/2))
				glRotatef(30.0f,-1.0f,0.0f,0.0f);
			glTranslatef(lL_racineR/2,-h_racineR/2,lL_racineR/2);
			pave *racine_unR=creer_pave(lL_racineR,h_racineR,lL_racineR,0.36f,0.25f,0.20f);
			affiche(racine_unR);
		glPopMatrix();

		glPushMatrix();
			glTranslatef(-lL_troncR/2,-h_troncR/2,lL_troncR/2);
			if((dep)&&(!(poszR % 2))&&((t_arbreR/2+poszR)<t_monde/2)&&((-t_arbreR/2+poszR)>-t_monde/2))
				glRotatef(30.0f,-1.0f,0.0f,0.0f);
			else if((dep)&&(!(posxR % 2))&&((t_arbreR/2+posxR)<t_monde/2)&&((-t_arbreR/2+posxR)>-t_monde/2))
				glRotatef(30.0f,-1.0f,0.0f,0.0f);
			glTranslatef(lL_racineR/2,-h_racineR/2,-lL_racineR/2);
			pave *racine_troisR=creer_pave(lL_racineR,h_racineR,lL_racineR,0.36f,0.25f,0.20f);
			affiche(racine_troisR);
		glPopMatrix();

		glPushMatrix();
			glTranslatef(lL_troncR/2,-h_troncR/2,-lL_troncR/2);
			if((dep)&&(poszR % 2)&&((t_arbreR/2+poszR)<t_monde/2)&&((-t_arbreR/2+poszR)>-t_monde/2))
				glRotatef(30.0f,-1.0f,0.0f,0.0f);
			else if((dep)&&(posxR % 2)&&((t_arbreR/2+posxR)<t_monde/2)&&((-t_arbreR/2+posxR)>-t_monde/2))
				glRotatef(30.0f,-1.0f,0.0f,0.0f);
			glTranslatef(-lL_racineR/2,-h_racineR/2,lL_racineR/2);
			pave *racine_deuxR=creer_pave(lL_racineR,h_racineR,lL_racineR,0.36f,0.25f,0.20f);
			affiche(racine_deuxR);
		glPopMatrix();

		glPushMatrix();
			glTranslatef(lL_troncR/2,-h_troncR/2,lL_troncR/2);
			if((dep)&&(poszR % 2)&&((t_arbreR/2+poszR)<t_monde/2)&&((-t_arbreR/2+poszR)>-t_monde/2))
				glRotatef(30.0f,-1.0f,0.0f,0.0f);
			else if((dep)&&(posxR % 2)&&((t_arbreR/2+posxR)<t_monde/2)&&((-t_arbreR/2+posxR)>-t_monde/2))
				glRotatef(30.0f,-1.0f,0.0f,0.0f);
			glTranslatef(-lL_racineR/2,-h_racineR/2,-lL_racineR/2);
			pave *racine_quatreR=creer_pave(lL_racineR,h_racineR,lL_racineR,0.36f,0.25f,0.20f);
			affiche(racine_quatreR);
		glPopMatrix();

  glPopMatrix();
}
Ejemplo n.º 21
0
// Methode d'apprentissage d'un PRFA prefixe
RESULT
PPRFA::DEES (T_ModeVariables modeVariables,
			 Sample & S,
			 double prec,
			 double epsprime,
			 bool verbose,
			 T_ModeReturn moderet,
			 T_ModeEpsilon modeeps,
			 unsigned int maxstates,
			 unsigned int seuil, 
			 int maxmots, 
			 int maxsearches,
			 bool bestsearch,
			 bool stepssave)
{
    try {
	// ------------------------- affichage des informations ---------------------- //
	if (verbose)
	{
		cout << "\t\t=== DEES ===";
		cout << "\nSample size = " << S.size ();
		cout << "\nprecision = " << prec;
		cout << "\nbound = " << epsprime;
		cout << "\nmoderet = ";
		switch (moderet)
		{
            case ::begin:
                cout << "begin";
                break;
            case ::end:
                cout << "end";
		}
		cout << "\nmodeeps = ";
		switch (modeeps)
		{
            case epsfixed:
                cout << "epsfixed";
                break;
            case variable:
                cout << "variable";
                break;
            case word_variable:
                cout << "word_variable";
                break;
		}
		cout << "\nmaxstates = " << maxstates;
		cout << "\nseuil = " << seuil;
		cout << "\nmaxmots = " << maxmots << endl;
	}
	
	if (prec == 0) {
		return becomePrefixTree(S);
	}
	
	// -------------------------- INITIALISATION ----------------------
	vide ();		// on initialise le PFA.
	if (S.size () == 0)
		throw 0;		// on verifie que l'echantillon n'est pas vide.
	S.prefixialise ();	// Transformation de l'Èchantillon en echantillon prefixiel.
	Sigma = S.alphabet ();	// on met ‡† jour l'alphabet
	alph = S.dictionnaire ();	// et le dictionnaire associÈ.
	
	// Declaration
	Word v;			// the word v which represent the word associated to the state to add.
	list < Word > X;		// The set of words which are potential prime residuals.
	Sample::const_iterator u;	// current word of the sample.
	float val;		// a floating value used to calculate tau.
	Word w;			// a word
	Word ww;			// another word
	Lettre a;		// a letter (we will have v=wa)
	Alphabet::const_iterator b;	// pour enumerer toutes les lettres
	SFunc solution;	// the system solution
	SFunc solutiontemp;	// a temporary solution
	StateSet::iterator q;	// Pour enumerer les états
	Simplex simplx;		// L'objet simplexe qui contient les algorithmes de resolution de systemes.
	set < Word, ordre_mot > W;	// L'ensemble de mots à tester
	Word::iterator z;	// last letter
	
	// --- init variables ---
	v.clear ();		// v = epsilon (empty word)
					// X is the set of one letter words of S when prefixialised
	val = 0;
	for (u = ++(S.begin ());
		 (u != S.end ()) && (u->first.size () < 2); ++u)
	{
		X.push_back (u->first);
		val += u->second;
	}
	// We create the first state (epsilon)
	addState (v, 1, 1 - (float(val) / float(S.size ())));
	W.clear ();
	
	// liste_mots_associes(W,v,S,maxmots);
	ajoute_mots_associes(W,v,S,maxmots);
	
	// There may be a general state
	State generalstate = -1;
	
	// Step saving
	string svgfile="etape-";
	
	// -------------------------- LEARNING LOOP  -----------------------
	if (verbose)
		cout << "Ajout des états : " << endl;
	
	// For each element in X (the temporary list)
	while (!X.empty ())
	{
		v = *(X.begin ());	// v <-- min X;
		X.pop_front ();	// X <-- X\{v} ;
						// wa=v
		w = v;
		a = *(w.rbegin ());
		z = w.end ();
		--z;
		w.erase (z);	//w.pop_back ();
		
		//~ if (verbose) {
		//~ cout << "[";
		//~ cout << affiche(v) <<"]";
		//~ cout.flush();
		//~ }
		
		if (stepssave) {
			save(svgfile+affiche(v));
		}
		
		
		/// 3 possible cases : 
		///     (1) not enought data (make a loop to the general state)
		///     (2) there is no solution (add a new state and update X)
		///     (3) there is a solution (make a return of transitions)
		
		if (S[v] < seuil) // case (1) not enought data
		{
			// cout << "CASE (1)" << endl;
			if (generalstate == -1)
			{		// if the general state was not created, we create it
				generalstate = addState (v, 0, 1 / float(Sigma.size () + 1));
				for (b = Sigma.begin (); b != Sigma.end (); ++b)
				{
					MA::addTransition (generalstate, *b, generalstate, 1 / float(Sigma.size () + 1));
				}
			}
			
			addTransition (w, a, generalstate, ((double) S[v] / (double) S[w]));
			XR[w + a] = generalstate;
			if (verbose)
			{
				cout << "S";
				cout.flush ();
			}
		}
		else
		{
			solution.clear ();	// init solutions
			// calculate the solution of the linear system
			sol (modeVariables, solution, v, S, simplx, prec / pow(float(S[v]), float(0.4)), moderet, modeeps, W, maxmots, false);	
			if (solution.empty ()) // if there is no solution (case (2) add a new state and update X
			{
				// cout << "CASE (2)" << endl;

				// if there is no solution then we add the state associated with v
				// updating X and tau (val will contain tau[v])
				val = 0;
				for (b = Sigma.begin (); b != Sigma.end (); b++)
				{		// pour toute les lettres de l'alphabet
					v += *b;
					//v.push_back (*b);     // on ajoute b a la fin de v
					if (S.find (v) != S.end ())
					{	// si vb appartient a l'echantillon, alors
						X.push_back (v);	// on l'ajoute a X
						val += S[v];	// et val = val + S(vb\Sigma^*)
					}
					z = v.end ();
					--z;
					v.erase (z);	//v.pop_back ();  // on efface la derniere lettre pour que la variable v = le mot v.
				}
				
				if (verbose)
				{
					cout << "A";
					cout.flush ();
				}
				
				addState (v,0, 1 - (val / (double) S[v]));	// adding the new state
				if (size () > maxstates)
					throw 1;
				addTransition (w, a, v, ((double) S[v] / (double) S[w]));	// updating phi : phi(w,a,wa) = S(wa)/S(w)
				
			}
			else
			{
				// cout << "CASE (3)" << endl;

				// else we return transitions
				
				if (verbose)
				{
					cout << "R";
					cout.flush ();
				}
				
				for (q = Q.begin (); q != Q.end (); q++)
				{
					val = (float) solution[*q] *
					((double) S[v] / (double) S[w]);
					if (val != 0)
					{
						addTransition (w, a, *q, val);
					}
				}
			}
		}
	}
	if (verbose) 
		cout << endl;
	
	erase_transitions (epsprime, -epsprime);	// deleting transitions less than epsprime
									//best_transition_delete(S,verbose);
	if (modeVariables == nonconstrained) {
		return VAL(0);
	}
	else {
		return renormalise ();	// renormalisation in order to disable borders effects
	}
}
catch (int erreur) {
	if (PFA_VERBOSE)
	{
		if (erreur != 1)
		{
			cerr << "PFA::DEES(Sample S)" << endl;
		}
		switch (erreur)
		{
            case 0:
                cerr << "Sample vide !!!" << endl;
                break;
            case 1:		// il y a trop d'etats
                erase_transitions (epsprime);
                return renormalise ();
                break;
            default:
                cerr << "Erreur n∞" << erreur << endl;
		}
	}
	return ERR (erreur);
}
}
Ejemplo n.º 22
0
Archivo: td1_6.c Proyecto: garry7/IN301
int main(void)
{
        affiche(500);  
    return 0;
}
Ejemplo n.º 23
0
Archivo: jeu.c Proyecto: pouet/rubik
int jeu(Cube * cube, struct SItem * it, int nbItem) {
  Bouton ** b;
  SDL_Rect rimg[6] = {
    { POS_X_CUBISO + 3, POS_Y_CUBISO + cube->nbCubLig * OFFSET_Y_H_CUBISO +
      cube->nbCubLig * 53 + 12, 0, 0 },
    { POS_X_CUBISO + cube->nbCubLig * OFFSET_X_H_CUBISO + 22 - 6,
      POS_Y_CUBISO + cube->nbCubLig * OFFSET_Y_H_CUBISO +
      (cube->nbCubLig - 1) * OFFSET_Y_H_CUBISO + cube->nbCubLig * 53 + 12, 0, 0 },
    { POS_X_CUBISO, POS_Y_CUBISO + (cube->nbCubLig - 1) * OFFSET_Y_H_CUBISO - 15 + 10, 0, 0 },
    { POS_X_CUBISO + cube->nbCubLig * OFFSET_X_H_CUBISO + 18, POS_Y_CUBISO - 15 + 10, 0, 0 },
    { POS_X_CUBISO + cube->nbCubLig * (OFFSET_X_H_CUBISO * 2 ) + 10,
      POS_Y_CUBISO + cube->nbCubLig * OFFSET_Y_H_CUBISO + 15, 0, 0 },
    { POS_X_CUBISO - 27, POS_Y_CUBISO + cube->nbCubLig * OFFSET_Y_H_CUBISO + 15, 0, 0 }
  };
  SDL_Rect roff[6] = {
    { OFFSET_X_H_CUBISO, OFFSET_Y_H_CUBISO, 0, 0 },
    { OFFSET_X_H_CUBISO, -OFFSET_Y_H_CUBISO, 0, 0 },
    { OFFSET_X_H_CUBISO, -OFFSET_Y_H_CUBISO, 0, 0 },
    { OFFSET_X_H_CUBISO, OFFSET_Y_H_CUBISO, 0, 0 },
    { 0, 53, 0, 0 },
    { 0, 53, 0, 0 }
  };
  Input * in;
  int ret = M_MENU;
  int nbBtn;
  int done;
  int clic;
  int timer;
  int i, j, k;
  
  if (cube == NULL)
    return ret;
  
  in = newEvent();
  
  nbBtn = nbItem + cube->nbCubLig * 6;
  b = emalloc((nbBtn + 1) * sizeof **b, "Erreur d'allocation de boutons.\n");
  b[nbBtn] = NULL;
  
  for (i = 0, j = 0; i < nbItem; i++, j++)
    b[i] = creerBoutonTexte(it[i].pItemName, SCR_W - g_boutons[0]->w - 12,
                            SCR_H - 6 - (nbItem - i) * (g_boutons[0]->h + 6), 1);
  
  for (k = 0; k < 6; k++)
    for (i = 0; i < cube->nbCubLig; i++, j++)
      b[j] = creerBoutonImage(k * 3, rimg[k].x + roff[k].x * i,
                              rimg[k].y + roff[k].y * i, 1);
  
  refreshScreen();
  
  timer = 0;
  clic = 0;
  done = 0;
  while (!done) {
    updateEvents(in);
    
    if (in->quit) {
      done = 1;
      ret = M_QUIT;
    }
    
    for (i = 0; i < nbBtn; i++) {
      if (b[i]->actif) {
        if (collisionPoint(&b[i]->r, &in->mouse)) {
          /* Si on clique */
          if (!clic && (in->mousebuttons[1] || in->mousebuttons[2])) {
            clic = 1;
            b[i]->etat = BTN_ETAT_CLIC;
            b[i]->majAff = 1;
          }
          /* Si on relâche le clic */
          else if (clic && b[i]->etat == BTN_ETAT_CLIC &&
                   !in->mousebuttons[1] && !in->mousebuttons[2]) {
            clic = 0;
            b[i]->etat = BTN_ETAT_NORMAL;
            b[i]->majAff = 1;
            
            if (i < nbItem) {
              if (it[i].nItemVal == M_MENU || it[i].nItemVal == M_QUIT) {
                ret = it[i].nItemVal;
                if (it[i].pVal)
                  *it[i].pVal = it[i].nVal;
                done = 1;
              }
              else if (it[i].nItemVal == M_MELANGE) {
                melangerCube(cube);
                timer = 0;
                cube->tpsTotal = 0;
                cube->nbCoups = 0;
              }
              else if (it[i].nItemVal == M_REINIT) {
                refreshScreen();
                initCube(cube, cube->nbCubLig);
                timer = 0;
              }
              else if (it[i].nItemVal == M_SAUVE) {
                sauverCube(cube);
              }
            }
            else if (i >= nbItem) {
              int tmp = i - nbItem;
              
              cube->nbCoups++;
              if (timer == 0)
                timer = 1;
              
              /* Ca va crescendo on teste la borne la plus basse et ainsi de suite
               * sans retester plus bas, c'est déjà test avant */
              /* Flèche haut gauche */
              if (tmp < cube->nbCubLig) {
                rotationCubeEntier(cube, R_GAUCHE);
                mouvement(cube, tmp, R_BAS);
                rotationCubeEntier(cube, R_DROITE);
              }
              /* Flèches haut droite */
              else if (tmp < cube->nbCubLig * 2) {
                tmp -= cube->nbCubLig;
                mouvement(cube, tmp, R_BAS);
              }
              /* Flèches bas gauche */
              else if (tmp < cube->nbCubLig * 3) {
                tmp -= (cube->nbCubLig * 2);
                mouvement(cube, tmp, R_HAUT);
              }
              /* Flèches bas droite */
              else if (tmp < cube->nbCubLig * 4) {
                tmp -= (cube->nbCubLig * 3);
                rotationCubeEntier(cube, R_GAUCHE);
                mouvement(cube, tmp, R_HAUT);
                rotationCubeEntier(cube, R_DROITE);
              }
              /* Flèches droite */
              else if (tmp < cube->nbCubLig * 5) {
                tmp -= (cube->nbCubLig * 4);
                mouvement(cube, tmp, R_DROITE);
              }
              /* Flèches gauche */
              else if (tmp < cube->nbCubLig * 6) {
                tmp -= (cube->nbCubLig * 5);
                mouvement(cube, tmp, R_GAUCHE);
              }
              else {
                cube->nbCoups--;
                aprintf("Bouton inconnu.\n");
              }
            }
            else {
              aprintf("Bouton inconnu.\n");
            }
          }
          else if (b[i]->etat != BTN_ETAT_CLIC) {
            if (b[i]->etat != BTN_ETAT_SURVOLE)
              b[i]->majAff = 1;
            b[i]->etat = BTN_ETAT_SURVOLE;
          }
        }
        else if (b[i]->etat != BTN_ETAT_CLIC) {
          if (b[i]->etat != BTN_ETAT_NORMAL)
            b[i]->majAff = 1;
          b[i]->etat = BTN_ETAT_NORMAL;
        }
      }
    }
    
    if (clic && !in->mousebuttons[1] && !in->mousebuttons[2]) {
      clic = 0;
      for (i = 0; i < nbBtn; i++)
        if (b[i]->etat == BTN_ETAT_CLIC) {
          b[i]->etat = BTN_ETAT_NORMAL;
          b[i]->majAff = 1;
        }
    }
    
    if (timer)
      cube->tpsTotal += TICK;
    
    affiche(BCK_JEU, cube, b);
  }
  
  for (i = 0; i < nbBtn; i++)
    detruireBouton(&b[i]);
  free(b);
  deleteEvent(&in);
  
  return ret;
}
Ejemplo n.º 24
0
/*******************************************************************************
	BALAYAGE D'UN DOSSIER
*******************************************************************************/
static int Balaie_Path(char *directory,int wx,int wy,int ww,int wh)
{
	char		old_path[FILENAME_MAX];
	int		old_drv;
	char		pfn[FILENAME_MAX];
	DTA		*mydta;
	int		i,Fin=0;
	int		cnt,pos;
/*	long		count;*/

	t2=0;
	old_drv=Dgetdrv();
	Dgetpath(old_path,1+old_drv);
	mydta=Fgetdta();
	if (directory[1]==':')
		Dsetdrv((int)directory[1]-65);

	strcpy(pfn,directory);
	strcat(pfn,"\\*.*");
	if (glb.opt.sl_rec)
		i=Fsfirst(pfn,FA_READONLY|FA_SUBDIR|FA_ARCHIVE);
	else
		i=Fsfirst(pfn,FA_READONLY|FA_ARCHIVE);
	pos=0;
loop1:
	cnt=0;
	while (!i)
	{
		cnt+=1;
		if (mydta->d_fname[0]!='.' && cnt>pos)
		{
			strcpy(pfn,directory);
			strcat(pfn,"\\");
			strcat(pfn,mydta->d_fname);
			if (mydta->d_attrib&FA_SUBDIR)
			{
				pos=cnt;
				if (Balaie_Path(pfn,wx,wy,ww,wh))
					return TRUE;
				strcpy(pfn,directory);
				strcat(pfn,"\\*.*");
				if (glb.opt.sl_rec)
					i=Fsfirst(pfn,FA_READONLY|FA_SUBDIR|FA_ARCHIVE);
				else
					i=Fsfirst(pfn,FA_READONLY|FA_ARCHIVE);
				goto loop1;
			}
		}
		if (Kbshift(-1)!=shift)
			return TRUE;
		i=Fsnext();
/*
		if (i!=0)
			{
				time(&t1);
				if(glb.opt.sl_pause)
				{
					count=1000L*max( 0 , (long)glb.opt.sl_ptime - (t1-t2) );
					evnt_timer( (int)(count&0xFFFFUL),(int)(count>>16) );
				}
				else
					count=0;
			}
*/
	}


	strcpy(pfn,directory);
	strcat(pfn,"\\");
	strcat(pfn,glb.opt.sl_name);

	if (glb.opt.sl_rec)
		i=Fsfirst(pfn,FA_READONLY|FA_SUBDIR|FA_ARCHIVE);
	else
		i=Fsfirst(pfn,FA_READONLY|FA_ARCHIVE);
	pos=0;
	cnt=0;
	while (!i)
	{
		cnt+=1;
		if (mydta->d_fname[0]!='.' && cnt>pos)
		{
			strcpy(pfn,directory);
			strcat(pfn,"\\");
			strcat(pfn,mydta->d_fname);
			if (!(mydta->d_attrib&FA_SUBDIR))
				affiche(pfn,wx,wy,ww,wh);
		}
		if (Kbshift(-1)!=shift)
			return TRUE;
		i=Fsnext();
/*
		if (i!=0)
			{
				time(&t1);
				if(glb.opt.sl_pause)
					count=1000L*max( 0 , (long)glb.opt.sl_ptime - (t1-t2) );
				else
					count=0;
				evnt_timer( (int)(count&0xFFFFUL),(int)(count>>16) );
			}
*/
	}


	Dsetdrv(old_drv);
	Dsetpath(old_path);
	return Fin;
}
Ejemplo n.º 25
0
/*------------------------------------------------------------------------------
	Description : primitive hors-noyau invoquée par défaut en terminaison de processus
*/
EXPORT void detruitProcessusAppelant() {
   affiche("declenchera detruitProcessus(obtientPid())");
   while (1);				// evite de partir dans la nature à la fin
}
Ejemplo n.º 26
0
int main(int argc, const char * argv[]) {

    struct maillon *p;
    struct maillon *tmp;
    bool continuer;
    int choix;
    int nbr;
    int numero;
    
    continuer = true;
    init(&p);
    
    while (continuer) {
        cout << "1. Afficher la liste" << endl;
        cout << "2. Ajouter un élément" << endl;
        cout << "3. Compter le nombre de maillon" << endl;
        cout << "4. Faire une rotation" << endl;
        cout << "5. Désinitialiser la liste" << endl;
        cout << "6. QUITTER" << endl;
        
        cout << "Saisir choix : ";
        cin >> choix;
        
        switch (choix) {
            case 1:
                affiche(p);
                break;
                
            case 2:
                cout << "Numéro de l'élément : ";
                cin >> numero;
				tmp = new struct maillon;
                (*tmp).numero = numero;
                ajout(&p, tmp);
				break;
            
            case 3:
                nbr = nbMaillon(p);
				cout << "Il y a " << nbr << " éléments dans la liste" << endl;
				break;

		    case 4:
				if (nbMaillon(p) > 0) {
					rotation(&p);
					cout << "Rotation effectuée." << endl;
				}
				else
					cout << "La liste est vide, impossible de faire une rotation." << endl;
			    break;

		    case 5:
			    desinit(&p);
			    cout << "Liste désinitialisée." << endl;
			    break;

		    case 6:
				continuer = false;
				break;
				
            default:
                break;
        }
    }
    
    return 0;
}
Ejemplo n.º 27
0
int main() {
	int i;
	liste li = nouvListe(), li2 = nouvListe();
	
	adjt(1, li);
	adjt(5, li);
	adjt(-7, li);
		
	printf ("liste : "); affiche(li);
	
	printf("taille : %d\n", taille(li));	
	printf("vide ? : %s\n", (estVide(li)?"oui":"non"));	

	for(i=1; i <= 10; ++i) {
		adjq(i*i, li2);
	} 
	printf ("liste : "); affiche(li2);
	printf("tete : %d queue : %d\n", tete(li2), queue(li2));
	printf("====== suppressions =========\n");
	supt(li2);
	printf ("apres supt : "); affiche(li2);
	supq(li2);
	printf ("apres supq : "); affiche(li2);

	// creation de deux listes avec des elements choisis au hasard
	printf("====== tris et renversement =========\n");

	srand(time(NULL));	// initialisation de la suite aleatoire
	printf("liste 11 : ");
	liste l1 = nouvListe();
	for(i=0; i < 15; ++i) {
	  adjt(rand()%30, l1);
	}
	affiche (l1);
	
	printf("liste 12 : ");
	liste l2 = nouvListe();
	for(i=0; i < 10; ++i) {
	  adjt(rand()%30, l2);
	}
	affiche (l2);

	liste l1t = trie(l1);
	liste l2t = trie(l2);
	printf("liste 11 apres trie : "); affiche(l1t);
	printf("liste 12 apres trie : "); affiche(l2t);
	liste l3t = interclasse(l1t,l2t);
	printf("interclassement : "); affiche(l3t);
	
	printf("renversement iter : "); affiche(renverse_iter(l3t));
	printf("renversement recur : "); affiche(renverse_recur(l3t));

	printf("====== palindrome =========\n");

	
	liste lpalin = nouvListe();
	adjt(1, lpalin); 
	adjt(2, lpalin); adjq(2, lpalin);
	adjt(8, lpalin); adjq(8, lpalin);
	printf("liste : "); affiche(lpalin);
	printf("Palindrome (iter) ? %s\n", (palindrome_iter(lpalin)?"oui":"non"));
	printf("Palindrome (recur) ? %s\n", (palindrome_recur(lpalin)?"oui":"non"));
	supt(lpalin);
	printf("liste : "); affiche(lpalin);
	printf("Palindrome (iter) ? %s\n", (palindrome_iter(lpalin)?"oui":"non"));
	printf("Palindrome (recur) ? %s\n", (palindrome_recur(lpalin)?"oui":"non"));
	
	return 0;
}
Ejemplo n.º 28
0
void affiche2(Solutions s) {
	affiche(s.z1);
	affiche(s.z2);
}