-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlits.rs
More file actions
231 lines (224 loc) · 15.6 KB
/
Copy pathlits.rs
File metadata and controls
231 lines (224 loc) · 15.6 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
use crate::board::{Board, BoardKind, Item, ItemKind};
use crate::uniqueness::{is_unique, Uniqueness};
use cspuz_rs_puzzles::puzzles::lits;
pub fn solve(url: &str) -> Result<Board, &'static str> {
let borders = lits::deserialize_problem(url).ok_or("invalid url")?;
let ans = lits::solve_lits(&borders);
let height = borders.horizontal.len() + 1;
let width = if borders.horizontal.is_empty() {
0
} else {
borders.horizontal[0].len()
};
let mut board = Board::new(
BoardKind::Grid,
height,
width,
ans.as_ref().map_or(Uniqueness::NoAnswer, |a| is_unique(a)),
);
board.add_borders(&borders, "black");
if let Some(is_black) = &ans {
board.add_block_dot_answer(is_black, "green");
}
Ok(board)
}
#[cfg(test)]
mod tests {
use super::solve;
use crate::board::*;
use crate::compare_board_and_check_no_solution_case;
use crate::uniqueness::Uniqueness;
#[test]
#[rustfmt::skip]
fn test_solve() {
compare_board_and_check_no_solution_case!(
solve("https://puzz.link/p?lits/10/10/08p0i3jbhmjg5j5ik048rgtr8q1e5gkf9hnu"),
Board {
kind: BoardKind::Grid,
height: 10,
width: 10,
data: vec![
Item { y: 2, x: 5, color: "black", kind: ItemKind::BoldWall },
Item { y: 2, x: 13, color: "black", kind: ItemKind::BoldWall },
Item { y: 1, x: 14, color: "black", kind: ItemKind::BoldWall },
Item { y: 4, x: 1, color: "black", kind: ItemKind::BoldWall },
Item { y: 4, x: 3, color: "black", kind: ItemKind::BoldWall },
Item { y: 3, x: 4, color: "black", kind: ItemKind::BoldWall },
Item { y: 3, x: 6, color: "black", kind: ItemKind::BoldWall },
Item { y: 4, x: 7, color: "black", kind: ItemKind::BoldWall },
Item { y: 4, x: 9, color: "black", kind: ItemKind::BoldWall },
Item { y: 4, x: 11, color: "black", kind: ItemKind::BoldWall },
Item { y: 3, x: 12, color: "black", kind: ItemKind::BoldWall },
Item { y: 6, x: 1, color: "black", kind: ItemKind::BoldWall },
Item { y: 6, x: 3, color: "black", kind: ItemKind::BoldWall },
Item { y: 6, x: 5, color: "black", kind: ItemKind::BoldWall },
Item { y: 5, x: 6, color: "black", kind: ItemKind::BoldWall },
Item { y: 6, x: 9, color: "black", kind: ItemKind::BoldWall },
Item { y: 6, x: 11, color: "black", kind: ItemKind::BoldWall },
Item { y: 5, x: 12, color: "black", kind: ItemKind::BoldWall },
Item { y: 6, x: 13, color: "black", kind: ItemKind::BoldWall },
Item { y: 6, x: 17, color: "black", kind: ItemKind::BoldWall },
Item { y: 6, x: 19, color: "black", kind: ItemKind::BoldWall },
Item { y: 8, x: 3, color: "black", kind: ItemKind::BoldWall },
Item { y: 7, x: 4, color: "black", kind: ItemKind::BoldWall },
Item { y: 7, x: 6, color: "black", kind: ItemKind::BoldWall },
Item { y: 7, x: 8, color: "black", kind: ItemKind::BoldWall },
Item { y: 8, x: 11, color: "black", kind: ItemKind::BoldWall },
Item { y: 8, x: 13, color: "black", kind: ItemKind::BoldWall },
Item { y: 7, x: 14, color: "black", kind: ItemKind::BoldWall },
Item { y: 7, x: 16, color: "black", kind: ItemKind::BoldWall },
Item { y: 8, x: 17, color: "black", kind: ItemKind::BoldWall },
Item { y: 9, x: 2, color: "black", kind: ItemKind::BoldWall },
Item { y: 9, x: 6, color: "black", kind: ItemKind::BoldWall },
Item { y: 9, x: 8, color: "black", kind: ItemKind::BoldWall },
Item { y: 10, x: 9, color: "black", kind: ItemKind::BoldWall },
Item { y: 9, x: 10, color: "black", kind: ItemKind::BoldWall },
Item { y: 10, x: 13, color: "black", kind: ItemKind::BoldWall },
Item { y: 10, x: 15, color: "black", kind: ItemKind::BoldWall },
Item { y: 10, x: 17, color: "black", kind: ItemKind::BoldWall },
Item { y: 9, x: 18, color: "black", kind: ItemKind::BoldWall },
Item { y: 11, x: 2, color: "black", kind: ItemKind::BoldWall },
Item { y: 12, x: 5, color: "black", kind: ItemKind::BoldWall },
Item { y: 11, x: 6, color: "black", kind: ItemKind::BoldWall },
Item { y: 11, x: 8, color: "black", kind: ItemKind::BoldWall },
Item { y: 12, x: 9, color: "black", kind: ItemKind::BoldWall },
Item { y: 12, x: 11, color: "black", kind: ItemKind::BoldWall },
Item { y: 11, x: 12, color: "black", kind: ItemKind::BoldWall },
Item { y: 11, x: 18, color: "black", kind: ItemKind::BoldWall },
Item { y: 14, x: 1, color: "black", kind: ItemKind::BoldWall },
Item { y: 13, x: 2, color: "black", kind: ItemKind::BoldWall },
Item { y: 13, x: 4, color: "black", kind: ItemKind::BoldWall },
Item { y: 14, x: 5, color: "black", kind: ItemKind::BoldWall },
Item { y: 14, x: 13, color: "black", kind: ItemKind::BoldWall },
Item { y: 14, x: 15, color: "black", kind: ItemKind::BoldWall },
Item { y: 14, x: 17, color: "black", kind: ItemKind::BoldWall },
Item { y: 13, x: 18, color: "black", kind: ItemKind::BoldWall },
Item { y: 14, x: 19, color: "black", kind: ItemKind::BoldWall },
Item { y: 16, x: 3, color: "black", kind: ItemKind::BoldWall },
Item { y: 15, x: 4, color: "black", kind: ItemKind::BoldWall },
Item { y: 15, x: 6, color: "black", kind: ItemKind::BoldWall },
Item { y: 16, x: 9, color: "black", kind: ItemKind::BoldWall },
Item { y: 16, x: 11, color: "black", kind: ItemKind::BoldWall },
Item { y: 15, x: 12, color: "black", kind: ItemKind::BoldWall },
Item { y: 15, x: 14, color: "black", kind: ItemKind::BoldWall },
Item { y: 16, x: 19, color: "black", kind: ItemKind::BoldWall },
Item { y: 18, x: 1, color: "black", kind: ItemKind::BoldWall },
Item { y: 17, x: 2, color: "black", kind: ItemKind::BoldWall },
Item { y: 18, x: 5, color: "black", kind: ItemKind::BoldWall },
Item { y: 17, x: 6, color: "black", kind: ItemKind::BoldWall },
Item { y: 18, x: 7, color: "black", kind: ItemKind::BoldWall },
Item { y: 17, x: 8, color: "black", kind: ItemKind::BoldWall },
Item { y: 18, x: 9, color: "black", kind: ItemKind::BoldWall },
Item { y: 18, x: 11, color: "black", kind: ItemKind::BoldWall },
Item { y: 18, x: 13, color: "black", kind: ItemKind::BoldWall },
Item { y: 17, x: 14, color: "black", kind: ItemKind::BoldWall },
Item { y: 18, x: 15, color: "black", kind: ItemKind::BoldWall },
Item { y: 18, x: 17, color: "black", kind: ItemKind::BoldWall },
Item { y: 17, x: 18, color: "black", kind: ItemKind::BoldWall },
Item { y: 19, x: 4, color: "black", kind: ItemKind::BoldWall },
Item { y: 1, x: 1, color: "green", kind: ItemKind::Dot },
Item { y: 1, x: 3, color: "green", kind: ItemKind::Dot },
Item { y: 1, x: 5, color: "green", kind: ItemKind::Dot },
Item { y: 1, x: 7, color: "green", kind: ItemKind::Dot },
Item { y: 1, x: 9, color: "green", kind: ItemKind::Block },
Item { y: 1, x: 11, color: "green", kind: ItemKind::Dot },
Item { y: 1, x: 13, color: "green", kind: ItemKind::Dot },
Item { y: 1, x: 15, color: "green", kind: ItemKind::Block },
Item { y: 1, x: 17, color: "green", kind: ItemKind::Dot },
Item { y: 1, x: 19, color: "green", kind: ItemKind::Dot },
Item { y: 3, x: 1, color: "green", kind: ItemKind::Dot },
Item { y: 3, x: 3, color: "green", kind: ItemKind::Dot },
Item { y: 3, x: 5, color: "green", kind: ItemKind::Block },
Item { y: 3, x: 7, color: "green", kind: ItemKind::Block },
Item { y: 3, x: 9, color: "green", kind: ItemKind::Block },
Item { y: 3, x: 11, color: "green", kind: ItemKind::Block },
Item { y: 3, x: 13, color: "green", kind: ItemKind::Block },
Item { y: 3, x: 15, color: "green", kind: ItemKind::Block },
Item { y: 3, x: 17, color: "green", kind: ItemKind::Dot },
Item { y: 3, x: 19, color: "green", kind: ItemKind::Dot },
Item { y: 5, x: 1, color: "green", kind: ItemKind::Block },
Item { y: 5, x: 3, color: "green", kind: ItemKind::Block },
Item { y: 5, x: 5, color: "green", kind: ItemKind::Block },
Item { y: 5, x: 7, color: "green", kind: ItemKind::Dot },
Item { y: 5, x: 9, color: "green", kind: ItemKind::Dot },
Item { y: 5, x: 11, color: "green", kind: ItemKind::Dot },
Item { y: 5, x: 13, color: "green", kind: ItemKind::Block },
Item { y: 5, x: 15, color: "green", kind: ItemKind::Dot },
Item { y: 5, x: 17, color: "green", kind: ItemKind::Dot },
Item { y: 5, x: 19, color: "green", kind: ItemKind::Dot },
Item { y: 7, x: 1, color: "green", kind: ItemKind::Block },
Item { y: 7, x: 3, color: "green", kind: ItemKind::Dot },
Item { y: 7, x: 5, color: "green", kind: ItemKind::Block },
Item { y: 7, x: 7, color: "green", kind: ItemKind::Dot },
Item { y: 7, x: 9, color: "green", kind: ItemKind::Block },
Item { y: 7, x: 11, color: "green", kind: ItemKind::Block },
Item { y: 7, x: 13, color: "green", kind: ItemKind::Block },
Item { y: 7, x: 15, color: "green", kind: ItemKind::Dot },
Item { y: 7, x: 17, color: "green", kind: ItemKind::Dot },
Item { y: 7, x: 19, color: "green", kind: ItemKind::Block },
Item { y: 9, x: 1, color: "green", kind: ItemKind::Block },
Item { y: 9, x: 3, color: "green", kind: ItemKind::Block },
Item { y: 9, x: 5, color: "green", kind: ItemKind::Block },
Item { y: 9, x: 7, color: "green", kind: ItemKind::Dot },
Item { y: 9, x: 9, color: "green", kind: ItemKind::Block },
Item { y: 9, x: 11, color: "green", kind: ItemKind::Dot },
Item { y: 9, x: 13, color: "green", kind: ItemKind::Dot },
Item { y: 9, x: 15, color: "green", kind: ItemKind::Dot },
Item { y: 9, x: 17, color: "green", kind: ItemKind::Dot },
Item { y: 9, x: 19, color: "green", kind: ItemKind::Block },
Item { y: 11, x: 1, color: "green", kind: ItemKind::Block },
Item { y: 11, x: 3, color: "green", kind: ItemKind::Dot },
Item { y: 11, x: 5, color: "green", kind: ItemKind::Block },
Item { y: 11, x: 7, color: "green", kind: ItemKind::Block },
Item { y: 11, x: 9, color: "green", kind: ItemKind::Dot },
Item { y: 11, x: 11, color: "green", kind: ItemKind::Dot },
Item { y: 11, x: 13, color: "green", kind: ItemKind::Dot },
Item { y: 11, x: 15, color: "green", kind: ItemKind::Dot },
Item { y: 11, x: 17, color: "green", kind: ItemKind::Dot },
Item { y: 11, x: 19, color: "green", kind: ItemKind::Block },
Item { y: 13, x: 1, color: "green", kind: ItemKind::Block },
Item { y: 13, x: 3, color: "green", kind: ItemKind::Dot },
Item { y: 13, x: 5, color: "green", kind: ItemKind::Dot },
Item { y: 13, x: 7, color: "green", kind: ItemKind::Block },
Item { y: 13, x: 9, color: "green", kind: ItemKind::Dot },
Item { y: 13, x: 11, color: "green", kind: ItemKind::Dot },
Item { y: 13, x: 13, color: "green", kind: ItemKind::Dot },
Item { y: 13, x: 15, color: "green", kind: ItemKind::Dot },
Item { y: 13, x: 17, color: "green", kind: ItemKind::Dot },
Item { y: 13, x: 19, color: "green", kind: ItemKind::Block },
Item { y: 15, x: 1, color: "green", kind: ItemKind::Dot },
Item { y: 15, x: 3, color: "green", kind: ItemKind::Dot },
Item { y: 15, x: 5, color: "green", kind: ItemKind::Dot },
Item { y: 15, x: 7, color: "green", kind: ItemKind::Block },
Item { y: 15, x: 9, color: "green", kind: ItemKind::Dot },
Item { y: 15, x: 11, color: "green", kind: ItemKind::Dot },
Item { y: 15, x: 13, color: "green", kind: ItemKind::Block },
Item { y: 15, x: 15, color: "green", kind: ItemKind::Block },
Item { y: 15, x: 17, color: "green", kind: ItemKind::Block },
Item { y: 15, x: 19, color: "green", kind: ItemKind::Block },
Item { y: 17, x: 1, color: "green", kind: ItemKind::Dot },
Item { y: 17, x: 3, color: "green", kind: ItemKind::Block },
Item { y: 17, x: 5, color: "green", kind: ItemKind::Block },
Item { y: 17, x: 7, color: "green", kind: ItemKind::Block },
Item { y: 17, x: 9, color: "green", kind: ItemKind::Block },
Item { y: 17, x: 11, color: "green", kind: ItemKind::Block },
Item { y: 17, x: 13, color: "green", kind: ItemKind::Block },
Item { y: 17, x: 15, color: "green", kind: ItemKind::Dot },
Item { y: 17, x: 17, color: "green", kind: ItemKind::Block },
Item { y: 17, x: 19, color: "green", kind: ItemKind::Dot },
Item { y: 19, x: 1, color: "green", kind: ItemKind::Block },
Item { y: 19, x: 3, color: "green", kind: ItemKind::Block },
Item { y: 19, x: 5, color: "green", kind: ItemKind::Dot },
Item { y: 19, x: 7, color: "green", kind: ItemKind::Dot },
Item { y: 19, x: 9, color: "green", kind: ItemKind::Dot },
Item { y: 19, x: 11, color: "green", kind: ItemKind::Dot },
Item { y: 19, x: 13, color: "green", kind: ItemKind::Block },
Item { y: 19, x: 15, color: "green", kind: ItemKind::Block },
Item { y: 19, x: 17, color: "green", kind: ItemKind::Block },
Item { y: 19, x: 19, color: "green", kind: ItemKind::Block },
],
uniqueness: Uniqueness::Unique,
},
);
}
}