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

0001 /***************************************************************************
0002  *   Copyright 2007      Francesco Rossi <redsh@email.it>                  *
0003  *   Copyright 2006-2007 Mick Kappenburg <ksudoku@kappendburg.net>         *
0004  *   Copyright 2006-2007 Johannes Bergmeier <johannes.bergmeier@gmx.net>   *
0005  *   Copyright 2015      Ian Wadham <iandw.au@gmail.com>                   *
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or modify  *
0008  *   it under the terms of the GNU General Public License as published by  *
0009  *   the Free Software Foundation; either version 2 of the License, or     *
0010  *   (at your option) any later version.                                   *
0011  *                                                                         *
0012  *   This program is distributed in the hope that it will be useful,       *
0013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0015  *   GNU General Public License for more details.                          *
0016  *                                                                         *
0017  *   You should have received a copy of the GNU General Public License     *
0018  *   along with this program; if not, write to the                         *
0019  *   Free Software Foundation, Inc.,                                       *
0020  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0021  ***************************************************************************/
0022 
0023 #ifndef _KSUDOKUPUZZLE_H_
0024 #define _KSUDOKUPUZZLE_H_
0025 
0026 #include "skgraph.h"
0027 #include "globals.h"
0028 
0029 namespace ksudoku {
0030     
0031 class Puzzle {
0032 public:
0033     /**
0034     * @param[in] sovler       The solver used for this puzzle (the GameType) (not deleted when Puzzle is deleted)
0035     * @param[in] withSolution Whether a the solution for this puzzle should be stored
0036     */
0037     explicit Puzzle(SKGraph* graph, bool withSolution = true);
0038 
0039 public:
0040     /**
0041     * Creates a puzzle without any content
0042     */
0043     bool init();
0044     /**
0045     * Creates a new puzzle based on the solver
0046     * @param[in] difficulty The difficulty of the new game.
0047     * @param[in] symmetry   The symmetry
0048     */
0049     bool init(int difficulty, int symmetry);
0050     /**
0051     * Tries to create a game on existing values
0052     * @param[in]  values The values used for the new puzzle
0053     * @param[out] forks  The count of forks did solving the puzzle
0054     * @return <0 on error, 0 for no solutions, 1 for exactly one solution and
0055     * 2 for more than 1 solutions. For return value <= 0 the init failed.
0056     */
0057     int init(const BoardContents& values);
0058     
0059     /**
0060     * Return game type
0061     */
0062     GameType gameType() const {
0063         return m_graph->type();
0064     }
0065 
0066     int value(int index) const;
0067     int solution(int index) const;
0068 
0069     /**
0070      * Get the index of the n'th move in the solution, for use as a hint.
0071      * @param moveNum   The number of the move for which a hint is required.
0072      * @return          The position of the move, or -1 if past end of list.
0073      */
0074     int hintIndex(int moveNum) const;
0075 
0076     inline bool hasSolution() const { return (m_solution.size() > 0); }
0077 
0078     ///@return order of game
0079     int order() const { return m_graph->order(); }
0080     
0081     ///@return total elements in puzzle
0082     int size() const { 
0083         return m_graph->sizeX() * m_graph->sizeY() * m_graph->sizeZ(); 
0084         }
0085 
0086     ///create new Puzzle with same solver and set withSolution to true
0087     Puzzle* dubPuzzle() { return new Puzzle(m_graph, true) ; }
0088 
0089 public:
0090     inline SKGraph *graph() const { return m_graph; }
0091 
0092 private:
0093     bool m_withSolution;
0094     SKGraph *m_graph;
0095 
0096     BoardContents m_puzzle;
0097     BoardContents m_solution;
0098     QList<int> m_hintList;
0099 
0100     bool m_initialized;
0101 };
0102 
0103 }
0104 
0105 #endif