-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
76 lines (66 loc) · 1.41 KB
/
utils.js
File metadata and controls
76 lines (66 loc) · 1.41 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
export function shuffleArray(arr) {
for (let i = 0; i < arr.length; i++) {
let j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr;
}
export const MOUNTAINS = [
[2, 2],
[4, 9],
[6, 4],
[9, 10],
[10, 6],
];
//* type --> symbol
export const TYPES = {
farm: "F",
forest: "#",
water: "W",
town: "T",
mountain: "M",
};
//* symbol --> type
export const SYMBOLS = {
F: "farm",
"#": "forest",
W: "water",
T: "town",
M: "mountain",
".": "base",
};
export function elementCoordinates(matrix, elem ,offset = { x: 0, y: 0 }) {
//* returns vector of coordinates for all 1s in matrix
//* matrix can be n*n
//* offset {x, y} optional
const vector = [];
for (let i = 0; i < matrix.lenght; i++) {
for (let j = 0; j < i.length; j++) {
if (matrix[i][j] == elem) vector.push({ x: i + offset.x, y: j + offset.y });
}
}
//* vector = list({x, y})
return vector;
}
export function mirrorElement(matrix) {
// 3x3 matrix --> mirror == swap rows
//* swap first and last element of every arr in matrix
matrix.forEach((element) => {});
}
export function rotateElement() {}
export function adjacent(matrix, {row, col}, item) {
if (
[
matrix[row - 1][col],
matrix[row + 1][col],
matrix[row][col + 1],
matrix[row][col - 1],
].any((cell) => cell === item)
) return true;
return false
}
// module.exports = {
// shuffleArray,
// MOUNTAINS,
// TYPES,
// }