-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindLand.js
73 lines (57 loc) · 1.75 KB
/
findLand.js
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
let map = ''
fetch('https://pvuhelper.info:8081/103.169.35.1:1569/listlandmap.txt').then(res => res.text()).then(text => map = text)
map.split('\r\n').forEach(land => {
const slots = land.split('|')
const mapping = slots.splice(1).reduce((acc, cur) => ({
...acc, [cur.substr(0, 3)]: cur.substr(4, 1)
}), {})
let has6SlotInSameColumn = false
let has6SlotInSameRow = false
for (let i = 1; i < 7; ++i) {
let has6SlotCont = true
for (let j = 0; j < 7; ++j) {
if (mapping[i + '-' + j] !== '0') has6SlotCont = false
}
// if (!has6SlotCont) {
// has6SlotCont = true
// for (let j = 1; j < 7; ++j) {
// if (mapping[i + '-' + j] !== '0') has6SlotCont = false
// }
// }
if (has6SlotCont) has6SlotInSameColumn = true
}
if (has6SlotInSameColumn) {
for (let i = 0; i < 6; ++i) {
let has6SlotCont = true
for (let j = 0; j < 6; ++j) {
if (mapping[j + '-' + i] !== '0') has6SlotCont = false
}
if (!has6SlotCont) {
has6SlotCont = true
for (let j = 1; j < 7; ++j) {
if (mapping[j + '-' + i] !== '0') has6SlotCont = false
}
}
if (has6SlotCont) has6SlotInSameRow = true
}
}
if (has6SlotInSameColumn && has6SlotInSameRow) {
let diagonalCount = 0
for (let i = 1; i < 6; ++i) {
for (let j = 1; j < 6; ++j) {
if (
mapping[i + '-' + j] === '0' &&
mapping[(i - 1) + '-' + (j - 1)] === '0' &&
mapping[(i - 1) + '-' + (j + 1)] === '0' &&
mapping[(i + 1) + '-' + (j - 1)] === '0' &&
mapping[(i + 1) + '-' + (j + 1)] === '0'
) {
diagonalCount++
}
}
}
if (diagonalCount >= 2) {
console.log(slots, diagonalCount)
}
}
})