forked from Marfung37/GluingFumens
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmirrorFumen.js
75 lines (64 loc) · 1.72 KB
/
mirrorFumen.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
74
75
const { decoder, encoder } = require('tetris-fumen');
colorMapping = {
"S": 7,
"J": 6,
"T": 5,
"Z": 4,
"O": 3,
"L": 2,
"I": 1
}
reverseMapping = {
7: 4,
4: 7,
6: 2,
2: 6,
5: 5,
3: 3,
1: 1,
0: 0,
8: 8
}
reverseMappingLetters = {
"L": "J",
"J": "L",
"S": "Z",
"Z": "S",
"T": "T",
"O": "O",
"I": "I",
}
reverseMappingRotation = {
"spawn": "spawn",
"right": "left",
"reverse": "reverse",
"left": "right"
}
var fumenCodes = []
for(let rawInput of process.argv.slice(2)){
fumenCodes.push(...rawInput.split(" "));
}
for (let code of fumenCodes) {
let inputPages = decoder.decode(code);
for (let i = 0; i < inputPages.length; i++) {
board = inputPages[i]["_field"]["field"]["pieces"];
for (let rowIndex = 0; rowIndex < 23; rowIndex++) {
row = board.slice(rowIndex * 10, (rowIndex + 1) * 10);
for (let colIndex = 0; colIndex < 10; colIndex++) {
board[rowIndex * 10 + colIndex] = reverseMapping[row[9 - colIndex]];
}
}
op = inputPages[i]["operation"];
if (op) {
op.type = reverseMappingLetters[op.type];
op.x = 9 - op.x;
if ("IO".includes(op.type)) { // thonk
if (op.rotation == "reverse") op.x++;
else if (op.rotation == "left" && op.type == "O") op.x++;
else if (op.rotation == "spawn" || op.type == "O") op.x--;
}
if ("SZLJT".includes(op.type)) op.rotation = reverseMappingRotation[op.rotation];
}
}
console.log(encoder.encode(inputPages));
}