def main(): image_dir = default_image_dir files = [image_dir+"/"+f for f in os.listdir(image_dir) if os.path.isfile(os.path.join(image_dir, f)) and f.endswith(".png")] git.clone_repo(REFERENCE_IMAGES_GIT, TEST_DIR) for method, arguments in test_arguments.iteritems(): for args in arguments: # Prepend a "-" for every key in the arguments dict and then flatten the list command_arguments = [i for tuple in args.items() for i in ("-"+str(tuple[0]),str(tuple[1]))] for f in files: tester.run_test(test_binary, reference_binary, method, command_arguments, f, run_reference_program=False, test_dir=TEST_DIR)
def main(): image_dir = default_image_dir files = [ image_dir + "/" + f for f in os.listdir(image_dir) if os.path.isfile(os.path.join(image_dir, f)) and f.endswith(".png") ] git.clone_repo(REFERENCE_IMAGES_GIT, TEST_DIR) for method, arguments in test_arguments.iteritems(): for args in arguments: # Prepend a "-" for every key in the arguments dict and then flatten the list command_arguments = [ i for tuple in args.items() for i in ("-" + str(tuple[0]), str(tuple[1])) ] for f in files: tester.run_test(test_binary, reference_binary, method, command_arguments, f, run_reference_program=False, test_dir=TEST_DIR)
def run_rest_test(): test_value = { 'Name': [int(request.args.get('name'))], 'Environment': [int(request.args.get('environment'))], 'Type': [int(request.args.get('type'))], 'Code': [int(request.args.get('code'))] } name = request.args.get('name') print("Received API: " + name) actual_status = [request.args.get('status')] prediction, probability, expectation = run_test(test_value, actual_status, get_training_data()) return jsonify({ "prediction": prediction, "probability": probability, "expectation": expectation })
def run_average_for_size(code,runs,size): sys.stdout.write("[") runtimes = [] for r in xrange(runs): shuffled = generate_shuffled_int_array(size) sortd = sorted(shuffled) # BUG if you remove the following line this doesn't work sys.stdout.write(".") sys.stdout.flush() #print "%s # %s" % (id(shuffled), id(sortd)) (eq, time) = run_test(code, shuffled, sortd) if (eq != True): return False; runtimes.append(time) sys.stdout.write("]") sys.stdout.flush() return reduce(lambda x, y: x + y, runtimes) / len(runtimes)
def train_loop(env: gym.Env, agents: Tuple[Agent, Agent]): """ Training loop for the agents :param env: The gym.Env :param agents: A tuple with the two agents: (defender, attacker) """ writer = SummaryWriter(log_dir=f'runs/OuterLoopTrain') logger.info(f'Starting training...') for epoch in range(SETTINGS.EPOCHS): logger.info(f'Epoch {epoch + 1}/{SETTINGS.EPOCHS}:') if SETTINGS.SIMULATE_MATCHES: simulated = simulate_matches(env, agents, SETTINGS.N_MATCHES, epoch, SETTINGS.USE_CUSTOM_GAMES) else: sim_name = f'matches_{epoch}_{SETTINGS.N_MATCHES}.pkl' simulated = load_matches(sim_name, matches_dir) if SETTINGS.GENERATE_DATASET: build_dataset(simulated, epoch + 1) for player, agent in zip(['DEF', 'ATK'], agents): logger.info(f'Training {player} agent...') for limit in LAST_MOVES: logger.info(f'Training with at most last {limit} moves...') dataset = load_dataset(epoch + 1, limit, SETTINGS.N_MATCHES, player, datasets_dir) agent.train(dataset, limit) logger.info(f'Agent {player} trained.') winners = run_test(env, agents, epoch + 1) writer.add_scalar(f"AgentWins/DEF", sum(1 for i in winners if i == 'DEF'), epoch) writer.add_scalar(f"AgentWins/ATK", sum(1 for i in winners if i == 'ATK'), epoch) writer.add_scalar(f"AgentWins/DRAWS", sum(1 for i in winners if i is None), epoch) writer.flush() writer.close()
raise tester.EndTest (True) def test12 (n): def t (test, name): h = test.inv.health (arkham.health_stamina) h.reduce (5) hv = h.cur () yield fun.matchclass (arkham.GameplayAction_Stay) # wait for next round for y in cast_spell (True, *list (5 if i < n else 1 for i in range (4))): yield y yield lambda action: " %d " % n in action.name () assert h.cur () == hv + n yield fun.matchclass (arkham.GameplayAction_Stay) raise tester.EndTest (True) return t if __name__ == "__main__": tester.run_test (test_ah.Game (Test (test_item ("Old Journal", test1)))) tester.run_test (test_ah.Game (Test (test_item ("Ancient Tome", test2)))) tester.run_test (test_ah.Game (Test (test_item ("Alien Statue", test3, mod_unique.UniqueDeck)))) tester.run_test (test_ah.Game (Test (test_item ("Ancient Tablet", test4, mod_unique.UniqueDeck)))) tester.run_test (test_ah.Game (Test (test_item ("Cabala of Saboth", test5, mod_unique.UniqueDeck)))) tester.run_test (test_ah.Game (Test (test_item ("Cultes des Goules", test6, mod_unique.UniqueDeck)))) tester.run_test (test_ah.Game (Test (test_item ("Healing Stone", test7, mod_unique.UniqueDeck)))) tester.run_test (test_ah.Game (Test (test_item ("Nameless Cults", test8, mod_unique.UniqueDeck)))) tester.run_test (test_ah.Game (Test (test_item ("Necronomicon", test9, mod_unique.UniqueDeck)))) tester.run_test (test_ah.Game (Test (test_item ("Ruby of R'lyeh", test10, mod_unique.UniqueDeck)))) tester.run_test (test_ah.Game (Test (test_item ("The King in Yellow", test11, mod_unique.UniqueDeck)))) tester.run_test (test_ah.Game (Test (test_item ("Heal", test12 (1), mod_spell.SpellDeck)))) tester.run_test (test_ah.Game (Test (test_item ("Heal", test12 (2), mod_spell.SpellDeck)))) tester.run_test (test_ah.Game (Test (test_item ("Heal", test12 (3), mod_spell.SpellDeck))))
import tester, sys res = tester.run_test(input_file="template.ecc", uut_name="template_test", inputs=[("a", 24), ("b", 24)], outputs=[("q", 16)], is_clocked=False, input_vectors=[[0x010203, 0x040506], [0x01FF00, 0x010100], [0x7F7F7F, 0x020304]], output_results=[[32], [0], [1143]]) sys.exit(res)
import tester, sys res = tester.run_test(input_file="rgb_greyscale.ecc", uut_name="rgb_greyscale", inputs=[("input", 24)], outputs=[("output", 24)], is_clocked=False, input_vectors=[[0xFF0000], [0x040404], [0x800080], [0x808000], [0xFFFFFF]], output_results=[[0x3F3F3F], [0x040404], [0x404040], [0x606060], [0xFDFDFD]]) sys.exit(res)
def __init__(self): tester.TestGame.__init__(self, Test1()) @self.pass_evade_check_hook.match(tester.match_combat(Game1), tester.match_investigator("1"), fun.any) def do(combat, investigator, monster): raise tester.EndTest(True) class Test2(Test1): def actions(self): yield fun.matchclass(arkham.GameplayAction_Stay) yield fun.matchclass(arkham.GameplayAction_DealWithMonster) yield fun.matchclass(arkham.GameplayAction_Evade) yield fun.matchclass(arkham.GameplayAction_NormalCheckHook) for roll in (4,): yield roll yield fun.matchclass(arkham.GameplayAction_FailRoll) class Game2(tester.TestGame): def __init__(self): tester.TestGame.__init__(self, Test2()) @self.fail_evade_check_hook.match(tester.match_combat(Game2), tester.match_investigator("1"), fun.any) def do(combat, investigator, monster): raise tester.EndTest(True) tester.run_test(Game1()) tester.run_test(Game2())
item = game.deck (self.__class__.item_deck)\ .draw (lambda arg: arg.name () == self.__class__.item_name) inv.take_item(game, item) assert inv.wield_item(game, item) class MyMonster(arkham.MonsterProto): def __init__(self): arkham.MonsterProto.__init__(self, "MyMonster") def horror_check(self): return arkham.pass_check for i in range(5): game.add_monster(arkham.Monster(MyMonster()), inv.location()) @classmethod def actions(cls, test): yield fun.matchclass(arkham.GameplayAction_Stay) yield fun.take_first() yield fun.matchclass(arkham.GameplayAction_Fight) yield fun.matchclass(arkham.GameplayAction_Multiple) yield fun.matchclass(arkham.GameplayAction_IncurDamage) assert len(test.inv.trophies()) == 5 raise tester.EndTest(True) if __name__ == "__main__": tester.run_test(test_ah.Game(Test(ModuleProto1))) tester.run_test(test_ah.Game(Test(ModuleProto2))) tester.run_test(test_ah.Game(Test(ModuleProto3)))
def setup_investigator (self, game, inv): item = game.deck (self.__class__.item_deck)\ .draw (lambda arg: arg.name () == self.__class__.item_name) inv.take_item (game, item) assert inv.wield_item (game, item) class MyMonster (arkham.MonsterProto): def __init__ (self): arkham.MonsterProto.__init__ (self, "MyMonster") def horror_check (self): return arkham.pass_check for i in range (5): game.add_monster (arkham.Monster (MyMonster ()), inv.location ()) @classmethod def actions (cls, test): yield fun.matchclass (arkham.GameplayAction_Stay) yield fun.take_first () yield fun.matchclass (arkham.GameplayAction_Fight) yield fun.matchclass (arkham.GameplayAction_Multiple) yield fun.matchclass (arkham.GameplayAction_IncurDamage) assert len (test.inv.trophies ()) == 5 raise tester.EndTest (True) if __name__ == "__main__": tester.run_test (test_ah.Game (Test (ModuleProto1))) tester.run_test (test_ah.Game (Test (ModuleProto2))) tester.run_test (test_ah.Game (Test (ModuleProto3)))
tester.TestGame.__init__ (self, Test1 ()) @self.pass_evade_check_hook.match \ (tester.match_combat (Game1), tester.match_investigator ("1"), fun.any) def do (combat, investigator, monster): raise tester.EndTest (True) class Test2 (Test1): def actions (self): yield fun.matchclass (arkham.GameplayAction_Stay) yield fun.matchclass (arkham.GameplayAction_DealWithMonster) yield fun.matchclass (arkham.GameplayAction_Evade) yield fun.matchclass (arkham.GameplayAction_NormalCheckHook) for roll in 4,: yield roll yield fun.matchclass (arkham.GameplayAction_FailRoll) class Game2 (tester.TestGame): def __init__ (self): tester.TestGame.__init__ (self, Test2 ()) @self.fail_evade_check_hook.match \ (tester.match_combat (Game2), tester.match_investigator ("1"), fun.any) def do (combat, investigator, monster): raise tester.EndTest (True) tester.run_test (Game1 ()) tester.run_test (Game2 ())
h = test.inv.health(arkham.health_stamina) h.reduce(5) hv = h.cur() yield fun.matchclass(arkham.GameplayAction_Stay) # wait for next round for y in cast_spell(True, *list(5 if i < n else 1 for i in range(4))): yield y yield lambda action: " %d " % n in action.name() assert h.cur() == hv + n yield fun.matchclass(arkham.GameplayAction_Stay) raise tester.EndTest(True) return t if __name__ == "__main__": tester.run_test(test_ah.Game(Test(test_item("Old Journal", test1)))) tester.run_test(test_ah.Game(Test(test_item("Ancient Tome", test2)))) tester.run_test( test_ah.Game( Test(test_item("Alien Statue", test3, mod_unique.UniqueDeck)))) tester.run_test( test_ah.Game( Test(test_item("Ancient Tablet", test4, mod_unique.UniqueDeck)))) tester.run_test( test_ah.Game( Test(test_item("Cabala of Saboth", test5, mod_unique.UniqueDeck)))) tester.run_test( test_ah.Game( Test(test_item("Cultes des Goules", test6, mod_unique.UniqueDeck)))) tester.run_test(
import mod_common import mod_unique from test_ah_items import * def test1(test, name): yield fun.and_(action_bound_item_named(name), fun.matchclass(arkham.GameplayAction_Multiple)) yield fun.matchclass(arkham.GameplayAction_NormalCheckHook) for die in 5, 5: yield die yield fun.matchclass(arkham.GameplayAction_IncurDamage) yield fun.matchclass(arkham.GameplayAction_Stay) yield fun.and_(action_bound_item_named(name), fun.matchclass(arkham.GameplayAction_Multiple)) yield fun.matchclass(arkham.GameplayAction_NormalCheckHook) for die in 5, 5: yield die yield fun.matchclass(arkham.GameplayAction_IncurDamage) yield fun.matchclass(arkham.GameplayAction_Stay) # check the item got dropped after two uses for item in test.inv.wields_items(): assert item.name() != name raise tester.EndTest(True) if __name__ == "__main__": tester.run_test( test_ah.Game( Test(test_item("Book of Dzyan", test1, mod_unique.UniqueDeck))))
import tester, sys res = tester.run_test(input_file="cond.ecc", uut_name="conditional", inputs=[("x", 8)], outputs=[("y", 8)], is_clocked=False, input_vectors=[[5], [127], [255]], output_results=[[5], [127], [1]]) sys.exit(res)
yield fun.matchclass (arkham.GameplayAction_Fight) yield fun.matchclass (arkham.GameplayAction_NormalCheckHook) for roll in 5,: yield roll # pass horror check for i in 1,2: yield fun.matchclass (arkham.GameplayAction_Fight) yield fun.matchclass (arkham.GameplayAction_NormalCheckHook) for roll in 1,1,1: yield roll yield fun.matchclass (arkham.GameplayAction_FailRoll) yield fun.matchclass (arkham.GameplayAction_EndCauseHarmLoop) yield fun.matchclass (arkham.GameplayAction_IncurDamage) yield fun.matchclass (mod_ah.GameplayAction_Incapacitated) assert self.inv.location ().attributes ().flag ("hospital") raise tester.EndTest (True) class Test2 (Test1): def actions (self): self.inv.health (arkham.health_sanity).reduce (3) yield fun.matchclass (arkham.GameplayAction_Stay) yield fun.matchclass (arkham.GameplayAction_DealWithMonster) yield fun.matchclass (arkham.GameplayAction_Fight) yield fun.matchclass (arkham.GameplayAction_NormalCheckHook) for roll in 1,: yield roll # fail horror check yield fun.matchclass (arkham.GameplayAction_FailRoll) yield fun.matchclass (arkham.GameplayAction_IncurDamage) yield fun.matchclass (mod_ah.GameplayAction_Incapacitated) assert self.inv.location ().attributes ().flag ("asylum") raise tester.EndTest (True) tester.run_test (test_ah.Game (Test1 ())) tester.run_test (test_ah.Game (Test2 ()))
yield 5 # pass horror check yield fun.matchclass(arkham.GameplayAction_Fight) yield fun.matchclass(arkham.GameplayAction_NormalCheckHook) for die in roll: yield die yield fun.matchclass(arkham.GameplayAction_Stay) raise tester.EndTest(True) class Game1(tester.TestGame): def __init__(self): tester.TestGame.__init__(self, Test1()) return Game1() tester.run_test(gen_test(arkham.family_physical, {}, 5, 5, 5)) tester.run_test( gen_test(arkham.family_physical, {arkham.monster_physical: arkham.reslev_resistance}, 5, 5)) tester.run_test( gen_test(arkham.family_physical, {arkham.monster_physical: arkham.reslev_immunity}, 5)) tester.run_test(gen_test(arkham.family_magical, {}, 5, 5, 5)) tester.run_test( gen_test(arkham.family_magical, {arkham.monster_physical: arkham.reslev_resistance}, 5, 5, 5)) tester.run_test( gen_test(arkham.family_magical, {arkham.monster_physical: arkham.reslev_immunity}, 5, 5, 5))
import mod_ah import test_ah import fun import arkham import mod_common import mod_unique from test_ah_items import * def test1(test, name): yield fun.and_(action_bound_item_named(name), fun.matchclass(arkham.GameplayAction_Multiple)) yield fun.matchclass(arkham.GameplayAction_NormalCheckHook) for die in 5, 5: yield die yield fun.matchclass(arkham.GameplayAction_IncurDamage) yield fun.matchclass(arkham.GameplayAction_Stay) yield fun.and_(action_bound_item_named(name), fun.matchclass(arkham.GameplayAction_Multiple)) yield fun.matchclass(arkham.GameplayAction_NormalCheckHook) for die in 5, 5: yield die yield fun.matchclass(arkham.GameplayAction_IncurDamage) yield fun.matchclass(arkham.GameplayAction_Stay) # check the item got dropped after two uses for item in test.inv.wields_items(): assert item.name() != name raise tester.EndTest(True) if __name__ == "__main__": tester.run_test(test_ah.Game(Test(test_item("Book of Dzyan", test1, mod_unique.UniqueDeck))))
class Test(tester.Controller): def __init__(self, proto, aspect): tester.Controller.__init__(self) self.aspect = aspect self.module = proto() def setup_players(self, game): self.inv, = self.use_investigators(game, ["\"Ashcan\" Pete"]) def add_modules(self, idx): idx.add_module(self.module) def actions(self): x = self.module.heal_action_times() y = self.module.expected_increment(x) h = self.inv.health(self.aspect).cur() for i in range(x): for action in self.module.actions(): yield action if y != _damage: yield fun.matchclass(arkham.GameplayAction_IncurDamage) assert self.inv.health(self.aspect).cur() == h - _damage + y raise tester.EndTest(True) tester.run_test(test_ah.Game(Test(ModuleProto1, arkham.health_stamina))) tester.run_test(test_ah.Game(Test(ModuleProto2, arkham.health_sanity))) tester.run_test(test_ah.Game(Test(ModuleProto3, arkham.health_stamina))) tester.run_test(test_ah.Game(Test(ModuleProto4, arkham.health_stamina))) tester.run_test(test_ah.Game(Test(ModuleProto5, arkham.health_stamina)))
class Test(tester.Controller): def __init__(self, proto, aspect): tester.Controller.__init__(self) self.aspect = aspect self.module = proto() def setup_players(self, game): self.inv, = self.use_investigators(game, ['"Ashcan" Pete']) def add_modules(self, idx): idx.add_module(self.module) def actions(self): x = self.module.heal_action_times() y = self.module.expected_increment(x) h = self.inv.health(self.aspect).cur() for i in range(x): for action in self.module.actions(): yield action if y != _damage: yield fun.matchclass(arkham.GameplayAction_IncurDamage) assert self.inv.health(self.aspect).cur() == h - _damage + y raise tester.EndTest(True) tester.run_test(test_ah.Game(Test(ModuleProto1, arkham.health_stamina))) tester.run_test(test_ah.Game(Test(ModuleProto2, arkham.health_sanity))) tester.run_test(test_ah.Game(Test(ModuleProto3, arkham.health_stamina))) tester.run_test(test_ah.Game(Test(ModuleProto4, arkham.health_stamina))) tester.run_test(test_ah.Game(Test(ModuleProto5, arkham.health_stamina)))
import tester, sys res = tester.run_test(input_file="adder.ecc", uut_name="adder", inputs=[("a", 8), ("b", 8)], outputs=[("q", 8)], is_clocked=False, input_vectors=[[1, 1], [12, 15], [255, 1]], output_results=[[2], [27], [0]]) sys.exit(res)
yield fun.matchclass (arkham.GameplayAction_Fight) yield fun.matchclass (arkham.GameplayAction_NormalCheckHook) yield 5 # pass horror check yield fun.matchclass (arkham.GameplayAction_Fight) yield fun.matchclass (arkham.GameplayAction_NormalCheckHook) for die in roll: yield die yield fun.matchclass (arkham.GameplayAction_Stay) raise tester.EndTest (True) class Game1 (tester.TestGame): def __init__ (self): tester.TestGame.__init__ (self, Test1 ()) return Game1 () tester.run_test (gen_test (arkham.family_physical, {}, 5, 5, 5)) tester.run_test (gen_test (arkham.family_physical, {arkham.monster_physical: arkham.reslev_resistance}, 5, 5)) tester.run_test (gen_test (arkham.family_physical, {arkham.monster_physical: arkham.reslev_immunity}, 5)) tester.run_test (gen_test (arkham.family_magical, {}, 5, 5, 5)) tester.run_test (gen_test (arkham.family_magical, {arkham.monster_physical: arkham.reslev_resistance}, 5, 5, 5)) tester.run_test (gen_test (arkham.family_magical, {arkham.monster_physical: arkham.reslev_immunity}, 5, 5, 5)) tester.run_test (gen_test (arkham.family_physical, {}, 5, 5, 5)) tester.run_test (gen_test (arkham.family_physical, {arkham.monster_magical: arkham.reslev_resistance}, 5, 5, 5)) tester.run_test (gen_test (arkham.family_physical, {arkham.monster_magical: arkham.reslev_immunity}, 5, 5, 5)) tester.run_test (gen_test (arkham.family_magical, {}, 5, 5, 5)) tester.run_test (gen_test (arkham.family_magical, {arkham.monster_magical: arkham.reslev_resistance}, 5, 5)) tester.run_test (gen_test (arkham.family_magical, {arkham.monster_magical: arkham.reslev_immunity}, 5))
yield fun.matchclass (arkham.GameplayAction_NormalCheckHook) for y in [5] * (5 + (3 if undead else 0)): yield y yield fun.matchclass (arkham.GameplayAction_Stay) raise tester.EndTest (True) return t def test17 (test): for y in fight_and_horror_check (5, 5): yield y yield fun.matchclass (arkham.GameplayAction_Fight) yield fun.matchclass (arkham.GameplayAction_NormalCheckHook) for y in 1,1,1,1,1,1,1,1,6: yield y yield fun.matchclass (arkham.GameplayAction_Stay) raise tester.EndTest (True) if __name__ == "__main__": tester.run_test (test_ah.Game (Test (test_weapon ("Dynamite", test1)))) tester.run_test (test_ah.Game (Test (test_weapon ("Powder of Ibn-Ghazi", test2, mod_unique.UniqueDeck)))) tester.run_test (test_ah.Game (Test (test_weapon ("Silver Key", test3, mod_unique.UniqueDeck)))) tester.run_test (test_ah.Game (Test (test_weapon ("Warding Statue", test4, mod_unique.UniqueDeck)))) tester.run_test (test_ah.Game (Test (test_weapon ("Dread Curse of Azathoth", test5 (-2, +9), mod_spell.SpellDeck)))) tester.run_test (test_ah.Game (Test (test_weapon ("Bind Monster", test6 (1), mod_spell.SpellDeck, toughness=1)))) tester.run_test (test_ah.Game (Test (test_weapon ("Bind Monster", test6 (2), mod_spell.SpellDeck, toughness=2)))) tester.run_test (test_ah.Game (Test (test_weapon ("Bind Monster", test6 (3), mod_spell.SpellDeck, toughness=3)))) tester.run_test (test_ah.Game (Test (test_weapons (test7, [("Enchant Weapon", mod_spell.SpellDeck), (".18 Derringer", mod_common.CommonDeck)], {arkham.monster_physical: arkham.reslev_immunity})))) tester.run_test (test_ah.Game (Test (test_weapon ("Mists of Releh", test8 (-1), mod_spell.SpellDeck, awareness=-1)))) tester.run_test (test_ah.Game (Test (test_weapon ("Mists of Releh", test8 (+1), mod_spell.SpellDeck, awareness=+1)))) # Test nighmarish/overwhelming. tester.run_test (test_ah.Game (Test (test_weapon (".18 Derringer", test9 (1), mod_common.CommonDeck,