Bug 690 - A non-travelable role can across the river
Summary: A non-travelable role can across the river
Status: RESOLVED FIXED
Alias: None
Product: River-Crossing-Puzzle-Solver
Classification: Unclassified
Component: Logic (show other bugs)
Version: v0.9.5
Hardware: PC Mac OS
: High major
Assignee: tsunychau2-c
URL:
Depends on:
Blocks:
 
Reported: 2022-11-05 19:57 HKT by tsunychau2-c
Modified: 2022-11-05 20:00 HKT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tsunychau2-c 2022-11-05 19:57:10 HKT
Way to Reproduce:
1. Create a RuleSet object 
i.e. RuleSet rs = new RuleSet(p);

2. Create a Move object 
i.e. Move m = new Move(grass,ship,0,1);

3. Call the function - isTravelable() inside RuleSet class.
i.e. boolean result = rs.isTravelable(m);

Actual Result:

result = True

Expect Result:

result = False
Comment 1 tsunychau2-c 2022-11-05 19:57:58 HKT
Bug is confirmed
Comment 2 tsunychau2-c 2022-11-05 20:00:37 HKT
The problem is fixed now. Since puzzle.getTravelables().containskey(role) in line 62 will always return true. It should be changed to puzzle.getTravelables().contains(role) and using hashset instead of hashmap.

Modification of code:
public boolean isTravelable(Move move)
	{
		ArrayList<String> travelers = move.getTravelers();
		
		boolean travelFlag = false;
		for (String role: travelers)
			if(puzzle.getTravelables().contains(role) == true)
				travelFlag = true;
		
		return travelFlag;
	}