Bug 690

Summary: A non-travelable role can across the river
Product: River-Crossing-Puzzle-Solver Reporter: tsunychau2-c
Component: LogicAssignee: tsunychau2-c
Status: RESOLVED FIXED    
Severity: major    
Priority: High    
Version: v0.9.5   
Hardware: PC   
OS: Mac OS   

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;
	}