Advertisement
tapette101

fonction vérification du projet

May 24th, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //fonction qui va permettre de compter le nombre de points gagnés par fruit/légume
  2. void verification(char tab[20][40], int *pointS,int *pointF,int *pointP,int *pointO,int *pointM){
  3.     int i, j, k, l, n=0, cas=0;
  4.     for(i=0;i<20;i++){
  5.         for(j=0;j<40;j++){
  6.            
  7.             while(1){       //boucle infinie qui ne se termine qu'une fois les tests effectués
  8.                                 //on commence par tester les 5== de suite en ligne et en colonne
  9.                 if(tab[i][j]==tab[i+1][j]==tab[i+2][j]==tab[i+3][j]==tab[i+4][j] || tab[i][j]==tab[i][j+1]==tab[i][j+2]==tab[i][j+3]==tab[i][j+4]){
  10.                     for (k=0;k<20;k++){
  11.                         for(l=0;l<40;l++){
  12.                             if(tab[k][l]==tab[i][j]) n++;       //ici, on cherche toutes les cases du tableau de même lettre que les 5 identiques horizontaux
  13.                         }
  14.                     }
  15.                     if(tab[i][j]=='S') pointS+=n;
  16.                     if(tab[i][j]=='F') pointF+=n;
  17.                     if(tab[i][j]=='P') pointP+=n;
  18.                     if(tab[i][j]=='O') pointO+=n;
  19.                     if(tab[i][j]=='M') pointM+=n;
  20.                     //fonction suprimer quelque part ici
  21.                     break;
  22.                 }               //puis les 4== en ligne
  23.                 if(tab[i][j]==tab[i+1][j]==tab[i+2][j]==tab[i+3][j]){
  24.                     cas=4;
  25.                     if(tab[i][j]=='S') pointS+=4;
  26.                     if(tab[i][j]=='F') pointF+=4;
  27.                     if(tab[i][j]=='P') pointP+=4;
  28.                     if(tab[i][j]=='O') pointO+=4;
  29.                     if(tab[i][j]=='M') pointM+=4;
  30.                     //fonction suprimer quelque part ici
  31.                     break;
  32.                 }               //et enfin les 3== en ligne
  33.                 if(tab[i][j]==tab[i+1][j]==tab[i+2][j]){
  34.                     cas=3;
  35.                     if(tab[i][j]=='S') pointS+=3;
  36.                     if(tab[i][j]=='F') pointF+=3;
  37.                     if(tab[i][j]=='P') pointP+=3;
  38.                     if(tab[i][j]=='O') pointO+=3;
  39.                     if(tab[i][j]=='M') pointM+=3;
  40.                     //fonction supprimer quelque part ici
  41.                     break;
  42.                 }               //maintenant, les 4== en colonne
  43.                 if(tab[i][j]==tab[i][j+1]==tab[i][j+2]==tab[i][j+3]){
  44.                     cas=6;
  45.                     if(tab[i][j]=='S') pointS+=4;
  46.                     if(tab[i][j]=='F') pointF+=4;
  47.                     if(tab[i][j]=='P') pointP+=4;
  48.                     if(tab[i][j]=='O') pointO+=4;
  49.                     if(tab[i][j]=='M') pointM+=4;
  50.                     //fonction supprimer quelque part ici
  51.                     break;
  52.                 }               //au tour des 3== en colonne
  53.                 if(tab[i][j]==tab[i][j+1]==tab[i][j+2]){
  54.                     cas=5;
  55.                     if(tab[i][j]=='S') pointS+=3;
  56.                     if(tab[i][j]=='F') pointF+=3;
  57.                     if(tab[i][j]=='P') pointP+=3;
  58.                     if(tab[i][j]=='O') pointO+=3;
  59.                     if(tab[i][j]=='M') pointM+=3;
  60.                     //fonction supprimer quelque part ici
  61.                     break;
  62.                 }
  63.                 else break;
  64.             } //fin de la boucle infinie while(1). Maintenant, on doit tester les différentes formes spéciales possibles selon les cas précédents
  65.            
  66.             if (cas==4){            //test qui cherche les différentes formes possibles (croix, L...) --> ici, pour le cas où on a 4 lettres identiques en ligne
  67.                 if (tab[i][j]==tab[i][j+1]==tab[i][j+2] || tab[i][j]==tab[i][j-1]==tab[i][j-2] || tab[i][j]==tab[i][j+1]==tab[i][j-1] || tab[i+1][j]==tab[i+1][j+1]==tab[i+1][j+2] || tab[i+1][j]==tab[i+1][j-1]==tab[i+1][j-2] || tab[i+1][j]==tab[i+1][j+1]==tab[i+1][j-1] || tab[i+2][j]==tab[i+2][j+1]==tab[i+2][j+2] || tab[i+2][j]==tab[i+2][j-1]==tab[i+2][j-2] || tab[i+2][j]==tab[i+2][j+1]==tab[i+2][j-1] || tab[i+3][j]==tab[i+3][j+1]==tab[i+3][j+2] || tab[i+3][j]==tab[i+3][j-1]==tab[i+3][j-2] || tab[i+3][j]==tab[i+3][j+1]==tab[i+3][j-1]){
  68.                     if(tab[i][j]=='S') pointS+=10;
  69.                     if(tab[i][j]=='F') pointF+=10;
  70.                     if(tab[i][j]=='P') pointP+=10;
  71.                     if(tab[i][j]=='O') pointO+=10;
  72.                     if(tab[i][j]=='M') pointM+=10;
  73.                 }
  74.             }
  75.             if (cas==3){            //pour le cas où il y a 3 lettres identiques horizontales
  76.                 if (tab[i][j]==tab[i][j+1]==tab[i][j+2] || tab[i][j]==tab[i][j-1]==tab[i][j-2] || tab[i][j]==tab[i][j+1]==tab[i][j-1] || tab[i+1][j]==tab[i+1][j+1]==tab[i+1][j+2] || tab[i+1][j]==tab[i+1][j-1]==tab[i+1][j-2] || tab[i+1][j]==tab[i+1][j+1]==tab[i+1][j-1] || tab[i+2][j]==tab[i+2][j+1]==tab[i+2][j+2] || tab[i+2][j]==tab[i+2][j-1]==tab[i+2][j-2] || tab[i+2][j]==tab[i+2][j+1]==tab[i+2][j-1]){
  77.                     if(tab[i][j]=='S') pointS+=9;
  78.                     if(tab[i][j]=='F') pointF+=9;
  79.                     if(tab[i][j]=='P') pointP+=9;
  80.                     if(tab[i][j]=='O') pointO+=9;
  81.                     if(tab[i][j]=='M') pointM+=9;
  82.                 }
  83.             }
  84.             if (cas==6){            //on test ici les formes possibles pour le cas où on a 4 lettres identiques en colonne
  85.                 if (tab[i][j]==tab[i+1][j]==tab[i+2][j] || tab[i][j]==tab[i-1][j]==tab[i-2][j] || tab[i][j]==tab[i+1][j]==tab[i-1][j] || tab[i][j+1]==tab[i+1][j+1]==tab[i+2][j+2] || tab[i][j+1]==tab[i-1][j+1]==tab[i-2][j+1] || tab[i][j+1]==tab[i+1][j+1]==tab[i-1][j+1] || tab[i][j+2]==tab[i+1][j+2]==tab[i+2][j+2] || tab[i][j+2]==tab[i-1][j+2]==tab[i-2][j+2] || tab[i][j+2]==tab[i+1][j+2]==tab[i-1][j+2] || tab[i][j+3]==tab[i+1][j+3]==tab[i+2][j+3] || tab[i][j+3]==tab[i-1][j+3]==tab[i-2][j+3] || tab[i][j+3]==tab[i+1][j+3]==tab[i-1][j+3]){
  86.                     if(tab[i][j]=='S') pointS+=10;
  87.                     if(tab[i][j]=='F') pointF+=10;
  88.                     if(tab[i][j]=='P') pointP+=10;
  89.                     if(tab[i][j]=='O') pointO+=10;
  90.                     if(tab[i][j]=='M') pointM+=10;
  91.                 }
  92.             }
  93.             if (cas==5){            //on test ici les formes possibles pour le cas où on a 3 lettres identiques verticalement
  94.                 if (tab[i][j]==tab[i+1][j]==tab[i+2][j] || tab[i][j]==tab[i-1][j]==tab[i-2][j] || tab[i][j]==tab[i+1][j]==tab[i-1][j] || tab[i][j+1]==tab[i+1][j+1]==tab[i+2][j+2] || tab[i][j+1]==tab[i-1][j+1]==tab[i-2][j+1] || tab[i][j+1]==tab[i+1][j+1]==tab[i-1][j+1] || tab[i][j+2]==tab[i+1][j+2]==tab[i+2][j+2] || tab[i][j+2]==tab[i-1][j+2]==tab[i-2][j+2] || tab[i][j+2]==tab[i+1][j+2]==tab[i-1][j+2]){
  95.                     if(tab[i][j]=='S') pointS+=10;
  96.                     if(tab[i][j]=='F') pointF+=10;
  97.                     if(tab[i][j]=='P') pointP+=10;
  98.                     if(tab[i][j]=='O') pointO+=10;
  99.                     if(tab[i][j]=='M') pointM+=10;
  100.                 }
  101.             }
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement