Bug 416

Summary: Error in isSwappableExist() in Map.java
Product: CandyCrush 2020 Reporter: ziruichen6-c
Component: Source CodeAssignee: jli262-c
Status: CONFIRMED ---    
Severity: enhancement    
Priority: ---    
Version: 1.0   
Hardware: PC   
OS: Windows   

Description ziruichen6-c 2020-11-18 21:58:02 HKT
The bug was found when running the JUnit test. The testHorizontalExist8(), testHorizontalExist9(), testVerticalExist8() and testVerticalExist9() return the false.

Steps to Reproduce:
Run testHorizontalExist8(), testHorizontalExist9(), testVerticalExist8() and testVerticalExist9() in TestMap.java

Actual Results: testHorizontalExist8(), testHorizontalExist9(), testVerticalExist8() and testVerticalExist9() in TestMap.java failures.

Expected Results:testHorizontalExist8(), testHorizontalExist9(), testVerticalExist8() and testVerticalExist9() in TestMap.java pass the JUnit test.
Comment 1 ziruichen6-c 2020-11-18 22:07:04 HKT
The error was caused by the lack of judgment condition in isHorizontalSwappableExist() and  isVerticalSwappableExist().
The solution would be adding judgment conditions to these two functions.
The previous version could not judge below four conditions:
X X |  X  |   X  | X 
 X  | X X | X    |   X       
    |     |   X  | X 

Added code:
Horizontal:
(j<SIZE-3&&itemArray[i][j].isSame(itemArray[i][j+2])&&((i>0&&itemArray[i][j].isSame(itemArray[i-1][j+1]))||(i<SIZE-1&&itemArray[i][j].isSame(itemArray[i+1][j+1]))))    
Vertical:
(i<SIZE-3&&itemArray[i][j].isSame(itemArray[i+2][j])&&((j>0&&itemArray[i][j].isSame(itemArray[i+1][j-1]))||(j<SIZE-1&&itemArray[i][j].isSame(itemArray[i+1][j+1]))))
Comment 2 ziruichen6-c 2020-11-29 11:43:26 HKT
The function isHorizontalSwappableExist() and  isVerticalSwappableExist() have been modified into new function, isEndingSwappableExist() and isMiddleSwappableExist(). The four situation mentioned before would be tested in isMiddleSwappableExist().