| Summary: | When the red king and black king are in the same column, the red king can directly kill the black king at its turn. But it is not checked as valid. | ||
|---|---|---|---|
| Product: | CS3343 2020 Group 9_Chinese Chess | Reporter: | guohan2-c |
| Component: | ChessGame | Assignee: | 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:38:29 HKT
The problem is located in the isValidMove() function under the Rule class. The checking for the situation where the red king and black king are in the same column, one king can kill the other king at its turn is set as a valid move. (In reply to guohan2-c from comment #1) > The problem is located in the isValidMove() function under the Rule class. > The checking for the situation where the red king and black king are in the > same column, one king can kill the other king at its turn is set as a valid > move. The added code part is as follows [line 58-81, Rule class] // no need to check King, Guard and Pawn if( chess instanceof Guard || chess instanceof Pawn) return true; // get starting point int from_x = chess.getPositionX(); int from_y = chess.getPositionY(); // Based on the rule, the middle point cannot have another pieces if(chess instanceof King ) { if(chess.getType().equals("red")) { for(int i=from_y + 1; i<=9;i++) { if (board[from_x][i] != null && !board[from_x][i].equals("black King")) { return true; } } return false; } else { for(int i=from_y - 1; i>=0;i--) { if (board[from_x][i]!=null && !board[from_x][i].equals("red King")) { return true; } } return false; } } |