Bug 698

Summary: Redo command cannot performed after an undo command
Product: River-Crossing-Puzzle-Solver Reporter: tsunychau2-c
Component: UIAssignee: tsunychau2-c
Status: RESOLVED FIXED    
Severity: normal    
Priority: High    
Version: v0.1.0   
Hardware: PC   
OS: Mac OS   

Description tsunychau2-c 2022-11-05 22:33:10 HKT
Way to Reproduce:

1. Run Main.java inside folder Default

2. Input "2" on the console for choosing Player Mode

3. Input "1" for choosing game level

4. Input "farmer" on the console

5. Input "sheep" on the console

6. Input "s" on the console to start the boat

7. Input "u" on the console to undo previous step

8. Input "r" on the console to undo previous step

Actual Result:

Please use the following command to take action: 
FULL NAME 			 Choose a role on the boat side and Enter the full role name put the role to the boat
's' 				 To start the boat
'e' 				 To exit the program
'u' 				 To undo the action if exist
'r' 				 To redo the action if exist
You command: r
Sorry nothing can be redo!



= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 
~ ~ ~ ~ ~ ~ ~ . . . . . . . . . B o a t . . . . . . . . . ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 
~ ~ ~ ~ ~ ~ ~ [                                         ]~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
farmer tiger sheep grass 

---------------------------------------------------------------------------------------------------------
Please use the following command to take action: 
FULL NAME 			 Choose a role on the boat side and Enter the full role name put the role to the boat
's' 				 To start the boat
'e' 				 To exit the program
'u' 				 To undo the action if exist
'r' 				 To redo the action if exist
You command: 


Expect Result:

Please use the following command to take action: 
FULL NAME 			 Choose a role on the boat side and Enter the full role name put the role to the boat
's' 				 To start the boat
'e' 				 To exit the program
'u' 				 To undo the action if exist
'r' 				 To redo the action if exist
You command: r

farmer sheep 
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
~ ~ ~ ~ ~ ~ ~ [                                         ]~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 
~ ~ ~ ~ ~ ~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= = = = = = = = = = = = = = = = = = = = = = 
tiger grass 

---------------------------------------------------------------------------------------------------------
Please use the following command to take action: 
FULL NAME 			 Choose a role on the boat side and Enter the full role name put the role to the boat
's' 				 To start the boat
'e' 				 To exit the program
'u' 				 To undo the action if exist
'r' 				 To redo the action if exist
You command:
Comment 1 tsunychau2-c 2022-11-05 22:33:30 HKT
Bug is confirmed
Comment 2 tsunychau2-c 2022-11-05 22:35:39 HKT
In RedoHandlerCommand.java, on line 23, gameState.undoRedoPointer should be <  gameState.history.size().

Modification of code:

public boolean canRedo() {
		if(gameState.undoRedoPointer < gameState.history.size() && gameState.round.getTravelers().size() == 0 && gameState.history.size() > 1)
			return true;
		else
			return false;
		
	}