diff --git a/EA/constants.py b/EA/constants.py index 2afa934..f347dab 100644 --- a/EA/constants.py +++ b/EA/constants.py @@ -14,8 +14,8 @@ CARD_DIRECTORY = config.CARD_DIR FORGE_PATH = config.FORGE_DIR DECKLIST_HEADER = '[metadata]\nName=candidate\n[Main]\n' -OPPONENTS = ["GB-sealed-opponent.dck", "UWg-sealed-opponent.dck", "RG-sealed-opponent1.dck" +OPPONENTS = ["GB-sealed-opponent.dck", "UWg-sealed-opponent.dck", "RG-sealed-opponent1.dck", "BGw-sealed-opponent.dck", "UR-sealed-opponent.dck", "RW-sealed-opponent.dck"] EXPERIMENT_TIMESTAMP = datetime.datetime.now().strftime("%d%m%H%M") EXPERIMENT_FOLDER = "results/" + EXPERIMENT_TIMESTAMP -CARDS = read_cards_json() +# CARDS = read_cards_json() diff --git a/EA/fitness.py b/EA/fitness.py index 787851e..31801c9 100644 --- a/EA/fitness.py +++ b/EA/fitness.py @@ -15,23 +15,15 @@ def evaluate_deck_by_wins(individual): decklist = genome_to_decklist(individual) filename = "candidate.dck" write_decklist(ct.CARD_DIRECTORY + filename, decklist) - total_damage = 0 wins = 0 for opponent in ct.OPPONENTS: cmd = build_cmd(filename, opponent, ct.MATCHES_PER_OPPONENT) p = subprocess.Popen(cmd, cwd=ct.FORGE_PATH, stdout=subprocess.PIPE) for line in p.stdout: line = line.decode("utf-8").strip() - #print(line) - # if 'combat damage to Ai(2' in line: - # hit_event = line.split(' ') - # # print(hit_event) #For debugging - # damage_index = hit_event.index('deals') + 1 - # damage = int(hit_event[damage_index]) - # total_damage += damage if 'Match result' in line: result = line.split(' ') wins += int(result[3]) p.wait() - fitness = wins # (wins/float(MATCHES_PER_OPPONENT*len(opponents)))*damage + fitness = wins return fitness, # MUST BE TUPLE! diff --git a/EA/helloworld.py b/EA/helloworld.py deleted file mode 100644 index c6943ce..0000000 --- a/EA/helloworld.py +++ /dev/null @@ -1,34 +0,0 @@ -import random -from deap import creator, base, tools, algorithms - -creator.create("FitnessMax", base.Fitness, weights=(1.0,)) -creator.create("Individual", list, fitness=creator.FitnessMax) - -toolbox = base.Toolbox() - -toolbox.register("attr_bool", random.randint, 0, 1) -toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_bool, n=100) -toolbox.register("population", tools.initRepeat, list, toolbox.individual) - - -def evalOneMax(individual): - return sum(individual), - -toolbox.register("evaluate", evalOneMax) -toolbox.register("mate", tools.cxTwoPoint) -toolbox.register("mutate", tools.mutFlipBit, indpb=0.05) -toolbox.register("select", tools.selTournament, tournsize=3) - -population = toolbox.population(n=300) - -NGEN=40 -for gen in range(NGEN): - offspring = algorithms.varAnd(population, toolbox, cxpb=0.5, mutpb=0.1) - fits = toolbox.map(toolbox.evaluate, offspring) - for fit, ind in zip(fits, offspring): - ind.fitness.values = fit - population = toolbox.select(offspring, k=len(population)) -top10 = tools.selBest(population, k=10) - -for individual in top10: - print(sum(individual)) \ No newline at end of file diff --git a/EA/logger.py b/EA/logger.py index b0636ba..258a998 100644 --- a/EA/logger.py +++ b/EA/logger.py @@ -57,8 +57,7 @@ def write_log(top_list, median_list, worst_list, global_maximum, time_to_complet def write_graph(top_list, median_list, worst_list, filename): - - plt.plot((top_list), 'blue') + plt.plot(top_list, 'blue') plt.plot(median_list, 'green') plt.plot(worst_list, 'red') plt.xlabel('Generations') diff --git a/EA/main.py b/EA/main.py index ed8fdb4..5bdf92a 100644 --- a/EA/main.py +++ b/EA/main.py @@ -70,8 +70,9 @@ def mate_individuals(ind1, ind2): def main(): # TODO: VELG BREEDING OG MUTASJONSSTRATEGI - + number_of_matches = int(ct.MATCHES_PER_OPPONENT) * len(ct.OPPONENTS) * ct.NUMBER_OF_GENERATIONS * ct.POPSIZE print('Starting experiment {}'.format(ct.EXPERIMENT_TIMESTAMP)) + print('Doing {} matches'.format(number_of_matches)) start_time = time.time() first_gen_decks = generate_first_generation_decks(ct.CARD_POOL)