-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_coloring.cpp
116 lines (104 loc) · 3.35 KB
/
simple_coloring.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "simple_coloring.h"
SimpleColoring::SimpleColoring(std::vector<Target> _targets, std::vector<Key> _keys, DigitChain _chain, int _val) {
targets = _targets;
keys = _keys;
chain = _chain;
val = _val;
}
void SimpleColoring::apply(BitMatrix* bits) {
for(int i=0; i < targets.size(); i++) {
targets[i].apply(bits);
}
}
void SimpleColoring::full_display(Output* out) {
for(int i=0; i < targets.size(); i++) {
Target target = targets[i];
for(int j=0; j < target.candidates.size(); j++) {
out->highlight_candidate(target.spot, target.candidates[j], 0.5, 0.5, 0.5);
}
if(target.to_value != 0) {
out->highlight_candidate(target.spot, target.to_value, 1.0, 1.0, 1.0);
}
}
for(int i=0; i < chain.verts.size(); i++) {
DigitVertex v = chain.verts[i];
if(v.color == DC_BLACK) {
out->highlight_cell(v.spot, 1.0, 0.7, 0.7);
} else if(v.color == DC_WHITE) {
out->highlight_cell(v.spot, 0.7, 1.0, 0.7);
}
}
}
void SimpleColoring::display_keys(Output* out) {
for(int i=0; i < keys.size(); i++) {
float weight = (keys[i].multiplicity == 1 ? 0.0 : (keys[i].multiplicity == 2 ? 0.5 : 0.8));
out->outline_cell(keys[i].spot, 1.5, 1.0, weight, weight);
}
}
std::vector<Target> SimpleColoring::target_list() {
return targets;
}
std::vector<Key> SimpleColoring::key_list() {
return keys;
}
Pattern* SimpleColoring::clone() {
return (new SimpleColoring(*this));
}
void SimpleColoring::describe(std::ostream& out) {
out << this;
}
std::ostream& operator<<(std::ostream& out, SimpleColoring* sc) {
out << "Simple Coloring";
return out;
}
std::vector<SimpleColoring> find_simple_colorings(Bits* bits) {
//std::cout << "SC" << std::endl;
std::vector<SimpleColoring> ret;
for(int digit=1; digit <= 9; digit++) {
//std::cout << digit << std::endl;
std::vector<int> vals;
vals.push_back(digit);
DigitChains dchains(digit);
//std::cout << "DC initted" << std::endl;
dchains.add_links(bits);
//std::cout << "DC added links" << std::endl;
//std::cout << digit << ": " << dchains.chains.size() << " chains" << std::endl;
for(int chidx=0; chidx < dchains.chains.size(); chidx++) {
std::vector<Target> targets;
dchains.chains[chidx].scan_false_color();
if(!dchains.chains[chidx].black) {
//std::cout << "false black" << std::endl;
for(int vidx=0; vidx < dchains.chains[chidx].verts.size(); vidx++) {
DigitVertex v = dchains.chains[chidx].verts[vidx];
if(v.color == DC_BLACK) {
targets.push_back(Target(v.spot, vals, 0));
} else {
targets.push_back(Target(v.spot, digit));
}
}
}
if(!dchains.chains[chidx].white) {
//std::cout << "false white" << std::endl;
for(int vidx=0; vidx < dchains.chains[chidx].verts.size(); vidx++) {
DigitVertex v = dchains.chains[chidx].verts[vidx];
if(v.color == DC_WHITE) {
targets.push_back(Target(v.spot, vals, 0));
} else {
targets.push_back(Target(v.spot, digit));
}
}
}
std::vector<Spot> boths = dchains.chains[chidx].both_cover(bits);
for(int i=0; i < boths.size(); i++) {
//std::cout << "found boths, " << boths[i] << " " << digit << std::endl;
targets.push_back(Target(boths[i], vals, 0));
}
if(targets.size() == 0) { continue; }
//std::cout << "\tfound colorings" << std::endl;
// NOTE NOTE NOTE
// need keys
ret.push_back(SimpleColoring(targets, std::vector<Key>(), dchains.chains[chidx], digit));
}
}
return ret;
}