After you try to find the tile in the board in the move function, you should check if the obtained array indices are valid or not. Because, in case user inputs number outside the permitted values, then some garbage value is used for further condition checking. So make the _i and _j variables -1 or something at the beginning and check if they are – 1 after the for loop in the move function. If they are, it means you have illegal input and can directly return false. Otherwise, you can proceed with the condition checking. Other code seems to be fine. You could also try using the debugger or go through the walkthrough for better understanding.
If this answers your question, click the green checkmark to close this question.
solved Why is my program of game of fifteen printing ‘_’ instead of the replaced number? [closed]