حرکت کنه بدونه اینکه وارد خونه تکراری بشه و در نهایت باید وارد تمامیه خونه هم بشه
من برنامشو نوشتم ولی قسمت پیدا کردن خونه ها رو از سورسی که توی سایت پیدا کردم نوشتم(به زبان CPP)
نمیخام سورس بزارید فقط درباره الگوریتمش حرف بزنید چون میخام برنامه کاملا ساخت خودم باشه، اینجوری احساسه بهتری دارم
کد:
# include <conio.h>
#include <dos.h>
#include <iostream.h>
#include <stdlib.h> //rand needed
#include <time.h> //srand parameter
#include<iomanip.h> //setw needed
int counter=1;
int scr[8][8];
/////////////////// my name ////////////////////
void hosein(int pos)
{
textcolor(4);
textbackground(9);
textbackground(6);
window(3,pos,3,pos+8),clrscr();
window(4,pos+4,5,pos+4),clrscr();
window(6,pos,6,pos+8),clrscr();
window(8,pos+4,8,pos+8),clrscr();
window(8,pos+4,10,pos+4),clrscr();
window(10,pos+4,10,pos+8),clrscr();
window(9,pos+8,9,pos+8),clrscr();
window(12,pos+4,14,pos+4),clrscr();
window(12,pos+4,12,pos+6),clrscr();
window(12,pos+6,14,pos+6),clrscr();
window(14,pos+6,14,pos+8),clrscr();
window(12,pos+8,14,pos+8),clrscr();
window(16,pos+4,18,pos+4),clrscr();
window(16,pos+4,16,pos+8),clrscr();
window(16,pos+6,18,pos+6),clrscr();
window(16,pos+8,18,pos+8),clrscr();
window(18,pos+4,18,pos+6),clrscr();
window(20,pos+4,20,pos+8),clrscr();
window(20,pos+2,20,pos+2),clrscr();
window(22,pos+4,22,pos+8),clrscr();
window(23,pos+5,24,pos+5),clrscr();
window(24,pos+5,24,pos+8),clrscr();
delay(3000);
for(int i=8;i<=79;i+=2)
{
if(i<=46)
window(3,8,3,i),textbackground(6),clrscr();
window(5,12,i-3,12),textbackground(4),clrscr();
delay(60);
}
int dly=100;
for(i=12;i<=80;i++)
{
if(i<=44)
window(40,12,40,i),textbackground(4),clrscr();
delay(dly);
if(i>46)
window(40-((i-5)-40),44,i-5,44),textbackground(4),clrscr();
}
window(40,13,40,43),textbackground(0),clrscr();
}
void mansouran(int x,int y)
{
textcolor(4);
textbackground(9);
textbackground(6);
int dly=400;
// m
delay(dly);
window(x-1,y,x+4,y),clrscr();
window(x,y,x,y+8),clrscr();
window(x+2,y,x+2,y+8),clrscr();
window(x+4,y,x+4,y+8),clrscr();
delay(dly);
// a
window(x+6,y+4,x+8,y+4),clrscr();
window(x+8,y+4,x+8,y+8),clrscr();
window(x+6,y+8,x+8,y+8),clrscr();
window(x+6,y+6,x+6,y+8),clrscr();
window(x+7,y+6,x+7,y+6),clrscr();
delay(dly);
// n
window(x+10,y+4,x+10,y+8),clrscr();
window(x+10,y+5,x+12,y+5),clrscr();
window(x+12,y+5,x+12,y+8),clrscr();
delay(dly);
// s
window(x+14,y+4,x+16,y+4),clrscr();
window(x+14,y+4,x+14,y+6),clrscr();
window(x+15,y+6,x+15,y+6),clrscr();
window(x+16,y+6,x+16,y+8),clrscr();
window(x+14,y+8,x+16,y+8),clrscr();
delay(dly);
// o
window(x+18,y+4,x+18,y+8),clrscr();
window(x+18,y+4,x+19,y+4),clrscr();
window(x+20,y+4,x+20,y+8),clrscr();
window(x+19,y+8,x+19,y+8),clrscr();
delay(dly);
// u
window(x+22,y+4,x+22,y+8),clrscr();
window(x+24,y+4,x+24,y+8),clrscr();
window(x+23,y+8,x+23,y+8),clrscr();
delay(dly);
// r
window(x+26,y+4,x+26,y+8),clrscr();
window(x+27,y+5,x+28,y+5),clrscr();
window(x+28,y+4,x+29,y+4),clrscr();
delay(dly);
// a
window(x+31,y+4,x+33,y+4),clrscr();
window(x+33,y+4,x+33,y+8),clrscr();
window(x+32,y+8,x+32,y+8),clrscr();
window(x+31,y+6,x+31,y+8),clrscr();
window(x+32,y+6,x+32,y+6),clrscr();
delay(dly);
// n
window(x+35,y+4,x+35,y+8),clrscr();
window(x+35,y+5,x+37,y+5),clrscr();
window(x+37,y+5,x+37,y+44),clrscr();
delay(dly);
}
void middle(dly)
{
for(int i=1;i<=10;i++)
{
window(4,13,76,43),textbackground(7),clrscr();
delay(40);
window(4,13,76,43),textbackground(0),clrscr();
delay(50);
}
for(i=36;i>=-36;i--)
{
if(i>=6)
{
window(12,i+7,12,43),textbackground(3),clrscr();
window(21,13,21,49-i),clrscr();
window(30,i+7,30,43),clrscr();
window(39,13,39,49-i),clrscr();
window(48,i+7,48,43),clrscr();
window(57,13,57,49-i),clrscr();
window(66,i+7,66,43),clrscr();
}
window(i+40,16,76,16),textbackground(3),clrscr();
window(4,20,40-i,20),clrscr();
window(i+40,24,76,24),clrscr();
window(4,28,40-i,28),clrscr();
window(i+40,32,76,32),clrscr();
window(4,36,40-i,36),clrscr();
window(i+40,40,76,40),clrscr();
delay(dly);
}
window(12,48,70,48),textbackground(0),clrscr();
textcolor(7),cprintf("Ready...Ready...Ready........Press Any Key To Start...");
getch();
}
void drawscreen()
{
textbackground(0);
clrscr();
hosein(2);
mansouran(40,2);
middle(100);
}
void fillcell(int col,int row)
{
++col,++row;
window(col*9-5,row*4+9,col*9+2,row*4+11),textbackground(2),clrscr();
gotoxy(4,2),cout<<counter;
counter++;
}
void asb()
{
}
//+++++++++++++++++++++++++++++++++ Source +++++++++
void RankIt(int c[][8]){
int rank;
for (int i=0;i<=7; i++) {
for(int j=0;j<=7; j++){
rank=0;
if ((i-2>=0) && (j-1>=0)) rank++;
if ((i-2>=0) && (j+1<=7)) rank++;
if ((i+2<=7) && (j-1>=0)) rank++;
if ((i+2<=7) && (j+1<=7)) rank++;
if ((j-2>=0) && (i+1<=7)) rank++;
if ((j-2>=0) && (i-1>=0)) rank++;
if ((j+2<=7) && (i-1>=0)) rank++;
if ((j+2<=7) && (i+1<=7)) rank++;
c[i][j]=rank;
}
}
}
void DecRank(int i,int j,int c[][8]){
if ((i-2>=0) && (j-1>=0)) if (c[i-2][j-1]>0) c[i-2][j-1]--;
if ((i-2>=0) && (j+1<=7)) if (c[i-2][j+1]>0) c[i-2][j+1]--;
if ((i+2<=7) && (j-1>=0)) if (c[i+2][j-1]>0) c[i+2][j-1]--;
if ((i+2<=7) && (j+1<=7)) if (c[i+2][j+1]>0) c[i+2][j+1]--;
if ((j-2>=0) && (i+1<=7)) if (c[i+1][j-2]>0) c[i+1][j-2]--;
if ((j-2>=0) && (i-1>=0)) if (c[i-1][j-2]>0) c[i-1][j-2]--;
if ((j+2<=7) && (i-1>=0)) if (c[i-1][j+2]>0) c[i-1][j+2]--;
if ((j+2<=7) && (i+1<=7)) if (c[i+1][j+2]>0) c[i+1][j+2]--;
}
int IsPossible(int i,int j,int counter,int c[][8]){
int isp=0;
if ((i-2>=0) && (j-1>=0)) if (c[i-2][j-1]>0) isp=1;
if ((i-2>=0) && (j+1<=7)) if (c[i-2][j+1]>0) isp=1;
if ((i+2<=7) && (j-1>=0)) if (c[i+2][j-1]>0) isp=1;
if ((i+2<=7) && (j+1<=7)) if (c[i+2][j+1]>0) isp=1;
if ((j-2>=0) && (i+1<=7)) if (c[i+1][j-2]>0) isp=1;
if ((j-2>=0) && (i-1>=0)) if (c[i-1][j-2]>0) isp=1;
if ((j+2<=7) && (i-1>=0)) if (c[i-1][j+2]>0) isp=1;
if ((j+2<=7) && (i+1<=7)) if (c[i+1][j+2]>0) isp=1;
if (counter>61) return 1;
return isp;
}
int IsFull(int c[][8]){
int i,j;
int isp=1;
for ( i=0;i<=7; i++) {
for( j=0;j<=7; j++){
if (c[i][j]>0) isp=0;
}
}
return isp;
}
int rnd(int min,int max){
int i=rand();
return ((i%(max-min+1))+min);
}
//++++++++++++++++++++++++++++++++++source up++++++++++++++
void main()
{
drawscreen();
// for(int i=1;i<=8;i++)
// for(int j;j<=8;i++)
// scr[i][j]=0;
asb();
// ****************************************8 Source Code *********88
getch();
srand(time(0));
Start:
int c[8][8];
int t[8][8]={0};
int im[63][2]={0};
int rs[8][2]={0};
int currenti=0;
int currentj=0;
int counter=1;
int i,j;
int tmin=0;
RankIt(c);
c[0][0]=0;
DecRank(0,0,c);
while (!(counter==63) ){
if (IsPossible(currenti,currentj,counter,c) ) {
t[currenti][currentj]=counter;
tmin=8;
for (j=0;j<8;j++) {
rs[j][0]=0;
rs[j][1]=0;
}
if ((currenti-2>=0) && (currentj-1>=0)) if (c[currenti-2][currentj-1]<tmin && c[currenti-2][currentj-1]>0) tmin=c[currenti-2][currentj-1];
if ((currenti-2>=0) && (currentj+1<=7)) if (c[currenti-2][currentj+1]<tmin && c[currenti-2][currentj+1]>0) tmin=c[currenti-2][currentj+1];
if ((currenti+2<=7) && (currentj-1>=0)) if (c[currenti+2][currentj-1]<tmin && c[currenti+2][currentj-1]>0) tmin=c[currenti+2][currentj-1];
if ((currenti+2<=7) && (currentj+1<=7)) if (c[currenti+2][currentj+1]<tmin && c[currenti+2][currentj+1]>0) tmin=c[currenti+2][currentj+1];
if ((currentj-2>=0) && (currenti+1<=7)) if (c[currenti+1][currentj-2]<tmin && c[currenti+1][currentj-2]>0) tmin=c[currenti+1][currentj-2];
if ((currentj-2>=0) && (currenti-1>=0)) if (c[currenti-1][currentj-2]<tmin && c[currenti-1][currentj-2]>0) tmin=c[currenti-1][currentj-2];
if ((currentj+2<=7) && (currenti-1>=0)) if (c[currenti-1][currentj+2]<tmin && c[currenti-1][currentj+2]>0) tmin=c[currenti-1][currentj+2];
if ((currentj+2<=7) && (currenti+1<=7)) if (c[currenti+1][currentj+2]<tmin && c[currenti+1][currentj+2]>0) tmin=c[currenti+1][currentj+2];
if ((currenti-2>=0) && (currentj-1>=0)) if (c[currenti-2][currentj-1]==tmin) {rs[0][0]=currenti-2;rs[0][1]=currentj-1;};
if ((currenti-2>=0) && (currentj+1<=7)) if (c[currenti-2][currentj+1]==tmin) {rs[1][0]=currenti-2;rs[1][1]=currentj+1;};
if ((currenti+2<=7) && (currentj-1>=0)) if (c[currenti+2][currentj-1]==tmin) {rs[2][0]=currenti+2;rs[2][1]=currentj-1;};
if ((currenti+2<=7) && (currentj+1<=7)) if (c[currenti+2][currentj+1]==tmin) {rs[3][0]=currenti+2;rs[3][1]=currentj+1;};
if ((currentj-2>=0) && (currenti+1<=7)) if (c[currenti+1][currentj-2]==tmin) {rs[4][0]=currenti+1;rs[4][1]=currentj-2;};
if ((currentj-2>=0) && (currenti-1>=0)) if (c[currenti-1][currentj-2]==tmin) {rs[5][0]=currenti-1;rs[5][1]=currentj-2;};
if ((currentj+2<=7) && (currenti-1>=0)) if (c[currenti-1][currentj+2]==tmin) {rs[6][0]=currenti-1;rs[6][1]=currentj+2;};
if ((currentj+2<=7) && (currenti+1<=7)) if (c[currenti+1][currentj+2]==tmin) {rs[7][0]=currenti+1;rs[7][1]=currentj+2;};
int test=1;
while (test) {
int h=0;
h=rnd(0,7);
if (rs[h][0]!=0 || rs[h][1]!=0){
currenti=rs[h][0];
currentj=rs[h][1];
test=0;
}
}
im[counter][0]=currenti;
im[counter][1]=currentj;
DecRank(currenti,currentj,c);
c[currenti][currentj]=0;
counter++;
}
if ((!IsPossible(currenti,currentj,counter,c)) ){
goto Start;
}
}
for ( i=0;i<=62; i++) {
delay(700),fillcell(im[i][0],im[i][1]);
}
for ( i=0;i<=62; i++) {
t[im[i][0]][im[i][1]]=i+1;
}
for ( i=0;i<=7; i++) {
for( j=0;j<=7; j++){
if( t[i][j]==0)delay(700),fillcell(i,j);
}
}
//cout<<"\nGraphical Answer:\n";
for ( i=0;i<=7; i++) {
for( j=0;j<=7; j++){
t[i][j]==0?t[i][j]=64:t[i][j]=t[i][j];
//cout<<setw(3)<<t[i][j]<<"";
}
//cout<<endl;
getch();
}
}