I have been working on the move function for fifteen for a few days and I don't understand where I am going wrong, please can someone advise me where/what I should focus on. Here is my code:
/**
* If tile borders empty space, moves tile and returns true, else
* returns false.
*/
bool move(int tile)
{
// TODO
//int row = board[d - 1][d - 1];
//int col = board[d - 1][d - 1];
//int temp;
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)
{
board[i][j] = board[i - 1][j];
board[i - 1][j] = board[i][j];
return true;
}
if (board[i + 1][j] == 0 && i + 1 < d)
{
board[i][j] = board[i + 1][j];
board[i + 1][j] = board[i][j];
return true;
}
if (board[i][j - 1] == 0 && j - 1 > 0)
{
tile = board[i][j - 1];
board[i][j - 1] = board[i][j];
return true;
}
if (board[i][j + 1] == 0 && j + 1 < d)
{
board[i][j] = board[i][j + 1];
board[i][j + 1] = board[i][j];
return true;
}
}
}
}
}
return false;
}
Many thanks