I need help with my move function. I can't figure out how to store the blank tile position only once without searching it together with the TILE input. Also, my move based on this code is always illegal. Draw and Init prints out the correct array.
bool move(int tile)
{
int r = DIM_MIN;
int c = DIM_MIN;
int blankr, blankc;
for (int row=0; row<d;row++)
{
for (int col=0; col<d;col++)
{
if (board[row][col] == tile)
{
r = row;
c = col;
}
else if (board[row][col] == 0)
{
blankr = row;
blankc = col;
}
}
}
return false;
if (r == DIM_MIN)
return false;
if (((abs(r-blankr)==1) || (abs(c-blankc)==1)) && !((abs(r-blankr)==1) && (abs(c-blankc)==1)))
{
int temp1 = board[r][c];
board[r][c]=board[blankr][blankc];
board[blankr][blankc]=temp1;
}
else return false;
}