Steps to reproduce: 1. Move red soldier from (4, 3) to (3, 2) 2. Move black soldier from (4, 6) to (4, 5) 3. Move red king from (4, 0) to (4, 9) Actual result: The movement is checked as invalid. The program prompt "The move you want to make is invalid!" Expected result: The black king should be killed by the red king. And the game is over.
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; } }
*** Bug 522 has been marked as a duplicate of this bug. ***