Here's my move function. The problem here is i know im not following the instructions. Because i don't understand why do i need to track and how to track the blank tile. My function works as expected. But to learn more, i want to know the official way of doing it...
bool move(int tile) {
for(int i = 0; i < d; i++)
{
for(int j = 0; j < d; j++)
{
if(board[i][j] == tile)
{
if((j - 1 > 0) && (board[i][j - 1] == 0))
{
swap(&board[i][j], &board[i][j - 1]);
return true;
}
if((j + 1 < d) && (board[i][j + 1] == 0))
{
swap(&board[i][j], &board[i][j + 1]);
return true;
}
if((i - 1 > 0) && (board[i - 1][j] == 0))
{
swap(&board[i][j], &board[i - 1][j]);
return true;
}
if((i + 1 < d) && (board[i + 1][j] == 0))
{
swap(&board[i][j], &board[i + 1][j]);
return true;
}
}
}
}
return false; }