summaryrefslogtreecommitdiff
path: root/src/sudoku.h
blob: 965de092c38b2463ac2da1cb21e133888bd73c60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

#ifndef __INCLUDED_SUDOKUSOLVER_SUDOKU__
#define __INCLUDED_SUDOKUSOLVER_SUDOKU__

#include "cell.h"

class Sudoku {
	
public:
	Sudoku();
	
	Sudoku(const Sudoku & other);
	
	void assign(const Sudoku & other);
	
	int compare_and_assign(const Sudoku & other);
	
	void reset();
	
	bool validate();

	bool solved();
	
	/**
	 * @brief reset solution space of the given cell
	 * */
	void reset_cell(int pos_row, int pos_column);
	
	/**
	 * @brief resolve sudoku constraint rules for a single cell
	 * */
	int solve_constraints(int pos_row, int pos_column);
	
	/**
	 * @brief resolve sudoku constraint rules
	 * */
	int solve_constraints();
	
	/**
	 * @brief resolve sudoku coverage rules
	 * */
	int solve_coverage();
	
	/**
	 * @brief solve the sudoku, using constraint and converage rules only
	 * */
	int solve_rules();
	
	/**
	 * @brief solve the sudoku, using full search
	 * */
	int solve_search();
	
	inline Cell & cell (int row, int column)
	{
		return sudoku_cell[row][column];
	}
	
	inline const Cell & cell(int row, int column) const 
	{
		return sudoku_cell[row][column];
	}
private:
	bool solve_search_step(int &iterations, Sudoku & solution);
	
	Cell sudoku_cell[9][9];
};

#endif // __INCLUDED_SUDOKUSOLVER_SUDOKU__