| Summary: | Function-GetLegalMoves() return a set of duplicate character | ||
|---|---|---|---|
| Product: | River-Crossing-Puzzle-Solver | Reporter: | tsunychau2-c |
| Component: | Logic | Assignee: | tsunychau2-c |
| Status: | RESOLVED FIXED | ||
| Severity: | enhancement | ||
| Priority: | Normal | ||
| Version: | v0.1.0 | ||
| Hardware: | PC | ||
| OS: | Mac OS | ||
|
Description
tsunychau2-c
2022-11-05 17:57:49 HKT
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;
}
|