1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
   |  
/* Verifie la diagonale partant de la droite */
int VerifDiagoDroite(int x,int y,char joueur, char tab[nb_ligne][nb_colonne]){
 int cpt=1;
 char stop='F';
 int win=1;
	while(win<4 && x+cpt<8 && y+cpt<7 && stop=='F'){
		if(tab[y+cpt][x+cpt]==joueur){
		cpt++;
		win++;
		printf("win droite1= %d",win); //retirer
		}
		else stop='V';
	}
 cpt=1;
 stop='F';
 while(win<4 && x-cpt>0 && y-cpt>0 && stop=='F'){
	if(tab[y-cpt][x-cpt]==joueur){  //y+cpt et pas -
	cpt++;
	win++;
	printf("win droite2 = %d",win); //retirer
	}
	else stop='V';
	}
 return win;
}
 
/* Verifie la diagonale partant de la gauche */
int VerifDiagoGauche(int x,int y,char joueur, char tab[nb_ligne][nb_colonne]){
 int cpt=1;
 char stop='F';
 int win=1;
 while(win<4 && x-cpt>0 && y+cpt<7 && stop=='F'){
	if(tab[y+cpt][x-cpt]==joueur){
	cpt++;
	win++;
	printf("win gauche1= %d",win); //retirer
	}
	else stop='V';
 }
 cpt=1;
 stop='F';
 while(win<4 && x+cpt<8 && y-cpt>0 && stop=='F'){
	if(tab[y-cpt][x+cpt]==joueur){
	cpt++;
	win++;
	printf("win gauche2= %d",win); //retirer
	}
	else stop='V';
 }
 return win;
}
 
/* Verifie les axes des diagonales */
int VerifDiago(int x,int y,char joueur, char tab[nb_ligne][nb_colonne]){
char victory='F';
int win;
win=VerifDiagoDroite(x,y,joueur,tab);
	if(win<=4)win=VerifDiagoGauche(x,y,joueur,tab);
 
	if (win>=4) victory='V';
return victory;
}
 
/* execute toute les sous-programme de verification du gagnant */
int VerifGagner(int x,int y,char joueur, char tab[nb_ligne][nb_colonne]){
  printf("Joueur %c tabpost %c x: %d y: %d\n",joueur,tab[x][y],x,y);
 char winner;//='F';
 winner=VerifVerticale(x, y,joueur,tab);
 printf("winner vaut == %c",winner);
	if(winner=='F') winner=VerifHoriz(x,y,joueur,tab);
	printf("\n%c\n",winner);
 
	if(winner=='F') winner=VerifDiago(x,y,joueur,tab);
	printf("\n%c\n",winner);
return winner;
} | 
Partager