Steps to Reproduce: 1. Create a Solver object (Solver s = new Solver();) 2. Create an ArrayList to store the moves (ArrayList <Move> result_moves = s.getLegalMoves(p, node);) 3. Print out every moves inside the ArrayList. Actual Result: [Move [farmer, farmer] from LandA to LandB, Move [farmer, grass] from LandA to LandB, Move [farmer, tiger] from LandA to LandB] Expect Result: [Move [farmer] from LandA to LandB, Move [farmer, grass] from LandA to LandB, Move [farmer, tiger] from LandA to LandB]
Bug is confirmed
The bug is fixed. There is a mistake on line 91 in the Solver.java. Replace roles with role. Modification of code: public ArrayList<Move> getLegalMoves(Puzzle puzzle, Node currState) { ArrayList<Move> moves = new ArrayList<Move>(); RuleSet ruleSet = new RuleSet(puzzle); HashSet<String> travelables = puzzle.getTravelables(); PuzzleState puzzleState = currState.getPuzzleState(); int origin = puzzleState.getBoatPos(); int dest = (origin==0)?1:0; ArrayList<String> roles = puzzleState.getLandByID(origin); //one traveler for(String travler : travelables) { Move move = new Move(travler,null, origin, dest); Response res = ruleSet.isValidMove(puzzleState, move); if (res.isValid()) moves.add(move); } //two travelers for(String travler : travelables) { for(String role : roles) { if(travler.equals(role)) continue; Move move = new Move(travler,role, origin, dest); Response res = ruleSet.isValidMove(puzzleState, move); if (res.isValid()) moves.add(move); } } return moves; }