Bug 401 - It's found that when one player checkmate and already wins the game, the opponent can still act by input "undo" and move command
Summary: It's found that when one player checkmate and already wins the game, the oppo...
Status: CONFIRMED
Alias: None
Product: CS3343 2020 Group 9_Chinese Chess
Classification: Unclassified
Component: ChessGame (show other bugs)
Version: V2.0
Hardware: PC Windows
: --- major
Deadline: 2020-10-30
Assignee: Marco
URL:
Depends on:
Blocks:
 
Reported: 2020-11-13 21:09 HKT by Marco
Modified: 2020-12-06 21:51 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 Marco 2020-11-13 21:09:59 HKT
Summary:
It's found that when one player checkmate and already wins the game, the opponent can still act by input "undo" and move command.

Steps to Reproduce:
1. Run the program
2. Input "new game"
3. Input "4 3 4 4"
4. Input "1 7 4 7"
5. Input "4 4 4 5"
6. Input "4 6 4 5"
7. Input "0 0 0 1"
8. Input "4 7 4 0"
9. Input "undo"

Actual Result:
The move "0 0 0 1" is undone.

Expected Result:
No further command is acceptable when one player already wins. And error message needs to be prompted.
Comment 1 Marco 2020-12-06 21:51:23 HKT
(In reply to Marco from comment #0)
> Summary:
> It's found that when one player checkmate and already wins the game, the
> opponent can still act by input "undo" and move command.
> 
> Steps to Reproduce:
> 1. Run the program
> 2. Input "new game"
> 3. Input "4 3 4 4"
> 4. Input "1 7 4 7"
> 5. Input "4 4 4 5"
> 6. Input "4 6 4 5"
> 7. Input "0 0 0 1"
> 8. Input "4 7 4 0"
> 9. Input "undo"
> 
> Actual Result:
> The move "0 0 0 1" is undone.
> 
> Expected Result:
> No further command is acceptable when one player already wins. And error
> message needs to be prompted.

Solution provided by Marco:
The bug is solved by adding a new boolean variable called "gameOver" in ChessBoard.java and it will be changed into "true" whenever game ends:

case ErrorCode.GAME_ALREADY_OVER:
	gameOver = true;
	System.out.println("The game is over!");
	break;

In this case, when we issue "undo" after game ends, the program will first check the value of "gameOver":

public int undo() {
	if (gameOver) {
		System.out.println("The game is over! Undo is not allowed.");
		return ErrorCode.GAME_ALREADY_OVER;
	}
        ... ...
}

Then this bug is successfully fixed.