Bug 408

Summary: "Dead" chess can be found by findChess()
Product: CS3343 2020 Group 9_Chinese Chess Reporter: yinuowang3-c
Component: ChessGameAssignee: Marco <kaipewang2-c>
Status: CONFIRMED ---    
Severity: major CC: guohan2-c, kaipewang2-c, longtduan2-c, yfeng28-c, yinuowang3-c, yujiawang7-c
Priority: ---    
Version: V2.0   
Hardware: PC   
OS: Windows   
Deadline: 2020-11-15   

Description yinuowang3-c 2020-11-15 15:48:20 HKT
Step1: move (0,0) to (0,1)
Step2: move (1,7) to (1,0), the black cannon kill the red horse
Step3: move (2,0) to (0,2)
Step4: move (1,0) to (4,0), the black cannon should be found and move to (4,0), but the result of findChess() is the red Horse, which should have been killed by the black cannon.
Comment 1 yinuowang3-c 2020-12-06 19:54:50 HKT
(In reply to yinuowang3-c from comment #0)
> Step1: move (0,0) to (0,1)
> Step2: move (1,7) to (1,0), the black cannon kill the red horse
> Step3: move (2,0) to (0,2)
> Step4: move (1,0) to (4,0), the black cannon should be found and move to
> (4,0), but the result of findChess() is the red Horse, which should have
> been killed by the black cannon.

Reason: It is because after a chess piece is taken, its isAlive state becomes false, but the piece is still in the Chesslist. When finding pieces, the findChess() function iterates over the Chesslist looking for pieces in a certain location, but does not check its state.

Solution: Add additional check in findChess(), when it traverse a Chesslist, it should check not only the position of the pieces but also their isAlive state.