
#include<iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#define maxn 105
using namespace std;
void findposition(vector<string> &a,int &x, int &y){
for(int i=0;i<4;i++){
for(int j=0;j<4;j++)
{
if(a[i][j]==' ')
{
x=i;
y=j;
return ;
}
}
}
};
void move(vector<string> &a,int x,int y,int n,int m, bool &flag){
if(x>=4||x<0||y>=4||y<0)
{
flag=false;
return ;
}
a[n][m]=a[x][y];
a[x][y]=' ';
flag=true;
return ;
};
void prsent(vector<string> &a){
for(int i=0;i<4;i++){
for(int j=0;j<4;j++)
cout<<a[i][j];
cout<<"\n";
}
system("pause");
system("cls");
};
bool A(vector<string> &a){
int n,m;
bool flag;
findposition(a,n,m);
move(a,n-1,m,n,m,flag);
if(!flag)
return false;
prsent(a);
return true;
};
bool B(vector<string> &a){
int n,m;
bool flag;
findposition(a,n,m);
move(a,n+1,m,n,m,flag);
if(!flag)
return false;
prsent(a);
return true;
};
bool L(vector<string> &a){
int n,m;
bool flag;
findposition(a,n,m);
move(a,n,m-1,n,m,flag);
if(!flag)
return false;
prsent(a);
return true;
};
bool R(vector<string> &a){
int n,m;
bool flag;
findposition(a,n,m);
move(a,n,m+1,n,m,flag);
if(!flag)
return false;
prsent(a);
return true;
};
bool finit(vector<string> &a,string &b){
int n=0;
for(int i=0;i<4;i++){
string temp;
for(int j=0;j<4;j++){
temp=temp+b[n];
n++;
}
a.push_back(temp);
}
return true;
};
int main(){
cout<<"begin the game"<<endl;
string s;
cin>>noskipws;
getline(cin,s);
vector<string> m;
if(!finit(m,s))
cout<<"error";
system("pause");
system("cls");
int n;
string temp;
while(1){
cout<<"put a number"<<endl;
cin>>n;
if(n==1)
{if(!A(m))
cout<<"error1";}
else if(n==2)
{if(!B(m))
cout<<"error2";}
else if(n==3)
{if(!L(m))
cout<<"error3";}
else if(n==4)
{if(!R(m))
cout<<"error4";}
else if(n==0)
break;
getline(cin,temp);
}
cout<<"good bye";
return 0;
}