چرا این جوری شده؟!
کد:برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید
چرا این جوری شده؟!
کد:برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید
این الان ستونی جا به جا میکنه؟؟؟
این کد رو خودت دادی بهم اجراش کن
متوجه میشی که سطری جا به جا میکنه
من میخوام همین ستونی جابه جا بشه
یعنی تو هر ستون یه وزیر که همدیگر رو گارد نکنه...
کد:برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید
خب نهایتا جای I, j عوض می شه تو آرایه
چه لزومی داره این کار رو بکنید؟
استاد خواسته بود
ممنونم
درستش کردم
in proje 8 vazer baray fatemeh and farshid
//gives a start home adress & cheks if 8 vazir could be placed by that start home.
#include<iostream.h>
#include<conio.h>
void place(int,int,int [][8],int [][8]);
void print(int,int,int [][8],int [][8]);
int main( )
{
clrscr( );
int const k=8;
int p[k][k];
int placed[k][k];
int a,b;
for(a=1;a<=8;a++)
{for(b=1;b<=8;b++)
{p[a][b]=1;
placed[a][b]=0;
}
}
for(a=1;a<=8;a++)
{ for(b=1;b<=8;b++)
{
place(a,b,p,placed);
print(a,b,p,placed);
}
}
getch( );
return(0);
}
void place(int i,int j,int p[][8],int placed[][8])
{
placed[i][j]=1;
int a,b,k;
for(k=1;k<=8;k++)
{ p[i][k]=0;
p[k][j]=0;
if(k+i<=8 && k+j<=8) {p[k+i][k+j]=0;}
if(k+i<=8 && j-k>=1) {p[k+i][j-k]=0;}
if(i-k>=1 && k+j<=8) {p[i-k][k+j]=0;}
if(i-k>=1 && j-k>=1) {p[i-k][j-k]=0;}
}
for(a=1;a<=8;a++)
{ for(b=1;b<=8;b++)
{ if(p[a][b]==1) place(a,b,p,placed);
}
}
}
void print(int i,int j,int p[][8],int placed[][8])
{
int a,b;
int c=0;
for(a=1;a<=8;a++)
{for(b=1;b<=8;b++)
{if(placed[a][b]==0) cout<<"_";
if(placed[a][b]==1)
{ c++; cout<<"v";
}
}cout<<"\n";
}
if(c!=8)cout<<"could not place all 8 vazir"
<<"for the start home("<<i<<","<<j
<<")!press any key to continue:\n\n\n";
if(c==8)
{cout<<"****all 8 vazir placed with starthome("<<i<<","
<<j<<")!****\n\n\n";
}
for(a=1;a<=8;a++)
{ for(b=1;b<=8;b++)
{ p[a][b]=1;
placed[a][b]=0;
}
}
getch( );
}
age on moshkel dareh pas az in poroje estefadeh koned
#include <iostream.h>
#include <conio.h>
#include <_defs.h>
int board[8][8]={0};
int value[8][8]={
{2,3,4,4,4,4,3,2},
{3,4,6,6,6,6,4,3},
{4,6,8,8,8,8,6,4},
{4,6,8,8,8,8,6,4},
{4,6,8,8,8,8,6,4},
{4,6,8,8,8,8,6,4},
{3,4,6,6,6,6,4,3},
{2,3,4,4,4,4,3,2}};
int row[8]= {-2,-2,-1,1,2,2,1,-1};
int col[]={-1 , 1 , 2 , 2 , 1 , -1 , -2 , -2 };
int satr,soton,count=0,min=8;
//************************************************** ***
void getfirstvalue();
void print();
void changevalue();
int move();
//************************************************** ***
int main()
{
getfirstvalue();
++count;
print();
while(move())
{
getch();
++count;
print();
}
getch();
return 0;
}
//************************************************** ***
void getfirstvalue()
{
cout<<"enter the satr and soton for start :\n";
do{
cout<<"enter satr : ";
cin>>satr;
}while(satr > 8 || satr < 1);
do{
cout<<"enter soton : ";
cin>>soton;
}while(soton > 8 || soton < 1);
board[(satr-1)][(soton-1)]=1;
value[satr-1][soton-1]=0;
changevalue();
}
//************************************************** ***
void print()
{
int i,j;
cout<<"satr : "<<satr<<"\t\tsoton"<<soton<<"\n";
for(i=0;i<8;i++){
for(j=0;j<8;j++){
cout<<" "<<board[i][j]<<" ";
}
cout<<"\n";
}
cout<<"-------------------------------------------------\n";
for(i=0;i<8;i++){
for(j=0;j<8;j++)
cout<<" "<<value[i][j]<<" ";
cout<<"\n";
}
}
//************************************************** ***
void changevalue()
{
int number,x[8],y[8];
for(number = 0; number < 8 ; number++){
x[number] = satr + row[number];
y[number] = soton + col[number];
if(x[number] > 0 && x[number] <= 8 && y[number] > 0 &&
y[number] <= 8 && board[(x[number]-1)][(y[number]-1)] != 1 )
value[x[number]-1][y[number]-1]--;
}
}
//************************************************** ***
int move()
{
int i,x[8],y[8],z,t;
min=8;
for(i=0;i<8;i++){
if(row[i]<-2)
row[i]+=1;
x[i]=satr+row[i];
y[i]=soton+col[i];
if( x[i] > 0 && x[i] <= 8 && y[i] > 0 && y[i] <= 8 &&
board[x[i]-1][y[i]-1] != 1)
if(value[x[i]-1][y[i]-1] <=min){
min=value[x[i]-1][y[i]-1];
z=x[i],t=y[i];
}
}
if(min > 7 || min < -1)
return 0;
if(z > 8 || z <= 0 || t > 8 || t <= 0 || board[z-1][t-1])
return 0;
satr=z;
soton=t;
board[z-1][t-1]=1;
value[z-1][t-1]=0;
changevalue();
return 1;
}
سلام
من تابع اون رو توی c# نوشتم
ب
کد:برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید
کدوم یکی ابتدایی تره و میشه به Nوزیر تبدیلش کرد
هم اکنون 1 کاربر در حال مشاهده این تاپیک میباشد. (0 کاربر عضو شده و 1 مهمان)