Skip to content

Commit c12a85b

Browse files
Copilotsemiexp
andauthored
Add ColoredGrid(&'static str) to BoardKind to eliminate manual light-colored grid line items (#214)
* Initial plan * Add ColoredGrid to BoardKind and update all applicable puzzle implementations Co-authored-by: semiexp <7336994+semiexp@users.noreply.github.com> Agent-Logs-Url: https://github.com/semiexp/cspuz_core/sessions/83884bca-6372-4a44-8e73-0df8011c58c6 * Fix to_json for ColoredGrid: use outer_grid style and prepend grid line Items Co-authored-by: semiexp <7336994+semiexp@users.noreply.github.com> Agent-Logs-Url: https://github.com/semiexp/cspuz_core/sessions/59b08ec1-4559-48d4-973a-8199450b3e5a --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: semiexp <7336994+semiexp@users.noreply.github.com>
1 parent d692b86 commit c12a85b

23 files changed

Lines changed: 191 additions & 975 deletions

cspuz_solver_backend/src/board.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ pub enum BoardKind {
222222
Grid,
223223
OuterGrid,
224224
DotGrid,
225+
ColoredGrid(&'static str),
225226
}
226227

227228
#[derive(Debug, PartialEq, Eq)]
@@ -338,7 +339,7 @@ impl Board {
338339
}
339340
}
340341
}
341-
if need_default_edge {
342+
if need_default_edge && !matches!(self.kind, BoardKind::ColoredGrid(_)) {
342343
self.push(Item {
343344
y: y * 2 + 2,
344345
x: x * 2 + 1,
@@ -366,7 +367,7 @@ impl Board {
366367
}
367368
}
368369
}
369-
if need_default_edge {
370+
if need_default_edge && !matches!(self.kind, BoardKind::ColoredGrid(_)) {
370371
self.push(Item {
371372
y: y * 2 + 1,
372373
x: x * 2 + 2,
@@ -430,10 +431,37 @@ impl Board {
430431
BoardKind::Grid => "grid",
431432
BoardKind::OuterGrid => "outer_grid",
432433
BoardKind::DotGrid => "dots",
434+
BoardKind::ColoredGrid(_) => "outer_grid",
433435
};
434-
let data = self
435-
.data
436+
let grid_line_items: Vec<Item> = if let BoardKind::ColoredGrid(color) = self.kind {
437+
let mut items = vec![];
438+
for y in 0..height {
439+
for x in 0..width {
440+
if y < height - 1 {
441+
items.push(Item {
442+
y: y * 2 + 2,
443+
x: x * 2 + 1,
444+
color,
445+
kind: ItemKind::Wall,
446+
});
447+
}
448+
if x < width - 1 {
449+
items.push(Item {
450+
y: y * 2 + 1,
451+
x: x * 2 + 2,
452+
color,
453+
kind: ItemKind::Wall,
454+
});
455+
}
456+
}
457+
}
458+
items
459+
} else {
460+
vec![]
461+
};
462+
let data = grid_line_items
436463
.iter()
464+
.chain(self.data.iter())
437465
.map(|item| item.to_json())
438466
.collect::<Vec<_>>()
439467
.join(",");

cspuz_solver_backend/src/puzzle/araf.rs

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ pub fn solve(url: &str) -> Result<Board, &'static str> {
88

99
let height = problem.len();
1010
let width = problem[0].len();
11-
let mut board = Board::new(BoardKind::OuterGrid, height, width, check_uniqueness(&ans));
11+
let mut board = Board::new(
12+
BoardKind::ColoredGrid("#cccccc"),
13+
height,
14+
width,
15+
check_uniqueness(&ans),
16+
);
1217
for y in 0..height {
1318
for x in 0..width {
1419
if let Some(clue) = problem[y][x] {
@@ -40,7 +45,7 @@ mod tests {
4045
compare_board_and_check_no_solution_case!(
4146
solve("https://puzz.link/p?araf/6/6/h3j3j3p-1cj8j8h"),
4247
Board {
43-
kind: BoardKind::OuterGrid,
48+
kind: BoardKind::ColoredGrid("#cccccc"),
4449
height: 6,
4550
width: 6,
4651
data: vec![
@@ -57,107 +62,65 @@ mod tests {
5762
Item { y: 11, x: 7, color: "black", kind: ItemKind::Circle },
5863
Item { y: 11, x: 7, color: "black", kind: ItemKind::Num(8) },
5964
Item { y: 2, x: 1, color: "green", kind: ItemKind::Cross },
60-
Item { y: 2, x: 1, color: "#cccccc", kind: ItemKind::Wall },
6165
Item { y: 1, x: 2, color: "green", kind: ItemKind::Cross },
62-
Item { y: 1, x: 2, color: "#cccccc", kind: ItemKind::Wall },
6366
Item { y: 2, x: 3, color: "green", kind: ItemKind::BoldWall },
6467
Item { y: 1, x: 4, color: "green", kind: ItemKind::Cross },
65-
Item { y: 1, x: 4, color: "#cccccc", kind: ItemKind::Wall },
6668
Item { y: 2, x: 5, color: "green", kind: ItemKind::Cross },
67-
Item { y: 2, x: 5, color: "#cccccc", kind: ItemKind::Wall },
6869
Item { y: 1, x: 6, color: "green", kind: ItemKind::Cross },
69-
Item { y: 1, x: 6, color: "#cccccc", kind: ItemKind::Wall },
7070
Item { y: 2, x: 7, color: "green", kind: ItemKind::Cross },
71-
Item { y: 2, x: 7, color: "#cccccc", kind: ItemKind::Wall },
7271
Item { y: 1, x: 8, color: "green", kind: ItemKind::Cross },
73-
Item { y: 1, x: 8, color: "#cccccc", kind: ItemKind::Wall },
7472
Item { y: 2, x: 9, color: "green", kind: ItemKind::Cross },
75-
Item { y: 2, x: 9, color: "#cccccc", kind: ItemKind::Wall },
7673
Item { y: 1, x: 10, color: "green", kind: ItemKind::Cross },
77-
Item { y: 1, x: 10, color: "#cccccc", kind: ItemKind::Wall },
7874
Item { y: 2, x: 11, color: "green", kind: ItemKind::Cross },
79-
Item { y: 2, x: 11, color: "#cccccc", kind: ItemKind::Wall },
8075
Item { y: 4, x: 1, color: "green", kind: ItemKind::BoldWall },
8176
Item { y: 3, x: 2, color: "green", kind: ItemKind::BoldWall },
8277
Item { y: 4, x: 3, color: "green", kind: ItemKind::Cross },
83-
Item { y: 4, x: 3, color: "#cccccc", kind: ItemKind::Wall },
8478
Item { y: 3, x: 4, color: "green", kind: ItemKind::BoldWall },
8579
Item { y: 4, x: 5, color: "green", kind: ItemKind::Cross },
86-
Item { y: 4, x: 5, color: "#cccccc", kind: ItemKind::Wall },
8780
Item { y: 3, x: 6, color: "green", kind: ItemKind::Cross },
88-
Item { y: 3, x: 6, color: "#cccccc", kind: ItemKind::Wall },
8981
Item { y: 4, x: 7, color: "green", kind: ItemKind::Cross },
90-
Item { y: 4, x: 7, color: "#cccccc", kind: ItemKind::Wall },
9182
Item { y: 3, x: 8, color: "green", kind: ItemKind::Cross },
92-
Item { y: 3, x: 8, color: "#cccccc", kind: ItemKind::Wall },
9383
Item { y: 4, x: 9, color: "green", kind: ItemKind::Cross },
94-
Item { y: 4, x: 9, color: "#cccccc", kind: ItemKind::Wall },
9584
Item { y: 3, x: 10, color: "green", kind: ItemKind::Cross },
96-
Item { y: 3, x: 10, color: "#cccccc", kind: ItemKind::Wall },
9785
Item { y: 4, x: 11, color: "green", kind: ItemKind::Cross },
98-
Item { y: 4, x: 11, color: "#cccccc", kind: ItemKind::Wall },
9986
Item { y: 6, x: 1, color: "green", kind: ItemKind::Cross },
100-
Item { y: 6, x: 1, color: "#cccccc", kind: ItemKind::Wall },
10187
Item { y: 5, x: 2, color: "green", kind: ItemKind::BoldWall },
10288
Item { y: 6, x: 3, color: "green", kind: ItemKind::Cross },
103-
Item { y: 6, x: 3, color: "#cccccc", kind: ItemKind::Wall },
10489
Item { y: 5, x: 4, color: "green", kind: ItemKind::BoldWall },
10590
Item { y: 6, x: 5, color: "green", kind: ItemKind::Cross },
106-
Item { y: 6, x: 5, color: "#cccccc", kind: ItemKind::Wall },
10791
Item { y: 5, x: 6, color: "green", kind: ItemKind::Cross },
108-
Item { y: 5, x: 6, color: "#cccccc", kind: ItemKind::Wall },
10992
Item { y: 6, x: 7, color: "green", kind: ItemKind::Cross },
110-
Item { y: 6, x: 7, color: "#cccccc", kind: ItemKind::Wall },
11193
Item { y: 5, x: 8, color: "green", kind: ItemKind::Cross },
112-
Item { y: 5, x: 8, color: "#cccccc", kind: ItemKind::Wall },
11394
Item { y: 6, x: 9, color: "green", kind: ItemKind::Cross },
114-
Item { y: 6, x: 9, color: "#cccccc", kind: ItemKind::Wall },
11595
Item { y: 5, x: 10, color: "green", kind: ItemKind::Cross },
116-
Item { y: 5, x: 10, color: "#cccccc", kind: ItemKind::Wall },
11796
Item { y: 6, x: 11, color: "green", kind: ItemKind::Cross },
118-
Item { y: 6, x: 11, color: "#cccccc", kind: ItemKind::Wall },
11997
Item { y: 8, x: 1, color: "green", kind: ItemKind::Cross },
120-
Item { y: 8, x: 1, color: "#cccccc", kind: ItemKind::Wall },
12198
Item { y: 7, x: 2, color: "green", kind: ItemKind::BoldWall },
12299
Item { y: 8, x: 3, color: "green", kind: ItemKind::Cross },
123-
Item { y: 8, x: 3, color: "#cccccc", kind: ItemKind::Wall },
124100
Item { y: 7, x: 4, color: "green", kind: ItemKind::BoldWall },
125101
Item { y: 8, x: 5, color: "green", kind: ItemKind::BoldWall },
126102
Item { y: 7, x: 6, color: "green", kind: ItemKind::Cross },
127-
Item { y: 7, x: 6, color: "#cccccc", kind: ItemKind::Wall },
128103
Item { y: 8, x: 7, color: "green", kind: ItemKind::BoldWall },
129104
Item { y: 7, x: 8, color: "green", kind: ItemKind::Cross },
130-
Item { y: 7, x: 8, color: "#cccccc", kind: ItemKind::Wall },
131105
Item { y: 8, x: 9, color: "green", kind: ItemKind::BoldWall },
132106
Item { y: 7, x: 10, color: "green", kind: ItemKind::Cross },
133-
Item { y: 7, x: 10, color: "#cccccc", kind: ItemKind::Wall },
134107
Item { y: 8, x: 11, color: "green", kind: ItemKind::Cross },
135-
Item { y: 8, x: 11, color: "#cccccc", kind: ItemKind::Wall },
136108
Item { y: 10, x: 1, color: "green", kind: ItemKind::Cross },
137-
Item { y: 10, x: 1, color: "#cccccc", kind: ItemKind::Wall },
138109
Item { y: 9, x: 2, color: "green", kind: ItemKind::BoldWall },
139110
Item { y: 10, x: 3, color: "green", kind: ItemKind::BoldWall },
140111
Item { y: 9, x: 4, color: "green", kind: ItemKind::Cross },
141-
Item { y: 9, x: 4, color: "#cccccc", kind: ItemKind::Wall },
142112
Item { y: 10, x: 5, color: "green", kind: ItemKind::BoldWall },
143113
Item { y: 9, x: 6, color: "green", kind: ItemKind::Cross },
144-
Item { y: 9, x: 6, color: "#cccccc", kind: ItemKind::Wall },
145114
Item { y: 10, x: 7, color: "green", kind: ItemKind::BoldWall },
146115
Item { y: 9, x: 8, color: "green", kind: ItemKind::Cross },
147-
Item { y: 9, x: 8, color: "#cccccc", kind: ItemKind::Wall },
148116
Item { y: 10, x: 9, color: "green", kind: ItemKind::BoldWall },
149117
Item { y: 9, x: 10, color: "green", kind: ItemKind::BoldWall },
150118
Item { y: 10, x: 11, color: "green", kind: ItemKind::Cross },
151-
Item { y: 10, x: 11, color: "#cccccc", kind: ItemKind::Wall },
152119
Item { y: 11, x: 2, color: "green", kind: ItemKind::Cross },
153-
Item { y: 11, x: 2, color: "#cccccc", kind: ItemKind::Wall },
154120
Item { y: 11, x: 4, color: "green", kind: ItemKind::Cross },
155-
Item { y: 11, x: 4, color: "#cccccc", kind: ItemKind::Wall },
156121
Item { y: 11, x: 6, color: "green", kind: ItemKind::Cross },
157-
Item { y: 11, x: 6, color: "#cccccc", kind: ItemKind::Wall },
158122
Item { y: 11, x: 8, color: "green", kind: ItemKind::BoldWall },
159123
Item { y: 11, x: 10, color: "green", kind: ItemKind::Cross },
160-
Item { y: 11, x: 10, color: "#cccccc", kind: ItemKind::Wall },
161124
],
162125
uniqueness: Uniqueness::Unique,
163126
},

0 commit comments

Comments
 (0)