1
/****************************************************************************
2
* Copyright 2011 Ian Wadham <iandw.au@gmail.com> *
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. *
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. *
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
****************************************************************************/
18
#ifndef PLAINSUDOKUBOARD_H
19
#define PLAINSUDOKUBOARD_H
21
#include "sudokuboard.h"
24
* @class PlainSudokuBoard plainsudokuboard.h
25
* @short Data-structures and methods for handling plain Sudoku puzzles.
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.
34
class PlainSudokuBoard : public SudokuBoard
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.
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).
54
PlainSudokuBoard (QObject * parent, SudokuType sudokuType, int blockSize);
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.
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.
65
virtual void setUpBoard();
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.
71
virtual void clear (BoardContents & boardValues);
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.
77
* @return The filled board-vector.
79
virtual BoardContents & fillBoard();
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.
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.
92
virtual qint32 makeRowColIndex (int i, int j, qint32 index);
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).
98
* @param index The current position in the list of groups.
99
* @return The updated position in the list of groups.
101
virtual qint32 makeBlockIndex (qint32 index);
105
* @class XSudokuBoard plainsudokuboard.h
106
* @short Data-structures and methods for handling XSudoku puzzles.
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.
112
class XSudokuBoard : public PlainSudokuBoard
117
* Constructs a new XSudokuBoard object with a required type and size.
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.
129
XSudokuBoard (QObject * parent, SudokuType sudokuType, int blockSize);
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).
138
* @param index The current position in the list of groups.
139
* @return The updated position in the list of groups.
141
virtual qint32 makeBlockIndex (qint32 index);
145
* @class JigsawBoard plainsudokuboard.h
146
* @short Data-structures and methods for handling Jigsaw Sudoku puzzles.
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.
152
class JigsawBoard : public PlainSudokuBoard
157
* Constructs a new JigsawBoard object with required type and size.
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
169
JigsawBoard (QObject * parent, SudokuType sudokuType, int blockSize);
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.
177
* @param index The current position in the list of groups.
178
* @return The updated position in the list of groups.
180
virtual qint32 makeBlockIndex (qint32 index);
183
#endif // PLAINSUDOKUBOARD_H