⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shiview.cpp

📁 本程序是进行路径的寻找的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			 dataimg[i][j]=0;
		 else 
			 dataimg[i][j]=1;
	   }
	}
///////////////////////////////////////////////
	{
     int stx=WIDTH/2,sty=0,enx=WIDTH/2,eny=HEIGHT-1;
     dc.FillSolidRect(stx,sty,3,3,RGB(255,0,0)); 
     dc.FillSolidRect(enx,eny,3,3,RGB(0,0,255)); 
       
         while(1)
		 {
		  /////////////////////////////
              static long ctcounter=0;
			  ctcounter++;
			  if(ctcounter>1000)
				  break;
          //////////////////////////////   
               static int ctclo=0;
			   ctclo++;

           searchnext2(dataimg,stx,sty);
           dc.FillSolidRect(stx,sty,3,3,
			   RGB(255*(ctclo%2),120*(ctclo%3),255*((ctclo+1)%2))); 

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////

           if(stx==enx&&sty==eny)
			   break;
		 }

     
	}


return;
//////////////////////////////////////////////////	
///////////////test//////////////////////////	
	{
    int i,j;
	int co=0;
   for(i=0;i<300;i++)
	   for(j=0;j<300;j++)
	   {
		   co=(int)(getoneshi(dataimg,i,j));
		   if(co>254)
			   co=254;
         dc.SetPixel(i+400,j,RGB(co,co,co));
	   }
   

	}
/////////////////////////////////////////////////

}
void CShiView::way3()
{

////////////////////////////////////////
   int dataimg[WIDTH][HEIGHT];
   	CClientDC dc(this); 

//////////////////////////////
	{
	CPoint tpos(1,1);
	CSize tsize(WIDTH,HEIGHT);
   tdib.Draw(GetDC(),tpos,tsize);
	}
////////////////////////////////////////	
	{
   int i,j;
   for(i=0;i<300;i++)
	   for(j=0;j<300;j++)
	   {
         if(dc.GetPixel(i+1,j+1)%256>100)
			 dataimg[i][j]=0;
		 else 
			 dataimg[i][j]=1;
	   }
	}
///////////////////////////////////////////////
	{
     int stx=WIDTH/2,sty=0,enx=WIDTH/2,eny=HEIGHT-1;
     dc.FillSolidRect(stx,sty,3,3,RGB(255,0,0)); 
     dc.FillSolidRect(enx,eny,3,3,RGB(0,0,255)); 
       
         while(1)
		 {
		  /////////////////////////////
              static long ctcounter=0;
			  ctcounter++;
			  if(ctcounter>10000)
				  break;
          //////////////////////////////   
               static int ctclo=0;
			   ctclo++;

           searchnext2(dataimg,stx,sty);
           dc.FillSolidRect(stx,sty,3,3,
			   RGB(255*(ctclo%2),120*(ctclo%3),255*((ctclo+1)%2))); 

///////////////////////////////////////////////////////////////
           if(gerrecentchange(stx,sty)==0&&T0<10)
		   {  
			   
			   static int first=0;
			   if(first<10)
			   {
          AfxMessageBox("ok to t0");
               first++;
			   T0=100000;
			   }

		   }
///////////////////////////////////////////////////////////

           if(stx==enx&&sty==eny)
			   break;
		 }

     
	}


return;
//////////////////////////////////////////////////	
///////////////test//////////////////////////	
	{
    int i,j;
	int co=0;
   for(i=0;i<300;i++)
	   for(j=0;j<300;j++)
	   {
		   co=(int)(getoneshi(dataimg,i,j));
		   if(co>254)
			   co=254;
         dc.SetPixel(i+400,j,RGB(co,co,co));
	   }
   

	}
/////////////////////////////////////////////////

}

void CShiView::way4()
{

////////////////////////////////////////
   int dataimg[WIDTH][HEIGHT];
   int dataout[WIDTH][HEIGHT];
   	CClientDC dc(this); 

//////////////////////////////
	{
	CPoint tpos(1,1);
	CSize tsize(WIDTH,HEIGHT);
   tdib.Draw(GetDC(),tpos,tsize);
	}
////////////////////////////////////////	
	{
   int i,j;
   for(i=0;i<300;i++)
	   for(j=0;j<300;j++)
	   {
         if(dc.GetPixel(i+1,j+1)%256>100)
			 dataimg[i][j]=0;
		 else 
			 dataimg[i][j]=1;
	   }
	}
///////////////////////////////////////////////
//filldata_jieL(dataimg,dataout);
filldata_jieL2(dataimg,dataout);
findway1(dataout);

return;
//////////////////////////////////////////////////	

}

