Advertisement
tapette101

Nouvelle fonction vérification

Jun 1st, 2015
292
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][j]==tab[i+2][j] && tab[i][j]==tab[i+3][j] && tab[i][j]==tab[i+4][j]) || (tab[i][j]==tab[i][j+1] && tab[i][j]==tab[i][j+2] && tab[i][j]==tab[i][j+3] && tab[i][j]==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
  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.                     break;                                  //bien noter la fonction break ici qui permet au while(1) de ne pas tourner à l'infini !
  21.                 }               //puis les 4== en ligne
  22.                 if(tab[i][j]==tab[i+1][j] && tab[i][j]==tab[i+2][j] && tab[i][j]==tab[i+3][j]){
  23.                     cas=4;
  24.                     if(tab[i][j]=='S') pointS+=8;
  25.                     if(tab[i][j]=='F') pointF+=8;
  26.                     if(tab[i][j]=='P') pointP+=8;
  27.                     if(tab[i][j]=='O') pointO+=8;
  28.                     if(tab[i][j]=='M') pointM+=8;
  29.                     break;
  30.                 }               //maintenant, les 4== en colonne
  31.                 if(tab[i][j]==tab[i][j+1] && tab[i][j]==tab[i][j+2] && tab[i][j]==tab[i][j+3]){
  32.                     cas=6;
  33.                     if(tab[i][j]=='S') pointS+=8;
  34.                     if(tab[i][j]=='F') pointF+=8;
  35.                     if(tab[i][j]=='P') pointP+=8;
  36.                     if(tab[i][j]=='O') pointO+=8;
  37.                     if(tab[i][j]=='M') pointM+=8;
  38.                     break;
  39.                 }               //et enfin les 3== en ligne
  40.                 if(tab[i][j]==tab[i+1][j]==tab[i+2][j]){
  41.                     cas=3;
  42.                     if(tab[i][j]=='S') pointS+=3;
  43.                     if(tab[i][j]=='F') pointF+=3;
  44.                     if(tab[i][j]=='P') pointP+=3;
  45.                     if(tab[i][j]=='O') pointO+=3;
  46.                     if(tab[i][j]=='M') pointM+=3;
  47.                     break;
  48.                 }              //au tour des 3== en colonne
  49.                 if(tab[i][j]==tab[i][j+1]==tab[i][j+2]){
  50.                     cas=5;
  51.                     if(tab[i][j]=='S') pointS+=3;
  52.                     if(tab[i][j]=='F') pointF+=3;
  53.                     if(tab[i][j]=='P') pointP+=3;
  54.                     if(tab[i][j]=='O') pointO+=3;
  55.                     if(tab[i][j]=='M') pointM+=3;
  56.                     break;
  57.                 }
  58.                 else break; //dans TOUS les cas, il y aura un break qui permettre de sortir du while(1)
  59.             } //fin de la boucle infinie while(1). Maintenant, on doit tester les différentes formes spéciales possibles selon les cas précédents
  60.            
  61.             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
  62.                 if ((tab[i][j]==tab[i][j+1] && tab[i][j]==tab[i][j+2]) || (tab[i][j]==tab[i][j-1] && tab[i][j]==tab[i][j-2]) || (tab[i][j]==tab[i][j+1] && tab[i][j]==tab[i][j-1]) || (tab[i+1][j]==tab[i+1][j+1] && tab[i+1][j]==tab[i+1][j+2]) || (tab[i+1][j]==tab[i+1][j-1] && tab[i+1][j]==tab[i+1][j-2]) || (tab[i+1][j]==tab[i+1][j+1] && tab[i+1][j]==tab[i+1][j-1]) || (tab[i+2][j]==tab[i+2][j+1] && tab[i+2][j]==tab[i+2][j+2]) || (tab[i+2][j]==tab[i+2][j-1] && tab[i+2][j]==tab[i+2][j-2]) || (tab[i+2][j]==tab[i+2][j+1] && tab[i+2][j]==tab[i+2][j-1]) || (tab[i+3][j]==tab[i+3][j+1] && tab[i+3][j]==tab[i+3][j+2]) || (tab[i+3][j]==tab[i+3][j-1] && tab[i+3][j]==tab[i+3][j-2]) || (tab[i+3][j]==tab[i+3][j+1] && tab[i+3][j]==tab[i+3][j-1])){
  63.                     if(tab[i][j]=='S') pointS+=6;
  64.                     if(tab[i][j]=='F') pointF+=6;
  65.                     if(tab[i][j]=='P') pointP+=6;
  66.                     if(tab[i][j]=='O') pointO+=6;
  67.                     if(tab[i][j]=='M') pointM+=6;
  68.                 }
  69.             }
  70.             if (cas==3){            //pour le cas où il y a 3 lettres identiques horizontales
  71.                 if ((tab[i][j]==tab[i][j+1] && tab[i][j]==tab[i][j+2]) || (tab[i][j]==tab[i][j-1] && tab[i][j]==tab[i][j-2]) || (tab[i][j]==tab[i][j+1] && tab[i][j]==tab[i][j-1]) || (tab[i+1][j]==tab[i+1][j+1] && tab[i+1][j]==tab[i+1][j+2]) || (tab[i+1][j]==tab[i+1][j-1] && tab[i+1][j]==tab[i+1][j-2]) || (tab[i+1][j]==tab[i+1][j+1] && tab[i+1][j]==tab[i+1][j-1]) || (tab[i+2][j]==tab[i+2][j+1] && tab[i+2][j]==tab[i+2][j+2]) || (tab[i+2][j]==tab[i+2][j-1] && tab[i+2][j]==tab[i+2][j-2]) || (tab[i+2][j]==tab[i+2][j+1] && tab[i+2][j]==tab[i+2][j-1])){
  72.                     if(tab[i][j]=='S') pointS+=9;
  73.                     if(tab[i][j]=='F') pointF+=9;
  74.                     if(tab[i][j]=='P') pointP+=9;
  75.                     if(tab[i][j]=='O') pointO+=9;
  76.                     if(tab[i][j]=='M') pointM+=9;
  77.                 }
  78.             }
  79.             if (cas==6){            //on test ici les formes possibles pour le cas où on a 4 lettres identiques en colonne
  80.                 if ((tab[i][j]==tab[i+1][j] && tab[i][j]==tab[i+2][j]) || (tab[i][j]==tab[i-1][j] && tab[i][j]==tab[i-2][j]) || (tab[i][j]==tab[i+1][j] && tab[i][j]==tab[i-1][j]) || (tab[i][j+1]==tab[i+1][j+1] && tab[i][j+1]==tab[i+2][j+2]) || (tab[i][j+1]==tab[i-1][j+1] && tab[i][j+1]==tab[i-2][j+1]) || (tab[i][j+1]==tab[i+1][j+1] && tab[i][j+1]==tab[i-1][j+1]) || (tab[i][j+2]==tab[i+1][j+2] && tab[i][j+2]==tab[i+2][j+2]) || (tab[i][j+2]==tab[i-1][j+2] && tab[i][j+2]==tab[i-2][j+2]) || (tab[i][j+2]==tab[i+1][j+2] && tab[i][j+2]==tab[i-1][j+2]) || (tab[i][j+3]==tab[i+1][j+3] && tab[i][j+3]==tab[i+2][j+3]) || (tab[i][j+3]==tab[i-1][j+3] && tab[i][j+3]==tab[i-2][j+3]) || (tab[i][j+3]==tab[i+1][j+3] && tab[i][j+3]==tab[i-1][j+3])){
  81.                     if(tab[i][j]=='S') pointS+=6;
  82.                     if(tab[i][j]=='F') pointF+=6;
  83.                     if(tab[i][j]=='P') pointP+=6;
  84.                     if(tab[i][j]=='O') pointO+=6;
  85.                     if(tab[i][j]=='M') pointM+=6;
  86.                 }
  87.             }
  88.             if (cas==5){            //on test ici les formes possibles pour le cas où on a 3 lettres identiques verticalement
  89.                 if ((tab[i][j]==tab[i+1][j] && tab[i][j]==tab[i+2][j]) || (tab[i][j]==tab[i-1][j] && tab[i][j]==tab[i-2][j]) || (tab[i][j]==tab[i+1][j] && tab[i][j]==tab[i-1][j]) || (tab[i][j+1]==tab[i+1][j+1] && tab[i][j+1]==tab[i+2][j+2]) || (tab[i][j+1]==tab[i-1][j+1] && tab[i][j+1]==tab[i-2][j+1]) || (tab[i][j+1]==tab[i+1][j+1] && tab[i][j+1]==tab[i-1][j+1]) || (tab[i][j+2]==tab[i+1][j+2] && tab[i][j+2]==tab[i+2][j+2]) || (tab[i][j+2]==tab[i-1][j+2] && tab[i][j+2]==tab[i-2][j+2]) || (tab[i][j+2]==tab[i+1][j+2] && tab[i][j+2]==tab[i-1][j+2])){
  90.                     if(tab[i][j]=='S') pointS+=9;
  91.                     if(tab[i][j]=='F') pointF+=9;
  92.                     if(tab[i][j]=='P') pointP+=9;
  93.                     if(tab[i][j]=='O') pointO+=9;
  94.                     if(tab[i][j]=='M') pointM+=9;
  95.                 }
  96.             }
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement