This repository was archived by the owner on Jun 15, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlevelCodeOptimizer.py
More file actions
Latest commit
92 lines (72 loc) · 2.35 KB
/
Copy pathlevelCodeOptimizer.py
File metadata and controls
92 lines (72 loc) · 2.35 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
importre
fromencoderimportdecode_string
fromcompressV3importcompressV3
fromlevelCodeConverterimportconvertV1toV3
fromloadCodeimportloadFromInput
defoptimize(cellarray):
# Optimizing V3 code
# g rcw rccw m s p w e t
# 01 23 45 67 89 ab cd ef gh
# ij kl mn op qr st uv wx yz
# AB CD EF GH IJ KL MN OP QR
# ST UV WX YZ !$ %& +- .= ?^
# + empty
# } {
# rotator cw
cellarray=re.sub(r"[kCU]", r"2", cellarray)
cellarray=re.sub(r"[lDV]", r"3", cellarray)
# rotator ccw
cellarray=re.sub(r"[mEW]", r"4", cellarray)
cellarray=re.sub(r"[nFX]", r"5", cellarray)
# slide
cellarray=re.sub(r"I", r"8", cellarray)
cellarray=re.sub(r"J", r"9", cellarray)
cellarray=re.sub(r"!", r"q", cellarray)
cellarray=re.sub(r"\$", r"r", cellarray)
# push
cellarray=re.sub(r"[sK%]", r"a", cellarray)
cellarray=re.sub(r"[tL&]", r"b", cellarray)
# wall
cellarray=re.sub(r"[uM+]", r"c", cellarray)
cellarray=re.sub(r"[vM-]", r"d", cellarray)
# enemy
cellarray=re.sub(r"[wO.]", r"e", cellarray)
cellarray=re.sub(r"[xP=]", r"f", cellarray)
# trash
cellarray=re.sub(r"[yQ?]", r"g", cellarray)
cellarray=re.sub(r"[zR^]", r"h", cellarray)
# Returning the cell array
returncellarray
try:
fromtermcolorimportcolored
importcolorama
colorama.init()
exceptModuleNotFoundError:
defcolored(text, _): returntext
# Accepting an input of the level code
print(colored("Paste level code here: ", "green"), end="")
levelcode=input()
# Loading the inputed code
inputData=loadFromInput(levelcode)
ifnotinputData:
# ERROR
print()
print(colored("ERROR", "red"))
print()
elifinputData=="V2":
print()
print(colored("Come on, it was said V2 doesn't work", "yellow"))
print()
else:
# Convert to V3 code if V1
ifinputData[0] =="V1":
inputData=convertV1toV3(inputData)
# Optimize V3 code
inputData[3] =optimize(inputData[3])
# Compress V3 code
inputData[3] =compressV3(inputData[3], decode_string(inputData[1]), decode_string(inputData[2]))
# Printing the output
print()
print(colored("Your level code is optimized:", "blue"))
print("\t"+";".join(inputData))
print()