The bug was found when running the JUnit test. testSquareExist8() and testSquareExist9() return false. Steps to Reproduce: Run testSquareExist8() and testSquareExist9() in TestMap.java Actual Results:testSquareExist8() and testSquareExist9() in TestMap.java failures which means the isSquareSwappableExist() could not judge below situations: X | X | X X X X | X X Expected Results: testSquareExist8() and testSquareExist9() in TestMap.java pass the JUnit test
The error was caused by the error of judgment condition in isSquareSwappableExist(). The solution would be to correct the judgment condition in isSquareSwappableExist() in Map.java Previous version: (itemArray[i+1][j+1].isSame(itemArray[i+1][j]) && itemArray[i+1][j+1].isSame(itemArray[i][j+1]) && ((i > 0 && itemArray[i][j].isSame(itemArray[i-1][j])) || (j > 0 && itemArray[i][j].isSame(itemArray[i][j-1]))) After correcting: itemArray[i+1][j+1].isSame(itemArray[i+1][j]) && itemArray[i+1][j+1].isSame(itemArray[i][j+1]) && ((i > 0 && itemArray[i+1][j+1].isSame(itemArray[i-1][j])) || (j > 0 && itemArray[i+1][j+1].isSame(itemArray[i][j-1])))
In version2, After further research, it is found that the four conditions detected in isSquareSwappableExist() will be covered by isHorizontalSwappableExist() and isVerticalSwappableExist(), so this function is deleted.