马踏棋盘所用的两个向量数组

马踏棋盘所用的两个向量数组

int direct[8][2]={2,1,2,-1,-2,1,-2,-1,1,2,-1,2,1,-2,-1,-2};  //落脚点向量
int judge[4][2]={1,0,-1,0,0,1,0,-1};                                //卡位向量

这里说明一下,在使用的时候可以不用太麻烦,我特意将两个向量对应了起来,如
for (i = 0 ;i < 4 ;i ++ )  
        
{  
            
if(chess[pos.x+judge[i][0]][pos.y+judge[i][1]]!=1)           //是否卡位
            {  
                
int x=pos.x+direct[i*2][0]; 
                
int y=pos.y+direct[i*2][1]; 
                
if(x<=p&&x>=1&&y<=q&&y>=1&&visited[x][y]!=1&&chess[x][y]!=1)  //该点能否落脚
                {  
                    visited[x][y]
=1;  
                    temp.x
=x;  
                    temp.y
=y;  
                    temp.step
=pos.step+1
                    que.push(temp);     
                }
  
                x
=pos.x+direct[i*2+1][0]; 
                y
=pos.y+direct[i*2+1][1]; 
                
if(x<=p&&x>=1&&y<=q&&y>=1&&visited[x][y]!=1&&chess[x][y]!=1)   //该点能否落脚
                {  
                    visited[x][y]
=1;  
                    temp.x
=x;  
                    temp.y
=y;  
                    temp.step
=pos.step+1;  
                    que.push(temp); 
                }
  
            }
  
        }


你可能感兴趣的:(马踏棋盘所用的两个向量数组)