is there any other way of doing this?
i mean the concept of moving the number with the blank...this is one of my friend's concept of moving the number, I couldnt use it due to the plagarism...
that's why i need a different way to do it ...
Code:
void puzzle_command(int arr[NROW][NCOL], int count) //count is the input that user key-ed in, which mean the number that user wanted to move with the blank
{
int value, num, temp;
int px1, py1, px2, py2, x, y;
for (x=0; x<NROW; x++)
for (y=0; y<NCOL; y++)
{
value = arr[x][y] ;
if (0 == value)
{
value = arr[x][y];
px1 = x;
py1 = y;
}
}
for (x=0; x<NROW; x++)
for (y=0; y<NCOL; y++)
{
value = arr[x][y] ;
if (count == value)
{
value = arr[x][y];
px2 = x;
py2 = y;
}
}
if ((arr[px2][py2] - arr[px2-1][py2])==count || (arr[px2][py2] - arr[px2+1][py2])==count
|| (arr[px2][py2] - arr[px2][py2-1])==count || (arr[px2][py2] - arr[px2][py2+1])==count)
{
temp = arr[px2][py2];
arr[px2][py2] = arr[px1][py1];
arr[px1][py1] = temp;
}
printf("\n\n\n\n\n\n\n\n\n\n\n");
print_puzzle(arr);
}