-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcoordinates.js
More file actions
71 lines (65 loc) · 2 KB
/
coordinates.js
File metadata and controls
71 lines (65 loc) · 2 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
import { disjoint, interval, matrixInterval } from "./utils.js";
const level0 = [
...interval(1, 12, (x) => [x, 0, 0]),
...interval(3, 10, (x) => [x, 1, 0]),
...interval(2, 11, (x) => [x, 2, 0]),
[0, 3.5, 0],
...interval(1, 12, (x) => [x, 3, 0]),
...interval(1, 12, (x) => [x, 4, 0]),
[13, 3.5, 0],
[14, 3.5, 0],
...interval(2, 11, (x) => [x, 5, 0]),
...interval(3, 10, (x) => [x, 6, 0]),
...interval(1, 12, (x) => [x, 7, 0]),
].reverse();
const level1 = matrixInterval(4, 9, 1, 6, (x, y) => [x, y, 1]).reverse();
const level2 = matrixInterval(5, 8, 2, 5, (x, y) => [x, y, 2]).reverse();
const level3 = matrixInterval(6, 7, 3, 4, (x, y) => [x, y, 3]).reverse();
const level4 = [[6.5, 3.5, 4]];
export const COORDINATES = [...level0, ...level1, ...level2, ...level3, ...level4];
function leftNeighbors(coord) {
if (
coord.toString() === [1, 3, 0].toString() ||
coord.toString() === [1, 4, 0].toString()
) {
return [[0, 3.5, 0]];
}
if (coord.toString() === [13, 3.5, 0].toString()) {
return [
[12, 3, 0],
[12, 4, 0],
];
}
const [x, y, z] = coord;
return [[x - 1, y, z]];
}
function rightNeighbors(coord) {
if (coord.toString() === [0, 3.5, 0].toString()) {
return [
[1, 3, 0],
[1, 4, 0],
];
}
if (
coord.toString() === [12, 3, 0].toString() ||
coord.toString() === [12, 4, 0].toString()
) {
return [[13, 3.5, 0]];
}
const [x, y, z] = coord;
return [[x + 1, y, z]];
}
export function isOpen(coord, currentCoords) {
if (disjoint([coord], currentCoords)) return false;
const [x, y, z] = coord;
if (
currentCoords.some(([a, b, c]) => a === x && b === y && c > z) ||
(z === 3 && currentCoords.some(([a, b, c]) => c === 4))
) {
return false;
}
return (
disjoint(leftNeighbors(coord), currentCoords) ||
disjoint(rightNeighbors(coord), currentCoords)
);
}