Take the 2-minute tour ×  I am trying to solve the famous
8-puzzle, where a 3*3 square is filled with 1 empty slot and 8
numbers, solving is to return it to the original state.  to do
this, I have a "state" of arraylist which stores the numbers
0~9, representing the puzzle.  the solution involves spawning
multitudes of possible move-states, meaning I save every legal
move made and the resulting puzzle. This is done using the below
methods, but my swapAndStore will not edit the original passed
array every pass. instead, when called upon in the
genSuccessors() below that, it will work fine for the first if
condition, then apply the next if condition on the result of the
first if. I thought I fixed the issue by making a new
puzzlestate called "oldBoard" to save the original input puzzle
for future reference, but this did not work either. A friend
told me this might have to do with the reference issue, which I
cannot grasp well. I understand that when x=0, y=1, java will
not do a swap(x,y) so that x = 1, y=0, but