-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sverrejb/argparser
Argparser
- Loading branch information
Showing
42 changed files
with
1,210 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This was BGw-sealed-opponent.dckplaying versus: | ||
GB-sealed-opponent.dck: 0 | ||
UWg-sealed-opponent.dck: 1 | ||
RG-sealed-opponent.dck: 0 | ||
BGw-sealed-opponent.dck: 0 | ||
UR-sealed-opponent.dck: 0 | ||
RW-sealed-opponent.dck: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This was GB-sealed-opponent.dckplaying versus: | ||
GB-sealed-opponent.dck: 0 | ||
UWg-sealed-opponent.dck: 0 | ||
RG-sealed-opponent.dck: 0 | ||
BGw-sealed-opponent.dck: 1 | ||
UR-sealed-opponent.dck: 2 | ||
RW-sealed-opponent.dck: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This was RG-sealed-opponent.dckplaying versus: | ||
GB-sealed-opponent.dck: 2 | ||
UWg-sealed-opponent.dck: 2 | ||
RG-sealed-opponent.dck: 0 | ||
BGw-sealed-opponent.dck: 1 | ||
UR-sealed-opponent.dck: 0 | ||
RW-sealed-opponent.dck: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
This was RG-sealed-opponent.dckBGw-sealed-opponent.dckplaying versus: | ||
GB-sealed-opponent.dck: 0 | ||
UWg-sealed-opponent.dck: 0 | ||
RG-sealed-opponent.dckBGw-sealed-opponent.dck: 0 | ||
UR-sealed-opponent.dck: 0 | ||
RW-sealed-opponent.dck: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This was RW-sealed-opponent.dckplaying versus: | ||
GB-sealed-opponent.dck: 2 | ||
UWg-sealed-opponent.dck: 1 | ||
RG-sealed-opponent.dck: 0 | ||
BGw-sealed-opponent.dck: 2 | ||
UR-sealed-opponent.dck: 2 | ||
RW-sealed-opponent.dck: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This was UR-sealed-opponent.dckplaying versus: | ||
GB-sealed-opponent.dck: 1 | ||
UWg-sealed-opponent.dck: 1 | ||
RG-sealed-opponent.dck: 2 | ||
BGw-sealed-opponent.dck: 2 | ||
UR-sealed-opponent.dck: 2 | ||
RW-sealed-opponent.dck: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This was UWg-sealed-opponent.dckplaying versus: | ||
GB-sealed-opponent.dck: 1 | ||
UWg-sealed-opponent.dck: 1 | ||
RG-sealed-opponent.dck: 1 | ||
BGw-sealed-opponent.dck: 2 | ||
UR-sealed-opponent.dck: 2 | ||
RW-sealed-opponent.dck: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import argparse | ||
import copy | ||
import os | ||
import time | ||
import sys | ||
from random import randint | ||
from statistics import median | ||
|
||
|
@@ -68,9 +70,30 @@ def mate_individuals(ind1, ind2): | |
return ind1, ind2 | ||
|
||
|
||
def parse_arguments(): | ||
ap = argparse.ArgumentParser() | ||
ap.add_argument('-g', '--gens', type=str, help='number of generations') | ||
ap.add_argument('-m', '--matches', type=float, help='matches per opponent') | ||
args = vars(ap.parse_args()) | ||
|
||
if args['gens'] is None: | ||
print('Number of generations not specified with -g, using default of 200') | ||
else: | ||
ct.NUMBER_OF_GENERATIONS = int(args['gens']) | ||
print(ct.NUMBER_OF_GENERATIONS) | ||
|
||
if args['matches'] is None: | ||
print("Number of matches per opponent not specified with -m, using default of 50") | ||
else: | ||
ct.MATCHES_PER_OPPONENT = str(int(args['matches'])) | ||
print(ct.MATCHES_PER_OPPONENT) | ||
|
||
|
||
def main(): | ||
# TODO: VELG BREEDING OG MUTASJONSSTRATEGI | ||
|
||
parse_arguments() | ||
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)) | ||
|
||
|
@@ -97,8 +120,11 @@ def main(): | |
|
||
for gen in range(ct.NUMBER_OF_GENERATIONS): | ||
offspring = algorithms.varAnd(population, toolbox, cxpb=ct.CROSSOVER_RATE, mutpb=ct.MUTATION_RATE) | ||
fits = list(futures.map(toolbox.evaluate, offspring)) | ||
print("Generation {}, {}".format(gen, fits)) | ||
|
||
offspring_and_matches = [(x, ct.MATCHES_PER_OPPONENT) for x in offspring] | ||
|
||
fits = list(futures.map(toolbox.evaluate, offspring_and_matches)) | ||
|
||
for fit, ind in zip(fits, offspring): | ||
ind.fitness.values = fit | ||
population = toolbox.select(offspring, k=len(population)) | ||
|
@@ -108,11 +134,17 @@ def main(): | |
for i, solution in enumerate(population): | ||
write_decklist(card_location + "/" + str(i) + '.dck', genome_to_decklist(solution)) | ||
fitness_list = [x[0] for x in fits] | ||
|
||
maximum = max(fitness_list) | ||
|
||
strongest_individual = tools.selBest(population, k=1) | ||
|
||
median_score = median(fitness_list) | ||
|
||
minimum = min(fitness_list) | ||
|
||
print("Generation {}, max: {} median: {} min: ".format(gen, median_score, median_score, minimum)) | ||
|
||
if median_score > best_median: | ||
best_median = median_score | ||
last_improvement = gen | ||
|
@@ -147,4 +179,3 @@ def main(): | |
except Exception as e: | ||
print("Unexpected error:\n{}".format(e)) | ||
send_mail(['[email protected]', '[email protected]'], "The program has crashed:\n{}".format(e)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import subprocess | ||
|
||
def build_cmd(candidate_name, opponent_name, nr_matches): | ||
return ['java', '-Xmx1024m', '-jar', | ||
'forge-gui-desktop-1.5.61-SNAPSHOT-jar-with-dependencies.jar', 'sim', | ||
'-d', candidate_name, opponent_name, | ||
'-n', nr_matches, '-f', 'sealed'] | ||
|
||
|
||
|
||
#total_damage = 0 | ||
wins = 0 | ||
OPPONENTS = ["GB-sealed-opponent.dck", "UWg-sealed-opponent.dck", "RG-sealed-opponent.dck", | ||
"BGw-sealed-opponent.dck", "UR-sealed-opponent.dck", "RW-sealed-opponent.dck"] | ||
|
||
for challenger in OPPONENTS: | ||
print(challenger) | ||
with open("results\\tournament\\" + challenger.replace(".dck", ".txt"),"w") as file: | ||
file.write("This was " + challenger + "playing versus:\n\n") | ||
for opponent in OPPONENTS: | ||
print(opponent) | ||
wins = 0 | ||
for i in range(25): | ||
print(i) | ||
cmd = build_cmd(challenger, opponent, str(50)) | ||
p = subprocess.Popen(cmd, cwd="C:\\Users\\Public\\IC\\forge-gui-desktop-1.5.60", stdout=subprocess.PIPE) | ||
for line in p.stdout: | ||
line = line.decode("utf-8").strip() | ||
#if challenger=="RG-sealed-opponent.dck": | ||
# 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[4]) | ||
p.wait() | ||
|
||
with open("results\\tournament\\" + challenger.replace(".dck", ".txt"), "a") as file: | ||
file.write(opponent + ": {}\n \n".format(wins)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import subprocess | ||
|
||
import constants as ct | ||
from decks import genome_to_decklist, write_decklist | ||
|
||
def build_cmd(candidate_name, opponent_name, nr_matches): | ||
return ['java', '-Xmx1024m', '-jar', | ||
'forge-gui-desktop-1.5.61-SNAPSHOT-jar-with-dependencies.jar', 'sim', | ||
'-d', candidate_name, opponent_name, | ||
'-n', nr_matches, '-f', 'sealed'] | ||
|
||
|
||
|
||
total_damage = 0 | ||
wins = 0 | ||
# colors,lands = colorsymbols_in_deck(CARDS, decklist) | ||
|
||
for challenger in ct.OPPONENTS: | ||
total_wins=0 | ||
for i in range(20): | ||
for opponent in ct.OPPONENTS: | ||
cmd = build_cmd(challenger, 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() | ||
total_wins+=wins |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[metadata] | ||
Name=RG aggro 2 | ||
[Main] | ||
8 Mountain | ||
1 Sky Skiff | ||
1 Harnessed Lightning | ||
2 Spireside Infiltrator | ||
1 Chandra's Pyrohelix | ||
1 Highspire Artisan | ||
1 Wayward Giant | ||
1 Blossoming Defense | ||
1 Wild Wanderer | ||
1 Whirlermaker | ||
8 Forest | ||
2 Welding Sparks | ||
1 Fairgrounds Trumpeter | ||
1 Fateful Showdown | ||
1 Elegant Edgecrafters | ||
1 Brazen Scourge | ||
1 Attune with Aether | ||
1 Thriving Rhino | ||
1 Cultivator of Blades | ||
1 Fleetwheel Cruiser | ||
1 Oviya Pashiri, Sage Lifecrafter | ||
2 Voltaic Brawler | ||
1 Renegade Freighter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[metadata] | ||
Name=RW aggro | ||
[Main] | ||
1 Bomat Bazaar Barge | ||
2 Brazen Scourge | ||
1 Chief of the Foundry | ||
1 Combustible Gearhulk | ||
1 Consul's Shieldguard | ||
1 Fleetwheel Cruiser | ||
1 Fragmentize | ||
3 Gearshift Ace | ||
1 Glint-Sleeve Artisan | ||
1 Inventor's Apprentice | ||
9 Mountain | ||
8 Plains | ||
1 Propeller Pioneer | ||
1 Renegade Freighter | ||
1 Revoke Privileges | ||
1 Scrapheap Scrounger | ||
1 Sky Skiff | ||
1 Skyship Stalker | ||
1 Thriving Grubs | ||
1 Veteran Motorist | ||
1 Visionary Augmenter | ||
1 Weldfast Monitor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
8 Mountain | ||
1 Sky Skiff | ||
1 Harnessed Lightning | ||
2 Spireside Infiltrator | ||
1 Chandra's Pyrohelix | ||
1 Highspire Artisan | ||
1 Wayward Giant | ||
1 Blossoming Defense | ||
1 Wild Wanderer | ||
1 Whirlermaker | ||
8 Forest | ||
2 Welding Sparks | ||
1 Fairgrounds Trumpeter | ||
1 Fateful Showdown | ||
1 Elegant Edgecrafters | ||
1 Brazen Scourge | ||
1 Attune with Aether | ||
1 Thriving Rhino | ||
1 Cultivator of Blades | ||
1 Fleetwheel Cruiser | ||
1 Oviya Pashiri, Sage Lifecrafter | ||
2 Voltaic Brawler | ||
1 Renegade Freighter | ||
|
||
1 Inspired Charge | ||
1 Refurbish | ||
1 Propeller Pioneer | ||
1 Skywhaler's Shot | ||
1 Herald of the Fair | ||
1 Acrobatic Maneuver | ||
1 Ninth Bridge Patrol | ||
1 Eddytrail Hawk | ||
3 Aviary Mechanic | ||
1 Tasseled Dromedary | ||
1 Failed Inspection | ||
1 Weldfast Wingsmith | ||
2 Disappearing Act | ||
2 Dramatic Reversal | ||
1 Curio Vendor | ||
1 Minister of Inquiries | ||
1 Demon of Dark Schemes | ||
1 Prakhata Club Security | ||
2 Maulfist Squad | ||
1 Aetherborn Marauder | ||
1 Essence Extraction | ||
1 Mind Rot | ||
1 Make Obsolete | ||
1 Live Fast | ||
2 Lawless Broker | ||
1 Foundry Screecher | ||
2 Fortuitous Find | ||
1 Syndicate Trafficker | ||
1 Subtle Strike | ||
2 Rush of Vitality | ||
1 Die Young | ||
1 Harsh Scrutiny | ||
1 Salivating Gremlins | ||
1 Spark of Creativity | ||
1 Renegade Tactics | ||
2 Cowl Prowler | ||
2 Larger Than Life | ||
1 Take Down | ||
2 Ornamental Courage | ||
1 Aradara Express | ||
1 Dynavolt Tower | ||
1 Woodweaver's Puzzleknot | ||
3 Torch Gauntlet | ||
1 Sky Skiff | ||
1 Metalspinner's Puzzleknot | ||
1 Fireforger's Puzzleknot | ||
1 Sequestered Stash |
Oops, something went wrong.