@Test public void testSolveWithExampleProblem() { byte[][] riddleBytes = QuadraticArrays.parse( "......3..", "9.3....2.", ".....8.1.", ".........", "6...2..51", "..8.5.79.", "73.5..96.", "5....2...", "29.7.158."); RiddleImpl riddle = new RiddleImpl(); riddle.setAll(riddleBytes); byte[][] solutionBytes = QuadraticArrays.parse( "862419375", "913675428", "475238619", "159847236", "647923851", "328156794", "731584962", "586392147", "294761583"); GameMatrixImpl solution = new GameMatrixImpl(); solution.setAll(solutionBytes); Solver solver = new Solver(riddle); List<GameMatrix> solutions = solver.solve(); assertEquals(1, solutions.size()); assertEquals(solution, solutions.get(0)); }
public List<GameMatrix> solve() { possibleSolutions.clear(); int freeCells = GameMatrix.TOTAL_FIELDS - riddle.getSetCount(); backtrack(freeCells, new int[2]); return Collections.unmodifiableList(possibleSolutions); }
Solver { public List<GameMatrix> solve() { possibleSolutions.clear(); int freeCells = GameMatrix.TOTAL_FIELDS - riddle.getSetCount(); backtrack(freeCells, new int[2]); return Collections.unmodifiableList(possibleSolutions); } }
Solver { public List<GameMatrix> solve() { possibleSolutions.clear(); int freeCells = GameMatrix.TOTAL_FIELDS - riddle.getSetCount(); backtrack(freeCells, new int[2]); return Collections.unmodifiableList(possibleSolutions); } Solver(final GameMatrix solveMe); }
Solver { public List<GameMatrix> solve() { possibleSolutions.clear(); int freeCells = GameMatrix.TOTAL_FIELDS - riddle.getSetCount(); backtrack(freeCells, new int[2]); return Collections.unmodifiableList(possibleSolutions); } Solver(final GameMatrix solveMe); void setLimit(final int set); List<GameMatrix> solve(); }
Solver { public List<GameMatrix> solve() { possibleSolutions.clear(); int freeCells = GameMatrix.TOTAL_FIELDS - riddle.getSetCount(); backtrack(freeCells, new int[2]); return Collections.unmodifiableList(possibleSolutions); } Solver(final GameMatrix solveMe); void setLimit(final int set); List<GameMatrix> solve(); static final int LIMIT; }