Skip to content

Commit 5d66dfb

Browse files
committed
refactor
1 parent 1ca2526 commit 5d66dfb

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

written/public/games/queens.html

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
for (let i = 1; i <= 10; i++) {
1010
cssRules += `
11-
#app:has(.row > *:nth-child(${i}):is(.cell.queen))
12-
.row
13-
> *:nth-child(${i}):after,
11+
#app:has(.row > *:nth-child(${i}):is(.cell.queen)) .row > *:nth-child(${i}):after,
1412
`;
1513
}
1614

@@ -21,23 +19,19 @@
2119
}`;
2220

2321
// Generate diagonal rules
22+
const directions = [
23+
[-1, -1], [-1, 1], [1, -1], [1, 1]
24+
];
25+
2426
for (let i = 1; i <= 10; i++) {
2527
for (let j = 1; j <= 10; j++) {
26-
cssRules += `
27-
#app:has(.row:nth-child(${i}) > *:nth-child(${j}):is(.cell.queen)) .row:nth-child(${
28-
i - 1
29-
}) > *:nth-child(${j - 1}):after,
30-
#app:has(.row:nth-child(${i}) > *:nth-child(${j}):is(.cell.queen)) .row:nth-child(${
31-
i - 1
32-
}) > *:nth-child(${j + 1}):after,
33-
#app:has(.row:nth-child(${i}) > *:nth-child(${j}):is(.cell.queen)) .row:nth-child(${
34-
i + 1
35-
}) > *:nth-child(${j - 1}):after,
36-
#app:has(.row:nth-child(${i}) > *:nth-child(${j}):is(.cell.queen)) .row:nth-child(${
37-
i + 1
38-
}) > *:nth-child(${j + 1}):after {
28+
directions.forEach(([di, dj]) => {
29+
cssRules += `
30+
#app:has(.row:nth-child(${i}) > *:nth-child(${j}):is(.cell.queen)) .row:nth-child(${i + di}) > *:nth-child(${j + dj}):after {
3931
content: "❌";
40-
}`;
32+
}
33+
`;
34+
});
4135
}
4236
}
4337

0 commit comments

Comments
 (0)