-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path]
108 lines (100 loc) · 2.57 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const defaultInput = `
D2FE28
`.trim();
export default {
name: "App",
components: {},
mounted() {
this.parseInput();
},
data() {
return {
input: defaultInput,
done1: false,
done2: false,
answer1: NaN,
answer2: NaN,
show1: false,
show2: false,
};
},
methods: {
resetInput() {
this.input = defaultInput;
this.parseInput();
},
parseInput() {
// reset
clearInterval(this.interval);
const inArr = this.input;
console.log(inArr);
this.done1 = false;
this.done2 = false;
},
stop() {
clearInterval(this.interval);
},
run1() {
clearInterval(this.interval);
this.done1 = false;
this.show1 = true;
this.show2 = false;
this.cave.setMap(this.chiton);
this.cave.startSearch();
this.scoreFun = (x) => {
this.answer1 = x;
};
this.finalFun = () => (this.done1 = true);
const dur = Math.ceil(500 / this.cave.xMax / this.cave.xMax);
this.interval = setInterval(this.move1, dur);
},
move1() {
if (this.cave.candidates.isEmpty()) {
clearInterval(this.interval);
return;
}
const block = (this.cave.xMax * this.cave.yMax * this.cave.xMax) / 1000;
for (let i = 0; i < block; i++) {
let node = this.cave.nextNode();
if (node.x == this.cave.xMax - 1 && node.y == this.cave.yMax - 1) {
clearInterval(this.interval);
this.scoreFun(node.cost);
while (node) {
node.onPath = true;
node = node.parent;
}
this.finalFun();
return;
}
}
},
run2() {
clearInterval(this.interval);
this.done2 = false;
this.show1 = false;
this.show2 = true;
const wip = this.inArr.map((l) => {
let a2 = [];
for (let i = 0; i < 5; i++) {
a2 = a2.concat(l.map((v) => v + i));
}
return a2;
});
let w2 = [];
for (let i = 0; i < 5; i++) {
const l2 = wip.map((l) => l.map((v) => ((v + i - 1) % 9) + 1));
w2 = w2.concat(l2);
}
const bigMap = w2.map((s, y) => s.map((t, x) => new Node(t, y, x)));
//const a2 = this.inArr.map((s, y) => s.map((t, x) => new Node(t, y, x)));
this.cave.setMap(bigMap);
this.cave.startSearch();
this.scoreFun = (x) => {
this.answer2 = x;
};
this.finalFun = () => (this.done2 = true);
const dur = 500 / this.cave.xMax / this.cave.xMax;
this.interval = setInterval(this.move1, dur);
},
},
};