| 1 | /* |
| 2 | * qqwing - A Sudoku solver and generator |
| 3 | * Copyright (C) 2006-2014 Stephen Ostermiller http://ostermiller.org/ |
| 4 | * Copyright (C) 2007 Jacques Bensimon ([email protected]) |
| 5 | * Copyright (C) 2011 Jean Guillerez (j.guillerez - orange.fr) |
| 6 | * Copyright (C) 2014 Michael Catanzaro ([email protected]) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | */ |
| 22 | #ifndef QQWING_HPP |
| 23 | #define QQWING_HPPcxx . . $ `qqwing.hpp:23:10`! |
| 24 | |
| 25 | #include <string> |
| 26 | #include <vector> |
| 27 | |
| 28 | namespace qqwingcxx . . $ qqwing/ { |
| 29 | |
| 30 | using namespace std; |
| 31 | |
| 32 | class LogItemcxx . . $ qqwing/LogItem#; |
| 33 | |
| 34 | const int GRID_SIZEcxx . . $ qqwing/GRID_SIZE. = 3; |
| 35 | const int ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE. = GRID_SIZEcxx . . $ qqwing/GRID_SIZE.*GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; |
| 36 | const int SEC_GROUP_SIZEcxx . . $ qqwing/SEC_GROUP_SIZE. = ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.*GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; |
| 37 | const int BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE. = ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.*ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; |
| 38 | const int POSSIBILITY_SIZEcxx . . $ qqwing/POSSIBILITY_SIZE. = BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.*ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; |
| 39 | |
| 40 | /** |
| 41 | * The version of QQwing, e.g. 1.2.3 |
| 42 | */ |
| 43 | stringcxx . . $ std/string# getVersioncxx . . $ qqwing/getVersion(efd28698952f529a).(); |
| 44 | |
| 45 | /** |
| 46 | * The board containing all the memory structures and |
| 47 | * methods for solving or generating sudoku puzzles. |
| 48 | */ |
| 49 | class SudokuBoardcxx . . $ qqwing/SudokuBoard# { |
| 50 | public: |
| 51 | enum PrintStylecxx . . $ qqwing/SudokuBoard#PrintStyle# { |
| 52 | ONE_LINEcxx . . $ qqwing/SudokuBoard#ONE_LINE., |
| 53 | COMPACTcxx . . $ qqwing/SudokuBoard#COMPACT., |
| 54 | READABLEcxx . . $ qqwing/SudokuBoard#READABLE., |
| 55 | CSVcxx . . $ qqwing/SudokuBoard#CSV. |
| 56 | }; |
| 57 | enum Difficultycxx . . $ qqwing/SudokuBoard#Difficulty# { |
| 58 | UNKNOWNcxx . . $ qqwing/SudokuBoard#UNKNOWN., |
| 59 | SIMPLEcxx . . $ qqwing/SudokuBoard#SIMPLE., |
| 60 | EASYcxx . . $ qqwing/SudokuBoard#EASY., |
| 61 | INTERMEDIATEcxx . . $ qqwing/SudokuBoard#INTERMEDIATE., |
| 62 | EXPERTcxx . . $ qqwing/SudokuBoard#EXPERT. |
| 63 | }; |
| 64 | enum Symmetrycxx . . $ qqwing/SudokuBoard#Symmetry# { |
| 65 | NONEcxx . . $ qqwing/SudokuBoard#NONE., |
| 66 | ROTATE90cxx . . $ qqwing/SudokuBoard#ROTATE90., |
| 67 | ROTATE180cxx . . $ qqwing/SudokuBoard#ROTATE180., |
| 68 | MIRRORcxx . . $ qqwing/SudokuBoard#MIRROR., |
| 69 | FLIPcxx . . $ qqwing/SudokuBoard#FLIP., |
| 70 | RANDOMcxx . . $ qqwing/SudokuBoard#RANDOM. |
| 71 | }; |
| 72 | SudokuBoardcxx . . $ qqwing/SudokuBoard#SudokuBoard(49f6e7a06ebc5aa8).(); |
| 73 | bool setPuzzlecxx . . $ qqwing/SudokuBoard#setPuzzle(18a3c31ed0aa5760).(int* initPuzzle); |
| 74 | const int* getPuzzlecxx . . $ qqwing/SudokuBoard#getPuzzle(22711e44a05427a).(); |
| 75 | const int* getSolutioncxx . . $ qqwing/SudokuBoard#getSolution(22711e44a05427a).(); |
| 76 | void printPuzzlecxx . . $ qqwing/SudokuBoard#printPuzzle(49f6e7a06ebc5aa8).(); |
| 77 | void printSolutioncxx . . $ qqwing/SudokuBoard#printSolution(49f6e7a06ebc5aa8).(); |
| 78 | bool solvecxx . . $ qqwing/SudokuBoard#solve(c9857a73d68e59ba).(); |
| 79 | |
| 80 | /** |
| 81 | * Count the number of solutions to the puzzle |
| 82 | */ |
| 83 | int countSolutionscxx . . $ qqwing/SudokuBoard#countSolutions(b126dc7c1de90089).(); |
| 84 | |
| 85 | /** |
| 86 | * Count the number of solutions to the puzzle |
| 87 | * but return two any time there are two or |
| 88 | * more solutions. This method will run much |
| 89 | * falter than countSolutions() when there |
| 90 | * are many possible solutions and can be used |
| 91 | * when you are interested in knowing if the |
| 92 | * puzzle has zero, one, or multiple solutions. |
| 93 | */ |
| 94 | int countSolutionsLimitedcxx . . $ qqwing/SudokuBoard#countSolutionsLimited(b126dc7c1de90089).(); |
| 95 | |
| 96 | /** |
| 97 | * return true if the puzzle has a solution |
| 98 | * and only a single solution |
| 99 | */ |
| 100 | bool hasUniqueSolutioncxx . . $ qqwing/SudokuBoard#hasUniqueSolution(c9857a73d68e59ba).(); |
| 101 | bool isSolvedcxx . . $ qqwing/SudokuBoard#isSolved(c9857a73d68e59ba).(); |
| 102 | void printSolveHistorycxx . . $ qqwing/SudokuBoard#printSolveHistory(49f6e7a06ebc5aa8).(); |
| 103 | void setRecordHistorycxx . . $ qqwing/SudokuBoard#setRecordHistory(b45ddcbc8423892c).(bool recHistory); |
| 104 | void setLogHistorycxx . . $ qqwing/SudokuBoard#setLogHistory(b45ddcbc8423892c).(bool logHist); |
| 105 | void setPrintStylecxx . . $ qqwing/SudokuBoard#setPrintStyle(d669926821d8d926).(PrintStylecxx . . $ qqwing/SudokuBoard#PrintStyle# ps); |
| 106 | bool generatePuzzlecxx . . $ qqwing/SudokuBoard#generatePuzzle(c9857a73d68e59ba).(); |
| 107 | bool generatePuzzleSymmetrycxx . . $ qqwing/SudokuBoard#generatePuzzleSymmetry(5cd0e10cf5c8b28a).(SudokuBoardcxx . . $ qqwing/SudokuBoard#::Symmetrycxx . . $ qqwing/SudokuBoard#Symmetry# symmetry); |
| 108 | int getGivenCountcxx . . $ qqwing/SudokuBoard#getGivenCount(b126dc7c1de90089).(); |
| 109 | int getSingleCountcxx . . $ qqwing/SudokuBoard#getSingleCount(b126dc7c1de90089).(); |
| 110 | int getHiddenSingleCountcxx . . $ qqwing/SudokuBoard#getHiddenSingleCount(b126dc7c1de90089).(); |
| 111 | int getNakedPairCountcxx . . $ qqwing/SudokuBoard#getNakedPairCount(b126dc7c1de90089).(); |
| 112 | int getHiddenPairCountcxx . . $ qqwing/SudokuBoard#getHiddenPairCount(b126dc7c1de90089).(); |
| 113 | int getBoxLineReductionCountcxx . . $ qqwing/SudokuBoard#getBoxLineReductionCount(b126dc7c1de90089).(); |
| 114 | int getPointingPairTripleCountcxx . . $ qqwing/SudokuBoard#getPointingPairTripleCount(b126dc7c1de90089).(); |
| 115 | int getGuessCountcxx . . $ qqwing/SudokuBoard#getGuessCount(b126dc7c1de90089).(); |
| 116 | int getBacktrackCountcxx . . $ qqwing/SudokuBoard#getBacktrackCount(b126dc7c1de90089).(); |
| 117 | void printSolveInstructionscxx . . $ qqwing/SudokuBoard#printSolveInstructions(49f6e7a06ebc5aa8).(); |
| 118 | SudokuBoardcxx . . $ qqwing/SudokuBoard#::Difficultycxx . . $ qqwing/SudokuBoard#Difficulty# getDifficultycxx . . $ qqwing/SudokuBoard#getDifficulty(d24da0b16ec1332b).(); |
| 119 | stringcxx . . $ std/string# getDifficultyAsStringcxx . . $ qqwing/SudokuBoard#getDifficultyAsString(efd28698952f529a).(); |
| 120 | ~cxx . . $ qqwing/SudokuBoard#`~SudokuBoard`(ced63f7c635d850d).SudokuBoardcxx . . $ qqwing/SudokuBoard#(); |
| 121 | |
| 122 | private: |
| 123 | /** |
| 124 | * The 81 integers that make up a sudoku puzzle. |
| 125 | * Givens are 1-9, unknowns are 0. |
| 126 | * Once initialized, this puzzle remains as is. |
| 127 | * The answer is worked out in "solution". |
| 128 | */ |
| 129 | int* puzzlecxx . . $ qqwing/SudokuBoard#puzzle.; |
| 130 | |
| 131 | /** |
| 132 | * The 81 integers that make up a sudoku puzzle. |
| 133 | * The solution is built here, after completion |
| 134 | * all will be 1-9. |
| 135 | */ |
| 136 | int* solutioncxx . . $ qqwing/SudokuBoard#solution.; |
| 137 | |
| 138 | /** |
| 139 | * Recursion depth at which each of the numbers |
| 140 | * in the solution were placed. Useful for backing |
| 141 | * out solve branches that don't lead to a solution. |
| 142 | */ |
| 143 | int* solutionRoundcxx . . $ qqwing/SudokuBoard#solutionRound.; |
| 144 | |
| 145 | /** |
| 146 | * The 729 integers that make up a the possible |
| 147 | * values for a Sudoku puzzle. (9 possibilities |
| 148 | * for each of 81 squares). If possibilities[i] |
| 149 | * is zero, then the possibility could still be |
| 150 | * filled in according to the Sudoku rules. When |
| 151 | * a possibility is eliminated, possibilities[i] |
| 152 | * is assigned the round (recursion level) at |
| 153 | * which it was determined that it could not be |
| 154 | * a possibility. |
| 155 | */ |
| 156 | int* possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.; |
| 157 | |
| 158 | /** |
| 159 | * An array the size of the board (81) containing each |
| 160 | * of the numbers 0-n exactly once. This array may |
| 161 | * be shuffled so that operations that need to |
| 162 | * look at each cell can do so in a random order. |
| 163 | */ |
| 164 | int* randomBoardArraycxx . . $ qqwing/SudokuBoard#randomBoardArray.; |
| 165 | |
| 166 | /** |
| 167 | * An array with one element for each position (9), in |
| 168 | * some random order to be used when trying each |
| 169 | * position in turn during guesses. |
| 170 | */ |
| 171 | int* randomPossibilityArraycxx . . $ qqwing/SudokuBoard#randomPossibilityArray.; |
| 172 | |
| 173 | /** |
| 174 | * Whether or not to record history |
| 175 | */ |
| 176 | bool recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.; |
| 177 | |
| 178 | /** |
| 179 | * Whether or not to print history as it happens |
| 180 | */ |
| 181 | bool logHistorycxx . . $ qqwing/SudokuBoard#logHistory.; |
| 182 | |
| 183 | /** |
| 184 | * A list of moves used to solve the puzzle. |
| 185 | * This list contains all moves, even on solve |
| 186 | * branches that did not lead to a solution. |
| 187 | */ |
| 188 | vectorcxx . . $ std/vector#<LogItemcxx . . $ qqwing/LogItem#*>* solveHistorycxx . . $ qqwing/SudokuBoard#solveHistory.; |
| 189 | |
| 190 | /** |
| 191 | * A list of moves used to solve the puzzle. |
| 192 | * This list contains only the moves needed |
| 193 | * to solve the puzzle, but doesn't contain |
| 194 | * information about bad guesses. |
| 195 | */ |
| 196 | vectorcxx . . $ std/vector#<LogItemcxx . . $ qqwing/LogItem#*>* solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions.; |
| 197 | |
| 198 | /** |
| 199 | * The style with which to print puzzles and solutions |
| 200 | */ |
| 201 | PrintStylecxx . . $ qqwing/SudokuBoard#PrintStyle# printStylecxx . . $ qqwing/SudokuBoard#printStyle.; |
| 202 | |
| 203 | /** |
| 204 | * The last round of solving |
| 205 | */ |
| 206 | int lastSolveRoundcxx . . $ qqwing/SudokuBoard#lastSolveRound.; |
| 207 | bool resetcxx . . $ qqwing/SudokuBoard#reset(c9857a73d68e59ba).(); |
| 208 | bool singleSolveMovecxx . . $ qqwing/SudokuBoard#singleSolveMove(83c267b20bac841a).(int round); |
| 209 | bool onlyPossibilityForCellcxx . . $ qqwing/SudokuBoard#onlyPossibilityForCell(83c267b20bac841a).(int round); |
| 210 | bool onlyValueInRowcxx . . $ qqwing/SudokuBoard#onlyValueInRow(83c267b20bac841a).(int round); |
| 211 | bool onlyValueInColumncxx . . $ qqwing/SudokuBoard#onlyValueInColumn(83c267b20bac841a).(int round); |
| 212 | bool onlyValueInSectioncxx . . $ qqwing/SudokuBoard#onlyValueInSection(83c267b20bac841a).(int round); |
| 213 | bool solvecxx . . $ qqwing/SudokuBoard#solve(83c267b20bac841a).(int round); |
| 214 | int countSolutionscxx . . $ qqwing/SudokuBoard#countSolutions(73da94e76e6bd037).(bool limitToTwo); |
| 215 | int countSolutionscxx . . $ qqwing/SudokuBoard#countSolutions(d455ce14f374a3ab).(int round, bool limitToTwo); |
| 216 | bool guesscxx . . $ qqwing/SudokuBoard#guess(cf9ef193275fa6d8).(int round, int guessNumber); |
| 217 | bool isImpossiblecxx . . $ qqwing/SudokuBoard#isImpossible(c9857a73d68e59ba).(); |
| 218 | void rollbackRoundcxx . . $ qqwing/SudokuBoard#rollbackRound(d4f767463ce0a6b3).(int round); |
| 219 | bool pointingRowReductioncxx . . $ qqwing/SudokuBoard#pointingRowReduction(83c267b20bac841a).(int round); |
| 220 | bool rowBoxReductioncxx . . $ qqwing/SudokuBoard#rowBoxReduction(83c267b20bac841a).(int round); |
| 221 | bool colBoxReductioncxx . . $ qqwing/SudokuBoard#colBoxReduction(83c267b20bac841a).(int round); |
| 222 | bool pointingColumnReductioncxx . . $ qqwing/SudokuBoard#pointingColumnReduction(83c267b20bac841a).(int round); |
| 223 | bool hiddenPairInRowcxx . . $ qqwing/SudokuBoard#hiddenPairInRow(83c267b20bac841a).(int round); |
| 224 | bool hiddenPairInColumncxx . . $ qqwing/SudokuBoard#hiddenPairInColumn(83c267b20bac841a).(int round); |
| 225 | bool hiddenPairInSectioncxx . . $ qqwing/SudokuBoard#hiddenPairInSection(83c267b20bac841a).(int round); |
| 226 | void markcxx . . $ qqwing/SudokuBoard#mark(b1146eedae1e1d0b).(int position, int round, int value); |
| 227 | int findPositionWithFewestPossibilitiescxx . . $ qqwing/SudokuBoard#findPositionWithFewestPossibilities(b126dc7c1de90089).(); |
| 228 | bool handleNakedPairscxx . . $ qqwing/SudokuBoard#handleNakedPairs(83c267b20bac841a).(int round); |
| 229 | int countPossibilitiescxx . . $ qqwing/SudokuBoard#countPossibilities(7864480464b09eea).(int position); |
| 230 | bool arePossibilitiesSamecxx . . $ qqwing/SudokuBoard#arePossibilitiesSame(cf9ef193275fa6d8).(int position1, int position2); |
| 231 | void addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(LogItemcxx . . $ qqwing/LogItem#* l); |
| 232 | void shuffleRandomArrayscxx . . $ qqwing/SudokuBoard#shuffleRandomArrays(49f6e7a06ebc5aa8).(); |
| 233 | void printcxx . . $ qqwing/SudokuBoard#print(11b0e290e57a7e53).(int* sudoku); |
| 234 | void rollbackNonGuessescxx . . $ qqwing/SudokuBoard#rollbackNonGuesses(49f6e7a06ebc5aa8).(); |
| 235 | void clearPuzzlecxx . . $ qqwing/SudokuBoard#clearPuzzle(49f6e7a06ebc5aa8).(); |
| 236 | void printHistorycxx . . $ qqwing/SudokuBoard#printHistory(e2ce33fb884b5958).(vectorcxx . . $ std/vector#<LogItemcxx . . $ qqwing/LogItem#*>* v); |
| 237 | bool removePossibilitiesInOneFromTwocxx . . $ qqwing/SudokuBoard#removePossibilitiesInOneFromTwo(1432650661211742).(int position1, int position2, int round); |
| 238 | }; |
| 239 | } |
| 240 | #endif |