📄 eight.h
字号:
#include <iostream>
using namespace std;
class point
{
public:
int row;
int cal;
void operator=(point &asign)
{
this->row=asign.row;
this->cal=asign.cal;
}
bool check()
{
if((cal<0)|(cal>2)|(row<0)|(row>2))
return false;
return true;
}
};
class eight
{
public:
eight()
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
vec[i][j]=0;
}
eight(eight & src)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
vec[i][j]=src.vec[i][j];
}
}
}
void input()
{
int temp=0;
cout<<"please input the number(0-8)"<<endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<"Now input position: "<<i*3+j<<endl;
cin>>temp;
if(temp==0)
{
blank.row=i;
blank.cal=j;
}
vec[i][j]=temp;
}
}
}
bool move(point &from,point &to,eight & result)//to value must be 0
{
if(vec[to.row][to.cal]!=0)
return false;
result.vec[to.row][to.cal]=vec[from.row][from.cal];
result.blank=from;
result.vec[from.row][from.cal]=0;
result.pre=to;
return true;
}
/*int valp(point pos)
{
return vec[pos.row][pos.cal];
}*/
int valp(int i,int j)
{
return vec[i][j];
}
void print()
{
for(int i=0;i<3;i++)
{
cout<<"\n";
for(int j=0;j<3;j++)
cout<<" "<<vec[i][j];
}
cout<<"\n-----------------\n";
}
bool operator==(eight & com)
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
if(this->valp(i,j)!=com.valp(i,j))
return false;
return true;
}
int toint()
{
int res=0;
int e=1;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
res+=e*vec[i][j];
e*=10;
}
}
return res;
}
int vec[3][3];
point pre;
point blank;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -