Exemplo n.º 1
0
def evolve_on_cloud(num_generations, current_pop):
    for i in np.arange(num_generations):
        print("Generation : "+str(i))
        line_up = list(itertools.combinations(current_pop, 2))
        #Post each chars deets for each match
        for match in np.arange(len(line_up)):
            genn = i
            matchnu=match
            p1n = line_up[match][0]
            p1moves = parse_file.read_cmd(p1n)
            p1str = parse_file.to_str(p1moves)
            p2n = line_up[match][1]
            p2moves = parse_file.read_cmd(p2n)
            p2str = parse_file.to_str(p2moves)
            tags = "Evolve"

            data = urllib.parse.urlencode({"matchnum":matchnu,"gen":genn,"p1name":p1n , "p1moves":p1str, "p2name": p2n, "p2moves":p2str, "tag":tags})
            data = data.encode('utf-8')
            request = urllib.request.Request("http://104.197.115.172")
            
            # adding charset parameter to the Content-Type header.
            request.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8")
            
            f = urllib.request.urlopen(request, data)
            print(f.read().decode('utf-8'))
        
        #after the matches are over we need to pull the reults for that generation
        #from the db
        #And just to make sure that all the simulations have completed well sleep for some time
        print("Wait for 45 seconds.")
        time.sleep(45)
        print("Updating char sheet...")
        #update the char sheet 
        update_gen_from_db(i)
        
        #Now just update relevent dfs and create new pop
        #Sort our current pupulation interms of ELO
        df_sorted = list_df_gen[i].sort_values('ELO', ascending = False)
        #print(df_sorted.head())
        #Get last elo
        v = df_sorted.iloc[-1].ELO
        ratio.append(v)
    
        #Only replace population if were not on the last generation
        if i < num_generations-1:        
            #hah! Get it?
            new_pop = nu_gen(df_sorted, len(df_sorted),i+1)
            #replace current pop with new pop
            current_pop = new_pop.Name.tolist()
            #keep track
            list_df_gen.append(new_pop)
        #On last generation... do some stuff with the list of dfs
        elif i == num_generations-1:
            print("DONE!")
            plt.scatter(range(0,len(ratio)), ratio)
            plt.title("Lowest ELO per Generation")
            plt.xlabel("Generation")
            plt.ylabel("ELO")
            plt.show()
Exemplo n.º 2
0
def cloud_cast(line, cur_gen, tag):
    match =0
    #Post each chars deets for each match
    #after assess names we get back a 3d list [[["p1","easy"],[p1,med],..]]
    for char in np.arange(len(line)):
        #them for each of their test martches
        for char_sim in np.arange(len(line[char])):
            #then we post the details
            genn = cur_gen
            matchnu=str(match)
            p1n = line[char][char_sim][0]
            print(p1n)
            p1moves = parse_file.read_cmd(p1n)
            p1str = parse_file.to_str(p1moves)
            p2n = line[char][char_sim][1]
            #dont need to get  moves for p2
            p2str = p2n+ "moves" ##parse_file.to_str(p2moves)
            tags = tag
    
            data = urllib.parse.urlencode({"matchnum":matchnu,"gen":genn,"p1name":p1n , "p1moves":p1str, "p2name": p2n, "p2moves":p2str, "tag":tags})
            data = data.encode('utf-8')
            request = urllib.request.Request("http://104.197.115.172")
            
            # adding charset parameter to the Content-Type header.
            request.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8")
            
            try:
                print("requesting simulation(exp)")
                f = urllib.request.urlopen(request, data)
                print(f.read().decode('utf-8'))
            except Exception as e:
                # Return code error (e.g. 404, 501, ...)
                # ...
                print(str(e))
                
            match+=1
Exemplo n.º 3
0
def experiment_on_cloud(num_generations, current_pop):
    for i in np.arange(num_generations):
        #Go about normal shiaattt 
        #first evolve
        print("Generation : "+str(i))
        line_up = list(itertools.combinations(current_pop, 2))
        for match in np.arange(len(line_up)):
            genn = i
            matchnu=match
            p1n = line_up[match][0]
            p1moves = parse_file.read_cmd(p1n)
            p1str = parse_file.to_str(p1moves)
            p2n = line_up[match][1]
            p2moves = parse_file.read_cmd(p2n)
            p2str = parse_file.to_str(p2moves)
            tags = "Evolve"

            data = urllib.parse.urlencode({"matchnum":matchnu,"gen":genn,"p1name":p1n , "p1moves":p1str, "p2name": p2n, "p2moves":p2str, "tag":tags})
            data = data.encode('utf-8')
            request = urllib.request.Request("http://104.197.115.172")
            
            # adding charset parameter to the Content-Type header.
            request.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8")
            
            #f = urllib.request.urlopen(request, data)
            #print(f.read().decode('utf-8'))

            try:
                print("requesting simulation")
                f = urllib.request.urlopen(request, data)
                print(f.read().decode('utf-8'))
            except Exception as e:
                # Return code error (e.g. 404, 501, ...)
                # ...
                print(str(e))

                
            
            
            
        #after the matches are over we need to pull the reults for that generation
        #from the db
        #And just to make sure that all the simulations have completed well sleep for some time
        print("Wait for 45 seconds.")
        time.sleep(45)
        print("Updating char sheet...")
        #update the char sheet 
        expected_sims_rr = int(sum(range(1,len(current_pop))))
        update_gen_from_db(i,expected_sims_rr)
        
        #Now just update relevent dfs and create new pop
        #Sort our current pupulation interms of ELO
        df_sorted = list_df_gen[i].sort_values('ELO', ascending = False)
        
        

        

        #Get last elo
        v = df_sorted.iloc[-1].ELO
        ratio.append(v)
    
        #Only replace population if were not on the last generation
        if i < num_generations-1:        
            #hah! Get it?
            new_pop,new_kids = nu_gen(df_sorted, len(df_sorted),i+1)
            print(new_kids)
            #replace current pop with new pop
            current_pop = new_pop.Name.tolist()
            
            #NOW assess the generations children/
            a_pop = assess_names(new_kids, i+1)
            #simulate on cloud
            cloud_cast(a_pop, i+1, "Experiment")
            #update the charstats
            print("Wait for 45 seconds.")
            time.sleep(45)
            print("Updating STATS sheet...")
            #each child vs easy med hard
            expected_pause = int(len(new_kids)*3)
            gen_stats = pull_stats_from_db(i+1, expected_pause)
            list_df_stats.append(gen_stats)
            
            #keep track
            list_df_gen.append(new_pop)
        #On last generation... do some stuff with the list of dfs
        elif i == num_generations-1:
            print("DONE!")
            plt.scatter(range(0,len(ratio)), ratio)
            plt.title("Lowest ELO per Generation")
            plt.xlabel("Generation")
            plt.ylabel("ELO")
            plt.show()