def __init__(self, level_name): # Load the game and start off at a pre-game step. try: # This is a test case filename, _ = os.path.splitext(level_name) input_file = read_input_file(filename) map_file = read_map(os.path.join('resources', 'maps' , input_file['map'])) level = map_file for key,val in input_file.items(): level[key] = val self.ghost_enabled = True except: # This is a normal map level = read_map(os.path.join('resources', 'maps', level_name)) self.ghost_enabled = False # map_file = read_map(os.path.join('resources', 'maps' , input_file['map'])) #level = {**map_file, **input_file} #NOTE: order is important here so that the input file values overwrite the map file vals self.game = lab.Game(level) self.window = [level['width'], level['height']] self.step = -1 self.path = level['path_corners'] # Load all appropriate test cases and initialize state regarding the display. self.test_in_name = os.path.join('cases',filename + ".in") #"<no .in file found>" self.test_out_name = os.path.join('cases',filename + ".out") #"<no .out file found>" self.ref_in, self.ref_out = [], [] try: self.load_test_output(level_name) except: pass self.trace = {"events": []}
def record_trace(test, window, events): level = readmap(os.path.join("resources", "maps", test)) game = lab.Game(level) yield copy.deepcopy(game.render(*window)) for keys in events: game.timestep(keys) yield copy.deepcopy(game.render(*window))
def __init__(self, level_name): # Load the game and start off at a pre-game step. level = read_map(os.path.join('resources', 'maps', level_name)) self.game = lab.Game(level) self.window = [level['width'], level['height']] self.step = -1 self.ghost_enabled = True self.path = level['path_corners'] # Load all appropriate test cases and initialize state regarding the display. self.test_in_name = "<no .in file found>" self.test_out_name = "<no .out file found>" self.ref_in, self.ref_out = [], [] self.load_test_output(level_name)
def record_trace(map_file_path, input_data): """ Steps through a series of timesteps and reports what was rendered at each step. """ game_info = read_map(os.path.join("resources", "maps", map_file_path)) for input_info in input_data: game_info[input_info] = input_data[input_info] game = lab.Game(game_info) yield copy.deepcopy(game.render()) # Process each timestep one at a time. for mouse in input_data["events"]: try: game.timestep(mouse) except Exception as e: if isinstance(e,lab.NotEnoughMoneyError): yield {"error": "NotEnoughMoneyError"} break else: raise e yield copy.deepcopy(game.render())
def __init__(self, levelname): level = readmap(os.path.join('resources', 'maps', levelname)) self.game = lab.Game(level) self.load_test_output(levelname) self.step = -1 self.ghost_enabled = True