ورود

View Full Version : برنامه پیمایش صفحه شطرنج با مهره اسب



maldini_milan
دوشنبه 21 خرداد 1386, 02:12 صبح
هر کی داره این برنامه را واسم میل کنه mani_a_f@yahoo.com

emad_67
دوشنبه 21 خرداد 1386, 08:54 صبح
یه جست و جو کنی پیدا میکنی
این یه نمونش
http://www.barnamenevis.org/forum/showthread.php?t=70044&highlight=%CD%D1%98%CA+%C7%D3%C8

maldini_milan
دوشنبه 21 خرداد 1386, 11:33 صبح
ina nemikham mikham safhe shartranja peymayesh kone bedone vorod be khane tekrari:عصبانی++:

emad_67
دوشنبه 21 خرداد 1386, 11:59 صبح
یعنی بر نامه صفحه شطرنج رو هم نشون بده

mojtaba_cpp
دوشنبه 21 خرداد 1386, 12:08 عصر
چه عجب ! تو خود تاپیک که نظری ندادید ...
میلان جان اون کد که گذاشتم هم همین کار رو می کنه یعنی وارد خونه تکراری نمی شه . ولی این اولین روشی بود که به ذهنم رسید . برو بخون اگه جاییش رو متوجه نشدی که مطمینم جایی هست ! توضیح بدم .
از بقیه هم می خوام که یه نظری چیزی بدن روشم درسته یا خیلی پیچوندمش ...

maldini_milan
دوشنبه 21 خرداد 1386, 15:29 عصر
اره فکر کنم صفحه شطرنج می خواد

mahan66
سه شنبه 22 خرداد 1386, 11:03 صبح
سلام . این اولین برنامه ای بود که با C++ نوشتم ! امیدوارم خوشتون بیاد . در ضمن اگه با TC یا BC برنامه رو اجرا می کنین باید از قسمت File/Change Dir فولدر BIN رو به BGI تغییر نام بدین ..


#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
int board[8][8]={0};
int movex[8]={2,1,-1,-2,-2,-1,1,2};
int movey[8]={-1,-2,-2,-1,1,2,2,1};
//-------- make the first Demo -----------------------------------\\
void Demo(){
int gm=DETECT,gd;
initgraph(&gm,&gd,"");
int a=0,b=0,c=0,d=200;
char ch;
setbkcolor(BLUE);
printf("\n\n\n\n\n\n\n Hi .... press Enter to begin this program... ");
do{
ch=getch();
}while(ch!=13);
while(b<150){
setbkcolor(BLUE);
setcolor(13);
settextstyle(0,0,2);
delay(70);
cleardevice();
moveto(a,b);
outtext("A work by :");
b+=10;
a+=10;
}
while(c<300){
setcolor(10);
delay(100);
cleardevice();
moveto(a,b);
outtext("A work by :");
moveto(c,d);
outtext("Mahmood Karimian");
c+=10;
}
setrgbpalette(0,255,255,0);
rectangle(0,410,650,430);
for(int i=0;i<650;i++){
delay(10);
setfillstyle(1,RED);
bar(0,411,i,429);
outtextxy(250,438,"Loading...");
}
}
//-------end of Demo ---------------------------------------------
//----Draw a chessboard---------------------------------------------
void chessboard(){
int gm=DETECT,gd;
initgraph(&gm,&gd,"");
int i,j,a=110,b=50,c=160,d=100,f=15;
for(i=0;i<8;i++){
for(j=0;j<8;j++){
setfillstyle(1,f);
bar3d(a,b,c,d,5,1);
if(f==15) f=0;
else if(f==0) f=15;
a+=50; c+=50;
}
if(f==15) f=0;
else if(f==0) f=15;
a=110; c=160;
b+=50; d+=50;
}
} //end of chessboard-------------------------------------------------
//---make a sound for end---------------------------------------------
void sound(){
int i,j,k,a,b,c;
for(j=0;j<5;j++){
sound(300);
delay(600);
nosound();
delay(400);
sound(600);
delay(50);
for(k=0;k<2;k++){
sound(300);
delay(80);
nosound();
delay(50);
nosound();
sound(300);
delay(100);
nosound();
}
for(i=0;i<3;i++){
sound(400);
delay(50);
nosound();
delay(50);
sound(200);
delay(30);
nosound();
delay(20);
}
}
}
//--- end of sound() -----------------------------------------------
//---get the acsesilibity of each block-------------------------------
int acsess(int m,int n){
int pic[8][8];
int i,s,l,k,a,b;
for(l=1;l<=8;l++){
for(k=1;k<=8;k++){
a=l; b=k; s=0;
for(i=0;i<8;i++){
l+=movex[i];
k+=movey[i];
if(l<=8 && l>=1 && k<=8 && k>=1 && board[l-1][k-1]==0)
s++;
l=a;
k=b;
}
pic[l-1][k-1]=s;
}
}
return (pic[m-1][n-1]);
}//end of acsess() -------------------------------------------------------
//-----give best move-----------------------------------------------------
int move(int x,int y){
int i,a=x,b=y,min=9,m,p;
for(i=0;i<8;i++){
x+=movex[i];
y+=movey[i];
if(x<=8 && x>=1 && y<=8 && y>=1 && board[x-1][y-1]==0){
m=acsess(x,y);
if(m<=min){
min=m;
p=i;
}
}
x=a;
y=b;
}
return (p);
} //end of move()-------------------------------------------------------
//---this is the main()--------------------------------------------------
void main(){
clrscr();
Demo();
clrscr();
int x,y,a,b,p,q;
int i,j=1,k=1,m,color=1;
int listx[64],listy[64];
char msg[80];
do{
printf("\n\n\n please Enter first postion (x y) : ");
scanf("%d %d" ,&x,&y);
if(x>8 || x<1 || y>8 || y<1)
printf(" \nx and y are between 1 and 8...retry! \n");
} while(x>8 || x<1 || y>8 || y<1);
clrscr();
chessboard(); //-- draw the chess board --\\
listx[0]=x;
listy[0]=y;
board[x-1][y-1]=1;
a=135+((y-1)*50);
b=75+((x-1)*50);
setcolor(RED);
outtextxy(a,b,"1");
//********* first of while *********
while(!kbhit() && k<=63){
delay(1000);
i=move(x,y); //-- get the best move --\\
p=movex[i];
q=movey[i];
listx[j]=x+p;
listy[j]=y+q;
j++; m=j;
a+=(q*50);
b+=(p*50);
printf("\a");
sprintf(msg,"%d",j);
outtextxy(a,b,msg);
board[x+p-1][y+q-1]=1;
x+=p;
y+=q;
k++;
}
// ********* end of while **********
getch();
cleardevice();
//----------------------------------
while(!kbhit()){
settextstyle(0,0,2);
delay(500);
setcolor(color);
outtextxy(60,100,"Press any key to see the Actions");
delay(500);
color++;
cleardevice();
}
//-----------------------------------
//-- print the list of actions to current action --
for(j=0;j<m;j++)
printf("%2d _ (%d,%d)\t",j+1,listx[j],listy[j]);
sound(); //-- make the end sound --\\
getch();
getch();
}
//end of main()----------------------------------------------------------

maldini_milan
سه شنبه 22 خرداد 1386, 14:36 عصر
aghaaa mer30 daste jofteton dard nakone

delangiz
چهارشنبه 12 دی 1386, 15:22 عصر
salam to ro khoda yeki ham bazi shatranjo to delfi begeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee