-
Notifications
You must be signed in to change notification settings - Fork 1
/
SudokuState.h
49 lines (37 loc) · 1.75 KB
/
SudokuState.h
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
#pragma once
#include <Arduino.h>
#include <array>
#include "SudokuSquare.h"
class SudokuState
{
public:
SudokuState() = default;
protected:
using tdSquares = std::array<std::array<SudokuSquare,9>,9>;
tdSquares Squares;
constexpr static uint8_t maxDepth = 64;
static bool hasSave;
public:
void GenerateEmpty() { for( uint8_t x = 0 ; x < 9 ; x++ ) for( uint8_t y = 0 ; y < 9 ; y++ ) Squares[x][y] = SudokuSquare(); };
void GenerateFromString( String str );
void GenerateRandom( uint8_t targetFixedCells, uint32_t targetSolveTimeMS );
bool Propagate(); // returns true if any changes were made
bool PropagateOnce( uint16_t iLoop = 0 ); // returns true if a change was made
bool SolveByGuessing( uint8_t depth = maxDepth ); // returns true if solved
uint8_t SolveUniquely( uint8_t depth = maxDepth, uint8_t x = 0, uint8_t y = 0, uint8_t count = 0 ); // returns 0 if unsolved, 1 if unique solution found or 2 if more than one solution found
bool Valid() const;
bool Solved() const;
uint16_t SumCount() const;
uint8_t CountFixed() const;
bool CheckPossible(uint8_t x, uint8_t y, uint8_t val) const;
Point<int8_t> FindLowestCountUnsolvedSquare() const;
void FixOneSquare();
SudokuSquare& GetSquare( Point<uint8_t> pt ) { return GetSquare(pt.x,pt.y); };
SudokuSquare& GetSquare( uint8_t x, uint8_t y ) { return Squares[x][y]; };
void Load();
void Save();
static void RemoveSave();
static bool HasSave() { return hasSave; };
static bool CheckHasSave();
void Dump() const;
};