def save_load_events(self): for e in pygame.event.get(): # quitter le jeu de force if e.type == pygame.QUIT: self.run = False pygame.quit() # récupérer les coordonnées de clic de la souris if e.type == pygame.MOUSEBUTTONDOWN: x = pygame.mouse.get_pos()[0] # False to save and True to load if x < self.bg.w / 2: self.s_l_choice = False else: self.s_l_choice = True # vérification du point de relâchement du clic de la souris if e.type == pygame.MOUSEBUTTONUP: x = pygame.mouse.get_pos()[0] # charger les données de sauvegarde if self.s_l_choice and x > self.bg.w / 2: infos = decoding() print(infos) self.buildings.empty() self.gold.quantity, self.stuff.quantity = infos[0] self.gold.add(0) self.stuff.add(0) self.bg.x, self.bg.y, self.bg.zoom = infos[1] for b in infos[2]: type = self.dict_loading[b[0][0]] image = self.pictures[type] batiment = Building(image, b[1], b[2], self.bg, type) self.buildings.add(batiment) self.s_l = False self.win.fill((0, 0, 0)) # sauvegarder les données de sauvegarde elif not self.s_l_choice and x < self.bg.w / 2: resources = [self.gold.quantity, self.stuff.quantity] building = [] for b in self.buildings: building.append([b.type, b.gap_x, b.gap_y]) data = [ resources, [self.bg.x, self.bg.y, self.bg.zoom], building ] encode(data) self.s_l = False self.win.fill((0, 0, 0)) # si la touche escape est pressée, le menu save/load est fermé if e.type == pygame.KEYDOWN: if e.key == pygame.K_ESCAPE: self.s_l = False self.win.fill((0, 0, 0))
def init(num_individuals=10, num_phases=3, num_nodes=4, num_classes=10): individuals = [] for i in range(num_individuals): individual = Individual(structure=encode(num_phases, num_nodes)) individual.model = Network(individual.structure, [(3, 32), (32, 128), (128, 128)], num_classes, (32, 32)) individuals.append(individual) return individuals
def init(num_individuals=10, num_phases=3, num_nodes=4): individuals = [] for i in range(num_individuals): individual = Individual(structure=encode(num_phases, num_nodes)) individual.model = Network(individual.structure, [(3, 64), (64, 128), (128, 256), (256, 512)]) individuals.append(individual) return individuals
}) elif tracker1[0] == "h": config.tracker_list.append({ "trac": tracker1, "type": "http" }) if key == b'announce': tracker = value.decode("utf-8") config.total_pieces = int(config.left / config.single_piece_len) + 1 config.last_piece_len = config.left - (config.total_pieces - 1) * config.single_piece_len config.file_size = config.total_pieces * config.single_piece_len #creating an info hash for the file info_hash_bencode = encode(info_hash) info_hash_sha1 = hashlib.sha1(info_hash_bencode).digest() config.info_hash = info_hash_sha1 info_has = escape(info_hash_sha1) #Creation ends here config.global_tracker_list = config.tracker_list #____________________Part 2 ends here____________________ #____________________Part 3: Http/ UDP request to the tracker is made here and list of peers is obtained____________________ #if there is no tracker list then use the tracker mentioned in announce if len(config.tracker_list) == 0: if tracker[0] == "u": config.tracker_list.append({"trac": tracker, "type": "udp"}) elif tracker[0] == "h":
def init(num_individuals=10, num_phases=3, num_nodes=4): individuals = [] for i in range(num_individuals): individual = Individual(structure=encode(num_phases, num_nodes)) individuals.append(individual) return individuals
# from Morse import * from Corpus import test_string, WORDS, MAX_WORD_LEN, WORD_PREFIX from Encode import encode, encode_nospace from Decode import decode, decode_nospace print(encode(test_string)) # print(encode_nospace(test_string)) decode(encode(test_string))
def encryptown(self): placehold = encode(self.key, self.imgString) #boQMTdk print(placehold) self.savefile(placehold, True) print("Encrypted")