Hi I am working on pset3 : fifteen and trying to implement move function. I'm not quite sure how to identify board edges and deal with this. My swap is also not working as the tile I want to move seems to override the blank "0" tile. Please see code below and I appreciate any suggestions on what to work on / why this isn't working...
bool move(int tile)
{
int temp;
for (int row = 0; row < d; row++){
for (int col = 0; col < d; col++){
if (board[row][col] == 0){
if (board[row][col-1] == tile || board[row][col+1] == tile || board[row+1][col]==tile || board[row-1][col]==tile) {
// legal move is permitted
temp = board[row][col];
board[row][col] = tile;
tile = temp;
return true;
}
}
}
}
return false;
}