Bug 409 - Minister can move across the river to the opponent's side, but it is not supposed to by rules.
Summary: Minister can move across the river to the opponent's side, but it is not supp...
Status: CONFIRMED
Alias: None
Product: CS3343 2020 Group 9_Chinese Chess
Classification: Unclassified
Component: ChessGame (show other bugs)
Version: V2.0
Hardware: PC Windows
: --- normal
Deadline: 2020-10-03
Assignee: FENG Yi
URL:
Depends on:
Blocks:
 
Reported: 2020-11-15 16:18 HKT by guohan2-c
Modified: 2020-12-06 21:49 HKT (History)
6 users (show)

See Also:


Attachments

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