def go_right(): i = 5 while (i < 0): PressKey(D) i = i - 1 #PressKey(D) ReleaseKey(A) ReleaseKey(S) time.sleep(d_time)
def no_keys(): if random.randrange(0, 3) == 1: PressKey(W) else: ReleaseKey(W) ReleaseKey(A) ReleaseKey(S) ReleaseKey(D)
def go_left(): i = 5 while (i < 0): PressKey(A) i = i - 1 ReleaseKey(S) ReleaseKey(D) time.sleep(d_time)
def PlayCurveFever(statusRefImg, color): # Settings colors = { 'red': np.array((69, 69, 255)), 'pink': np.array((186, 164, 255)), 'yellow': np.array((43, 233, 255)), 'green': np.array((48, 255, 106)), 'aqua': np.array((192, 209, 2)), 'blue': np.array((255, 68, 68)), 'orange': np.array((52, 136, 255)) } full = {"top": 10, "left": 1320, "width": 2535 - 1320, "height": 1023 - 10} sct = mss.mss() PlayerColor = colors[color] # red colMin = PlayerColor - 20 colMax = PlayerColor + 20 states = [] pyauto.click(x=1900, y=500) while 'Play': last_time = time.time() state1, status = cfb.GrabScreen(statusRefImg, sct, full, colMin, colMax) if status == 'Play': states.append(state1) if (len(states) == 3): p1, p2 = cfb.proccesTwoStates(states[0], states[1], states[2]) fit, params, dists = cfb.getParameters(p1, p2) # imgView = cv2.line(state2, # (int(p2[0]), int(p2[1])), # (int(params['collisionPoint'][0]), int(params['collisionPoint'][1])), # (255, 255, 255), # 2) # dodac odelglosc punkt przeciecia dla sladu print(cfb.checkPathCollsion(states[2], fit, params, p2)) if cfb.checkPathCollsion(states[2], fit, params, p2): PressKey(A) else: ReleaseKey(A) if params['walldist'] > 150: #print("UP |", "DIST: ", params['walldist'], "ANGLE: ", params['angle'] ReleaseKey(A) else: # print("DOWN |", "DIST: ", params['walldist'], "ANGLE: ", params['angle']) # press = np.abs(params['angle']) * 1.2 / 180 PressKey(A) states.pop(0)
def restart(): wait() time.sleep(1) PressKey(SPACE) time.sleep(0.05) ReleaseKey(SPACE) time.sleep(0.2)
def main(): model = create_model() model.load_weights('model_opt.hdf') # weights = model.layers[0].get_weights()[0] # biases = model.layers[0].get_weights()[1] for i in list(range(5))[::-1]: print(i + 1) time.sleep(1) paused = False while (True): if not paused: screen = grab_screen(region=(0, 64, 640, 480)) screen = cv2.resize(screen, (160, 120)) screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB) screen = np.expand_dims(screen, axis=0) prediction = model.predict(screen)[0] # print(prediction) maxval = max(prediction) if prediction[1] == maxval: straight() print('straigh', maxval) elif prediction[2] == maxval: right() print('right', maxval) elif prediction[0] == maxval: left() print('left', maxval) keys = key_check() if 'P' in keys: if paused: paused = False time.sleep(1) else: paused = True ReleaseKey(A) ReleaseKey(W) ReleaseKey(D) time.sleep(1)
def controller(key): if chr(key) == 'A': PressKey(A) print("A") time.sleep(0.10) ReleaseKey(A) if chr(key) == 'B': PressKey(B) print("B") time.sleep(0.10) ReleaseKey(B) if chr(key) == 'U': PressKey(Z) print("U") time.sleep(0.10) ReleaseKey(Z) if chr(key) == 'D': PressKey(S) print("D") time.sleep(0.10) ReleaseKey(S)
def left(): PressKey(A) # ReleaseKey(W) # this was commented ReleaseKey(D)
def straight(): PressKey(W) ReleaseKey(A) ReleaseKey(D)
def slow_ya_roll(): ReleaseKey(W) ReleaseKey(A) ReleaseKey(D)
def t_key(key_a, key_b, key_c): PressKey(key_a) ReleaseKey(key_b) ReleaseKey(key_c) time.sleep(keytime)
def go_reverse_right(): PressKey(S) PressKey(D) ReleaseKey(W) ReleaseKey(A)