~ubuntu-branches/ubuntu/quantal/kdegames/quantal

« back to all changes in this revision

Viewing changes to ksudoku/src/generator/plainsudokuboard.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:50 UTC
  • mfrom: (1.3.14)
  • Revision ID: package-import@ubuntu.com-20111215141750-6tj6brf4azhrt915
Tags: 4:4.7.90-0ubuntu1
new upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 *    Copyright 2011  Ian Wadham <iandw.au@gmail.com>                       *
 
3
 *                                                                          *
 
4
 *    This program is free software; you can redistribute it and/or         *
 
5
 *    modify it under the terms of the GNU General Public License as        *
 
6
 *    published by the Free Software Foundation; either version 2 of        *
 
7
 *    the License, or (at your option) any later version.                   *
 
8
 *                                                                          *
 
9
 *    This program is distributed in the hope that it will be useful,       *
 
10
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
11
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
12
 *    GNU General Public License for more details.                          *
 
13
 *                                                                          *
 
14
 *    You should have received a copy of the GNU General Public License     *
 
15
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 
16
 ****************************************************************************/
 
17
 
 
18
#ifndef PLAINSUDOKUBOARD_H
 
19
#define PLAINSUDOKUBOARD_H
 
20
 
 
21
#include "sudokuboard.h"
 
22
 
 
23
/**
 
24
 * @class PlainSudokuBoard  plainsudokuboard.h
 
25
 * @short Data-structures and methods for handling plain Sudoku puzzles.
 
26
 *
 
27
 * A plain or classic Sudoku puzzle has a single square grid containing smaller
 
28
 * blocks of n x n cells.  The overall grid also has n x n rows and n x n
 
29
 * columns and the rows, columns and blocks must be filled with numbers in
 
30
 * the range 1 to n x n.  In the classic form, n = 3 and numbers 1 to 9 must
 
31
 * be used in the solution.  The grid has 9 rows, 9 columns and 9 blocks.  The
 
32
 * PlainSudokuBoard class can also handle 2 x 2, 4 x 4 and 5 x 5.
 
33
 */
 
34
class PlainSudokuBoard : public SudokuBoard
 
35
{
 
36
    Q_OBJECT
 
37
public:
 
38
    /**
 
39
     * Constructs a new PlainSudokuBoard object with a required type and size.
 
40
     * This will become a puzzle of the classic Sudoku type (here called a plain
 
41
     * Sudoku), but possibly with block size other than 3x3.
 
42
     *
 
43
     * @param parent        A pointer to the object that owns this object and
 
44
     *                      will delete it automatically.
 
45
     * @param sudokuType    The type of Sudoku board required, which should
 
46
     *                      always be SudokuType::Plain.
 
47
     * @param blockSize     The size of blocks required (value 2 to 5).  The
 
48
     *                      board will have blocks, rows and columns with
 
49
     *                      blockSize squared cells and the numbers to be
 
50
     *                      filled in will range from 1 to blockSize squared
 
51
     *                      (e.g. a classic Sudoku has blockSize = 3).
 
52
     * @see globals.h
 
53
     */
 
54
    PlainSudokuBoard (QObject * parent, SudokuType sudokuType, int blockSize);
 
55
 
 
56
    /**
 
57
     * Sets up an empty board with the required number of cells and makes
 
58
     * indices to the required groups of cells: rows, columns and blocks.
 
59
     *
 
60
     * If blockSize = 3, the board will contain 9x9 = 81 cells and there will
 
61
     * be 9 rows, 9 columns and 9 blocks of 3x3 cells, to be filled in with
 
62
     * values 1 to 9 (i.e. a classic Sudoku).  Thus there will be 27 groups of
 
63
     * 9 cells each.  See the  SudokuBoard class description for an overview.
 
64
     */
 
65
    virtual void            setUpBoard();
 
66
 
 
67
    /**
 
68
     * Clear a board-vector of the required type and size. All the cells in this
 
69
     * type of Sudoku are set to zero (i.e. empty).  There are no unused cells.
 
70
     */
 
71
    virtual void            clear (BoardContents & boardValues);
 
72
 
 
73
    /**
 
74
     * Fill the board with randomly chosen valid values, thus generating a
 
75
     * solution from which a puzzle of the plain Sudoku type can be created.
 
76
     *
 
77
     * @return              The filled board-vector.
 
78
     */
 
79
    virtual BoardContents & fillBoard();
 
80
 
 
81
protected:
 
82
    /**
 
83
     * Make a list of cells in rows and columns of the board.  In a plain
 
84
     * Sudoku, the rows and columns indexed take up the entire board of
 
85
     * blockSize squared rows and columns.
 
86
     *
 
87
     * @param i             The row-number of the top left cell (i.e. 0).
 
88
     * @param j             The column-number of the top left cell (i.e. 0).
 
89
     * @param index         The current position in the list of groups.
 
90
     * @return              The updated position in the list of groups.
 
91
     */
 
92
    virtual qint32          makeRowColIndex (int i, int j, qint32 index);
 
93
 
 
94
    /**
 
95
     * Make a list of cells in blocks of the board.  In a plain Sudoku a block
 
96
     * is a small square of cells of size blockSize * blockSize (e.g. 3x3).
 
97
     *
 
98
     * @param index         The current position in the list of groups.
 
99
     * @return              The updated position in the list of groups.
 
100
     */
 
101
    virtual qint32          makeBlockIndex (qint32 index);
 
102
};
 
