Debian Codegraph @

qqwing.cpp

raw symbols SCIP
1 /*
2 * qqwing - 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 #include "config.h"cxx . . $ `<file>/config.h`/
23
24 #include <cstdlib>
25 #include <iostream>
26
27 #include "qqwing.hpp"cxx . . $ `<file>/qqwing.hpp`/
28
29 namespace qqwingcxx . . $ qqwing/ {
30
31 stringcxx . . $ std/string# getVersioncxx . . $ qqwing/getVersion(efd28698952f529a).(){
32 return VERSIONcxx . . $ `config.h:78:9`!;
33 }
34
35 /**
36 * While solving the puzzle, log steps taken in a log item.
37 * This is useful for later printing out the solve history
38 * or gathering statistics about how hard the puzzle was to
39 * solve.
40 */
41 class LogItemcxx . . $ qqwing/LogItem# {
42 public:
43 enum LogTypecxx . . $ qqwing/LogItem#LogType# {
44 GIVENcxx . . $ qqwing/LogItem#GIVEN.,
45 SINGLEcxx . . $ qqwing/LogItem#SINGLE.,
46 HIDDEN_SINGLE_ROWcxx . . $ qqwing/LogItem#HIDDEN_SINGLE_ROW.,
47 HIDDEN_SINGLE_COLUMNcxx . . $ qqwing/LogItem#HIDDEN_SINGLE_COLUMN.,
48 HIDDEN_SINGLE_SECTIONcxx . . $ qqwing/LogItem#HIDDEN_SINGLE_SECTION.,
49 GUESScxx . . $ qqwing/LogItem#GUESS.,
50 ROLLBACKcxx . . $ qqwing/LogItem#ROLLBACK.,
51 NAKED_PAIR_ROWcxx . . $ qqwing/LogItem#NAKED_PAIR_ROW.,
52 NAKED_PAIR_COLUMNcxx . . $ qqwing/LogItem#NAKED_PAIR_COLUMN.,
53 NAKED_PAIR_SECTIONcxx . . $ qqwing/LogItem#NAKED_PAIR_SECTION.,
54 POINTING_PAIR_TRIPLE_ROWcxx . . $ qqwing/LogItem#POINTING_PAIR_TRIPLE_ROW.,
55 POINTING_PAIR_TRIPLE_COLUMNcxx . . $ qqwing/LogItem#POINTING_PAIR_TRIPLE_COLUMN.,
56 ROW_BOXcxx . . $ qqwing/LogItem#ROW_BOX.,
57 COLUMN_BOXcxx . . $ qqwing/LogItem#COLUMN_BOX.,
58 HIDDEN_PAIR_ROWcxx . . $ qqwing/LogItem#HIDDEN_PAIR_ROW.,
59 HIDDEN_PAIR_COLUMNcxx . . $ qqwing/LogItem#HIDDEN_PAIR_COLUMN.,
60 HIDDEN_PAIR_SECTIONcxx . . $ qqwing/LogItem#HIDDEN_PAIR_SECTION.
61 };
62 LogItemcxx . . $ qqwing/LogItem#LogItem(16ed3834183c0131).(int round, LogTypecxx . . $ qqwing/LogItem#LogType# type);
63 LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(int round, LogTypecxx . . $ qqwing/LogItem#LogType# type, int value, int position);
64 int getRoundcxx . . $ qqwing/LogItem#getRound(b126dc7c1de90089).();
65 void printcxx . . $ qqwing/LogItem#print(49f6e7a06ebc5aa8).();
66 LogTypecxx . . $ qqwing/LogItem#LogType# getTypecxx . . $ qqwing/LogItem#getType(5dbf097fb2db9719).();
67 ~cxx . . $ qqwing/LogItem#`~LogItem`(ced63f7c635d850d).LogItemcxx . . $ qqwing/LogItem#();
68 private:
69 void initcxx . . $ qqwing/LogItem#init(e8fb13d4a1fc0532).(int round, LogTypecxx . . $ qqwing/LogItem#LogType# type, int value, int position);
70 /**
71 * The recursion level at which this item was gathered.
72 * Used for backing out log items solve branches that
73 * don't lead to a solution.
74 */
75 int roundcxx . . $ qqwing/LogItem#round.;
76
77 /**
78 * The type of log message that will determine the
79 * message printed.
80 */
81 LogTypecxx . . $ qqwing/LogItem#LogType# typecxx . . $ qqwing/LogItem#type.;
82
83 /**
84 * Value that was set by the operation (or zero for no value)
85 */
86 int valuecxx . . $ qqwing/LogItem#value.;
87
88 /**
89 * position on the board at which the value (if any) was set.
90 */
91 int positioncxx . . $ qqwing/LogItem#position.;
92 };
93
94 void shuffleArraycxx . . $ qqwing/shuffleArray(621ccea12ecf5b06).(int* array, int size);
95 SudokuBoardcxx . . $ qqwing/SudokuBoard#::Symmetrycxx . . $ qqwing/SudokuBoard#Symmetry# getRandomSymmetrycxx . . $ qqwing/getRandomSymmetry(40885f473ab4624b).();
96 int getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(vectorcxx . . $ std/vector#<LogItemcxx . . $ qqwing/LogItem#*>* v, LogItemcxx . . $ qqwing/LogItem#::LogTypecxx . . $ qqwing/LogItem#LogType# type);
97 static inline int cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(int cell);
98 static inline int cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(int cell);
99 static inline int cellToSectionStartCellcxx . . $ qqwing/cellToSectionStartCell(7864480464b09eea).(int cell);
100 static inline int cellToSectioncxx . . $ qqwing/cellToSection(7864480464b09eea).(int cell);
101 static inline int rowToFirstCellcxx . . $ qqwing/rowToFirstCell(7864480464b09eea).(int row);
102 static inline int columnToFirstCellcxx . . $ qqwing/columnToFirstCell(7864480464b09eea).(int column);
103 static inline int sectionToFirstCellcxx . . $ qqwing/sectionToFirstCell(7864480464b09eea).(int section);
104 static inline int getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(int valueIndex, int cell);
105 static inline int rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(int row, int column);
106 static inline int sectionToCellcxx . . $ qqwing/sectionToCell(9b79fb6aee4c0440).(int section, int offset);
107
108 /**
109 * Create a new Sudoku board
110 */
111 SudokuBoardcxx . . $ qqwing/SudokuBoard#::SudokuBoardcxx . . $ qqwing/SudokuBoard#SudokuBoard(49f6e7a06ebc5aa8).() :
112 puzzlecxx . . $ qqwing/SudokuBoard#puzzle. ( new int[BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.] ),
113 solutioncxx . . $ qqwing/SudokuBoard#solution. ( new int[BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.] ),
114 solutionRoundcxx . . $ qqwing/SudokuBoard#solutionRound. ( new int[BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.] ),
115 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities. ( new int[POSSIBILITY_SIZEcxx . . $ qqwing/POSSIBILITY_SIZE.] ),
116 randomBoardArraycxx . . $ qqwing/SudokuBoard#randomBoardArray. ( new int[BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.] ),
117 randomPossibilityArraycxx . . $ qqwing/SudokuBoard#randomPossibilityArray. ( new int[ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.] ),
118 recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory. ( false ),
119 logHistorycxx . . $ qqwing/SudokuBoard#logHistory.( false ),
120 solveHistorycxx . . $ qqwing/SudokuBoard#solveHistory. ( new vectorcxx . . $ std/vector#<LogItemcxx . . $ qqwing/LogItem#*>() ),
121 solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions. ( new vectorcxx . . $ std/vector#<LogItemcxx . . $ qqwing/LogItem#*>() ),
122 printStylecxx . . $ qqwing/SudokuBoard#printStyle. ( READABLEcxx . . $ qqwing/SudokuBoard#READABLE. ),
123 lastSolveRoundcxx . . $ qqwing/SudokuBoard#lastSolveRound. (0)
124 {
125 {for (int i=0; i<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; i++){
126 randomBoardArraycxx . . $ qqwing/SudokuBoard#randomBoardArray.[i] = i;
127 }}
128 {for (int i=0; i<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; i++){
129 randomPossibilityArraycxx . . $ qqwing/SudokuBoard#randomPossibilityArray.[i] = i;
130 }}
131 }
132
133 /**
134 * Get the number of cells that are
135 * set in the puzzle (as opposed to
136 * figured out in the solution
137 */
138 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::getGivenCountcxx . . $ qqwing/SudokuBoard#getGivenCount(b126dc7c1de90089).(){
139 int count = 0;
140 {for (int i=0; i<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; i++){
141 if (puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[i] != 0) count++;
142 }}
143 return count;
144 }
145
146 /**
147 * Set the board to the given puzzle.
148 * The given puzzle must be an array of 81 integers.
149 */
150 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::setPuzzlecxx . . $ qqwing/SudokuBoard#setPuzzle(18a3c31ed0aa5760).(int* initPuzzle){
151 {for (int i=0; i<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; i++){
152 puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[i] = (initPuzzle==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)?0:initPuzzle[i];
153 }}
154 return resetcxx . . $ qqwing/SudokuBoard#reset(c9857a73d68e59ba).();
155 }
156
157 /**
158 * Retrieves the puzzle as an unmodifiable array of 81 integers.
159 */
160 const int* SudokuBoardcxx . . $ qqwing/SudokuBoard#::getPuzzlecxx . . $ qqwing/SudokuBoard#getPuzzle(22711e44a05427a).(){
161 return puzzlecxx . . $ qqwing/SudokuBoard#puzzle.;
162 }
163
164 /**
165 * Retrieves the puzzle's solution as an unmodifiable array of 81 integers.
166 */
167 const int* SudokuBoardcxx . . $ qqwing/SudokuBoard#::getSolutioncxx . . $ qqwing/SudokuBoard#getSolution(22711e44a05427a).(){
168 return solutioncxx . . $ qqwing/SudokuBoard#solution.;
169 }
170
171 /**
172 * Reset the board to its initial state with
173 * only the givens.
174 * This method clears any solution, resets statistics,
175 * and clears any history messages.
176 */
177 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::resetcxx . . $ qqwing/SudokuBoard#reset(c9857a73d68e59ba).(){
178 {for (int i=0; i<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; i++){
179 solutioncxx . . $ qqwing/SudokuBoard#solution.[i] = 0;
180 }}
181 {for (int i=0; i<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; i++){
182 solutionRoundcxx . . $ qqwing/SudokuBoard#solutionRound.[i] = 0;
183 }}
184 {for (int i=0; i<POSSIBILITY_SIZEcxx . . $ qqwing/POSSIBILITY_SIZE.; i++){
185 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[i] = 0;
186 }}
187
188 {for (unsigned int i=0; i<solveHistorycxx . . $ qqwing/SudokuBoard#solveHistory.->sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++){
189 delete solveHistorycxx . . $ qqwing/SudokuBoard#solveHistory.->atcxx . . $ std/vector#at(428bb168810b9e52).(i);
190 }}
191 solveHistorycxx . . $ qqwing/SudokuBoard#solveHistory.->clearcxx . . $ std/vector#clear(ced63f7c635d850d).();
192 solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions.->clearcxx . . $ std/vector#clear(ced63f7c635d850d).();
193
194 int round = 1;
195 for (int position=0; position<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; position++){
196 if (puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[position] > 0){
197 int valIndex = puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[position]-1;
198 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
199 int value = puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[position];
200 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] != 0) return false;
201 markcxx . . $ qqwing/SudokuBoard#mark(b1146eedae1e1d0b).(position,round,value);
202 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::GIVENcxx . . $ qqwing/LogItem#GIVEN., value, position));
203 }
204 }
205 return true;
206 }
207
208 /**
209 * Get the difficulty rating.
210 */
211 SudokuBoardcxx . . $ qqwing/SudokuBoard#::Difficultycxx . . $ qqwing/SudokuBoard#Difficulty# SudokuBoardcxx . . $ qqwing/SudokuBoard#::getDifficultycxx . . $ qqwing/SudokuBoard#getDifficulty(d24da0b16ec1332b).(){
212 if (getGuessCountcxx . . $ qqwing/SudokuBoard#getGuessCount(b126dc7c1de90089).() > 0) return SudokuBoardcxx . . $ qqwing/SudokuBoard#::EXPERTcxx . . $ qqwing/SudokuBoard#EXPERT.;
213 if (getBoxLineReductionCountcxx . . $ qqwing/SudokuBoard#getBoxLineReductionCount(b126dc7c1de90089).() > 0) return SudokuBoardcxx . . $ qqwing/SudokuBoard#::INTERMEDIATEcxx . . $ qqwing/SudokuBoard#INTERMEDIATE.;
214 if (getPointingPairTripleCountcxx . . $ qqwing/SudokuBoard#getPointingPairTripleCount(b126dc7c1de90089).() > 0) return SudokuBoardcxx . . $ qqwing/SudokuBoard#::INTERMEDIATEcxx . . $ qqwing/SudokuBoard#INTERMEDIATE.;
215 if (getHiddenPairCountcxx . . $ qqwing/SudokuBoard#getHiddenPairCount(b126dc7c1de90089).() > 0) return SudokuBoardcxx . . $ qqwing/SudokuBoard#::INTERMEDIATEcxx . . $ qqwing/SudokuBoard#INTERMEDIATE.;
216 if (getNakedPairCountcxx . . $ qqwing/SudokuBoard#getNakedPairCount(b126dc7c1de90089).() > 0) return SudokuBoardcxx . . $ qqwing/SudokuBoard#::INTERMEDIATEcxx . . $ qqwing/SudokuBoard#INTERMEDIATE.;
217 if (getHiddenSingleCountcxx . . $ qqwing/SudokuBoard#getHiddenSingleCount(b126dc7c1de90089).() > 0) return SudokuBoardcxx . . $ qqwing/SudokuBoard#::EASYcxx . . $ qqwing/SudokuBoard#EASY.;
218 if (getSingleCountcxx . . $ qqwing/SudokuBoard#getSingleCount(b126dc7c1de90089).() > 0) return SudokuBoardcxx . . $ qqwing/SudokuBoard#::SIMPLEcxx . . $ qqwing/SudokuBoard#SIMPLE.;
219 return SudokuBoardcxx . . $ qqwing/SudokuBoard#::UNKNOWNcxx . . $ qqwing/SudokuBoard#UNKNOWN.;
220 }
221
222 /**
223 * Get the difficulty rating.
224 */
225 stringcxx . . $ std/string# SudokuBoardcxx . . $ qqwing/SudokuBoard#::getDifficultyAsStringcxx . . $ qqwing/SudokuBoard#getDifficultyAsString(efd28698952f529a).(){
226 SudokuBoardcxx . . $ qqwing/SudokuBoard#::Difficultycxx . . $ qqwing/SudokuBoard#Difficulty# difficulty = getDifficultycxx . . $ qqwing/SudokuBoard#getDifficulty(d24da0b16ec1332b).();
227 switch (difficulty){
228 case SudokuBoardcxx . . $ qqwing/SudokuBoard#::EXPERTcxx . . $ qqwing/SudokuBoard#EXPERT.: return "Expert"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
229 case SudokuBoardcxx . . $ qqwing/SudokuBoard#::INTERMEDIATEcxx . . $ qqwing/SudokuBoard#INTERMEDIATE.: return "Intermediate"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
230 case SudokuBoardcxx . . $ qqwing/SudokuBoard#::EASYcxx . . $ qqwing/SudokuBoard#EASY.: return "Easy"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
231 case SudokuBoardcxx . . $ qqwing/SudokuBoard#::SIMPLEcxx . . $ qqwing/SudokuBoard#SIMPLE.: return "Simple"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
232 default: return "Unknown"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
233 }
234 }
235
236 /**
237 * Get the number of cells for which the solution was determined
238 * because there was only one possible value for that cell.
239 */
240 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::getSingleCountcxx . . $ qqwing/SudokuBoard#getSingleCount(b126dc7c1de90089).(){
241 return getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::SINGLEcxx . . $ qqwing/LogItem#SINGLE.);
242 }
243
244 /**
245 * Get the number of cells for which the solution was determined
246 * because that cell had the only possibility for some value in
247 * the row, column, or section.
248 */
249 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::getHiddenSingleCountcxx . . $ qqwing/SudokuBoard#getHiddenSingleCount(b126dc7c1de90089).(){
250 return getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::HIDDEN_SINGLE_ROWcxx . . $ qqwing/LogItem#HIDDEN_SINGLE_ROW.) +
251 getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::HIDDEN_SINGLE_COLUMNcxx . . $ qqwing/LogItem#HIDDEN_SINGLE_COLUMN.) +
252 getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::HIDDEN_SINGLE_SECTIONcxx . . $ qqwing/LogItem#HIDDEN_SINGLE_SECTION.);
253 }
254
255 /**
256 * Get the number of naked pair reductions that were performed
257 * in solving this puzzle.
258 */
259 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::getNakedPairCountcxx . . $ qqwing/SudokuBoard#getNakedPairCount(b126dc7c1de90089).(){
260 return getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::NAKED_PAIR_ROWcxx . . $ qqwing/LogItem#NAKED_PAIR_ROW.) +
261 getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::NAKED_PAIR_COLUMNcxx . . $ qqwing/LogItem#NAKED_PAIR_COLUMN.) +
262 getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::NAKED_PAIR_SECTIONcxx . . $ qqwing/LogItem#NAKED_PAIR_SECTION.);
263 }
264
265 /**
266 * Get the number of hidden pair reductions that were performed
267 * in solving this puzzle.
268 */
269 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::getHiddenPairCountcxx . . $ qqwing/SudokuBoard#getHiddenPairCount(b126dc7c1de90089).(){
270 return getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::HIDDEN_PAIR_ROWcxx . . $ qqwing/LogItem#HIDDEN_PAIR_ROW.) +
271 getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::HIDDEN_PAIR_COLUMNcxx . . $ qqwing/LogItem#HIDDEN_PAIR_COLUMN.) +
272 getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::HIDDEN_PAIR_SECTIONcxx . . $ qqwing/LogItem#HIDDEN_PAIR_SECTION.);
273 }
274
275 /**
276 * Get the number of pointing pair/triple reductions that were performed
277 * in solving this puzzle.
278 */
279 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::getPointingPairTripleCountcxx . . $ qqwing/SudokuBoard#getPointingPairTripleCount(b126dc7c1de90089).(){
280 return getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::POINTING_PAIR_TRIPLE_ROWcxx . . $ qqwing/LogItem#POINTING_PAIR_TRIPLE_ROW.)+
281 getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::POINTING_PAIR_TRIPLE_COLUMNcxx . . $ qqwing/LogItem#POINTING_PAIR_TRIPLE_COLUMN.);
282 }
283
284 /**
285 * Get the number of box/line reductions that were performed
286 * in solving this puzzle.
287 */
288 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::getBoxLineReductionCountcxx . . $ qqwing/SudokuBoard#getBoxLineReductionCount(b126dc7c1de90089).(){
289 return getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::ROW_BOXcxx . . $ qqwing/LogItem#ROW_BOX.)+
290 getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::COLUMN_BOXcxx . . $ qqwing/LogItem#COLUMN_BOX.);
291 }
292
293 /**
294 * Get the number lucky guesses in solving this puzzle.
295 */
296 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::getGuessCountcxx . . $ qqwing/SudokuBoard#getGuessCount(b126dc7c1de90089).(){
297 return getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions., LogItemcxx . . $ qqwing/LogItem#::GUESScxx . . $ qqwing/LogItem#GUESS.);
298 }
299
300 /**
301 * Get the number of backtracks (unlucky guesses) required
302 * when solving this puzzle.
303 */
304 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::getBacktrackCountcxx . . $ qqwing/SudokuBoard#getBacktrackCount(b126dc7c1de90089).(){
305 return getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(solveHistorycxx . . $ qqwing/SudokuBoard#solveHistory., LogItemcxx . . $ qqwing/LogItem#::ROLLBACKcxx . . $ qqwing/LogItem#ROLLBACK.);
306 }
307
308 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::shuffleRandomArrayscxx . . $ qqwing/SudokuBoard#shuffleRandomArrays(49f6e7a06ebc5aa8).(){
309 shuffleArraycxx . . $ qqwing/shuffleArray(621ccea12ecf5b06).(randomBoardArraycxx . . $ qqwing/SudokuBoard#randomBoardArray., BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.);
310 shuffleArraycxx . . $ qqwing/shuffleArray(621ccea12ecf5b06).(randomPossibilityArraycxx . . $ qqwing/SudokuBoard#randomPossibilityArray., ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.);
311 }
312
313 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::clearPuzzlecxx . . $ qqwing/SudokuBoard#clearPuzzle(49f6e7a06ebc5aa8).(){
314 // Clear any existing puzzle
315 {for (int i=0; i<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; i++){
316 puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[i] = 0;
317 }}
318 resetcxx . . $ qqwing/SudokuBoard#reset(c9857a73d68e59ba).();
319 }
320
321 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::generatePuzzlecxx . . $ qqwing/SudokuBoard#generatePuzzle(c9857a73d68e59ba).(){
322 return generatePuzzleSymmetrycxx . . $ qqwing/SudokuBoard#generatePuzzleSymmetry(5cd0e10cf5c8b28a).(SudokuBoardcxx . . $ qqwing/SudokuBoard#::NONEcxx . . $ qqwing/SudokuBoard#NONE.);
323 }
324
325 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::generatePuzzleSymmetrycxx . . $ qqwing/SudokuBoard#generatePuzzleSymmetry(5cd0e10cf5c8b28a).(SudokuBoardcxx . . $ qqwing/SudokuBoard#::Symmetrycxx . . $ qqwing/SudokuBoard#Symmetry# symmetry){
326
327 if (symmetry == SudokuBoardcxx . . $ qqwing/SudokuBoard#::RANDOMcxx . . $ qqwing/SudokuBoard#RANDOM.) symmetry = getRandomSymmetrycxx . . $ qqwing/getRandomSymmetry(40885f473ab4624b).();
328
329 // Don't record history while generating.
330 bool recHistory = recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.;
331 setRecordHistorycxx . . $ qqwing/SudokuBoard#setRecordHistory(b45ddcbc8423892c).(false);
332 bool lHistory = logHistorycxx . . $ qqwing/SudokuBoard#logHistory.;
333 setLogHistorycxx . . $ qqwing/SudokuBoard#setLogHistory(b45ddcbc8423892c).(false);
334
335 clearPuzzlecxx . . $ qqwing/SudokuBoard#clearPuzzle(49f6e7a06ebc5aa8).();
336
337 // Start by getting the randomness in order so that
338 // each puzzle will be different from the last.
339 shuffleRandomArrayscxx . . $ qqwing/SudokuBoard#shuffleRandomArrays(49f6e7a06ebc5aa8).();
340
341 // Now solve the puzzle the whole way. The solve
342 // uses random algorithms, so we should have a
343 // really randomly totally filled sudoku
344 // Even when starting from an empty grid
345 solvecxx . . $ qqwing/SudokuBoard#solve(c9857a73d68e59ba).();
346
347 if (symmetry == SudokuBoardcxx . . $ qqwing/SudokuBoard#::NONEcxx . . $ qqwing/SudokuBoard#NONE.){
348 // Rollback any square for which it is obvious that
349 // the square doesn't contribute to a unique solution
350 // (ie, squares that were filled by logic rather
351 // than by guess)
352 rollbackNonGuessescxx . . $ qqwing/SudokuBoard#rollbackNonGuesses(49f6e7a06ebc5aa8).();
353 }
354
355 // Record all marked squares as the puzzle so
356 // that we can call countSolutions without losing it.
357 {for (int i=0; i<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; i++){
358 puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[i] = solutioncxx . . $ qqwing/SudokuBoard#solution.[i];
359 }}
360
361 // Rerandomize everything so that we test squares
362 // in a different order than they were added.
363 shuffleRandomArrayscxx . . $ qqwing/SudokuBoard#shuffleRandomArrays(49f6e7a06ebc5aa8).();
364
365 // Remove one value at a time and see if
366 // the puzzle still has only one solution.
367 // If it does, leave it out the point because
368 // it is not needed.
369 {for (int i=0; i<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; i++){
370 // check all the positions, but in shuffled order
371 int position = randomBoardArraycxx . . $ qqwing/SudokuBoard#randomBoardArray.[i];
372 if (puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[position] > 0){
373 int positionsym1 = -1;
374 int positionsym2 = -1;
375 int positionsym3 = -1;
376 switch (symmetry){
377 case ROTATE90cxx . . $ qqwing/SudokuBoard#ROTATE90.:
378 positionsym2 = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.-1-cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(position),cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(position));
379 positionsym3 = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(position),ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.-1-cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(position));
380 case ROTATE180cxx . . $ qqwing/SudokuBoard#ROTATE180.:
381 positionsym1 = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.-1-cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(position),ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.-1-cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(position));
382 break;
383 case MIRRORcxx . . $ qqwing/SudokuBoard#MIRROR.:
384 positionsym1 = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(position),ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.-1-cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(position));
385 break;
386 case FLIPcxx . . $ qqwing/SudokuBoard#FLIP.:
387 positionsym1 = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.-1-cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(position),cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(position));
388 break;
389 case RANDOMcxx . . $ qqwing/SudokuBoard#RANDOM.: // NOTE: Should never happen
390 break;
391 case NONEcxx . . $ qqwing/SudokuBoard#NONE.: // NOTE: No need to do anything
392 break;
393 }
394 // try backing out the value and
395 // counting solutions to the puzzle
396 int savedValue = puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[position];
397 puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[position] = 0;
398 int savedSym1 = 0;
399 if (positionsym1 >= 0){
400 savedSym1 = puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[positionsym1];
401 puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[positionsym1] = 0;
402 }
403 int savedSym2 = 0;
404 if (positionsym2 >= 0){
405 savedSym2 = puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[positionsym2];
406 puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[positionsym2] = 0;
407 }
408 int savedSym3 = 0;
409 if (positionsym3 >= 0){
410 savedSym3 = puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[positionsym3];
411 puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[positionsym3] = 0;
412 }
413 resetcxx . . $ qqwing/SudokuBoard#reset(c9857a73d68e59ba).();
414 if (countSolutionscxx . . $ qqwing/SudokuBoard#countSolutions(d455ce14f374a3ab).(2, true) > 1){
415 // Put it back in, it is needed
416 puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[position] = savedValue;
417 if (positionsym1 >= 0 && savedSym1 != 0) puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[positionsym1] = savedSym1;
418 if (positionsym2 >= 0 && savedSym2 != 0) puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[positionsym2] = savedSym2;
419 if (positionsym3 >= 0 && savedSym3 != 0) puzzlecxx . . $ qqwing/SudokuBoard#puzzle.[positionsym3] = savedSym3;
420 }
421 }
422 }}
423
424 // Clear all solution info, leaving just the puzzle.
425 resetcxx . . $ qqwing/SudokuBoard#reset(c9857a73d68e59ba).();
426
427 // Restore recording history.
428 setRecordHistorycxx . . $ qqwing/SudokuBoard#setRecordHistory(b45ddcbc8423892c).(recHistory);
429 setLogHistorycxx . . $ qqwing/SudokuBoard#setLogHistory(b45ddcbc8423892c).(lHistory);
430
431 return true;
432
433 }
434
435 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::rollbackNonGuessescxx . . $ qqwing/SudokuBoard#rollbackNonGuesses(49f6e7a06ebc5aa8).(){
436 // Guesses are odd rounds
437 // Non-guesses are even rounds
438 {for (int i=2; i<=lastSolveRoundcxx . . $ qqwing/SudokuBoard#lastSolveRound.; i+=2){
439 rollbackRoundcxx . . $ qqwing/SudokuBoard#rollbackRound(d4f767463ce0a6b3).(i);
440 }}
441 }
442
443 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::setPrintStylecxx . . $ qqwing/SudokuBoard#setPrintStyle(d669926821d8d926).(PrintStylecxx . . $ qqwing/SudokuBoard#PrintStyle# ps){
444 printStylecxx . . $ qqwing/SudokuBoard#printStyle. = ps;
445 }
446
447 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::setRecordHistorycxx . . $ qqwing/SudokuBoard#setRecordHistory(b45ddcbc8423892c).(bool recHistory){
448 recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory. = recHistory;
449 }
450
451 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::setLogHistorycxx . . $ qqwing/SudokuBoard#setLogHistory(b45ddcbc8423892c).(bool logHist){
452 logHistorycxx . . $ qqwing/SudokuBoard#logHistory. = logHist;
453 }
454
455 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(LogItemcxx . . $ qqwing/LogItem#* l){
456 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory.){
457 l->printcxx . . $ qqwing/LogItem#print(49f6e7a06ebc5aa8).();
458 coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
459 }
460 if (recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.){
461 solveHistorycxx . . $ qqwing/SudokuBoard#solveHistory.->push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(l);
462 solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions.->push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(l);
463 } else {
464 delete l;
465 }
466 }
467
468 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::printHistorycxx . . $ qqwing/SudokuBoard#printHistory(e2ce33fb884b5958).(vectorcxx . . $ std/vector#<LogItemcxx . . $ qqwing/LogItem#*>* v){
469 if (!recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.){
470 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "History was not recorded.";
471 if (printStylecxx . . $ qqwing/SudokuBoard#printStyle. == CSVcxx . . $ qqwing/SudokuBoard#CSV.){
472 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " -- ";
473 } else {
474 coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
475 }
476 }
477 {for (unsigned int i=0;i<v->sizecxx . . $ std/vector#size(c9b1e749b64d5edc).();i++){
478 coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). i+1 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ". ";
479 v->atcxx . . $ std/vector#at(428bb168810b9e52).(i)->printcxx . . $ qqwing/LogItem#print(49f6e7a06ebc5aa8).();
480 if (printStylecxx . . $ qqwing/SudokuBoard#printStyle. == CSVcxx . . $ qqwing/SudokuBoard#CSV.){
481 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " -- ";
482 } else {
483 coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
484 }
485 }}
486 if (printStylecxx . . $ qqwing/SudokuBoard#printStyle. == CSVcxx . . $ qqwing/SudokuBoard#CSV.){
487 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ",";
488 } else {
489 coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
490 }
491 }
492
493 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::printSolveInstructionscxx . . $ qqwing/SudokuBoard#printSolveInstructions(49f6e7a06ebc5aa8).(){
494 if (isSolvedcxx . . $ qqwing/SudokuBoard#isSolved(c9857a73d68e59ba).()){
495 printHistorycxx . . $ qqwing/SudokuBoard#printHistory(e2ce33fb884b5958).(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions.);
496 } else {
497 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "No solve instructions - Puzzle is not possible to solve." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
498 }
499 }
500
501 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::printSolveHistorycxx . . $ qqwing/SudokuBoard#printSolveHistory(49f6e7a06ebc5aa8).(){
502 printHistorycxx . . $ qqwing/SudokuBoard#printHistory(e2ce33fb884b5958).(solveHistorycxx . . $ qqwing/SudokuBoard#solveHistory.);
503 }
504
505 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::solvecxx . . $ qqwing/SudokuBoard#solve(c9857a73d68e59ba).(){
506 resetcxx . . $ qqwing/SudokuBoard#reset(c9857a73d68e59ba).();
507 shuffleRandomArrayscxx . . $ qqwing/SudokuBoard#shuffleRandomArrays(49f6e7a06ebc5aa8).();
508 return solvecxx . . $ qqwing/SudokuBoard#solve(83c267b20bac841a).(2);
509 }
510
511 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::solvecxx . . $ qqwing/SudokuBoard#solve(83c267b20bac841a).(int round){
512 lastSolveRoundcxx . . $ qqwing/SudokuBoard#lastSolveRound. = round;
513
514 while (singleSolveMovecxx . . $ qqwing/SudokuBoard#singleSolveMove(83c267b20bac841a).(round)){
515 if (isSolvedcxx . . $ qqwing/SudokuBoard#isSolved(c9857a73d68e59ba).()) return true;
516 if (isImpossiblecxx . . $ qqwing/SudokuBoard#isImpossible(c9857a73d68e59ba).()) return false;
517 }
518
519 int nextGuessRound = round+1;
520 int nextRound = round+2;
521 for (int guessNumber=0; guesscxx . . $ qqwing/SudokuBoard#guess(cf9ef193275fa6d8).(nextGuessRound, guessNumber); guessNumber++){
522 if (isImpossiblecxx . . $ qqwing/SudokuBoard#isImpossible(c9857a73d68e59ba).() || !solvecxx . . $ qqwing/SudokuBoard#solve(83c267b20bac841a).(nextRound)){
523 rollbackRoundcxx . . $ qqwing/SudokuBoard#rollbackRound(d4f767463ce0a6b3).(nextRound);
524 rollbackRoundcxx . . $ qqwing/SudokuBoard#rollbackRound(d4f767463ce0a6b3).(nextGuessRound);
525 } else {
526 return true;
527 }
528 }
529 return false;
530 }
531
532 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::hasUniqueSolutioncxx . . $ qqwing/SudokuBoard#hasUniqueSolution(c9857a73d68e59ba).(){
533 return countSolutionsLimitedcxx . . $ qqwing/SudokuBoard#countSolutionsLimited(b126dc7c1de90089).() == 1;
534 }
535
536 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::countSolutionscxx . . $ qqwing/SudokuBoard#countSolutions(b126dc7c1de90089).(){
537 return countSolutionscxx . . $ qqwing/SudokuBoard#countSolutions(73da94e76e6bd037).(false);
538 }
539
540 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::countSolutionsLimitedcxx . . $ qqwing/SudokuBoard#countSolutionsLimited(b126dc7c1de90089).(){
541 return countSolutionscxx . . $ qqwing/SudokuBoard#countSolutions(73da94e76e6bd037).(true);
542 }
543
544 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::countSolutionscxx . . $ qqwing/SudokuBoard#countSolutions(73da94e76e6bd037).(bool limitToTwo){
545 // Don't record history while generating.
546 bool recHistory = recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.;
547 setRecordHistorycxx . . $ qqwing/SudokuBoard#setRecordHistory(b45ddcbc8423892c).(false);
548 bool lHistory = logHistorycxx . . $ qqwing/SudokuBoard#logHistory.;
549 setLogHistorycxx . . $ qqwing/SudokuBoard#setLogHistory(b45ddcbc8423892c).(false);
550
551 resetcxx . . $ qqwing/SudokuBoard#reset(c9857a73d68e59ba).();
552 int solutionCount = countSolutionscxx . . $ qqwing/SudokuBoard#countSolutions(d455ce14f374a3ab).(2, limitToTwo);
553
554 // Restore recording history.
555 setRecordHistorycxx . . $ qqwing/SudokuBoard#setRecordHistory(b45ddcbc8423892c).(recHistory);
556 setLogHistorycxx . . $ qqwing/SudokuBoard#setLogHistory(b45ddcbc8423892c).(lHistory);
557
558 return solutionCount;
559 }
560
561 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::countSolutionscxx . . $ qqwing/SudokuBoard#countSolutions(d455ce14f374a3ab).(int round, bool limitToTwo){
562 while (singleSolveMovecxx . . $ qqwing/SudokuBoard#singleSolveMove(83c267b20bac841a).(round)){
563 if (isSolvedcxx . . $ qqwing/SudokuBoard#isSolved(c9857a73d68e59ba).()){
564 rollbackRoundcxx . . $ qqwing/SudokuBoard#rollbackRound(d4f767463ce0a6b3).(round);
565 return 1;
566 }
567 if (isImpossiblecxx . . $ qqwing/SudokuBoard#isImpossible(c9857a73d68e59ba).()){
568 rollbackRoundcxx . . $ qqwing/SudokuBoard#rollbackRound(d4f767463ce0a6b3).(round);
569 return 0;
570 }
571 }
572
573 int solutions = 0;
574 int nextRound = round+1;
575 for (int guessNumber=0; guesscxx . . $ qqwing/SudokuBoard#guess(cf9ef193275fa6d8).(nextRound, guessNumber); guessNumber++){
576 solutions += countSolutionscxx . . $ qqwing/SudokuBoard#countSolutions(d455ce14f374a3ab).(nextRound, limitToTwo);
577 if (limitToTwo && solutions >=2){
578 rollbackRoundcxx . . $ qqwing/SudokuBoard#rollbackRound(d4f767463ce0a6b3).(round);
579 return solutions;
580 }
581 }
582 rollbackRoundcxx . . $ qqwing/SudokuBoard#rollbackRound(d4f767463ce0a6b3).(round);
583 return solutions;
584 }
585
586 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::rollbackRoundcxx . . $ qqwing/SudokuBoard#rollbackRound(d4f767463ce0a6b3).(int round){
587 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(16ed3834183c0131).(round, LogItemcxx . . $ qqwing/LogItem#::ROLLBACKcxx . . $ qqwing/LogItem#ROLLBACK.));
588 {for (int i=0; i<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; i++){
589 if (solutionRoundcxx . . $ qqwing/SudokuBoard#solutionRound.[i] == round){
590 solutionRoundcxx . . $ qqwing/SudokuBoard#solutionRound.[i] = 0;
591 solutioncxx . . $ qqwing/SudokuBoard#solution.[i] = 0;
592 }
593 }}
594 {for (int i=0; i<POSSIBILITY_SIZEcxx . . $ qqwing/POSSIBILITY_SIZE.; i++){
595 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[i] == round){
596 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[i] = 0;
597 }
598 }}
599
600 while(solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions.->sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() > 0 && solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions.->backcxx . . $ std/vector#back(6baabfa6fc7b3a8e).()->getRoundcxx . . $ qqwing/LogItem#getRound(b126dc7c1de90089).() == round){
601 solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions.->pop_backcxx . . $ std/vector#pop_back(ced63f7c635d850d).();
602 }
603 }
604
605 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::isSolvedcxx . . $ qqwing/SudokuBoard#isSolved(c9857a73d68e59ba).(){
606 {for (int i=0; i<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; i++){
607 if (solutioncxx . . $ qqwing/SudokuBoard#solution.[i] == 0){
608 return false;
609 }
610 }}
611 return true;
612 }
613
614 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::isImpossiblecxx . . $ qqwing/SudokuBoard#isImpossible(c9857a73d68e59ba).(){
615 for (int position=0; position<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; position++){
616 if (solutioncxx . . $ qqwing/SudokuBoard#solution.[position] == 0){
617 int count = 0;
618 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
619 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
620 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0) count++;
621 }
622 if (count == 0) {
623 return true;
624 }
625 }
626 }
627 return false;
628 }
629
630 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::findPositionWithFewestPossibilitiescxx . . $ qqwing/SudokuBoard#findPositionWithFewestPossibilities(b126dc7c1de90089).(){
631 int minPossibilities = 10;
632 int bestPosition = 0;
633 {for (int i=0; i<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; i++){
634 int position = randomBoardArraycxx . . $ qqwing/SudokuBoard#randomBoardArray.[i];
635 if (solutioncxx . . $ qqwing/SudokuBoard#solution.[position] == 0){
636 int count = 0;
637 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
638 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
639 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0) count++;
640 }
641 if (count < minPossibilities){
642 minPossibilities = count;
643 bestPosition = position;
644 }
645 }
646 }}
647 return bestPosition;
648 }
649
650 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::guesscxx . . $ qqwing/SudokuBoard#guess(cf9ef193275fa6d8).(int round, int guessNumber){
651 int localGuessCount = 0;
652 int position = findPositionWithFewestPossibilitiescxx . . $ qqwing/SudokuBoard#findPositionWithFewestPossibilities(b126dc7c1de90089).();
653 {for (int i=0; i<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; i++){
654 int valIndex = randomPossibilityArraycxx . . $ qqwing/SudokuBoard#randomPossibilityArray.[i];
655 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
656 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
657 if (localGuessCount == guessNumber){
658 int value = valIndex+1;
659 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::GUESScxx . . $ qqwing/LogItem#GUESS., value, position));
660 markcxx . . $ qqwing/SudokuBoard#mark(b1146eedae1e1d0b).(position, round, value);
661 return true;
662 }
663 localGuessCount++;
664 }
665 }}
666 return false;
667 }
668
669 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::singleSolveMovecxx . . $ qqwing/SudokuBoard#singleSolveMove(83c267b20bac841a).(int round){
670 if (onlyPossibilityForCellcxx . . $ qqwing/SudokuBoard#onlyPossibilityForCell(83c267b20bac841a).(round)) return true;
671 if (onlyValueInSectioncxx . . $ qqwing/SudokuBoard#onlyValueInSection(83c267b20bac841a).(round)) return true;
672 if (onlyValueInRowcxx . . $ qqwing/SudokuBoard#onlyValueInRow(83c267b20bac841a).(round)) return true;
673 if (onlyValueInColumncxx . . $ qqwing/SudokuBoard#onlyValueInColumn(83c267b20bac841a).(round)) return true;
674 if (handleNakedPairscxx . . $ qqwing/SudokuBoard#handleNakedPairs(83c267b20bac841a).(round)) return true;
675 if (pointingRowReductioncxx . . $ qqwing/SudokuBoard#pointingRowReduction(83c267b20bac841a).(round)) return true;
676 if (pointingColumnReductioncxx . . $ qqwing/SudokuBoard#pointingColumnReduction(83c267b20bac841a).(round)) return true;
677 if (rowBoxReductioncxx . . $ qqwing/SudokuBoard#rowBoxReduction(83c267b20bac841a).(round)) return true;
678 if (colBoxReductioncxx . . $ qqwing/SudokuBoard#colBoxReduction(83c267b20bac841a).(round)) return true;
679 if (hiddenPairInRowcxx . . $ qqwing/SudokuBoard#hiddenPairInRow(83c267b20bac841a).(round)) return true;
680 if (hiddenPairInColumncxx . . $ qqwing/SudokuBoard#hiddenPairInColumn(83c267b20bac841a).(round)) return true;
681 if (hiddenPairInSectioncxx . . $ qqwing/SudokuBoard#hiddenPairInSection(83c267b20bac841a).(round)) return true;
682 return false;
683 }
684
685 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::colBoxReductioncxx . . $ qqwing/SudokuBoard#colBoxReduction(83c267b20bac841a).(int round){
686 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
687 for (int col=0; col<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; col++){
688 int colStart = columnToFirstCellcxx . . $ qqwing/columnToFirstCell(7864480464b09eea).(col);
689 bool inOneBox = true;
690 int colBox = -1;
691 {for (int i=0; i<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; i++){
692 for (int j=0; j<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; j++){
693 int row = i*GRID_SIZEcxx . . $ qqwing/GRID_SIZE.+j;
694 int position = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row, col);
695 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
696 if(possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
697 if (colBox == -1 || colBox == i){
698 colBox = i;
699 } else {
700 inOneBox = false;
701 }
702 }
703
704 }
705 }}
706 if (inOneBox && colBox != -1){
707 bool doneSomething = false;
708 int row = GRID_SIZEcxx . . $ qqwing/GRID_SIZE.*colBox;
709 int secStart = cellToSectionStartCellcxx . . $ qqwing/cellToSectionStartCell(7864480464b09eea).(rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row, col));
710 int secStartRow = cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(secStart);
711 int secStartCol = cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(secStart);
712 {for (int i=0; i<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; i++){
713 for (int j=0; j<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; j++){
714 int row2 = secStartRow+i;
715 int col2 = secStartCol+j;
716 int position = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row2, col2);
717 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
718 if (col != col2 && possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
719 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] = round;
720 doneSomething = true;
721 }
722 }
723 }}
724 if (doneSomething){
725 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::COLUMN_BOXcxx . . $ qqwing/LogItem#COLUMN_BOX., valIndex+1, colStart));
726 return true;
727 }
728 }
729 }
730 }
731 return false;
732 }
733
734 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::rowBoxReductioncxx . . $ qqwing/SudokuBoard#rowBoxReduction(83c267b20bac841a).(int round){
735 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
736 for (int row=0; row<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; row++){
737 int rowStart = rowToFirstCellcxx . . $ qqwing/rowToFirstCell(7864480464b09eea).(row);
738 bool inOneBox = true;
739 int rowBox = -1;
740 {for (int i=0; i<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; i++){
741 for (int j=0; j<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; j++){
742 int column = i*GRID_SIZEcxx . . $ qqwing/GRID_SIZE.+j;
743 int position = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row, column);
744 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
745 if(possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
746 if (rowBox == -1 || rowBox == i){
747 rowBox = i;
748 } else {
749 inOneBox = false;
750 }
751 }
752
753 }
754 }}
755 if (inOneBox && rowBox != -1){
756 bool doneSomething = false;
757 int column = GRID_SIZEcxx . . $ qqwing/GRID_SIZE.*rowBox;
758 int secStart = cellToSectionStartCellcxx . . $ qqwing/cellToSectionStartCell(7864480464b09eea).(rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row, column));
759 int secStartRow = cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(secStart);
760 int secStartCol = cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(secStart);
761 {for (int i=0; i<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; i++){
762 for (int j=0; j<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; j++){
763 int row2 = secStartRow+i;
764 int col2 = secStartCol+j;
765 int position = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row2, col2);
766 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
767 if (row != row2 && possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
768 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] = round;
769 doneSomething = true;
770 }
771 }
772 }}
773 if (doneSomething){
774 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::ROW_BOXcxx . . $ qqwing/LogItem#ROW_BOX., valIndex+1, rowStart));
775 return true;
776 }
777 }
778 }
779 }
780 return false;
781 }
782
783 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::pointingRowReductioncxx . . $ qqwing/SudokuBoard#pointingRowReduction(83c267b20bac841a).(int round){
784 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
785 for (int section=0; section<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; section++){
786 int secStart = sectionToFirstCellcxx . . $ qqwing/sectionToFirstCell(7864480464b09eea).(section);
787 bool inOneRow = true;
788 int boxRow = -1;
789 for (int j=0; j<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; j++){
790 {for (int i=0; i<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; i++){
791 int secVal=secStart+i+(ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.*j);
792 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,secVal);
793 if(possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
794 if (boxRow == -1 || boxRow == j){
795 boxRow = j;
796 } else {
797 inOneRow = false;
798 }
799 }
800 }}
801 }
802 if (inOneRow && boxRow != -1){
803 bool doneSomething = false;
804 int row = cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(secStart) + boxRow;
805 int rowStart = rowToFirstCellcxx . . $ qqwing/rowToFirstCell(7864480464b09eea).(row);
806
807 {for (int i=0; i<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; i++){
808 int position = rowStart+i;
809 int section2 = cellToSectioncxx . . $ qqwing/cellToSection(7864480464b09eea).(position);
810 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
811 if (section != section2 && possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
812 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] = round;
813 doneSomething = true;
814 }
815 }}
816 if (doneSomething){
817 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::POINTING_PAIR_TRIPLE_ROWcxx . . $ qqwing/LogItem#POINTING_PAIR_TRIPLE_ROW., valIndex+1, rowStart));
818 return true;
819 }
820 }
821 }
822 }
823 return false;
824 }
825
826 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::pointingColumnReductioncxx . . $ qqwing/SudokuBoard#pointingColumnReduction(83c267b20bac841a).(int round){
827 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
828 for (int section=0; section<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; section++){
829 int secStart = sectionToFirstCellcxx . . $ qqwing/sectionToFirstCell(7864480464b09eea).(section);
830 bool inOneCol = true;
831 int boxCol = -1;
832 {for (int i=0; i<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; i++){
833 for (int j=0; j<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; j++){
834 int secVal=secStart+i+(ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.*j);
835 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,secVal);
836 if(possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
837 if (boxCol == -1 || boxCol == i){
838 boxCol = i;
839 } else {
840 inOneCol = false;
841 }
842 }
843 }
844 }}
845 if (inOneCol && boxCol != -1){
846 bool doneSomething = false;
847 int col = cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(secStart) + boxCol;
848 int colStart = columnToFirstCellcxx . . $ qqwing/columnToFirstCell(7864480464b09eea).(col);
849
850 {for (int i=0; i<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; i++){
851 int position = colStart+(ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.*i);
852 int section2 = cellToSectioncxx . . $ qqwing/cellToSection(7864480464b09eea).(position);
853 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
854 if (section != section2 && possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
855 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] = round;
856 doneSomething = true;
857 }
858 }}
859 if (doneSomething){
860 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::POINTING_PAIR_TRIPLE_COLUMNcxx . . $ qqwing/LogItem#POINTING_PAIR_TRIPLE_COLUMN., valIndex+1, colStart));
861 return true;
862 }
863 }
864 }
865 }
866 return false;
867 }
868
869 int SudokuBoardcxx . . $ qqwing/SudokuBoard#::countPossibilitiescxx . . $ qqwing/SudokuBoard#countPossibilities(7864480464b09eea).(int position){
870 int count = 0;
871 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
872 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
873 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0) count++;
874 }
875 return count;
876 }
877
878 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::arePossibilitiesSamecxx . . $ qqwing/SudokuBoard#arePossibilitiesSame(cf9ef193275fa6d8).(int position1, int position2){
879 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
880 int valPos1 = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position1);
881 int valPos2 = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position2);
882 if ((possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos1] == 0 || possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos2] == 0) && (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos1] != 0 || possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos2] != 0)){
883 return false;
884 }
885 }
886 return true;
887 }
888
889 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::removePossibilitiesInOneFromTwocxx . . $ qqwing/SudokuBoard#removePossibilitiesInOneFromTwo(1432650661211742).(int position1, int position2, int round){
890 bool doneSomething = false;
891 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
892 int valPos1 = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position1);
893 int valPos2 = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position2);
894 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos1] == 0 && possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos2] == 0){
895 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos2] = round;
896 doneSomething = true;
897 }
898 }
899 return doneSomething;
900 }
901
902 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::hiddenPairInColumncxx . . $ qqwing/SudokuBoard#hiddenPairInColumn(83c267b20bac841a).(int round){
903 for (int column=0; column<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; column++){
904 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
905 int r1 = -1;
906 int r2 = -1;
907 int valCount = 0;
908 for (int row=0; row<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; row++){
909 int position = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row,column);
910 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
911 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
912 if (r1 == -1 || r1 == row){
913 r1 = row;
914 } else if (r2 == -1 || r2 == row){
915 r2 = row;
916 }
917 valCount++;
918 }
919 }
920 if (valCount==2){
921 for (int valIndex2=valIndex+1; valIndex2<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex2++){
922 int r3 = -1;
923 int r4 = -1;
924 int valCount2 = 0;
925 for (int row=0; row<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; row++){
926 int position = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row,column);
927 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex2,position);
928 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
929 if (r3 == -1 || r3 == row){
930 r3 = row;
931 } else if (r4 == -1 || r4 == row){
932 r4 = row;
933 }
934 valCount2++;
935 }
936 }
937 if (valCount2==2 && r1==r3 && r2==r4){
938 bool doneSomething = false;
939 for (int valIndex3=0; valIndex3<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex3++){
940 if (valIndex3 != valIndex && valIndex3 != valIndex2){
941 int position1 = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(r1,column);
942 int position2 = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(r2,column);
943 int valPos1 = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex3,position1);
944 int valPos2 = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex3,position2);
945 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos1] == 0){
946 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos1] = round;
947 doneSomething = true;
948 }
949 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos2] == 0){
950 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos2] = round;
951 doneSomething = true;
952 }
953 }
954 }
955 if (doneSomething){
956 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::HIDDEN_PAIR_COLUMNcxx . . $ qqwing/LogItem#HIDDEN_PAIR_COLUMN., valIndex+1, rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(r1,column)));
957 return true;
958 }
959 }
960 }
961 }
962 }
963 }
964 return false;
965 }
966
967 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::hiddenPairInSectioncxx . . $ qqwing/SudokuBoard#hiddenPairInSection(83c267b20bac841a).(int round){
968 for (int section=0; section<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; section++){
969 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
970 int si1 = -1;
971 int si2 = -1;
972 int valCount = 0;
973 for (int secInd=0; secInd<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; secInd++){
974 int position = sectionToCellcxx . . $ qqwing/sectionToCell(9b79fb6aee4c0440).(section,secInd);
975 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
976 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
977 if (si1 == -1 || si1 == secInd){
978 si1 = secInd;
979 } else if (si2 == -1 || si2 == secInd){
980 si2 = secInd;
981 }
982 valCount++;
983 }
984 }
985 if (valCount==2){
986 for (int valIndex2=valIndex+1; valIndex2<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex2++){
987 int si3 = -1;
988 int si4 = -1;
989 int valCount2 = 0;
990 for (int secInd=0; secInd<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; secInd++){
991 int position = sectionToCellcxx . . $ qqwing/sectionToCell(9b79fb6aee4c0440).(section,secInd);
992 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex2,position);
993 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
994 if (si3 == -1 || si3 == secInd){
995 si3 = secInd;
996 } else if (si4 == -1 || si4 == secInd){
997 si4 = secInd;
998 }
999 valCount2++;
1000 }
1001 }
1002 if (valCount2==2 && si1==si3 && si2==si4){
1003 bool doneSomething = false;
1004 for (int valIndex3=0; valIndex3<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex3++){
1005 if (valIndex3 != valIndex && valIndex3 != valIndex2){
1006 int position1 = sectionToCellcxx . . $ qqwing/sectionToCell(9b79fb6aee4c0440).(section,si1);
1007 int position2 = sectionToCellcxx . . $ qqwing/sectionToCell(9b79fb6aee4c0440).(section,si2);
1008 int valPos1 = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex3,position1);
1009 int valPos2 = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex3,position2);
1010 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos1] == 0){
1011 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos1] = round;
1012 doneSomething = true;
1013 }
1014 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos2] == 0){
1015 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos2] = round;
1016 doneSomething = true;
1017 }
1018 }
1019 }
1020 if (doneSomething){
1021 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::HIDDEN_PAIR_SECTIONcxx . . $ qqwing/LogItem#HIDDEN_PAIR_SECTION., valIndex+1, sectionToCellcxx . . $ qqwing/sectionToCell(9b79fb6aee4c0440).(section,si1)));
1022 return true;
1023 }
1024 }
1025 }
1026 }
1027 }
1028 }
1029 return false;
1030 }
1031
1032 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::hiddenPairInRowcxx . . $ qqwing/SudokuBoard#hiddenPairInRow(83c267b20bac841a).(int round){
1033 for (int row=0; row<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; row++){
1034 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
1035 int c1 = -1;
1036 int c2 = -1;
1037 int valCount = 0;
1038 for (int column=0; column<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; column++){
1039 int position = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row,column);
1040 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
1041 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
1042 if (c1 == -1 || c1 == column){
1043 c1 = column;
1044 } else if (c2 == -1 || c2 == column){
1045 c2 = column;
1046 }
1047 valCount++;
1048 }
1049 }
1050 if (valCount==2){
1051 for (int valIndex2=valIndex+1; valIndex2<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex2++){
1052 int c3 = -1;
1053 int c4 = -1;
1054 int valCount2 = 0;
1055 for (int column=0; column<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; column++){
1056 int position = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row,column);
1057 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex2,position);
1058 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
1059 if (c3 == -1 || c3 == column){
1060 c3 = column;
1061 } else if (c4 == -1 || c4 == column){
1062 c4 = column;
1063 }
1064 valCount2++;
1065 }
1066 }
1067 if (valCount2==2 && c1==c3 && c2==c4){
1068 bool doneSomething = false;
1069 for (int valIndex3=0; valIndex3<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex3++){
1070 if (valIndex3 != valIndex && valIndex3 != valIndex2){
1071 int position1 = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row,c1);
1072 int position2 = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row,c2);
1073 int valPos1 = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex3,position1);
1074 int valPos2 = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex3,position2);
1075 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos1] == 0){
1076 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos1] = round;
1077 doneSomething = true;
1078 }
1079 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos2] == 0){
1080 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos2] = round;
1081 doneSomething = true;
1082 }
1083 }
1084 }
1085 if (doneSomething){
1086 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::HIDDEN_PAIR_ROWcxx . . $ qqwing/LogItem#HIDDEN_PAIR_ROW., valIndex+1, rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row,c1)));
1087 return true;
1088 }
1089 }
1090 }
1091 }
1092 }
1093 }
1094 return false;
1095 }
1096
1097 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::handleNakedPairscxx . . $ qqwing/SudokuBoard#handleNakedPairs(83c267b20bac841a).(int round){
1098 for (int position=0; position<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; position++){
1099 int possibilities = countPossibilitiescxx . . $ qqwing/SudokuBoard#countPossibilities(7864480464b09eea).(position);
1100 if (possibilities == 2){
1101 int row = cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(position);
1102 int column = cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(position);
1103 int section = cellToSectionStartCellcxx . . $ qqwing/cellToSectionStartCell(7864480464b09eea).(position);
1104 for (int position2=position; position2<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; position2++){
1105 if (position != position2){
1106 int possibilities2 = countPossibilitiescxx . . $ qqwing/SudokuBoard#countPossibilities(7864480464b09eea).(position2);
1107 if (possibilities2 == 2 && arePossibilitiesSamecxx . . $ qqwing/SudokuBoard#arePossibilitiesSame(cf9ef193275fa6d8).(position, position2)){
1108 if (row == cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(position2)){
1109 bool doneSomething = false;
1110 for (int column2=0; column2<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; column2++){
1111 int position3 = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row,column2);
1112 if (position3 != position && position3 != position2 && removePossibilitiesInOneFromTwocxx . . $ qqwing/SudokuBoard#removePossibilitiesInOneFromTwo(1432650661211742).(position, position3, round)){
1113 doneSomething = true;
1114 }
1115 }
1116 if (doneSomething){
1117 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::NAKED_PAIR_ROWcxx . . $ qqwing/LogItem#NAKED_PAIR_ROW., 0, position));
1118 return true;
1119 }
1120 }
1121 if (column == cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(position2)){
1122 bool doneSomething = false;
1123 for (int row2=0; row2<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; row2++){
1124 int position3 = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row2,column);
1125 if (position3 != position && position3 != position2 && removePossibilitiesInOneFromTwocxx . . $ qqwing/SudokuBoard#removePossibilitiesInOneFromTwo(1432650661211742).(position, position3, round)){
1126 doneSomething = true;
1127 }
1128 }
1129 if (doneSomething){
1130 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::NAKED_PAIR_COLUMNcxx . . $ qqwing/LogItem#NAKED_PAIR_COLUMN., 0, position));
1131 return true;
1132 }
1133 }
1134 if (section == cellToSectionStartCellcxx . . $ qqwing/cellToSectionStartCell(7864480464b09eea).(position2)){
1135 bool doneSomething = false;
1136 int secStart = cellToSectionStartCellcxx . . $ qqwing/cellToSectionStartCell(7864480464b09eea).(position);
1137 {for (int i=0; i<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; i++){
1138 for (int j=0; j<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; j++){
1139 int position3=secStart+i+(ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.*j);
1140 if (position3 != position && position3 != position2 && removePossibilitiesInOneFromTwocxx . . $ qqwing/SudokuBoard#removePossibilitiesInOneFromTwo(1432650661211742).(position, position3, round)){
1141 doneSomething = true;
1142 }
1143 }
1144 }}
1145 if (doneSomething){
1146 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::NAKED_PAIR_SECTIONcxx . . $ qqwing/LogItem#NAKED_PAIR_SECTION., 0, position));
1147 return true;
1148 }
1149 }
1150 }
1151 }
1152 }
1153 }
1154 }
1155 return false;
1156 }
1157
1158 /**
1159 * Mark exactly one cell which is the only possible value for some row, if
1160 * such a cell exists.
1161 * This method will look in a row for a possibility that is only listed
1162 * for one cell. This type of cell is often called a "hidden single"
1163 */
1164 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::onlyValueInRowcxx . . $ qqwing/SudokuBoard#onlyValueInRow(83c267b20bac841a).(int round){
1165 for (int row=0; row<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; row++){
1166 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
1167 int count = 0;
1168 int lastPosition = 0;
1169 for (int col=0; col<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; col++){
1170 int position = (row*ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.)+col;
1171 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
1172 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
1173 count++;
1174 lastPosition = position;
1175 }
1176 }
1177 if (count == 1){
1178 int value = valIndex+1;
1179 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::HIDDEN_SINGLE_ROWcxx . . $ qqwing/LogItem#HIDDEN_SINGLE_ROW., value, lastPosition));
1180 markcxx . . $ qqwing/SudokuBoard#mark(b1146eedae1e1d0b).(lastPosition, round, value);
1181 return true;
1182 }
1183 }
1184 }
1185 return false;
1186 }
1187
1188 /**
1189 * Mark exactly one cell which is the only possible value for some column, if
1190 * such a cell exists.
1191 * This method will look in a column for a possibility that is only listed
1192 * for one cell. This type of cell is often called a "hidden single"
1193 */
1194 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::onlyValueInColumncxx . . $ qqwing/SudokuBoard#onlyValueInColumn(83c267b20bac841a).(int round){
1195 for (int col=0; col<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; col++){
1196 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
1197 int count = 0;
1198 int lastPosition = 0;
1199 for (int row=0; row<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; row++){
1200 int position = rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(row,col);
1201 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
1202 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
1203 count++;
1204 lastPosition = position;
1205 }
1206 }
1207 if (count == 1){
1208 int value = valIndex+1;
1209 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::HIDDEN_SINGLE_COLUMNcxx . . $ qqwing/LogItem#HIDDEN_SINGLE_COLUMN., value, lastPosition));
1210 markcxx . . $ qqwing/SudokuBoard#mark(b1146eedae1e1d0b).(lastPosition, round, value);
1211 return true;
1212 }
1213 }
1214 }
1215 return false;
1216 }
1217
1218 /**
1219 * Mark exactly one cell which is the only possible value for some section, if
1220 * such a cell exists.
1221 * This method will look in a section for a possibility that is only listed
1222 * for one cell. This type of cell is often called a "hidden single"
1223 */
1224 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::onlyValueInSectioncxx . . $ qqwing/SudokuBoard#onlyValueInSection(83c267b20bac841a).(int round){
1225 for (int sec=0; sec<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; sec++){
1226 int secPos = sectionToFirstCellcxx . . $ qqwing/sectionToFirstCell(7864480464b09eea).(sec);
1227 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
1228 int count = 0;
1229 int lastPosition = 0;
1230 {for (int i=0; i<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; i++){
1231 for (int j=0; j<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; j++){
1232 int position = secPos + i + ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.*j;
1233 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
1234 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
1235 count++;
1236 lastPosition = position;
1237 }
1238 }
1239 }}
1240 if (count == 1){
1241 int value = valIndex+1;
1242 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::HIDDEN_SINGLE_SECTIONcxx . . $ qqwing/LogItem#HIDDEN_SINGLE_SECTION., value, lastPosition));
1243 markcxx . . $ qqwing/SudokuBoard#mark(b1146eedae1e1d0b).(lastPosition, round, value);
1244 return true;
1245 }
1246 }
1247 }
1248 return false;
1249 }
1250
1251 /**
1252 * Mark exactly one cell that has a single possibility, if such a cell exists.
1253 * This method will look for a cell that has only one possibility. This type
1254 * of cell is often called a "single"
1255 */
1256 bool SudokuBoardcxx . . $ qqwing/SudokuBoard#::onlyPossibilityForCellcxx . . $ qqwing/SudokuBoard#onlyPossibilityForCell(83c267b20bac841a).(int round){
1257 for (int position=0; position<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; position++){
1258 if (solutioncxx . . $ qqwing/SudokuBoard#solution.[position] == 0){
1259 int count = 0;
1260 int lastValue = 0;
1261 for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
1262 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
1263 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
1264 count++;
1265 lastValue=valIndex+1;
1266 }
1267 }
1268 if (count == 1){
1269 markcxx . . $ qqwing/SudokuBoard#mark(b1146eedae1e1d0b).(position, round, lastValue);
1270 if (logHistorycxx . . $ qqwing/SudokuBoard#logHistory. || recordHistorycxx . . $ qqwing/SudokuBoard#recordHistory.) addHistoryItemcxx . . $ qqwing/SudokuBoard#addHistoryItem(1e682de0ae4452c8).(new LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(round, LogItemcxx . . $ qqwing/LogItem#::SINGLEcxx . . $ qqwing/LogItem#SINGLE., lastValue, position));
1271 return true;
1272 }
1273 }
1274 }
1275 return false;
1276 }
1277
1278 /**
1279 * Mark the given value at the given position. Go through
1280 * the row, column, and section for the position and remove
1281 * the value from the possibilities.
1282 *
1283 * @param position Position into the board (0-80)
1284 * @param round Round to mark for rollback purposes
1285 * @param value The value to go in the square at the given position
1286 */
1287 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::markcxx . . $ qqwing/SudokuBoard#mark(b1146eedae1e1d0b).(int position, int round, int value){
1288 if (solutioncxx . . $ qqwing/SudokuBoard#solution.[position] != 0) throw ("Marking position that already has been marked.");
1289 if (solutionRoundcxx . . $ qqwing/SudokuBoard#solutionRound.[position] !=0) throw ("Marking position that was marked another round.");
1290 int valIndex = value-1;
1291 solutioncxx . . $ qqwing/SudokuBoard#solution.[position] = value;
1292
1293 int possInd = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
1294 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[possInd] != 0) throw ("Marking impossible position.");
1295
1296 // Take this value out of the possibilities for everything in the row
1297 solutionRoundcxx . . $ qqwing/SudokuBoard#solutionRound.[position] = round;
1298 int rowStart = cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(position)*ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.;
1299 for (int col=0; col<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; col++){
1300 int rowVal=rowStart+col;
1301 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,rowVal);
1302 //cout << "Row Start: " << rowStart << " Row Value: " << rowVal << " Value Position: " << valPos << endl;
1303 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
1304 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] = round;
1305 }
1306 }
1307
1308 // Take this value out of the possibilities for everything in the column
1309 int colStart = cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(position);
1310 {for (int i=0; i<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; i++){
1311 int colVal=colStart+(ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.*i);
1312 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,colVal);
1313 //cout << "Col Start: " << colStart << " Col Value: " << colVal << " Value Position: " << valPos << endl;
1314 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
1315 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] = round;
1316 }
1317 }}
1318
1319 // Take this value out of the possibilities for everything in section
1320 int secStart = cellToSectionStartCellcxx . . $ qqwing/cellToSectionStartCell(7864480464b09eea).(position);
1321 {for (int i=0; i<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; i++){
1322 for (int j=0; j<GRID_SIZEcxx . . $ qqwing/GRID_SIZE.; j++){
1323 int secVal=secStart+i+(ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.*j);
1324 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,secVal);
1325 //cout << "Sec Start: " << secStart << " Sec Value: " << secVal << " Value Position: " << valPos << endl;
1326 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
1327 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] = round;
1328 }
1329 }
1330 }}
1331
1332 //This position itself is determined, it should have possibilities.
1333 {for (int valIndex=0; valIndex<ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.; valIndex++){
1334 int valPos = getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(valIndex,position);
1335 if (possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] == 0){
1336 possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.[valPos] = round;
1337 }
1338 }}
1339 }
1340
1341 /**
1342 * print the given BOARD_SIZEd array of ints
1343 * as a sudoku puzzle. Use print options from
1344 * member variables.
1345 */
1346 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::printcxx . . $ qqwing/SudokuBoard#print(11b0e290e57a7e53).(int* sudoku){
1347 for(int i=0; i<BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.; i++){
1348 if (printStylecxx . . $ qqwing/SudokuBoard#printStyle. == READABLEcxx . . $ qqwing/SudokuBoard#READABLE.){
1349 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " ";
1350 }
1351 if (sudoku[i]==0){
1352 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '.';
1353 } else {
1354 coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). sudoku[i];
1355 }
1356 if (i == BOARD_SIZEcxx . . $ qqwing/BOARD_SIZE.-1){
1357 if (printStylecxx . . $ qqwing/SudokuBoard#printStyle. == CSVcxx . . $ qqwing/SudokuBoard#CSV.){
1358 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ",";
1359 } else {
1360 coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
1361 }
1362 if (printStylecxx . . $ qqwing/SudokuBoard#printStyle. == READABLEcxx . . $ qqwing/SudokuBoard#READABLE. || printStylecxx . . $ qqwing/SudokuBoard#printStyle. == COMPACTcxx . . $ qqwing/SudokuBoard#COMPACT.){
1363 coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
1364 }
1365 } else if (i%ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.==ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.-1){
1366 if (printStylecxx . . $ qqwing/SudokuBoard#printStyle. == READABLEcxx . . $ qqwing/SudokuBoard#READABLE. || printStylecxx . . $ qqwing/SudokuBoard#printStyle. == COMPACTcxx . . $ qqwing/SudokuBoard#COMPACT.){
1367 coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
1368 }
1369 if (i%SEC_GROUP_SIZEcxx . . $ qqwing/SEC_GROUP_SIZE.==SEC_GROUP_SIZEcxx . . $ qqwing/SEC_GROUP_SIZE.-1){
1370 if (printStylecxx . . $ qqwing/SudokuBoard#printStyle. == READABLEcxx . . $ qqwing/SudokuBoard#READABLE.){
1371 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "-------|-------|-------" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
1372 }
1373 }
1374 } else if (i%GRID_SIZEcxx . . $ qqwing/GRID_SIZE.==GRID_SIZEcxx . . $ qqwing/GRID_SIZE.-1){
1375 if (printStylecxx . . $ qqwing/SudokuBoard#printStyle. == READABLEcxx . . $ qqwing/SudokuBoard#READABLE.){
1376 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " |";
1377 }
1378 }
1379 }
1380 }
1381
1382 /**
1383 * Print the sudoku puzzle.
1384 */
1385 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::printPuzzlecxx . . $ qqwing/SudokuBoard#printPuzzle(49f6e7a06ebc5aa8).(){
1386 printcxx . . $ qqwing/SudokuBoard#print(11b0e290e57a7e53).(puzzlecxx . . $ qqwing/SudokuBoard#puzzle.);
1387 }
1388
1389 /**
1390 * Print the sudoku solution.
1391 */
1392 void SudokuBoardcxx . . $ qqwing/SudokuBoard#::printSolutioncxx . . $ qqwing/SudokuBoard#printSolution(49f6e7a06ebc5aa8).(){
1393 printcxx . . $ qqwing/SudokuBoard#print(11b0e290e57a7e53).(solutioncxx . . $ qqwing/SudokuBoard#solution.);
1394 }
1395
1396 SudokuBoardcxx . . $ qqwing/SudokuBoard#::~cxx . . $ qqwing/SudokuBoard#`~SudokuBoard`(ced63f7c635d850d).SudokuBoardcxx . . $ qqwing/SudokuBoard#(){
1397 clearPuzzlecxx . . $ qqwing/SudokuBoard#clearPuzzle(49f6e7a06ebc5aa8).();
1398 delete[] puzzlecxx . . $ qqwing/SudokuBoard#puzzle.;
1399 delete[] solutioncxx . . $ qqwing/SudokuBoard#solution.;
1400 delete[] possibilitiescxx . . $ qqwing/SudokuBoard#possibilities.;
1401 delete[] solutionRoundcxx . . $ qqwing/SudokuBoard#solutionRound.;
1402 delete[] randomBoardArraycxx . . $ qqwing/SudokuBoard#randomBoardArray.;
1403 delete[] randomPossibilityArraycxx . . $ qqwing/SudokuBoard#randomPossibilityArray.;
1404 delete solveHistorycxx . . $ qqwing/SudokuBoard#solveHistory.;
1405 delete solveInstructionscxx . . $ qqwing/SudokuBoard#solveInstructions.;
1406 }
1407
1408 LogItemcxx . . $ qqwing/LogItem#::LogItemcxx . . $ qqwing/LogItem#LogItem(16ed3834183c0131).(int r, LogTypecxx . . $ qqwing/LogItem#LogType# t){
1409 initcxx . . $ qqwing/LogItem#init(e8fb13d4a1fc0532).(r,t,0,-1);
1410 }
1411
1412 LogItemcxx . . $ qqwing/LogItem#::LogItemcxx . . $ qqwing/LogItem#LogItem(e8fb13d4a1fc0532).(int r, LogTypecxx . . $ qqwing/LogItem#LogType# t, int v, int p){
1413 initcxx . . $ qqwing/LogItem#init(e8fb13d4a1fc0532).(r,t,v,p);
1414 }
1415
1416 void LogItemcxx . . $ qqwing/LogItem#::initcxx . . $ qqwing/LogItem#init(e8fb13d4a1fc0532).(int r, LogTypecxx . . $ qqwing/LogItem#LogType# t, int v, int p){
1417 roundcxx . . $ qqwing/LogItem#round. = r;
1418 typecxx . . $ qqwing/LogItem#type. = t;
1419 valuecxx . . $ qqwing/LogItem#value. = v;
1420 positioncxx . . $ qqwing/LogItem#position. = p;
1421 }
1422
1423 LogItemcxx . . $ qqwing/LogItem#::~cxx . . $ qqwing/LogItem#`~LogItem`(ced63f7c635d850d).LogItemcxx . . $ qqwing/LogItem#(){
1424 }
1425
1426 int LogItemcxx . . $ qqwing/LogItem#::getRoundcxx . . $ qqwing/LogItem#getRound(b126dc7c1de90089).(){
1427 return roundcxx . . $ qqwing/LogItem#round.;
1428 }
1429
1430 /**
1431 * Get the type of this log item.
1432 */
1433 LogItemcxx . . $ qqwing/LogItem#::LogTypecxx . . $ qqwing/LogItem#LogType# LogItemcxx . . $ qqwing/LogItem#::getTypecxx . . $ qqwing/LogItem#getType(5dbf097fb2db9719).(){
1434 return typecxx . . $ qqwing/LogItem#type.;
1435 }
1436
1437 /**
1438 * Print the current log item. The message used is
1439 * determined by the type of log item.
1440 */
1441 void LogItemcxx . . $ qqwing/LogItem#::printcxx . . $ qqwing/LogItem#print(49f6e7a06ebc5aa8).(){
1442 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Round: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). getRoundcxx . . $ qqwing/LogItem#getRound(b126dc7c1de90089).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " - ";
1443 switch(typecxx . . $ qqwing/LogItem#type.){
1444 case GIVENcxx . . $ qqwing/LogItem#GIVEN.:{
1445 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Mark given";
1446 } break;
1447 case ROLLBACKcxx . . $ qqwing/LogItem#ROLLBACK.:{
1448 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Roll back round";
1449 } break;
1450 case GUESScxx . . $ qqwing/LogItem#GUESS.:{
1451 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Mark guess (start round)";
1452 } break;
1453 case HIDDEN_SINGLE_ROWcxx . . $ qqwing/LogItem#HIDDEN_SINGLE_ROW.:{
1454 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Mark single possibility for value in row";
1455 } break;
1456 case HIDDEN_SINGLE_COLUMNcxx . . $ qqwing/LogItem#HIDDEN_SINGLE_COLUMN.:{
1457 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Mark single possibility for value in column";
1458 } break;
1459 case HIDDEN_SINGLE_SECTIONcxx . . $ qqwing/LogItem#HIDDEN_SINGLE_SECTION.:{
1460 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Mark single possibility for value in section";
1461 } break;
1462 case SINGLEcxx . . $ qqwing/LogItem#SINGLE.:{
1463 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Mark only possibility for cell";
1464 } break;
1465 case NAKED_PAIR_ROWcxx . . $ qqwing/LogItem#NAKED_PAIR_ROW.:{
1466 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Remove possibilities for naked pair in row";
1467 } break;
1468 case NAKED_PAIR_COLUMNcxx . . $ qqwing/LogItem#NAKED_PAIR_COLUMN.:{
1469 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Remove possibilities for naked pair in column";
1470 } break;
1471 case NAKED_PAIR_SECTIONcxx . . $ qqwing/LogItem#NAKED_PAIR_SECTION.:{
1472 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Remove possibilities for naked pair in section";
1473 } break;
1474 case POINTING_PAIR_TRIPLE_ROWcxx . . $ qqwing/LogItem#POINTING_PAIR_TRIPLE_ROW.: {
1475 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Remove possibilities for row because all values are in one section";
1476 } break;
1477 case POINTING_PAIR_TRIPLE_COLUMNcxx . . $ qqwing/LogItem#POINTING_PAIR_TRIPLE_COLUMN.: {
1478 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Remove possibilities for column because all values are in one section";
1479 } break;
1480 case ROW_BOXcxx . . $ qqwing/LogItem#ROW_BOX.: {
1481 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Remove possibilities for section because all values are in one row";
1482 } break;
1483 case COLUMN_BOXcxx . . $ qqwing/LogItem#COLUMN_BOX.: {
1484 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Remove possibilities for section because all values are in one column";
1485 } break;
1486 case HIDDEN_PAIR_ROWcxx . . $ qqwing/LogItem#HIDDEN_PAIR_ROW.: {
1487 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Remove possibilities from hidden pair in row";
1488 } break;
1489 case HIDDEN_PAIR_COLUMNcxx . . $ qqwing/LogItem#HIDDEN_PAIR_COLUMN.: {
1490 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Remove possibilities from hidden pair in column";
1491 } break;
1492 case HIDDEN_PAIR_SECTIONcxx . . $ qqwing/LogItem#HIDDEN_PAIR_SECTION.: {
1493 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Remove possibilities from hidden pair in section";
1494 } break;
1495 default:{
1496 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "!!! Performed unknown optimization !!!";
1497 } break;
1498 }
1499 if (valuecxx . . $ qqwing/LogItem#value. > 0 || positioncxx . . $ qqwing/LogItem#position. > -1){
1500 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " (";
1501 bool printed = false;
1502 if (positioncxx . . $ qqwing/LogItem#position. > -1){
1503 if (printed) coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " - ";
1504 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Row: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(positioncxx . . $ qqwing/LogItem#position.)+1 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " - Column: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(positioncxx . . $ qqwing/LogItem#position.)+1;
1505 printed = true;
1506 }
1507 if (valuecxx . . $ qqwing/LogItem#value. > 0){
1508 if (printed) coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " - ";
1509 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Value: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). valuecxx . . $ qqwing/LogItem#value.;
1510 printed = true;
1511 }
1512 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")";
1513 }
1514 }
1515
1516 /**
1517 * Given a vector of LogItems, determine how many
1518 * log items in the vector are of the specified type.
1519 */
1520 int getLogCountcxx . . $ qqwing/getLogCount(48ecb76dfea1e276).(vectorcxx . . $ std/vector#<LogItemcxx . . $ qqwing/LogItem#*>* v, LogItemcxx . . $ qqwing/LogItem#::LogTypecxx . . $ qqwing/LogItem#LogType# type){
1521 unsigned int count = 0;
1522 {for (unsigned int i=0; i<v->sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++){
1523 if(v->atcxx . . $ std/vector#at(428bb168810b9e52).(i)->getTypecxx . . $ qqwing/LogItem#getType(5dbf097fb2db9719).() == type) count++;
1524 }}
1525 return count;
1526 }
1527
1528 /**
1529 * Shuffle the values in an array of integers.
1530 */
1531 void shuffleArraycxx . . $ qqwing/shuffleArray(621ccea12ecf5b06).(int* array, int size){
1532 {for (int i=0; i<size; i++){
1533 int tailSize = size-i;
1534 int randTailPos = rand()%tailSize+i;
1535 int temp = array[i];
1536 array[i] = array[randTailPos];
1537 array[randTailPos] = temp;
1538 }}
1539 }
1540
1541 SudokuBoardcxx . . $ qqwing/SudokuBoard#::Symmetrycxx . . $ qqwing/SudokuBoard#Symmetry# getRandomSymmetrycxx . . $ qqwing/getRandomSymmetry(40885f473ab4624b).(){
1542 switch (rand()%4){
1543 case 0: return SudokuBoardcxx . . $ qqwing/SudokuBoard#::ROTATE90cxx . . $ qqwing/SudokuBoard#ROTATE90.;
1544 case 1: return SudokuBoardcxx . . $ qqwing/SudokuBoard#::ROTATE180cxx . . $ qqwing/SudokuBoard#ROTATE180.;
1545 case 2: return SudokuBoardcxx . . $ qqwing/SudokuBoard#::MIRRORcxx . . $ qqwing/SudokuBoard#MIRROR.;
1546 case 3: return SudokuBoardcxx . . $ qqwing/SudokuBoard#::FLIPcxx . . $ qqwing/SudokuBoard#FLIP.;
1547 }
1548 return SudokuBoardcxx . . $ qqwing/SudokuBoard#::ROTATE90cxx . . $ qqwing/SudokuBoard#ROTATE90.; // NOTE: default action
1549 }
1550
1551 /**
1552 * Given the index of a cell (0-80) calculate
1553 * the column (0-8) in which that cell resides.
1554 */
1555 static inline int cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(int cell){
1556 return cell%ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.;
1557 }
1558
1559 /**
1560 * Given the index of a cell (0-80) calculate
1561 * the row (0-8) in which it resides.
1562 */
1563 static inline int cellToRowcxx . . $ qqwing/cellToRow(7864480464b09eea).(int cell){
1564 return cell/ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.;
1565 }
1566
1567 /**
1568 * Given the index of a cell (0-80) calculate
1569 * the section (0-8) in which it resides.
1570 */
1571 static inline int cellToSectioncxx . . $ qqwing/cellToSection(7864480464b09eea).(int cell){
1572 return (cell/SEC_GROUP_SIZEcxx . . $ qqwing/SEC_GROUP_SIZE.*GRID_SIZEcxx . . $ qqwing/GRID_SIZE.)
1573 + (cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(cell)/GRID_SIZEcxx . . $ qqwing/GRID_SIZE.);
1574 }
1575
1576 /**
1577 * Given the index of a cell (0-80) calculate
1578 * the cell (0-80) that is the upper left start
1579 * cell of that section.
1580 */
1581 static inline int cellToSectionStartCellcxx . . $ qqwing/cellToSectionStartCell(7864480464b09eea).(int cell){
1582 return (cell/SEC_GROUP_SIZEcxx . . $ qqwing/SEC_GROUP_SIZE.*SEC_GROUP_SIZEcxx . . $ qqwing/SEC_GROUP_SIZE.)
1583 + (cellToColumncxx . . $ qqwing/cellToColumn(7864480464b09eea).(cell)/GRID_SIZEcxx . . $ qqwing/GRID_SIZE.*GRID_SIZEcxx . . $ qqwing/GRID_SIZE.);
1584 }
1585
1586 /**
1587 * Given a row (0-8) calculate the first cell (0-80)
1588 * of that row.
1589 */
1590 static inline int rowToFirstCellcxx . . $ qqwing/rowToFirstCell(7864480464b09eea).(int row){
1591 return ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.*row;
1592 }
1593
1594 /**
1595 * Given a column (0-8) calculate the first cell (0-80)
1596 * of that column.
1597 */
1598 static inline int columnToFirstCellcxx . . $ qqwing/columnToFirstCell(7864480464b09eea).(int column){
1599 return column;
1600 }
1601
1602 /**
1603 * Given a section (0-8) calculate the first cell (0-80)
1604 * of that section.
1605 */
1606 static inline int sectionToFirstCellcxx . . $ qqwing/sectionToFirstCell(7864480464b09eea).(int section){
1607 return (section%GRID_SIZEcxx . . $ qqwing/GRID_SIZE.*GRID_SIZEcxx . . $ qqwing/GRID_SIZE.)
1608 + (section/GRID_SIZEcxx . . $ qqwing/GRID_SIZE.*SEC_GROUP_SIZEcxx . . $ qqwing/SEC_GROUP_SIZE.);
1609 }
1610
1611 /**
1612 * Given a value for a cell (0-8) and a cell (0-80)
1613 * calculate the offset into the possibility array (0-728).
1614 */
1615 static inline int getPossibilityIndexcxx . . $ qqwing/getPossibilityIndex(9b79fb6aee4c0440).(int valueIndex, int cell){
1616 return valueIndex+(ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.*cell);
1617 }
1618
1619 /**
1620 * Given a row (0-8) and a column (0-8) calculate the
1621 * cell (0-80).
1622 */
1623 static inline int rowColumnToCellcxx . . $ qqwing/rowColumnToCell(9b79fb6aee4c0440).(int row, int column){
1624 return (row*ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.)+column;
1625 }
1626
1627 /**
1628 * Given a section (0-8) and an offset into that section (0-8)
1629 * calculate the cell (0-80)
1630 */
1631 static inline int sectionToCellcxx . . $ qqwing/sectionToCell(9b79fb6aee4c0440).(int section, int offset){
1632 return sectionToFirstCellcxx . . $ qqwing/sectionToFirstCell(7864480464b09eea).(section)
1633 + ((offset/GRID_SIZEcxx . . $ qqwing/GRID_SIZE.)*ROW_COL_SEC_SIZEcxx . . $ qqwing/ROW_COL_SEC_SIZE.)
1634 + (offset%GRID_SIZEcxx . . $ qqwing/GRID_SIZE.);
1635 }
1636 }