I'm making a peg solitaire resolver with backtracking in java.
This is the method I've done:
private void solve(Board board, ArrayList<Movement> solution, Boolean result) {
ArrayList<Movement> movs = board.getMovements();
for (Movement movement : movs) {
if (board.isMovementValid(movement)) {
board.doMovement(movement);
if(!board.isSolution()) {
solution.add(movement);
solve(board, solution, result);
result.setValue(false);
} else {
result.setValue(true);
}
}
}
result.setValue(false);
}
The problem is that I can't find the solution. Here is the output of the code: http://pastebin.com/raw.php?i=BhkLu3qr. As you can see the solution array is incomplete.
Thanks.