So, my move function is ALMOST working, but sometimes when swaping numbers both tile AND blank space shows up as a blank space...can you guys check my code? Thanks! Ps..Blank is a global variable, where the function draw(); keeps the location of the blank space.
bool move(int tile)
{
int row;
int column;
//iterates over the board until tile user typed is found
for (int i=0; i<d; i++){
for (int j=0; j<d; j++){
if (board[i][j] == tile){
row = i;
column= j;
}
}
}
//check if tile is valid: left, right, top or bottom to underline, and return true.
if (board[row+1][column] == blank)
{
int aux = board[row][column];
board[row][column]=blank;
board[row+1][column]=aux;
return true;
}
else
if (board[row-1][column] == blank){
int aux = board[row][column];
board[row][column]=blank;
board[row-1][column]=aux;
return true;
}
else
if (board[row][column+1] == blank){
int aux = board[row][column];
board[row][column]=blank;
board[row][column+1]=aux;
return true;
}
else
if (board[row][column-1] == blank){
int aux = board[row][column];
board[row][column]=blank;
board[row][column-1]=aux;
return true;
}
//otherwise return false.
return false;
}