sia0368
02-03-2009, 16:23
با سلام من این برنامه رو تو اینترنت گیر اوردم ولی بعضی از قسمتهاش رو نفهمیدم اگه میشه یه نفر قسمتهای رنگی رو برام توضیح بده ممنون
#include <stdio.h>
#include <conio.h>
int temp[9][3];
int vazirha[100][9];
int vazir_num;
int check(int satr,int sotoon, int tmp_num);
int main()
{
int satr,sotoona,sotoonb,sotoonc,sotoond,sotoone,sotoo nf,sotoong,sotoonh,s,shomare_sotoon=1;
int chap=0;
clrscr();
for(sotoona=1;sotoona<=8;sotoona++){
satr=1;
//if(!check(satr,sotoona,satr-1))
//continue;
//else{
temp[satr][1]=satr;
temp[satr][2]=sotoona;
//}
for(sotoonb=1;sotoonb<=8;sotoonb++){
satr=2;
if(!check(satr,sotoonb,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoonb;
}
for(sotoonc=1;sotoonc<=8;sotoonc++){
satr=3;
if(!check(satr,sotoonc,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoonc;
}
for(sotoond=1;sotoond<=8;sotoond++){
satr=4;
if(!check(satr,sotoond,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoond;
}
for(sotoone=1;sotoone<=8;sotoone++){
satr=5;
if(!check(satr,sotoone,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoone;
}
for(sotoonf=1;sotoonf<=8;sotoonf++){
satr=6;
if(!check(satr,sotoonf,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoonf;
}
for(sotoong=1;sotoong<=8;sotoong++){
satr=7;
if(!check(satr,sotoong,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoong;
}
for(sotoonh=1;sotoonh<=8;sotoonh++){
satr=8;
if(!check(satr,sotoonh,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoonh;
clrscr();
printf("tabrik\n shoma be javab residid \n\n");
//sotoona=sotoonb=sotoonc=sotoond=sotoone=sotoonf=so toong=sotoonh=20;
printf("vazirha = ");
for (s=1;s<=8;s++){
vazirha[vazir_num][s]=temp[s][2] ;
}
vazir_num++;
printf ("%i",vazir_num);
if(vazir_num>100){
sotoona=sotoonb=sotoonc=sotoond=sotoone=20;
sotoonf=sotoong=sotoonh=20;
}//end if
}
}///// for sotoon-h
}///// for sotoon-g
}///// for sotoon-f
}///// for sotoon-e
}///// for sotoon-d
}///// for sotoon-c
}///// for sotoon-b
}///// for sotoona
getch();
printf ("\n\n entehaye batname\n");
for(chap=0;chap<vazir_num;chap++){
if (chap<10)
printf("0=");
else
printf ("%i=",chap);
for(shomare_sotoon=1;shomare_sotoon<=8;shomare_sotoon++)
printf ("%i",vazirha[chap][shomare_sotoon]);
printf ("\n");
}
getch();
return 0;
}
//$$$$$$$$$$ Check kardane barkhordha $$$$$$$$$;
int check(int satr,int sotoon, int tmp_num){
int sa,so,i,j,k=1; // motaghayerhaye komaki baraye satr va sotoone vazirhaye ghabli
for (i=1;i<=tmp_num;i++){
sa=temp[i][1]; // satre vazire i'om
so=temp[i][2]; // sotoone vazire i'om
/*
satr va sotoone vazire jari nabayad ba hich yek az
vazirhaye sabet shodeye ghabli barabar bashad
banabarin az amalgare 'or' estefade mikonim
chon hata yeki az in do barabar bashad vazirha barkhord peyda mikonand
*/
if ( satr==sa || sotoon==so)
return 0;
//------------------------------------------------
/*
baraye halate zarbedari
ebteda bazooye chap va payin ra barresi mikonim
*/
for(j=sa , k=so; j && k; j-- , k--)
if (satr==j && sotoon==k)
return 0;
// bazooye samte rast va bala
for(j=sa , k=so; j<=8 && k<=8; j++ , k++)
if (satr==j && sotoon==k)
return 0;
// bazooye rast va payin
for(j=sa , k=so; j && k<=8; j-- , k++)
if (satr==j && sotoon==k)
return 0;
// bazooye chap va bala
for(j=sa , k=so; j<=8 && k; j++ , k--)
if (satr==j && sotoon==k)
return 0;
}// payane for temp[i]
/*
dar soorati ke dar bala sharayet bargharar nashavad
va meghdar 0 bargardande nashavad yani vazire jari
ba hichyek az vazirhaye ghabli barkhord nadashte
va meghdar 1 bargardande mishavad
*/
return 1;
}
#include <stdio.h>
#include <conio.h>
int temp[9][3];
int vazirha[100][9];
int vazir_num;
int check(int satr,int sotoon, int tmp_num);
int main()
{
int satr,sotoona,sotoonb,sotoonc,sotoond,sotoone,sotoo nf,sotoong,sotoonh,s,shomare_sotoon=1;
int chap=0;
clrscr();
for(sotoona=1;sotoona<=8;sotoona++){
satr=1;
//if(!check(satr,sotoona,satr-1))
//continue;
//else{
temp[satr][1]=satr;
temp[satr][2]=sotoona;
//}
for(sotoonb=1;sotoonb<=8;sotoonb++){
satr=2;
if(!check(satr,sotoonb,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoonb;
}
for(sotoonc=1;sotoonc<=8;sotoonc++){
satr=3;
if(!check(satr,sotoonc,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoonc;
}
for(sotoond=1;sotoond<=8;sotoond++){
satr=4;
if(!check(satr,sotoond,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoond;
}
for(sotoone=1;sotoone<=8;sotoone++){
satr=5;
if(!check(satr,sotoone,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoone;
}
for(sotoonf=1;sotoonf<=8;sotoonf++){
satr=6;
if(!check(satr,sotoonf,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoonf;
}
for(sotoong=1;sotoong<=8;sotoong++){
satr=7;
if(!check(satr,sotoong,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoong;
}
for(sotoonh=1;sotoonh<=8;sotoonh++){
satr=8;
if(!check(satr,sotoonh,satr-1))
continue;
else{
temp[satr][1]=satr;
temp[satr][2]=sotoonh;
clrscr();
printf("tabrik\n shoma be javab residid \n\n");
//sotoona=sotoonb=sotoonc=sotoond=sotoone=sotoonf=so toong=sotoonh=20;
printf("vazirha = ");
for (s=1;s<=8;s++){
vazirha[vazir_num][s]=temp[s][2] ;
}
vazir_num++;
printf ("%i",vazir_num);
if(vazir_num>100){
sotoona=sotoonb=sotoonc=sotoond=sotoone=20;
sotoonf=sotoong=sotoonh=20;
}//end if
}
}///// for sotoon-h
}///// for sotoon-g
}///// for sotoon-f
}///// for sotoon-e
}///// for sotoon-d
}///// for sotoon-c
}///// for sotoon-b
}///// for sotoona
getch();
printf ("\n\n entehaye batname\n");
for(chap=0;chap<vazir_num;chap++){
if (chap<10)
printf("0=");
else
printf ("%i=",chap);
for(shomare_sotoon=1;shomare_sotoon<=8;shomare_sotoon++)
printf ("%i",vazirha[chap][shomare_sotoon]);
printf ("\n");
}
getch();
return 0;
}
//$$$$$$$$$$ Check kardane barkhordha $$$$$$$$$;
int check(int satr,int sotoon, int tmp_num){
int sa,so,i,j,k=1; // motaghayerhaye komaki baraye satr va sotoone vazirhaye ghabli
for (i=1;i<=tmp_num;i++){
sa=temp[i][1]; // satre vazire i'om
so=temp[i][2]; // sotoone vazire i'om
/*
satr va sotoone vazire jari nabayad ba hich yek az
vazirhaye sabet shodeye ghabli barabar bashad
banabarin az amalgare 'or' estefade mikonim
chon hata yeki az in do barabar bashad vazirha barkhord peyda mikonand
*/
if ( satr==sa || sotoon==so)
return 0;
//------------------------------------------------
/*
baraye halate zarbedari
ebteda bazooye chap va payin ra barresi mikonim
*/
for(j=sa , k=so; j && k; j-- , k--)
if (satr==j && sotoon==k)
return 0;
// bazooye samte rast va bala
for(j=sa , k=so; j<=8 && k<=8; j++ , k++)
if (satr==j && sotoon==k)
return 0;
// bazooye rast va payin
for(j=sa , k=so; j && k<=8; j-- , k++)
if (satr==j && sotoon==k)
return 0;
// bazooye chap va bala
for(j=sa , k=so; j<=8 && k; j++ , k--)
if (satr==j && sotoon==k)
return 0;
}// payane for temp[i]
/*
dar soorati ke dar bala sharayet bargharar nashavad
va meghdar 0 bargardande nashavad yani vazire jari
ba hichyek az vazirhaye ghabli barkhord nadashte
va meghdar 1 bargardande mishavad
*/
return 1;
}