File indexing completed on 2024-04-28 04:04:44

0001 /****************************************************************************
0002  *    Copyright 2015  Ian Wadham <iandw.au@gmail.com>                       *
0003  *                                                                          *
0004  *    This program is free software; you can redistribute it and/or         *
0005  *    modify it under the terms of the GNU General Public License as        *
0006  *    published by the Free Software Foundation; either version 2 of        *
0007  *    the License, or (at your option) any later version.                   *
0008  *                                                                          *
0009  *    This program is distributed in the hope that it will be useful,       *
0010  *    but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *    GNU General Public License for more details.                          *
0013  *                                                                          *
0014  *    You should have received a copy of the GNU General Public License     *
0015  *    along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0016  ****************************************************************************/
0017 
0018 #ifndef MATHDOKUGENERATOR_H
0019 #define MATHDOKUGENERATOR_H
0020 
0021 #include "globals.h"
0022 
0023 
0024 class SKGraph;
0025 
0026 /**
0027  * @class MathdokuGenerator
0028  * @short Generator for Killer Sudoku and Mathdoku puzzles.
0029  *
0030  * Generates a Killer Sudoku or Mathdoku puzzle from a Latin Square that
0031  * satisfies Sudoku-type constraints. It acts as a controller for makeCages().
0032  */
0033 class MathdokuGenerator
0034 {
0035 public:
0036     explicit MathdokuGenerator (SKGraph * graph);
0037 
0038     /**
0039      * Generate a Mathdoku or Killer Sudoku puzzle.
0040      *
0041      * @param puzzle             The generated puzzle (returned).
0042      * @param solution           The values that must go into the solution.
0043      * @param solutionMoves      A pointer that returns an ordered list of cells
0044      *                           found by the solver when it reached a solution.
0045      * @param difficultyRequired The requested level of difficulty.
0046      *
0047      * @return                   True if puzzle-generation succeeded, false
0048      *                           if too many tries were required.
0049      */
0050     bool generateMathdokuTypes (BoardContents & puzzle,
0051                                 BoardContents & solution,
0052                                 QList<int> * solutionMoves,
0053                                 Difficulty difficultyRequired);
0054 
0055     /**
0056      * Solve a Mathdoku or Killer Sudoku and check how many solutions there are.
0057      * The solver requires only the puzzle-graph, which contains all the cages.
0058      *
0059      * @param solution           The values returned as the solution.
0060      * @param solutionMoves      A pointer that returns an ordered list of cells
0061      *                           found by the solver when it reached a solution.
0062      *
0063      * @return                   0  = there is no solution,
0064      *                           1  = there is a unique solution,
0065      *                           >1 = there is more than one solution.
0066      */
0067     int solveMathdokuTypes     (BoardContents & solution,
0068                                 QList<int> * solutionMoves);
0069 
0070 private:
0071     SKGraph *  mGraph;      // The layout, rules and geometry of the puzzle.
0072 };
0073 
0074 #endif // MATHDOKUGENERATOR_H