-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicCommands.py
More file actions
359 lines (290 loc) · 13.4 KB
/
basicCommands.py
File metadata and controls
359 lines (290 loc) · 13.4 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
from memoryWatcher import MemoryWatcher;
from random import *;
from math import *;
class BasicCommands:
def __init__(self, memoryWatcher, controller):
self.memoryWatcher = memoryWatcher;
self.controller = controller;
self.p2x="00453F20"
self.p2y="00453F24"
self.rightlock = False
self.leftlock = False
def dashDance(self):
self.memoryWatcher.pauseForTime(12)
self.controller.inputAnalog("MAIN","0.5","0.5")
x=15;
while (x>0):
self.memoryWatcher.pauseForTime(11)
self.controller.inputAnalog("MAIN","0","0.5")
self.memoryWatcher.pauseForTime(11)
self.controller.inputAnalog("MAIN","1","0.5")
x=x-1
# def walk (self):
# def run (self):
# def jab (self):
def upB(self,xCord,yCord):
# self.memoryWatcher.pauseForTime(10)
self.controller.inputAnalog("MAIN","0.5","1")
self.memoryWatcher.pauseForTime(15)
self.controller.inputs("B")
self.memoryWatcher.pauseForTime(2)
self.controller.inputAnalog("MAIN",xCord,yCord)
self.memoryWatcher.pauseForTime(70)
def sideB(self,Shorten,dirr):
self.memoryWatcher.pauseForTime(3)
if (dirr=="left"):
self.controller.inputAnalog("MAIN","0","0.5")
else: self.controller.inputAnalog("MAIN","1","0.5")
self.memoryWatcher.pauseForTime(2)
self.controller.inputs("B",1)
self.memoryWatcher.pauseForTime(1)
if Shorten is True:
self.controller.releaseButtons()
self.memoryWatcher.pauseForTime(19)
self.controller.inputs("B")
self.memoryWatcher.pauseForTime(1)
#performs a jump cancelled up Smash
def upSmash(self):
self.controller.inputAnalog("MAIN","0.5","1")
self.memoryWatcher.pauseForTime(2)
self.controller.inputs("A",1)
self.memoryWatcher.pauseForTime(1)
def upTilt(self):
self.controller.inputAnalog("MAIN","0.5","0.6")
self.memoryWatcher.pauseForTime(2)
self.controller.inputs("A",1)
self.memoryWatcher.pauseForTime(3)
def shield(self):
self.controller.triggerAnalog("L","1")
self.memoryWatcher.pauseForTime(2);
self.controller.releaseButtons();
def roll(self,dir):
self.shield()
self.memoryWatcher.pauseForTime(9)
print (dir)
if dir=="right":
self.controller.inputAnalog("MAIN","1","0.5")
elif dir is "left":
self.controller.inputAnalog("MAIN","0","0.5")
self.memoryWatcher.pauseForTime(1)
def dashAttack(self,dir):
if (dir=="right"):
self.controller.inputAnalog("MAIN","1","0.5")
elif (dir=="left"):
self.controller.inputAnalog("MAIN","0","0.5")
self.memoryWatcher.pauseForTime(9)
self.controller.inputs("A")
self.memoryWatcher.pauseForTime(1)
def waveDash(self,dir):
# timer = self.memoryWatcher;
if dir=="left": self.controller.inputAnalog("MAIN","0","0.3")
elif dir=="right": self.controller.inputAnalog("MAIN","1","0.3")
self.controller.inputs("X")
self.memoryWatcher.pauseForTime(4)
self.controller.inputs("L")
self.memoryWatcher.pauseForTime(7)
#pass in 2 frames for short hop, 3 or more for full hop
def jump(self,pauseTime,dirr):
if (dirr=="right"): self.controller.inputAnalog("MAIN","1","0.5")
elif (dirr=="left"): self.controller.inputAnalog("MAIN","0","0.5")
self.controller.inputs("X");
timer = self.memoryWatcher;
self.controller.inputs("X");
timer.pauseForTime(pauseTime)
self.controller.releaseButtons();
# print("not okay!!!!!!!!!!!")
def recover(self):
while (True):
# self.memoryWatcher.getHitStun()
# print ("This is the X please print",self.memoryWatcher.getX())
if (self.memoryWatcher.getHitStun()==0):
# currentX = self.memoryWatcher.getX();
if ( 1120447161< self.memoryWatcher.getX() <1124447162 ):
# print ("this is the one:",self.memoryWatcher.getX())
# print ("This is the other branch")
self.upB("0","1")
self.controller.releaseButtons()
elif (self.memoryWatcher.getX() > 3268000000):
# print ("This is the X",currentX)
self.upB("1","1")
self.controller.releaseButtons()
def test3(self):
value = self.memoryWatcher.getHitStun();
x=0
counter = 0
while (x<20):
if (self.memoryWatcher.getHitStun()!=-1):
# print (value)
counter=counter+1
else:
# print("no")
counter=counter-1
x=x+1
# print ("This is the counter",counter)
return counter
def recover2(self):
value = self.memoryWatcher.getHitStun();
self.controller.inputAnalog("MAIN","0.5","0.7")
if ( self.test3()>= -16):
print (value)
self.controller.releaseButtons()
self.controller.inputAnalog("MAIN","0","0.5")
self.memoryWatcher.pauseForTime(2)
self.controller.inputAnalog("MAIN","1","0.5")
self.controller.releaseButtons()
else:
# currentX = self.memoryWatcher.getX(self.p2x);
# currentY = self.memoryWatcher.getX(self.p2y);
curX = self.memoryWatcher.state['p2']['x'];
print("curX: ",curX)
if ( curX>81 ):
# self.recoveryHelper("left","left")
self.jump(2,"left")
self.memoryWatcher.pauseForTime(10)
curY = self.memoryWatcher.state['p2']['y'];
if (curY>-10):
if (randint(0,10)<7):self.sideB(False,"left")
else: self.upB("0","0.8")
else: self.upB("0","1")
elif (curX < -81):
self.jump(2,"right")
self.memoryWatcher.pauseForTime(10)
curY = self.memoryWatcher.state['p2']['y'];
if (curY>-10):
if (randint(0,10)<7):self.sideB(False,"right")
else: self.upB("1","0.8")
else: self.upB("1","1")
self.controller.releaseButtons();
def recoveryHelper(self,jumpDir,upBdir):
self.memoryWatcher.pauseForTime(10)
self.jump(2,jumpDir)
# if (currentY>1000000000): self.sideB(False,"left")
# else: self.upB("0","1")
if upBdir=="left":self.upB("0","1")
else: self.upB("1","1")
self.controller.releaseButtons()
def shdl(self):
self.jump(2, "")
self.controller.releaseButtons();
self.memoryWatcher.pauseForTime(2);
self.controller.inputs("B",True);
self.memoryWatcher.pauseForTime(1);
self.controller.releaseButtons();
self.memoryWatcher.pauseForTime(5);
self.controller.inputs("B",True);
self.memoryWatcher.pauseForTime(5);
self.controller.releaseButtons();
self.memoryWatcher.pauseForTime(13)
def facePlayer(self,curXPlayer,curXCPU):
# rightlock = False;
# leftlock = False;
# while True:
# curXPlayer = self.memoryWatcher.state['p1']['x'];
# curXCPU = self.memoryWatcher.state['p2']['x'];
self.memoryWatcher.pauseForTime(1)
if (curXPlayer > curXCPU and self.rightlock == False):
self.controller.inputAnalog("MAIN","0.6","0.5")
self.memoryWatcher.pauseForTime(2)
self.controller.releaseButtons()
self.rightlock = True
self.leftlock = False
elif (curXPlayer < curXCPU and self.leftlock == False):
self.controller.inputAnalog("MAIN","0.4","0.5")
self.memoryWatcher.pauseForTime(2)
self.controller.releaseButtons()
self.leftlock = True
self.rightlock = False
def SHAerial(self,x):
#check to see when AI can move
actionFrame = self.memoryWatcher.state['p1']['action'];
while (actionFrame!=14): #when this address reaches 14, the AI is actionable
self.memoryWatcher.readMemory() # update the addresses
actionFrame = self.memoryWatcher.state['p1']['action'];
print ("not 14 yet")
print("starting the SHAerial function y value: ", self.memoryWatcher.state['p2']['y']);
#do a short hop and then immediately do a neutral air
self.jump(2,"")#the short hop is done here
self.memoryWatcher.pauseForTime(2); #wait 2 frames
self.controller.inputs("A",True) #then press A while in the air causing a neutral air attack
self.memoryWatcher.pauseForTime(2); #the A must be pressed for 2 frames for it to register in the game
self.controller.releaseButtons();
print("SHAerial, y value: ", self.memoryWatcher.state['p2']['y']);
while True:
#check if Fox is falling, done by checking when Y starts decreasing, we do this using two Y values
curYCPU = self.memoryWatcher.state['p2']['y']; #the first Y address
self.memoryWatcher.readMemory() # update the addresses
curYCPU2 = self.memoryWatcher.state['p2']['y']; #the second Y address
#when Y starts decreasing do a fast all and get ready to L cancel
if (curYCPU>curYCPU2):
self.controller.inputAnalog("MAIN","0.5","0") #press down to start the fastfall
self.memoryWatcher.pauseForTime(2) #need to press down for at least 2 frames for it to register
self.controller.releaseButtons();
self.LCancel() #function that waits for the right time to L cancel
break;
print("ending the SHAerial function ");
#this function waits until Fox is just about to land
#then it presses L to reduce the landing lag of the aerial by half
#right now it's hard coded to work for only his neutral aerial
def LCancel(self):
curY = self.memoryWatcher.state['p2']['y'];
#if Y is >2 as Fox is falling down, wait as it's not time to L cancel yet
while ( curY>2 ):
curY = self.memoryWatcher.state['p2']['y'];
self.memoryWatcher.readMemory();
print ("L cancel while loop")
self.shield() #do the L cancel
# self.memoryWatcher.pauseForTime(6); #waits until the landing lag of the neutral air ends
def test2(self):
self.memoryWatcher.pauseForTime(97)
self.controller.releaseButtons()
# self.SHAerial(1);
# self.shdl()
# self.dashDance()
# self.shortHopAerial()
# self.controller.releaseButtons()
# self.memoryWatcher.pauseForTime(13)
# self.sideB(True,"left");
# self.shield()
# self.recover2()
# self.roll("right")
# self.upTilt()
# self.upB("0","0")
# self.dashAttack("right")
# self.waveDash("right")
# self.dashDance()
#basic loop to demonstrate the AI
#Fox will short hop and double laser if the opponent is far
#will neutral air if they come close
#will recover if offstage
while True:
x=1
curXPlayer = self.memoryWatcher.state['p1']['x'];
curXCPU = self.memoryWatcher.state['p2']['x'];
# print ("this is curXCPU",curXCPU)
self.memoryWatcher.pauseForTime(1)
self.facePlayer(curXPlayer,curXCPU)
if (curXCPU>61 or curXCPU <-61): self.recover2()
else:
self.memoryWatcher.pauseForTime(1)
distance = (abs(curXPlayer-curXCPU))
if (distance>40):
self.shdl()
else:
if (curXPlayer > curXCPU and curXCPU<=62 and curXCPU>=-62):
self.controller.inputAnalog("MAIN","1","0.5")
self.memoryWatcher.pauseForTime(3)
self.controller.releaseButtons()
self.SHAerial(x)
self.controller.releaseButtons()
if (curXPlayer < curXCPU and curXCPU>=-62 and curXCPU<=62):
self.controller.inputAnalog("MAIN","0","0.5")
self.memoryWatcher.pauseForTime(3)
self.controller.releaseButtons()
self.SHAerial(x)
self.controller.releaseButtons()
self.controller.releaseButtons()
return;
# def main():
# print("inside the basic commands file");
# if __name__ == '__main__':
# main();