def meteor_fall( self): #Définir la méthode pour faire tomber la pluie de comètes """Faire tomber la pluie de 10 comètes""" if self.game.paused is False: if self.game.level == 1: # Action s'exécutant si le niveau est à 1 for i in range(1, 11): # Répéter 10 fois l'action suivante self.all_comets.add( Comet(self)) # Ajouter une comète au groupe elif self.game.level == 2: # Action s'exécutant si le niveau est à 2 for i in range(1, 13): # Répéter 12 fois l'action suivante self.all_comets.add( Comet(self)) # Ajouter une comète au groupe elif self.game.level == 3: # Action s'exécutant si le niveau est à 3 for i in range(1, 16): # Répéter 15 fois l'action suivante self.all_comets.add( Comet(self)) # Ajouter une comète au groupe elif self.game.level == 10: for i in range(1, 10): self.all_comets.add(Comet(self)) else: # Action s'exécutant si le niveau est au moins à 4 mais n'atteint pas le niveau 10 for i in range(1, 21): # Répéter 20 fois l'action suivante self.all_comets.add( Comet(self)) # Ajouter une comète au groupe
def __init__(self, x, y, name, owner): self.world_x = x self.world_y = y self.name = name self.owner = owner self.color = _colors[random.randrange(len(_colors))] self.bodies = [] self.fleets = [] min_distance = 3 max_distance = min(config.system_width, config.system_height) // 2 for n in range(min_distance, max_distance + 1, 3): chance = random.randint(1, 100) if len(self.bodies) < config.max_planet_per_system \ and chance <= config.probability_planet: angle = random.randint(0, 359) self.bodies.append(Planet(self, angle, n)) else: chance = random.randint(1, 100) if chance <= config.probability_asteroids: nb_asteroids = random.randrange( config.max_asteroids_per_belt // 3, config.max_asteroids_per_belt) for a in range(nb_asteroids): angle = random.randint(0, 359) self.bodies.append(Asteroid(self, angle, n)) else: chance = random.randint(1, 100) if chance <= config.probability_station: angle = random.randint(0, 359) self.bodies.append(Station(self, angle, n)) else: chance = random.randint(1, 100) if chance <= config.probability_comet: angle = random.randint(0, 359) self.bodies.append(Comet(self, angle, n))
def optimize(log_output=False, dest='Mars'): # AU # earth_radius = 0.00004258756 # AU^3/year^2 # earth_attractor = 0.0001184 phi = [np.random.uniform(0, 2 * np.pi) for i in range(2) ] + [0] + [np.random.uniform(0, 2 * np.pi) for i in range(5)] Earth = Planet(1, 1, phi[2], "Earth") Mercury = Planet(0.374496, 0.241, phi[0], "Mercury") Mars = Planet(1.5458, 1.8821, phi[3], "Mars") Venus = Planet(0.726088, 0.6156, phi[1], "Venus") Jupiter = Planet(5.328, 11.87, phi[4], "Jupiter") Saturn = Planet(9.5497, 29.446986, phi[5], "Saturn") Uranus = Planet(19.2099281, 84.01538, phi[6], "Uranus") Neptune = Planet(30.0658708, 164.78845, phi[7], "Neptune") num_gens = 1 num_evolutions = 75 pop_size = 200 cometX = Comet() if dest == "Comet": planets = [ Earth, Earth, Mercury, Mars, Venus, Jupiter, Saturn, Neptune, Uranus, cometX ] else: choices = [ Earth, Earth, Mercury, Mars, Venus, Jupiter, Saturn, Neptune, Uranus ] destination = [x for x in choices if x.get_name() == dest] choices.remove(destination[0]) planets = choices + [destination[0]] if dest == "Venus" or dest == "Mercury": max_enctrs = 1 else: max_enctrs = len(planets) - 2 times = [0] + [0.1] * (max_enctrs + 1) max_times = [5] * (max_enctrs + 2) # optimize t0 = time.time() udp = gprob(planets, times, max_times, max_enctr=max_enctrs) uda = pg.algorithm(pg.sade(gen=num_gens, memory=True)) if (not log_output ): # this avoids the persistent looping to get the fitness data archi = pg.archipelago(algo=uda, prob=udp, n=8, pop_size=pop_size) archi.evolve(num_evolutions) archi.wait() else: # this is where we loop and evolve and get the fitness data for each island archi = pg.archipelago(algo=uda, prob=udp, n=8, pop_size=pop_size) islands = [] for i in range(num_evolutions): archi.evolve() archi.wait() avgFit = [ -1.0 * np.average(island.get_population().get_f()) for island in archi ] islands.append(np.array(avgFit)) # islands.append(np.array(archi.get_champions_f())) # get the best scores from each island after each stage showlog(np.array(islands), 8, num_evolutions) t1 = time.time() sols = archi.get_champions_f() idx = sols.index(min(sols)) # print("index: {}, Scores: ".format(idx) + str(sols) + "\n\n") mission = udp.pretty(archi.get_champions_x()[idx]) # [print(str(l) + "\n") for l in mission] convert(mission[0], mission[1], mission[2]) logger.log(mission[1][0], mission[1][-1], phi) print("\n\nTime for soln: {} sec\n\n".format(t1 - t0))
def meteor_fall(self): for i in range(1, 15): # apparaitre une premiere boule de feu self.all_comets.add(Comet(self))
self.orbit * np.cos(self.omega * t + self.phi), self.orbit * np.sin(self.omega * t + self.phi), 0 ]) # AU earth_radius = 0.00004258756 # AU^3/year^2 earth_attractor = 0.0001184 # The sun only has one parameter of interest, it's attractor Sun = 39.42 Earth = Planet(1, 1, 0) Mercury = Planet(0.374496, 0.241, np.pi / 2) Mars = Planet(1.5458, 1.8821, np.pi + .7) Venus = Planet(0.726088, 0.6156, 3 * np.pi / 4) Jupiter = Planet(5.328, 11.87, np.pi / 2 + .38) Saturn = Planet(9.5497, 29.446986, 0) Uranus = Planet(19.2099281, 84.01538, 0) Neptune = Planet(30.0658708, 164.78845, 0) # lambert_sol = izzo_fast(Sun, Earth.get_pos(0), np.array([-6.74393, -0.197631,0]), 3, M=0, numiter=10, rtol=1e-2) # for v0, v in lambert_sol: # print("V0: {}, Vf: {}".format(v0[:2], v[:2])) Comet = Comet() print(Comet.get_pos(0)) for i in range(100): print(Comet.get_pos(i))
def main(config_file): # initialize control streams with open(config_file) as config_file: config = yaml.safe_load(config_file) log_level = log.DEBUG if config['debug'] else log.INFO log.basicConfig(level=log_level) log.info("Opening DMX port.") try: dmx_port = dmx.select_port() except dmx.EnttecPortOpenError as err: log.error(err) quit() log.info("Opened DMX port.") control_queue = Queue() config["receive host"] = socket.gethostbyname(socket.gethostname()) log.info("Using local IP address {}".format(config["receive host"])) osc_controller = OSCController(config, control_queue) # which italian hot rod you like? fixture_choice = config['fixture'] if fixture_choice == 'comet': fixture = Comet(int(config['dmx_addr'])) setup_controls = setup_comet_controls control_map = comet_control_map log.info("Controlling a Comet.") elif fixture_choice == 'venus': fixture = Venus(int(config['dmx_addr'])) setup_controls = setup_venus_controls control_map = venus_control_map log.info("Controlling the Venus.") elif fixture_choice == 'lumasphere': fixture = Lumasphere(int(config['dmx_addr'])) control_map, setup_controls = build_lumasphere_controls() log.info("Controlling the Lumasphere.") else: log.error("Unknown fixture type: {}".format(fixture_choice)) return setup_controls(osc_controller) def process_control_event(timeout): """Drain the control queue and apply the action.""" try: (control, value) = control_queue.get(timeout=timeout) except Empty: pass else: # if we got a UI event, process it try: control_map[control](fixture, value) except KeyError: raise ControlError("Unknown control: '{}'".format(control)) log.info("Starting OSC server.") osc_thread = threading.Thread(target=osc_controller.receiver.serve_forever) osc_thread.start() def render_action(frame_number, frame_time, fixture): fixture.render(dmx_port.dmx_frame) dmx_port.render() try: run_show(render_action=render_action, control_action=process_control_event, update_action=lambda timestep: fixture.update(timestep), retrieve_show_state=lambda: fixture, quit_check=lambda: False, update_interval=int(config['update_interval']), report_framerate=config['debug']) finally: log.info("Closing OSCServer.") osc_controller.receiver.close() log.info("Waiting for server thread to finish.") osc_thread.join() log.info("Done.")
def meteor_fall(self): # boucle pour les valeurs entre 1 et 10 for i in range(1, 10): self.all_comet.add( Comet(self)) # faire apparaitre 1 instance de comet
def meteor_fall(self): #boucle pour les valeurs entre 1 et 10 for i in range(1, 10): #apparaitre 1 premiere boule de feu self.all_comets.add(Comet(self))
def metor_fall(self): for i in range(20): self.all_comets.add(Comet(self)) mixer.Sound(os.path.join('assets', 'sounds', 'meteorite.ogg')).play()
def meteor_fall(self): for i in range(1, 35): self.all_comets.add(Comet(self))
def meteor_fall(self): for i in range(1, 20): # faire appretre une boule de feu self.all_comets.add(Comet(self))
def meteor_fall(self): # boucle pour faire apparaître 10 boules de feu for i in range(1, 10): # faire apparaître une boule de feu self.all_cometes.add(Comet(self))
def meteor_fall(self): number_comet = random.randint(10, 20) for i in range(1, number_comet): self.all_comets.add(Comet(self))
def meteor_fall(self): #boucle pour les comettes en 1 et 10 for i in range(1, 10): #faire apparaitre la premiere comette self.all_comets.add(Comet(self))
def meteor_fall(self): for i in range(1, 10): # faire apparaitre les comètes self.all_comets.add(Comet(self))
def meteor_fall(self): #apparaitre des bppules de feu (entre 1 et 10) for i in range(random.randint(1, 10)): self.all_comets.add(Comet(self))
def meteor_fall(self): #boule de valeur entre 1 et 10 for i in range(1, 10): #apparaitre boule de feu self.all_comets.add(Comet(self))
def meteor_fall(self): for i in range(1, 10): # Faire apparaitre les boules de feu self.all_comets.add(Comet(self))
def meteor_fall(self): #faire tomber 10 comètes for i in range(1,10): self.all_comets.add(Comet(self))