When I try to move a legal tile (i.e one adjacent to the 'blank' tile 0), nothing happens. If the tile is illegal the program functions as it should. Here is the move function:
bool move(int tile)
{
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (board[i][j] == tile)
{
// stops program from going out of bounds
if (j < d)
{
if (board[i][j + 1] == 0)
{
swap(board[i][j], board[i][j + 1]);
return true;
}
}
if (j > 0)
{
if (board[i][j - 1] == 0)
{
swap(board[i][j], board[i][j - 1]);
return true;
}
}
if (i > 0)
{
if (board[i - 1][j] == 0)
{
swap(board[i][j], board[i - 1][j]);
return true;
}
}
if (i < d)
{
if (board[i + 1][j] == 0)
{
swap(board[i][j], board[i + 1][j]);
return true;
}
}
}
}
}
return false;
}
and the swap function:
void swap(int i, int j)
{
int temp = i;
i = j;
j = temp;
}
What happens is the board remains looking the same with no changes made.