Alright, so I've had a go at this for a very long time, and haven't been making much progress. My problems is with this move function. It doesn't accept some illegal moves, however, some illegal moves will be accepted. What is happening and how can i fix it? Thanks.
bool move(int tile)
{
// TODO
int placeholder;
int tileX;
int tileY;
if(tile > d*d -1 || tile < 1){
return false;
}
for(int i = 0; i < d; i++){
for(int j = 0; j < d; j++){
if(board[i][j] == tile){
tileX = i;
tileY = j;
break;
}
}
}
if(board[blankX][blankY] == board[tileX-1][tileY]||board[blankX][blankY] ==
board[tileX+1][tileY]||board[blankX][blankY] == board[tileX][tileY-
1]||board[blankX][blankY] == board[tileX][tileY+1]){
placeholder = board[tileX][tileY];
board[tileX][tileY] = board[blankX][blankY];
board[blankX][blankY] = placeholder;
blankX = tileX;
blankY = tileY;
return true;
}
else{ return false; } }