-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsudoku-gen.h
56 lines (41 loc) · 1.1 KB
/
sudoku-gen.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
50
51
52
53
54
55
56
#include <set>
#include <deque>
#include <memory>
#include <sstream>
struct coord {
int i = 0;
int j = 0;
};
class SudokuCell {
public:
coord pos;
std::set<coord> neighbors{}; // neighbors to look at when filling from top-left to bottom right
int value = 0;
SudokuCell() {}
void setPosition(coord pos);
private:
void generateOptimalNeighbors ();
};
using cellQueue = std::deque<std::shared_ptr<SudokuCell>>;
class SudokuBoard {
cellQueue cells;
public:
SudokuBoard();
void fillCells();
std::string serialize();
private:
bool doFillCells(int index);
std::shared_ptr<SudokuCell> at(int index);
std::shared_ptr<SudokuCell> at(coord position);
};
SudokuBoard generateAndFillBoard();
void generateAndFillBoards(int numBoards);
#ifdef WASM
#include <emscripten/bind.h>
EMSCRIPTEN_BINDINGS(sudoku_gen) {
emscripten::function("generateAndFillBoard", &generateAndFillBoard);
emscripten::function("generateAndFillBoards", &generateAndFillBoards);
emscripten::class_<SudokuBoard>("SudokuBoard")
.function("serialize", &SudokuBoard::serialize);
}
#endif