def test(self): global position global _winners if position == 4: position = 0 main.reset(_records) self.newWinner(position) position += 1
def crd_unit_begin(crd): print( "\n\n*************** Create mode crd test units ***************\n\n") create(crd) print( "\n\n*************** Read mode crd test units ***************\n\n") read(crd) print( "\n\n*************** Delete mode crd test units ***************\n\n") delete(crd) print( "\n\n*************** Reset mode crd test units ***************\n\n") print(main.reset(crd.client)) print(main.reset("87Lane"))
def evolve(): """ Generate a new population based on the result of the earlier one """ d.next_gen = [] """ Keep the best car """ net_best = copy.deepcopy(d.best_car.neural_net) d.next_gen.append(Car(net_best)) """ Make strong mutations from the best car """ for _ in range(d.BEST_CAR_MUTATION_HIGH): net = copy.deepcopy(d.best_car.neural_net) net = mutate(net, True) d.next_gen.append(Car(net)) """ Make small mutation from the best car """ for _ in range(d.BEST_CAR_MUTATION_LOW): net = copy.deepcopy(d.best_car.neural_net) net = mutate(net, False) d.next_gen.append(Car(net)) """ Make mutations from the shitty cars """ for i in range(d.SHITTY_CAR_COUNT): net = copy.deepcopy(d.shitty_cars[i].neural_net) net = mutate(net, True) d.next_gen.append(Car(net)) """ Make a few randoms """ for i in range(d.RANDOM_CAR_COUNT): # A new instance of a NN is always random net = NeuralNetWork(d.SENSOR_COUNT, d.HIDDEN_LAYERS, 1) d.next_gen.append(Car(net)) """ Cross-Breed the rest of the population """ children = [] breed_count = d.POPULATION_COUNT - len(d.next_gen) for _ in range(breed_count): # Find parents mom = d.fittest_cars[random.randint(0, len(d.fittest_cars) - 1)] dad = mom # Make sure the two parent are different while dad == mom: dad = d.fittest_cars[random.randint(0, len(d.fittest_cars) - 1)] # Make children net = breed(mom.neural_net, dad.neural_net) children.append(net) # Mutate half of the crossed children for i in range(int(len(children) / 2)): children[i] = mutate(children[i], True) # Add the children to the population for i in range(len(children)): d.next_gen.append(Car(children[i])) """ Start a new simulation with the new population """ main.reset()
def test1(): arr_num_nodes = [3600, 4800] keys = [] b = "set_1000_keys_lookup.txt" with open(b, 'r') as filedata: keys = json.load(filedata) datas = [] for node in arr_num_nodes: config.NODES = node b = "set_" + str(node) + "_nodes.txt" with open(b, 'r') as filedata: datas = json.load(filedata) main.load(datas) result_test = test_lookup(keys['keys']) name = "topo_" + str(config.NODES) + "_nodes_" + str( 1000) + "_keys_lookup_with_original_chord.json" with open(name, "w") as fw: json.dump(result_test, fw) main.reset() return json.dumps("ket thuc", indent=3)
def test1(): keys = [] b = "set_2000_keys_lookup.txt" with open(b, 'r') as filedata: keys = json.load(filedata) datas = [] filename = "set_1024_nodes_ring.txt" with open(filename, 'r') as filedata: datas = json.load(filedata) i = 0 for data in datas: main.load(data) result_test = test_lookup(keys['keys']) name = "topo_" + str( config.NODES) + "_nodes_" + str(2000) + "_keys_lookup_with_" + str( i) + "%_faulty_nodes_improved_chord.json" with open(name, "w") as fw: json.dump(result_test, fw) main.reset() i += 10 return json.dumps("ket thuc", indent=3)
def test_insert(): keys = [] b = "set_1000_keys.txt" with open(b, 'r') as filedata: keys = json.load(filedata) a = "data_insert/insert_data_1024nodes.txt" datas = [] with open(a, 'r') as filedata: datas = json.load(filedata) result = [] j = 1 for data in datas: main.load(data) result_test = insert(keys['keys']) a = str(j) + "nd:the_cost_insertion_1000_data_with_" + str( config.NODES) + "_nodes_and_partition=" + str(config.N) + ".json" with open(a, "w") as fw: json.dump(result_test, fw) main.reset() j += 1 return json.dumps("ket thuc", indent=3)
def test_finger(): keys = [] b = "set_2000_keys_lookup.txt" with open(b, 'r') as filedata: keys = json.load(filedata) print len(keys) a = "set_1024_nodes.txt" datas = [] with open(a, 'r') as filedata: datas = json.load(filedata) result = [] i = 0 for data in datas: main.load(data) result_test = test_lookup(keys['keys']) name = "topo_" + str( config.NODES) + "_nodes_" + str(2000) + "_keys_lookup_with_" + str( i) + "%_faulty_nodes_original_chord.json" with open(name, "w") as fw: json.dump(result_test, fw) return json.dumps("ket thuc", indent=3) main.reset() i += 10 return json.dumps("ket thuc", indent=3)
def reset(): return main.reset()
def jugarPartida(modo): pygame.init() pygame.display.set_caption('Tres en Raya - ' + modo) screen.fill(bg) btReiniciar = boton(col.dorado, 170, 305, 80, 40, 'Reiniciar', fontSize=15) btSalir = boton(col.rojo, 250, 305, 40, 40, 'X', fontSize=15) # estas variables se inicializan al importar el script, fuera de cualquier funcion global turnoJ1, jugadasJ1, jugadasJ2, estado while True: # Guarda una copia del estado de la partida copiaEstado = np.copy(estado) screen.fill(bg) # Muestra los botones btReiniciar.draw(screen) btSalir.draw(screen) ''' SE MUESTRA SI TERMINO O NO LA PARTIDA Y SI HUBO UN EMPATE/GANADOR ''' mostrarInfoTurno(modo) ''' CONTROL DE EVENTOS (CLICKS O TECLAS) + ACTUALIZA LA COPIA DEL ESTADO CON LA NUEVA JUGADA HECHA ''' # Capturar eventos ev = pygame.event.get() for event in ev: mousePos = pygame.mouse.get_pos() if event.type == pygame.QUIT: quit() # Si se pulsa una tecla if event.type == pygame.KEYDOWN: key = pygame.key.get_pressed() if key == 'r': # TODO -> revisar pq no funciona esto... reset() # Si hay un click if event.type == pygame.MOUSEBUTTONDOWN: if btReiniciar.mouseIsOver(mousePos): reset() elif btSalir.mouseIsOver(mousePos): quit() if btReiniciar.mouseIsOver(mousePos): btReiniciar.color = col.doradoClaro else: btReiniciar.color = col.dorado if btSalir.mouseIsOver(mousePos): btSalir.color = col.rojoClaro else: btSalir.color = col.rojo mouseclick = pygame.mouse.get_pressed() # si termino la partida, el bucle continua pq podria darle a "Reiniciar" o a "X" # si no termino la partida if not fin: # si se pulso el raton en 1 VS 1 if modo == "1 VS 1" and sum(mouseclick) > 0: # posicion del raton (en pixeles) posX, posY = pygame.mouse.get_pos() # calculo de celda celX, celY = int(np.floor(posX / dimCW)), int(np.floor(posY / dimCH)) # Si clicka dentro de el espacio de juego if posX < width and posY < 300: # Si la celda no estaba ya "jugada" (elegida) if copiaEstado[celX, celY] == 0: # actualiza estado de la celda copiaEstado[celX, celY] = 1 #print("Se actualizo la casilla ", celX, celY, " con valor = ", copiaEstado[celX, celY]) # Apunta la jugada y cambia el turno if turnoJ1: jugadasJ1 += str(celX) + str(celY) + " " else: jugadasJ2 += str(celX) + str(celY) + " " turnoJ1 = not turnoJ1 elif modo == "1 VS PC": # Si le toca al J1 y se pulso el raton if turnoJ1 and sum(mouseclick) > 0: # J1 clicka una casilla y juega # posicion del raton (en pixeles) posX, posY = pygame.mouse.get_pos() # calculo de celda celX, celY = int(np.floor(posX / dimCW)), int(np.floor(posY / dimCH)) # Si clicka dentro de el espacio de juego if posX < width and posY < 300: # Si la celda no estaba ya ocupada if copiaEstado[celX, celY] == 0: # actualizar estado de la celda copiaEstado[celX, celY] = 1 #print("Se actualizo la casilla ", celX, celY, " con valor = ", copiaEstado[celX, celY]) # Apunta la jugada y devuelve el turno al PC jugadasJ1 += str(celX) + str(celY) + " " turnoJ1 = False # Si le toca al PC elif not turnoJ1: # PC calcula su jugada y juega celX, celY = pcCalculaJugada(copiaEstado) # actualizar estado de la celda copiaEstado[celX, celY] = 1 # Apunta la jugada y devuelve el turno al J1 jugadasJ2 += str(celX) + str(celY) + " " turnoJ1 = True ''' RENDER DEL TABLERO ''' renderTablero() # Carga el nuevo estado de la partida estado = copiaEstado pygame.display.flip()
async def display(ctx): await ctx.send(main.generate(main.reset(), "l"))
async def female(ctx): await ctx.send(main.generate(main.reset(), "f"))
from main import reset reset()
def reset(self): return main.reset(self.client, filepath=self.filepath)
def setUp(self): main.reset()
def reset(option): main.reset(file_name, option)