def get_random_ghost(self, ghost_num): ''' :param: ghost_num :return: ghost_list: [Airplane,...] 幽灵飞机列表 ''' ghost_list = [] for i in range(ghost_num): # 随机生成icao、start、end、speed、starttime icao = random.randint(700000, 799999) start = [ self.loaction[0] + random.uniform(-3, 3), self.loaction[1] + random.uniform(-3, 3), 5000 + random.randint(-10, 10) * 50 ] end = [ self.loaction[0] + random.uniform(-3, 3), self.loaction[1] + random.uniform(-3, 3), 5000 + random.randint(-10, 10) * 50 ] speed = random.randint(150, 300) starttime = random.randint(1000, 16000) # 根据随机数据生成飞机 ghost = Airplane(str(icao), start, end, speed, starttime) # 标记为ghost,且放入发射器位置 ghost.get_ghost_flag(self.loaction) # 放入ghost库中 ghost_list.append(ghost) self.ghost_list.append(ghost) # return ghost return ghost_list
def nextOne_air(): """生成敌人""" type = random.randint(0, 100) if type < 50 and score < 3000: return Airplane(screen, sets.airImage[0], 1) elif type < 30 and type > 10: return Airplane(screen, sets.airImage[1], 2) elif type < 40 and type > 10: return Airplane(screen, sets.airImage[2], 3) elif type < 10 and score > 20000: return Airplane(screen, sets.airImage[3], 4)
class Symulator(object): def __init__(self): self.airplane = Airplane() def start(self): while True: self.airplane.add_turbulence() print "angle after turbulence: %.3f" % self.airplane.current_angle self.airplane.correct_position() print "correction made: %.3f" % self.airplane.correction print "new angle: %.3f \n" % self.airplane.current_angle time.sleep(2)
def generate_dataset( N=100, sigma=0.1, mu=0, balanced_sample=True, # equal number of each class p=[1. / 5] * 5, # for multinomial distribution of classes datapath="/home/joel/datasets/csi5138-img/dataset1" ): # do not add trailing / for i in range(N): if balanced_sample: c = i % 5 else: c = np.random.multinomial(1, p) # choose class from distribution p c = np.argmax(c) # construct vector of N(mu, sigma**2) var = sigma * np.random.randn(5) + mu # no switch statement in Python?#yes noswitch statement in python if c == 0: obj = Dog(*var) elif c == 1: obj = Truck(*var) elif c == 2: obj = Airplane(*var) elif c == 3: obj = Person(*var) else: obj = Frog(*var) obj.generate(datapath, i)
def generate_random_object(screen): rand_int = randint(0, 1) if (rand_int == 0): enemy_bird = copy(enemy_bird_prototype) enemy_bird.copy_setter(H) return enemy_bird return Airplane(screen)
def initialize_airplane(debug=False, capacity=0.0, option=0): if debug: plane = Airplane(airplane_choices[option]) plane.create_cabin(capacity) else: # CHOOSE AIRPLANE MODEL option = len(airplane_choices) attempts = 3 # have a prompt to select airplane: use input to select 0, 1, 2 print("Choose an Airplane Model") for opt, apln in airplane_choices.items(): print("\tEnter {} for {}".format(opt, apln)) while option not in list(airplane_choices.keys()): input_plane_option = input("Enter Option: ") print() try: assert isinstance(int(input_plane_option), int), "\nNOT A VALID ENTRY. TRY AGAIN" option = int(input_plane_option) assert option in list(range( 0, len(airplane_choices))), "\nNOT A VALID AIRPLANE CHOICE" except Exception as e: attempts -= 1 print(e) print("\tRemaining Attempts: {}\n".format(attempts)) ### BUILD AIRPLANE plane = Airplane(airplane_choices[option]) # now enter a capacity: attempts = 3 print("Set a value between 0-100 for capacity (%)") capacity = None while capacity is None and attempts > 0: capacity = input("Enter Value: ") try: assert isinstance(float(capacity), float), "\n NOT A VALID ENTRY. TRY AGAIN" capacity = float(capacity) / 100 except Exception as e: print(e) capacity = None attempts -= 1 print("\tRemaining Attempts: {}\n".format(attempts)) plane.create_cabin(capacity) return plane
def input_and_get_plane(self): number = input('Number: ') if not number: print('Invalid input!') return if self.airplanes.exists(number): print('Plane already exists!') return pilot = input('Pilot: ') seats = input('Seats: ') return Airplane(number, pilot, seats)
def get_random_airplane(self, plane_num): ''' :param: num :return: plane_list: [Airplane,...] 飞机列表 ''' plane_list = [] for i in range(plane_num): # 随机生成icao、start、end、speed、starttime icao = random.randint(700000, 799999) start = [random.uniform(115, 125), random.uniform(28, 34)] end = [ start[0] + random.uniform(-3, 3), start[1] + random.uniform(-3, 3) ] speed = random.randint(150, 300) starttime = random.randint(1000, 16000) # 根据随机数据生成飞机 plane = Airplane(str(icao), start, end, speed, starttime) # 放入plane库中 # plane_list.append(plane) self.plane_list.append(plane) # return ghost return plane_list
class AirplaneStatusBarApp(rumps.App): def __init__(self): self.ap_handler = Airplane() super(AirplaneStatusBarApp, self).__init__(">", quit_button=None) #airplane @rumps.clicked("Airplane Mode") def airplane_mode(self, sender): global airplane_active airplane_active = not airplane_active sender.state = airplane_active if airplane_active: self.icon = icon_on self.ap_handler.activate() else: self.icon = icon_off self.ap_handler.deactivate() #status = "Airplane Mode OFF" #msg = "Airplane Mode is inactive" #time_st = datetime.datetime.fromtimestamp(time.time()).strftime('%H:%M:%S') #'%Y-%m-%d %H:%M:%S' #rumps.notification("Airplane "+str(time_st), "Status: "+str(status), str(msg)) #@rumps.clicked("Status") #def status(self, _): # ''' # Checking status of airplane mode # ''' # status = "Airplane Mode OFF" # msg = "Airplane Mode is inactive" # time_st = datetime.datetime.fromtimestamp(time.time()).strftime('%H:%M:%S') #'%Y-%m-%d %H:%M:%S' # rumps.notification("Airplane "+str(time_st), "Status: "+str(status), str(msg)) @rumps.clicked('Quit') def clean_quit_application(self, _): self.ap_handler.shut_down() rumps.quit_application()
def __init__(self): self.ap_handler = Airplane() super(AirplaneStatusBarApp, self).__init__(">", quit_button=None) #airplane
import random from airplane import Airplane from car import Car from tank import Tank machines = [ Car(), Car(), Car(), Tank(), Airplane(), Airplane(), ] for m in machines: m.show_pos() for m in machines: time = random.randint(1, 150) m.drive(time) for m in machines: m.fire(random.choice(machines))
from receiver import Receiver #接收器类 from airplane import Airplane #飞机类 from attacker import Attacker #攻击者类 from multiple import Multiple #生成多条数据类 import matplotlib.pyplot as plt if __name__ == '__main__': #一架飞机 airplane = Airplane('782034', [120.1549, 30, 8500], [115, 28.15455, 7500], 180, 0) # 一个接收器 receiver = Receiver([118, 32, 1000]) receiver.fin_time_track(airplane) # print(receiver.airplane_dic["782034"]) receiver.plt_location(airplane) # # # 一个位置固定的攻击者 # attacker = Attacker([116, 30], 1) # # # 飞机的报文到接收器的时间轨迹 # time_track_of_plane = receiver.fin_time_track(airplane) # # # 攻击者的报文到接收器的时间轨迹 # time_track2 = receiver.ghost_time_track(attacker.ghost_list[0]) # # # #生成多条航线例程 # m = Multiple(30,10) #30条航线,10个接收器 # m.match_RA() #一一对应航线和接收器 # print(m.receiver_list[0]) #输出第一个接收器的所有信息
def init_airplane(self, rows, seats_per_row): plane = Airplane(rows, seats_per_row) return plane
os.system("clear") # reset to aisle symbol airplane.cabin.iloc[row - airplane.start_row, aisle] = '| |' else: pass sys.stdout.write(Status_Msg) airplane.cabin.to_csv(sys.stdout) LOCAL_RESULTS_DIR = os.path.join(LOCAL_REPO_DIR, "results") fn = os.path.join(LOCAL_RESULTS_DIR, "Airbus_380/run_003.csv") airplane_model = os.path.basename(os.path.dirname(fn)) my_plane = Airplane(airplane_model) my_plane.create_cabin(1) passenger_df = pd.read_csv(fn, dtype=object) try: passenger_df = passenger_df.drop(['Unnamed: 0'], axis=1) except: pass #------------------------------- # my attempt at animation #------------------------------- show_boarding(passenger_df, my_plane) time.sleep(10)
{"name": "airland5.txt", "results": {}}, ] # Loop through each data set. for dataset in datasets: # Read the data into memory with open('datasets/{}'.format(dataset["name"]), 'r') as file: line = file.readline().split() num_planes, freeze_time = int(line[0]), int(line[1]) planes = [] for idx in range(num_planes): params = file.readline().split() params = [int(x) for x in params[:-2]] + [float(params[-2]), float(params[-1])] separation_times = [int(x) for x in file.readline().split()] arrival_time, earliest_time, target_time, latest_time, early_penalty, late_penalty = params planes.append(Airplane(idx, arrival_time, earliest_time, target_time, latest_time, separation_times, early_penalty, late_penalty)) log("\n\nDATASET {}: num_planes {} freeze_time {} items_read {}".format(dataset["name"], num_planes, freeze_time, len(planes))) planes = sorted(planes, key=attrgetter('arrival_time', 'earliest_time', 'latest_time')) for idx, p in enumerate(planes): log((p.plane_id, p.arrival_time, p.earliest_time, p.target_time, p.latest_time)) log(" Iteration", end=" ") # Perform 30 independent iterations. for iteration in range(30): log(iteration+1, end=" ") thing = TabuSearch(copy.deepcopy(planes)) initial_fitness = thing.fitness start_time = datetime.now() total_iterations, stagnation, combination = thing.run() execution_time = datetime.now() - start_time
__author__ = 'Andrew' from airplane import Airplane snoopy=Airplane(1,1,0,15) redBaron=Airplane(10,10,100,15) print(snoopy.getSpeed()) print(redBaron.getSpeed()) snoopy.speedUp(200) print(snoopy.getSpeed())
pygame.init() screen_info = pygame.display.Info() screen_size = (screen_width, screen_height) = \ (int(screen_info.current_w * 1), int(screen_info.current_h * 1)) screen = pygame.display.set_mode(screen_size) clock = pygame.time.Clock() character = Airplane((120, 120)) enemies = pygame.sprite.Group() enemies.empty() for i in range(10): enemies.add(Enemy) def main(): while True: clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: character.acce1.x += 0.1 if event.key == pygame.K_LEFT: character.acce1.x-=0.1
#窗口初始化 screen = pygame.display.set_mode((600,800)) pygame.display.set_caption('消灭病毒') window_image = pygame.image.load('./airplane.jpg') pygame.display.set_icon(window_image) # 帧率设置 clock = pygame.time.Clock() # 左上角计算分数 countObj = pygame.font.SysFont('arial', 50) textObj = countObj.render('SCORE:0', True, (255, 0, 0)) textRectObj = textObj.get_rect() screen.blit(textObj, textRectObj) # 这个是计算分数 count_num = 0 # 创建飞机 airplane = Airplane(screen) # 子弹容器 bullet_sprites = pygame.sprite.RenderUpdates() # 创建sprite容器 树 AddEnemy = pygame.USEREVENT + 1 # 添加子弹的时间 pygame.time.set_timer(AddEnemy, 300) pygame.display.flip() while True: clock.tick(60) screen.fill((255, 255, 255)) # 背景色 screen.blit(airplane.image, airplane.rect) ''' 添加新病毒 ''' if virusers.group.__len__() < 3: virusers.viruse_new() # 病毒实例化 virusers.group.update() # 病毒
def __init__(self): threading.Thread.__init__(self) def run(self): self.root = Tk() self.root.geometry("400x300") self.app = Window(self.root) self.root.mainloop() def close(self): self.root.quit() self.app.quit() surface = Surface() plane = Airplane(100000, 100, 15) airplane = plane plane.position = np.array((0., 0., 10000.)) plane.velocity = np.array((150., 150., 2.)) sim = Simulation(plane, surface) pygame.init() display = (800,600) pygame.display.set_mode(display, DOUBLEBUF|OPENGL) tx = 0 ty = 0 tz = 0 ry = 0 rz = 0
def __init__(self): self.airplane = Airplane()
def main(game): """ Main game logic. :param game: Game object :return: """ airplane = Airplane(game.get_airplane_img(), 200, 200) obstacles = [Obstacle(game.get_obstacle_img(), 700)] window = game.get_window() clock = game.get_clock() font = game.get_font() # Define position of sliding background images bg_x = 0 bg_x2 = game.get_window_width() # Start game run = True while run: is_jump = False clock.tick(FPS) # Limit game loop to 30 iterations per second # Process user input from keyboard for event in pygame.event.get(): if event.type == pygame.QUIT: # Close the game window run = False pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: airplane.jump() is_jump = True if not is_jump: airplane.move() # Check if airplane has fallen off screen if airplane.get_y() <= 0 or airplane.get_y() >= game.get_window_height( ): # Game over. Go to game over screen run = False game.set_game_in_session(False) return # Generate obstacle add_obstacle = False for obstacle in obstacles: if obstacle.collide(airplane): # Airplane hit obstacle. Go to game over screen run = False game.set_game_in_session(False) return if not obstacle.get_passed( ) and obstacle.get_x() < airplane.get_x(): # Obstacle has been successfully passed, set flag to generate new obstacle obstacle.set_passed(True) add_obstacle = True obstacle.move() if add_obstacle: # Generate a new obstacle and increment score by 1 game.increment_score() obstacles.append(Obstacle(game.get_obstacle_img(), 700)) # Update game window with changes draw_window(window, airplane, obstacles, game.get_bg_img(), bg_x, bg_x2, font, game.get_score()) # Sliding background bg_x -= 2 bg_x2 -= 2 if bg_x < -game.get_window_width(): bg_x = game.get_window_width() if bg_x2 < -game.get_window_width(): bg_x2 = game.get_window_width()
def takeplane(destination): print('Flying to ' + destination + ' =====>') plane = Airplane(destination) plane.plane_trip()