Bug 409

Summary: Minister can move across the river to the opponent's side, but it is not supposed to by rules.
Product: CS3343 2020 Group 9_Chinese Chess Reporter: guohan2-c
Component: ChessGameAssignee: FENG Yi <yfeng28-c>
Status: CONFIRMED ---    
Severity: normal CC: guohan2-c, kaipewang2-c, longtduan2-c, yfeng28-c, yinuowang3-c, yujiawang7-c
Priority: ---    
Version: V2.0   
Hardware: PC   
OS: Windows   
Deadline: 2020-10-03   

Description guohan2-c 2020-11-15 16:18:28 HKT
Steps to reproduce:
1. Move the red minister from (2, 0) to (0, 2)
2. Move the black horse from (0, 9) to (0, 8)
3. Move the red minister from (0, 2) to (2, 4)
4. Move the black horse from (0, 8) to (0, 7)
5. Move the red minister from (2, 4) to (4, 6)

Actual result:
The move is successfully performed without error alert.

Expected result:
The movement should be checked as invalid. The program prompt "The move you want to make is invalid!"
Comment 1 guohan2-c 2020-11-29 18:17:19 HKT
The problem is located in the isValidMove() under the Rule class. The move which tries to let the minister chess pieces across the river is checked as an invalid one. Solved.
Comment 2 guohan2-c 2020-12-06 21:49:11 HKT
(In reply to guohan2-c from comment #1)
> The problem is located in the isValidMove() under the Rule class. The move
> which tries to let the minister chess pieces across the river is checked as
> an invalid one. Solved.

The part of code modified can be referred to line 82-93
if(chess instanceof Minister){
			int middle_x = (from_x + this.to_x) / 2;
			int middle_y = (from_y + this.to_y) / 2;
			if(chess.getType().equals("red")) {
				if(this.to_y >= 5) return false;
			}
			else {
				if(this.to_y < 5) return false;
			}
			if(board[middle_x][middle_y] != null) return false;
			return true;
		}