I rewrote almost the entire code and I finally was able to make the tiles swap. Problem is at every swap the blank tile gets duplicated and the tile swapped disappears, eventually rendering a Segfault.
I have checked similar problems in this forum, but I think I have all my possible issue makers covered. My i and j don't go over 3 and I am swapping the values, not the indexes. I'm tapped out.
Can anyone tell me what's wrong with my code (it's partially pseudo)?
...
int blank: 0;
int blank_row: d - 1; //keeps track of blank top-bottom
int blank_col: d - 1; //keeps track of blank left-right
for (i = 0...)
{
for (j = 0...)
{
if (board[i][j] == tile) //search for tile
{
... ii ...
... jj ...
}
}
}
if ((ii > 0 && board[ii - 1][jj] == blank ) || (ii <= (blank_row - 1) && board[ii + 1][jj] == blank) || (jj > 0 && board[ii][jj - 1] == blank) || (jj <= (blank_col - 1) && board[ii][jj + 1] == blank))
{
board[ii][jj] = blank;
board[blank_row][blank_col] = tile;
return true;
}
else
return false;