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
Bug is confirmed
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; }