Bug 403 (Invalid, Minister, Move) - It's found that a valid move of the minister is determined to be invaild by the program.
Summary: It's found that a valid move of the minister is determined to be invaild by t...
Status: CONFIRMED
Alias: Invalid, Minister, Move
Product: CS3343 2020 Group 9_Chinese Chess
Classification: Unclassified
Component: ChessGame (show other bugs)
Version: V2.0
Hardware: PC Windows
: High critical
Assignee: Marco
URL:
Depends on:
Blocks:
 
Reported: 2020-11-14 13:37 HKT by Marco
Modified: 2020-12-06 21:14 HKT (History)
6 users (show)

See Also:


Attachments
Source code of the Minister Class. (1.60 KB, text/plain)
2020-11-14 13:48 HKT, Marco
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marco 2020-11-14 13:37:25 HKT
Summary:
The bug is found when I try to undo a minister movement. The program prompted that the move of minister is judged invalid. But I'm confident to say that it's a valid move of minister according to rules of Chinese Chess.

Steps to Reproduce:
1. Run the program
2. Input command "new game"
3. Input command "2 0 4 2"

Actual Results:
The program prompt "The move you want to make is invalid!"

Expected Results:
This move is judged valid and successfully performed. No error message will be shown.
Comment 1 Marco 2020-11-14 13:48:45 HKT
Created attachment 42 [details]
Source code of the Minister Class.

For HAN Guo's reference.
Bug may exist in getPossibleMove() function.
Comment 2 guohan2-c 2020-12-06 18:54:50 HKT
(In reply to Marco from comment #1)
> Created attachment 42 [details]
> Source code of the Minister Class.
> 
> For HAN Guo's reference.
> Bug may exist in getPossibleMove() function.

Bugs are found in getPossibleMove() function. Since the boundary of the loop is set wrongly. The code has changed as below
int[] possibleX = {curx-2, curx+2};
            int[] possibleY = {cury-2, cury+2};
            
            for(int x1: possibleX){
                    for(int y1: possibleY){
                            if(checkLegal(x1, y1))
                                  res.add(new ChessPosition(x1, y1));
                    }
            }
            return res; 

problem solved