Bug 416 - Error in isSwappableExist() in Map.java
Summary: Error in isSwappableExist() in Map.java
Status: CONFIRMED
Alias: None
Product: CandyCrush 2020
Classification: Unclassified
Component: Source Code (show other bugs)
Version: 1.0
Hardware: PC Windows
: --- enhancement
Assignee: jli262-c
URL:
Depends on:
Blocks:
 
Reported: 2020-11-18 21:58 HKT by ziruichen6-c
Modified: 2020-11-29 15:04 HKT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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().