103
 
 
104
/**
 
105
 * @class XSudokuBoard  plainsudokuboard.h
 
106
 * @short Data-structures and methods for handling XSudoku puzzles.
 
107
 *
 
108
 * An XSudoku puzzle is exactly like a plain Sudoku puzzle, except that the two
 
109
 * diagonals of the board also form groups that must be filled with the values
 
110
 * 1 to blockSize * blockSize.
 
111
 */
 
112
class XSudokuBoard : public PlainSudokuBoard
 
113
{
 
114
    Q_OBJECT
 
115
public:
 
116
    /**
 
117
     * Constructs a new XSudokuBoard object with a required type and size.
 
118
     *
 
119
     * @param parent        A pointer to the object that owns this object and
 
120
     *                      will delete it automatically.
 
121
     * @param sudokuType    The type of Sudoku board required, which should
 
122
     *                      always be SudokuType::XSudoku.
 
123
     * @param blockSize     The size of blocks required (value 3 to 5).  The
 
124
     *                      board will have blocks, rows and columns with
 
125
     *                      blockSize squared cells and the numbers to be
 
126
     *                      filled in will range from 1 to blockSize squared.
 
127
     * @see globals.h
 
128
     */
 
129
    XSudokuBoard (QObject * parent, SudokuType sudokuType, int blockSize);
 
130
 
 
131
protected:
 
132
    /**
 
133
     * Make a list of cells in blocks of the board.  This exactly the same as
 
134
     * in a plain Sudoku, but with two blocks added, to represent the fact
 
135
     * that the diagonals of the overall grid must also contain the numbers
 
136
     * 1 to blockSize * blockSize (e.g. 1 to 9).
 
137
     *
 
138
     * @param index         The current position in the list of groups.
 
139
     * @return              The updated position in the list of groups.
 
140
     */
 
141
    virtual qint32          makeBlockIndex (qint32 index);
 
142
};
 
143
 
 
144
/**
 
145
 * @class JigsawBoard  plainsudokuboard.h
 
146
 * @short Data-structures and methods for handling Jigsaw Sudoku puzzles.
 
147
 *
 
148
 * A Jigsaw Sudoku puzzle is exactly like a plain Sudoku puzzle, except that
 
149
 * only the central block is square.  The surrounding blocks have tabs and holes
 
150
 * and interlock like jigsaw puzzle pieces.  The block size is always 3.
 
151
 */
 
152
class JigsawBoard : public PlainSudokuBoard
 
153
{
 
154
    Q_OBJECT
 
155
public:
 
156
    /**
 
157
     * Constructs a new JigsawBoard object with required type and size.
 
158
     *
 
159
     * @param parent        A pointer to the object that owns this object and
 
160
     *                      will delete it automatically.
 
161
     * @param sudokuType    The type of Sudoku board required, which should
 
162
     *                      always be SudokuType::Jigsaw.
 
163
     * @param blockSize     The size of blocks required (must be 3).  The board
 
164
     *                      will have blocks, rows and columns with 3x3 = 9
 
165
     *                      cells and the numbers to be filled in will range
 
166
     *                      from 1 to 9.
 
167
     * @see globals.h
 
168
     */
 
169
    JigsawBoard (QObject * parent, SudokuType sudokuType, int blockSize);
 
170
 
 
171
protected:
 
172
    /**
 
173
     * Make a list of cells in blocks of the board.  This differs completely
 
174
     * from the plain Sudoku's makeBlockIndex() because of the irregular
 
175
     * arrangement of the blocks.
 
176
     *
 
177
     * @param index         The current position in the list of groups.
 
178
     * @return              The updated position in the list of groups.
 
179
     */
 
180
    virtual qint32          makeBlockIndex (qint32 index);
 
181
};
 
182
 
 
183
#endif // PLAINSUDOKUBOARD_H