From afc39b78e0f5fc0a95f5f53d53dd4ca994e0b7bb Mon Sep 17 00:00:00 2001 From: Christopher Beckmann Date: Sun, 22 Nov 2015 14:34:07 +0100 Subject: [PATCH] QQWing Solver now works for 6x6. Still a lot of work left. --- .../sudoku/controller/QQWingController.java | 12 ++++++++- .../sudoku/controller/qqwing/QQWing.java | 25 ++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/tu_darmstadt/sudoku/controller/QQWingController.java b/app/src/main/java/tu_darmstadt/sudoku/controller/QQWingController.java index b7cc413..3230d10 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/controller/QQWingController.java +++ b/app/src/main/java/tu_darmstadt/sudoku/controller/QQWingController.java @@ -33,6 +33,7 @@ public class QQWingController { // TODO: GameType options. opts.gameDifficulty = difficulty; opts.action = Action.GENERATE; + opts.threads = Runtime.getRuntime().availableProcessors(); doAction(type); return generated; } @@ -52,7 +53,12 @@ public class QQWingController { opts.action = Action.SOLVE; opts.printSolution = true; + opts.threads = 1; doAction(gameBoard.getGameType()); + if(solveImpossible) { + // TODO: do something else. + + } return solution; } @@ -206,7 +212,11 @@ public class QQWingController { private boolean getPuzzleToSolve(int[] puzzle) { if(level != null) { - puzzle = level; + if(puzzle.length == level.length) { + for(int i = 0; i < level.length; i++) { + puzzle[i] = level[i]; + } + } level = null; return true; } diff --git a/app/src/main/java/tu_darmstadt/sudoku/controller/qqwing/QQWing.java b/app/src/main/java/tu_darmstadt/sudoku/controller/qqwing/QQWing.java index 11d9e10..52cc81b 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/controller/qqwing/QQWing.java +++ b/app/src/main/java/tu_darmstadt/sudoku/controller/qqwing/QQWing.java @@ -147,6 +147,18 @@ public class QQWing { BOARD_SIZE = (ROW_COL_SEC_SIZE * ROW_COL_SEC_SIZE); // 9 * 9 = 81 // 36 POSSIBILITY_SIZE = (BOARD_SIZE * ROW_COL_SEC_SIZE); // 81 * 9 + + puzzle = new int[BOARD_SIZE]; + + solution = new int[BOARD_SIZE]; + + solutionRound = new int[BOARD_SIZE]; + + possibilities = new int[POSSIBILITY_SIZE]; + + randomBoardArray = fillIncrementing(new int[BOARD_SIZE]); + + randomPossibilityArray = fillIncrementing(new int[ROW_COL_SEC_SIZE]); } private static int[] fillIncrementing(int[] arr){ @@ -765,9 +777,9 @@ public class QQWing { int rowStart = rowToFirstCell(row); boolean inOneBox = true; int rowBox = -1; - for (int i = 0; i < GRID_SIZE_COL; i++) { - for (int j = 0; j < GRID_SIZE_ROW; j++) { - int column = i * GRID_SIZE_COL + j; + for (int i = 0; i < GRID_SIZE_ROW; i++) { + for (int j = 0; j < GRID_SIZE_COL; j++) { + int column = i * GRID_SIZE_ROW + j; int position = rowColumnToCell(row, column); int valPos = getPossibilityIndex(valIndex, position); if (possibilities[valPos] == 0) { @@ -807,14 +819,15 @@ public class QQWing { return false; } + // CHECKED! private boolean pointingRowReduction(int round) { for (int valIndex = 0; valIndex < ROW_COL_SEC_SIZE; valIndex++) { for (int section = 0; section < ROW_COL_SEC_SIZE; section++) { int secStart = sectionToFirstCell(section); boolean inOneRow = true; int boxRow = -1; - for (int j = 0; j < GRID_SIZE_COL; j++) { - for (int i = 0; i < GRID_SIZE_ROW; i++) { + for (int j = 0; j < GRID_SIZE_ROW; j++) { + for (int i = 0; i < GRID_SIZE_COL; i++) { int secVal = secStart + i + (ROW_COL_SEC_SIZE * j); int valPos = getPossibilityIndex(valIndex, secVal); if (possibilities[valPos] == 0) { @@ -1509,7 +1522,7 @@ public class QQWing { */ static int cellToSectionStartCell(int cell) { return ((cell / SEC_GROUP_SIZE * SEC_GROUP_SIZE) - + (cellToColumn(cell) / GRID_SIZE_COL * GRID_SIZE_ROW)); + + (cellToColumn(cell) / GRID_SIZE_COL * GRID_SIZE_COL)); } /**