if distance_x <= 150 and not time2: time2 = time.time() speeds.append( ((distance1 - distance_x) / 150) / (time2 - time1)) time2 = 0 if len(speeds) > 10: speed = mean(speeds) speeds.clear() length = scanner.obstacle_length(distance_x) distance_y1, distance_y2 = scanner.obstacle_height( distance_x, length) game.set_state(distance_x, distance_y1, length, speed) game.activate_brain() if game.brain_output <= .45: game.press_down() elif game.brain_output >= .55: game.press_up() else: game.release_all_keys() else: if genetic_algorithm.train_mode: if not game.stopped: if genetic_algorithm.generation.current_individual.has_experience( ): genetic_algorithm.generation.current_individual.save_score( game.obstacles if game.obstacles > 1 else 0)