-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolver.cpp
73 lines (66 loc) · 1.71 KB
/
solver.cpp
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
70
71
72
73
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
class Puzzle {
public:
Puzzle() {}
~Puzzle() {}
short slot_count() {return this->n_slot;}
void print();
void init_from_file(const string);
private:
short n_slot;
short grid[9][9];
short candidates[9][9];
};
void Puzzle::print()
{
for (int x = 0; x < 9; ++x) {
for (int y = 0; y < 9; ++y) {
short v = grid[x][y];
if (v == 0) {
cout << "_";
} else {
cout << v;
}
}
cout << endl;
}
}
void Puzzle::init_from_file(const string filename)
{
ifstream ifile;
ifile.open(filename.c_str());
char c;
for (int x = 0; x < 9; ++x) {
for (int y = 0; y < 9; ++y) {
ifile.read(&c, 1);
if (c == '_') {
this->grid[x][y] = 0;
} else {
this->grid[x][y] = c - '0';
}
}
ifile.read(&c, 1); // '\n'
}
ifile.close();
}
Puzzle resolve(const Puzzle puzzle)
{
vector<Puzzle> stack;
stack.push_back(puzzle);
while (!stack.empty()) {
Puzzle result = stack.pop_back();
return result
}
}
int main(int argv, char *argc[])
{
Puzzle p;
p.init_from_file("puzzle1");
p.print();
cout << "result" << endl;
Puzzle result = resolve(p);
result.print();
}