Exemple #1
0
 private void executeOnlyChoiceRule() {
   accept(
       new SquareVisitor() {
         @Override
         public void visit(Square square) {
           if (square.candidates.size() == 1) {
             setValue(square, square.candidates.iterator().next());
           }
         }
       });
   boolean changeMade;
   do {
     changeMade = false;
     for (int i = 1; i <= size; i++) {
       changeMade = executeRuleTwo(i) || changeMade;
     }
   } while (changeMade);
 }
Exemple #2
0
  private boolean executeRuleTwo(final int value) {
    final boolean[] result = new boolean[1];
    result[0] = false;
    accept(
        new SquareCollectionVisitor() {

          @Override
          public void visit(SquareCollection collection) {
            RuleTwoVisitor visitor = new RuleTwoVisitor(value);
            collection.accept(visitor);
            Square candidate = visitor.getCandidate();
            if (candidate != null) {
              result[0] = true;
              setValue(candidate, value);
            }
          }
        });
    return result[0];
  }
Exemple #3
0
 public int getRemainingCandidates() {
   RemainingCandidatesVisitor visitor = new RemainingCandidatesVisitor();
   accept(visitor);
   return visitor.getRemainingCandidates();
 }
Exemple #4
0
 public int getRemainingSquares() {
   RemainingSquaresVisitor visitor = new RemainingSquaresVisitor();
   accept(visitor);
   return visitor.getRemainingSquares();
 }