forked from roguelike2d/TekkenBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotationParser.py
182 lines (167 loc) · 6.89 KB
/
NotationParser.py
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
from ButtonCommandEnum import Command
INPUT_DELAY = 4
def ParseMoveList(moveList:str):
commands = []
tempTiming = None
timingOccurances = 0
for i, moveOrTiming in enumerate(moveList.split(',')):
notationResult = ConvertNotationToCommands(moveOrTiming.strip(), timingOccurances)
timingOccurances = notationResult[1]
commands += notationResult[0]
# print(commands)
return commands
def ConvertNotationToCommands(notation:str, timingOccurances:int):
commands = []
occurances = 0
attackCommands = GetAttackCommands(notation)
if 'recovery' in notation:
commands.append((Command.FullRecovery, 0))
elif 'S!' in notation or 'L!' in notation:
commands.append((Command.FullRecovery, 0))
elif 'nextmove' in notation:
commands.append((Command.Nextmove, 0))
elif 'startup' in notation:
commands.append((Command.Startupmove, 0))
elif 'debug' in notation:
commands.append((Command.HoldBack, 1))
commands.append((Command.HoldDown, 2))
commands.append((Command.ReleaseBack, 2))
commands.append((Command.HoldForward, 2))
commands += attackCommands
commands.append((Command.ReleaseAll, 2))
elif 'dp' in notation:
commands.append((Command.TapForward, 1))
commands.append((Command.TapDown, 1))
commands.append((Command.TapForward, 1))
commands.append((Command.TapDown, 1))
commands += attackCommands
elif 'qcb' in notation:
commands.append((Command.HoldDown, 2))
commands.append((Command.HoldBack, 2))
commands.append((Command.ReleaseDown, 2))
commands += attackCommands
commands.append((Command.ReleaseBack, 2))
elif 'qcf' in notation:
commands.append((Command.HoldDown, 1))
commands.append((Command.HoldForward, 1))
commands.append((Command.ReleaseDown, 1))
commands += attackCommands
commands.append((Command.ReleaseForward, 2))
elif 'pewgf' in notation:
commands.append((Command.TapForward, 0))
commands.append((Command.TapDown, 2))
commands.append((Command.TapForward, 0))
commands += attackCommands
commands.append((Command.ReleaseDown, 1))
elif 'ewgf' in notation:
commands.append((Command.TapForward, 0))
commands.append((Command.HoldDown, 2))
commands.append((Command.TapForward, 1))
commands += attackCommands
commands.append((Command.ReleaseDown, 1))
elif 'iWS' in notation:
commands.append((Command.HoldDown, 0))
commands.append((Command.HoldForward, 2))
commands.append((Command.ReleaseDown, 2))
commands.append((Command.ReleaseForward, 0))
commands.append((Command.Wait, 2))
commands += attackCommands
elif ':' in notation:
waitFrames = int(notation.split('[')[1].split(']')[0])
commands.append((Command.Wait, waitFrames - INPUT_DELAY))
elif 'UF' in notation:
commands.append((Command.HoldForward, 1))
commands.append((Command.HoldUp, 0))
waitFrames = int(notation.split('[')[1].split(']')[0])
commands.append((Command.Wait, waitFrames))
commands.append((Command.ReleaseForward, 1))
commands.append((Command.ReleaseUp, 0))
elif 'ff' in notation:
commands.append((Command.TapForward, 0))
commands.append((Command.HoldForward, 2))
waitFrames = int(notation.split('[')[1].split(']')[0])
commands.append((Command.Wait, 1 + waitFrames ))
commands += attackCommands
commands.append((Command.ReleaseForward, 1))
elif notation.isdigit() and '+' not in notation:
commands.append((Command.Wait, int(notation)))
elif '>' in notation:
occurances = notation.count('>')
for i in range(occurances):
if (i + timingOccurances) % 2 == 0:
commands.append((Command.Recovery, 0))
else:
commands.append((Command.Nextmove, 0))
elif 'wr' in notation:
commands.append((Command.TapForward, 0))
commands.append((Command.Wait, 2))
commands.append((Command.TapForward, 0))
commands.append((Command.Wait, 2))
commands.append((Command.HoldForward, 0))
waitFrames = int(notation.split('[')[1].split(']')[0])
commands.append((Command.Wait, 2 + waitFrames))
commands += attackCommands
commands.append((Command.ReleaseForward, 2))
elif 'rel' in notation:
commands.append((Command.ReleaseAll, 0))
elif '-U' in notation:
commands.append((Command.ReleaseUp, 0))
elif '-D' in notation:
commands.append((Command.ReleaseDown, 0))
elif '-B' in notation:
commands.append((Command.ReleaseBack, 0))
elif '-F' in notation:
commands.append((Command.ReleaseForward, 0))
elif '-R' in notation:
commands.append((Command.ReleaseRage, 0))
else:
if 'u' in notation:
commands.append((Command.TapUp, 0))
if 'd' in notation:
commands.append((Command.TapDown, 0))
if 'b' in notation:
commands.append((Command.TapBack, 0))
if 'f' in notation:
commands.append((Command.TapForward, 0))
if 'U' in notation:
commands.append((Command.HoldUp, 0))
if 'D' in notation:
commands.append((Command.HoldDown, 0))
if 'B' in notation:
commands.append((Command.HoldBack, 0))
if 'F' in notation:
commands.append((Command.HoldForward, 0))
if 'R' in notation:
commands.append((Command.HoldRage, 0))
commands += GetAttackCommands(notation)
return (commands, timingOccurances + occurances)
def GetAttackCommands(notation:str):
commands = []
if '*' in notation:
if '+1' in notation:
commands.append((Command.Hold1, 0))
if '+2' in notation:
commands.append((Command.Hold2, 0))
if '+3' in notation:
commands.append((Command.Hold3, 0))
if '+4' in notation:
commands.append((Command.Hold4, 0))
elif '-' in notation:
if '+1' in notation:
commands.append((Command.Release1, 0))
if '+2' in notation:
commands.append((Command.Release2, 0))
if '+3' in notation:
commands.append((Command.Release3, 0))
if '+4' in notation:
commands.append((Command.Release4, 0))
else:
if '+1' in notation:
commands.append((Command.Tap1, 0))
if '+2' in notation:
commands.append((Command.Tap2, 0))
if '+3' in notation:
commands.append((Command.Tap3, 0))
if '+4' in notation:
commands.append((Command.Tap4, 0))
return commands