src/main/java/de/uapcore/sudoku/Solver.java

changeset 10
369903afbb29
parent 9
576e7a2861ae
child 12
1c62c6009161
     1.1 --- a/src/main/java/de/uapcore/sudoku/Solver.java	Sat Jul 25 14:01:28 2020 +0200
     1.2 +++ b/src/main/java/de/uapcore/sudoku/Solver.java	Sat Jul 25 15:29:51 2020 +0200
     1.3 @@ -30,14 +30,10 @@
     1.4  import java.util.List;
     1.5  
     1.6  /**
     1.7 - *
     1.8 - * @author mike
     1.9 + * Implements the backtracking algorithm for solving the Sudoku.
    1.10   */
    1.11  public final class Solver {
    1.12 -    
    1.13 -    public Solver() {
    1.14 -    }
    1.15 -    
    1.16 +
    1.17      private Integer fillInCandidate(Field f, List<Integer>[][] candidates, int x, int y) {
    1.18          Integer c = candidates[x][y].remove(0);
    1.19          f.setCellValue(x, y, c);
    1.20 @@ -138,7 +134,17 @@
    1.21          
    1.22          return true;
    1.23      }
    1.24 -    
    1.25 +
    1.26 +    /**
    1.27 +     * Attempts to solve the given Sudoku field.
    1.28 +     *
    1.29 +     * The solution, if any, is directly entered into the field.
    1.30 +     * All solved fields will be in modified state.
    1.31 +     * The already given fields are left untouched.
    1.32 +     *
    1.33 +     * @param f the field to solve
    1.34 +     * @return true if a solution could be found, false if the field is unsolvable
    1.35 +     */
    1.36      public boolean solve(Field f) {
    1.37          
    1.38          // Calculate initial candidates
    1.39 @@ -175,7 +181,13 @@
    1.40          // Backtrack
    1.41          return solve(f, candidates);
    1.42      }
    1.43 -    
    1.44 +
    1.45 +    /**
    1.46 +     * Performs a fast check whether any field violates the Sudoku rules.
    1.47 +     *
    1.48 +     * @param f the field to check
    1.49 +     * @return true, if the check succeeds, false otherwise
    1.50 +     */
    1.51      public boolean check(Field f) {
    1.52          int line[];
    1.53          for (int i = 0 ; i < 9 ; i++) {

mercurial