This is my move function:
bool move(int tile)
{
// TODO
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (tile == board[i][j])
{
board[i][j] = tile;
{
if (board[i - 1][j] == 0 && i - 1 >= 0)
{
tile = board[i - 1][j];
board[i - 1][j] = board[i][j];
board[i][j] = tile;
return true;
}
if (board[i + 1][j] == 0 && i + 1 <= d - 1)
{
tile = board[i + 1][j];
board[i + 1][j] = board[i][j];
board[i][j] = tile;
return true;
}
if (board[i][j - 1] == 0 && j - 1 >= 0)
{
tile = board[i][j - 1];
board[i][j - 1] = board[i][j];
board[i][j] = tile;
return true;
}
else if (board[i][j + 1] == 0 && j + 1 <= d - 1)
{
tile = board[i][j + 1];
board[i][j + 1] = board[i][j];
board[i][j] = tile;
return true;
}
}
}
}
}
return false;
}
Many thanks