#include <stdio.h>
#include <malloc.h>
#include <string.h>
/*
1 2 1 2
2 1 2 1
2 1 2 2
1 1 2 2 只对比上下左右,如果有相等的,赋为零
*/
void xiaochu(int i_compare, int x, int y ,int p[][4])
{
if(x-1>= 0)
{
if(p[x-1][y] == i_compare)
{
p[x-1][y] = 0;
x = x -1;
int d[4][4];
for(int i = 0;i<4;i++)
{
for(int j = 0;j<4;j++)
d[i][j] = p[i][j];
}
return xiaochu(i_compare, x, y, d);
}
}
if(x+1< 4)
{
if(p[x+1][y] == i_compare)
{
p[x+1][y] = 0;
x = x +1;
int d[4][4];
for(int i = 0;i<4;i++)
{
for(int j = 0;j<4;j++)
d[i][j] = p[i][j];
}
return xiaochu(i_compare, x, y, d);
}
}
if(y -1>=0)
{
if(p[x][y-1] == i_compare)
{
p[x][y-1] = 0;
y = y -1;
int d[4][4];
for(int i = 0;i<4;i++)
{
for(int j = 0;j<4;j++)
d[i][j] = p[i][j];
}
return xiaochu(i_compare, x, y, d);
}
}
if(y + 1<4)
{
if(p[x][y+1] == i_compare)
{
p[x][y+1] = 0;
y = y +1;
int d[4][4];
for(int i = 0;i<4;i++)
{
for(int j = 0;j<4;j++)
d[i][j] = p[i][j];
}
return xiaochu(i_compare, x, y, d);
}
}
for(int i = 0;i<4;i++)
{
for(int j = 0;j<4;j++)
printf("%d ",p[i][j]);
printf("\n ");
}
}
void main()
{
int p[4][4] = {{1,2,1, 2 },{2,1,2,1},{2,1,2,2}, {1,1,2,2}};
//printf("%d", p[0][0]);
int i_compare = p[1][2];
p[1][2] = 0;
int x = 1,y =2;
printf(" ");
xiaochu(i_compare, x, y, p);
}