diff --git a/src/deplacement.c b/src/deplacement.c index aaf4e632f975d07e30e4ccf56c54b97f82bcc398..cb02450b414370b798266e6ba77e0a401e709245 100644 --- a/src/deplacement.c +++ b/src/deplacement.c @@ -59,16 +59,16 @@ void case_destination(pile **tableau,int N,int i_src,int j_src, int *i_dest,int valide=roi(i_src,j_src,*i_dest,*j_dest); break; case 'D' : - valide=dames(i_src,j_src,*i_dest,*j_dest); + valide=dames(tableau,i_src,j_src,*i_dest,*j_dest); break; case 'T' : - valide=tours(i_src,j_src,*i_dest,*j_dest); + valide=tours(tableau,i_src,j_src,*i_dest,*j_dest); break; case 'F' : - valide=fous(i_src,j_src,*i_dest,*j_dest); + valide=fous(tableau,i_src,j_src,*i_dest,*j_dest); break; case 'C' : - valide=cavaliers(i_src,j_src,*i_dest,*j_dest); + valide=cavaliers(tableau,i_src,j_src,*i_dest,*j_dest); break; default : valide=0; @@ -101,17 +101,22 @@ int pions(pile **tableau,int i_src,int j_src,int i_dest,int j_dest,int tour) } if (nb_de_pion(tableau[i_dest][j_dest],"BN"[tour%2+1])==0 && i_dest==i_src+k && j_dest==j_src){ return 1; - } else if (i_dest==i_src+k && (j_dest==j_src+1 && j_dest==j_src-1)){ + } else if (i_dest==i_src+k && (j_dest==j_src+1 || j_dest==j_src-1)){ return 1; } return 0; } -int dames(int i_src,int j_src,int i_dest,int j_dest) +int dames(pile ** tableau,int i_src,int j_src,int i_dest,int j_dest) { - if ((j_dest==j_src && i_dest!=i_src) || (i_dest==i_src && j_dest!=j_src) || (abs(i_dest-i_src)==abs(j_dest-j_src) && i_dest!=i_src)){ - return 1; + if ((j_dest==j_src && i_dest!=i_src) || (i_dest==i_src && j_dest!=j_src)){ + return tours(tableau,i_src,j_src,i_dest,j_dest); + } + + if (abs(i_dest-i_src)==abs(j_dest-j_src) && i_dest!=i_src){ + return fous(tableau,i_src,j_src,i_dest,j_dest); } + return 0; } @@ -125,23 +130,81 @@ int roi(int i_src,int j_src,int i_dest,int j_dest) return 1; return 0; } -int tours(int i_src,int j_src,int i_dest,int j_dest) +int tours(pile **tableau,int i_src,int j_src,int i_dest,int j_dest) { - if ((i_dest == i_src && j_dest!=j_src) || (j_dest ==j_src && i_dest!=i_src)){ + int k; + if (j_dest==j_src && i_dest!=i_src){ + for (k=1;k<abs(i_dest-i_src);k++){ + if (i_dest>i_src){ + if (longueur_pile(tableau[i_src+k][j_src])!=0){ + return 0; + break; + } + } else { + if (longueur_pile(tableau[i_src-k][j_src])!=0){ + return 0; + break; + } + } + } + return 1; + } + if (i_dest==i_src && j_dest!=j_src){ + for (k=1;k<abs(j_dest-j_src);k++){ + if (j_dest>j_src){ + if (longueur_pile(tableau[i_src][j_src+k])!=0){ + return 0; + break; + } + } else { + if (longueur_pile(tableau[i_src][j_src-k])!=0){ + return 0; + break; + } + } + } return 1; } return 0; } -int fous(int i_src,int j_src,int i_dest, int j_dest) +int fous(pile** tableau,int i_src,int j_src,int i_dest, int j_dest) { - if (abs(j_dest-j_src)==abs(i_dest-i_src) && i_dest!=i_src){ + int k; + if (abs(i_dest-i_src)==abs(j_dest-j_src) && i_dest!=i_src){ + for (k=1;k<abs(i_dest-i_src);k++){ + if (j_dest>j_src){ + if (i_dest>i_src){ + if (longueur_pile(tableau[i_src+k][j_src+k])!=0){ + return 0; + break; + } + } else { + if (longueur_pile(tableau[i_src-k][j_src+k])!=0){ + return 0; + break; + } + } + } else { + if (i_dest>i_src){ + if (longueur_pile(tableau[i_src+k][j_src-k])!=0){ + return 0; + break; + } + } else { + if (longueur_pile(tableau[i_src-k][j_src-k])!=0){ + return 0; + break; + } + } + } + } return 1; } return 0; } -int cavaliers(int i_src,int j_src,int i_dest,int j_dest) +int cavaliers(pile **tableau,int i_src,int j_src,int i_dest,int j_dest) { if (i_dest==i_src+2 || i_dest==i_src-2){ if (j_dest==j_src+1 || j_dest==j_src-1){ diff --git a/src/deplacement.h b/src/deplacement.h index d162db63be38f2a6c810a26f879f627fbd406f74..953bf50e45fc28f3ab142a9b2e0ea608c7ee7f82 100644 --- a/src/deplacement.h +++ b/src/deplacement.h @@ -44,28 +44,28 @@ int roi(int i_src,int j_src,int i_dest,int j_dest); * @assign * @ensure : verifie que le déplacement est valide pour une dame */ -int dames(int i_src,int j_src,int i_dest,int j_dest); +int dames(pile **tableau,int i_src,int j_src,int i_dest,int j_dest); /* * @require * @assign * @ensure : verifie que le déplacement est valide pour une tour */ -int tours(int i_src,int j_src,int i_dest,int j_dest); +int tours(pile **tableau,int i_src,int j_src,int i_dest,int j_dest); /* * @require * @assign * @ensure : verifie que le déplacement est valide pour un fou */ -int fous(int i_src,int j_src,int i_dest,int j_dest); +int fous(pile **tableau,int i_src,int j_src,int i_dest,int j_dest); /* * @require * @assign * @ensure : verifie que le déplacement est valide pour un cavalier */ -int cavaliers(int i_src,int j_src,int i_dest,int j_dest); +int cavaliers(pile ** tableau,int i_src,int j_src,int i_dest,int j_dest); /* * @require * @assign diff --git a/stackchess b/stackchess index f9fdf53180ba9dec72463d0f5e66f3cd0f3ab6fc..d5d40f291292aa9666dbdd2d91ea6ff9493a81c1 100755 Binary files a/stackchess and b/stackchess differ