void CShiView::way5()
{

////////////////////////////////////////
   int dataimg[WIDTH][HEIGHT];
   int dataout[WIDTH][HEIGHT];
   	CClientDC dc(this); 

//////////////////////////////
	{
	CPoint tpos(1,1);
	CSize tsize(WIDTH,HEIGHT);
   tdib.Draw(GetDC(),tpos,tsize);
	}
////////////////////////////////////////	
	{
   int i,j;
   for(i=0;i<300;i++)
	   for(j=0;j<300;j++)
	   {
         if(dc.GetPixel(i+1,j+1)%256>100)
			 dataimg[i][j]=0;
		 else 
			 dataimg[i][j]=1;
	   }
	}
///////////////////////////////////////////////
filldata_jieL(dataimg,dataout);
findway1(dataout);

return;
//////////////////////////////////////////////////	

}

void CShiView::OnWay2() 
{
way2();
}

void CShiView::OnWay3() 
{
way3();	
}

void CShiView::OnWay4() 
{
way4();	
}

void CShiView::filldata_jieL(int tdata[WIDTH][HEIGHT],int dataout[WIDTH][HEIGHT])
{
int i,j;
CClientDC dc(this);

int enx=WIDTH/2;
int eny=HEIGHT-1;
int stx=WIDTH/2;
int sty=0;

for(i=0;i<WIDTH;i++)
for(j=0;j<HEIGHT;j++)
{
dataout[i][j]=-tdata[i][j];
}


dataout[stx][sty]=1;

int h,k;
int ctmin;
int ctdist=1;

////////////////////////////////////////////////
while(1)
{
static int counter=0;
counter++;
if(counter>10)
{
counter=0;
}
//AfxMessageBox("stop");
////////////////////////////

ctdist++;

	for(i=0;i<WIDTH;i++)
		for(j=0;j<HEIGHT;j++)
		{
          if(dataout[i][j]==0)
		  {
//////////////////////////////////////////
            for(h=-1;h<=1;h++)
				for(k=-1;k<=1;k++)
				if(abs(h)+abs(k)==1)
				{
                  if(i+h>=0&&i+h<WIDTH&&j+k>=0&&j+k<HEIGHT)
				  {
                    if(dataout[i+h][j+k]==ctdist-1)
					{
					   dataout[i][j]=ctdist;
					    dc.SetPixel(i,j,RGB(255,0,0));
                        if(i==enx&&j==eny)
							return;                          
					}
				  } 

				}

/////////////////////////////////////////////////////////		

		  }

		}

}


////////////////////////////////////////////////


/////////////////////////////////////////////////
}
////////////////////////////////////////////

void CShiView::filldata_jieL2(int tdata[WIDTH][HEIGHT],int dataout[WIDTH][HEIGHT])
{
int i,j;
CClientDC dc(this);

int stx=WIDTH/2;
int sty=0;

for(i=0;i<WIDTH;i++)
for(j=0;j<HEIGHT;j++)
{
dataout[i][j]=-tdata[i][j];
}


dataout[stx][sty]=1;

int h,k;
int ctmin;

int refresh=0;


////////////////////////////////////////////////
while(1)
{
////////////////////////////

refresh=0;

///////////////////////
	for(i=0;i<WIDTH;i++)
		for(j=0;j<HEIGHT;j++)
		{
          if(dataout[i][j]==0)
		  {
//////////////////////////////////////////
			 ctmin=10000;  
            for(h=-1;h<=1;h++)
				for(k=-1;k<=1;k++)
				if(abs(h)+abs(k)==1)
				{
                  if(i+h>=0&&i+h<WIDTH&&j+k>=0&&j+k<HEIGHT)
				  {
                    if(dataout[i+h][j+k]>0)
					{
                     if(dataout[i+h][j+k]<ctmin)
						 ctmin=dataout[i+h][j+k];
					}
				  } 

				}
			if(ctmin!=10000)
			{
				dataout[i][j]=ctmin+1;
                dc.SetPixel(i,j,RGB(255,0,0));
				refresh=1;
			}
////////////////////////////////////////////		

		  }

		}

if(refresh==0)break;

}



//AfxMessageBox("go");
}

void CShiView::findway1(int datal[WIDTH][HEIGHT])
{
int stx=WIDTH/2;
int sty=0;
int enx=WIDTH/2;
int eny=HEIGHT-1;

CClientDC dc(this);

int ctx=enx,cty=eny;
int ctl=datal[enx][eny];


int h,k;

while(1)
{
   for(h=-1;h<=1;h++)
	 for(k=-1;k<=1;k++)
	    if(abs(h)+abs(k)==1)
           if(ctx+h>=0&&ctx+h<WIDTH&&cty+k>=0&&cty+k<HEIGHT)
		   {
               if(datal[ctx+h][cty+k]==ctl-1)
			   {
                 dc.SetPixel(ctx,cty,RGB(0,255,0));
                 dc.SetPixel(ctx+1,cty,RGB(0,255,0));
                 dc.SetPixel(ctx,cty+1,RGB(0,255,0));
                  ctx=ctx+h;
                  cty=cty+k;
				  ctl--;
				  goto whileend;
			   }


		   
		   }

   whileend:  if(ctx==stx&&cty==sty)break;

}



}

void CShiView::OnWay5() 
{
way5();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -