def execute(args): persistence.connect_existing(os.getcwd()) last_trial_id = persistence.last_trial_id() trial_id = args.trial if args.trial != None else last_trial_id if not 1 <= trial_id <= last_trial_id: utils.print_msg('inexistent trial id', True) sys.exit(1) print_trial(persistence.load_trial(trial_id).fetchone()) if args.modules: print_modules(persistence.load_dependencies()) if args.function_defs: print_function_defs(persistence.load('function_def', trial_id=trial_id)) if args.environment: environment = { attr['name']: attr['value'] for attr in persistence.load('environment_attr', trial_id=trial_id) } utils.print_map( 'this trial has been executed under the following environment conditions', environment) if args.function_activations: print_function_activations( persistence.load('function_activation', caller_id=None, trial_id=trial_id).fetchone()) if args.file_accesses: print_file_accesses(persistence.load('file_access', trial_id=trial_id))
def main(): with open("maps/map1.txt", "r") as f: strs = f.read().split("\n") map_grid = generate_map(*strs) print(generate_map_descriptor(map_grid)) print_map(map_grid)
def main(): with open("../maps/sample_arena5.txt", "r") as f: strs = f.read().split("\n") map_real = generate_map(*strs) bot = SimulatorBot(START_POS, Direction.EAST, lambda m: None) bot.map = map_real exp = Exploration(bot, lambda: None) exp.run_exploration() print_map(exp.explored_map) print_map(map_real)
def main(): with open("maps/map3.txt", "r") as f: strs = f.read().split("\n") map_test = generate_map(*strs) fp = FastestPath(map_test, Direction.EAST, START_POS, GOAL_POS) print_map(FastestPath.add_virtual_obstacles(map_test), fp.steps) if fp.path_found: for i, step in enumerate(fp.steps): print("{}.".format(i + 1), step) for i, movement in enumerate(fp.movements): print("{}.".format(i + 1), movement)
# Project site: https://github.com/bravikov/pylee import utils x0 = 2 y0 = 12 map_width = 15 map_height = 15 my_map = utils.generate_map(map_width, map_height) utils.add_obstacle(my_map, 6, 5, 3, 4) utils.print_map(my_map) start_location = utils.Location() start_location.x = x0 start_location.y = y0 locations = [start_location] weight = 1 while len(locations) > 0: nextLocations = [] for location in locations: utils.set_weight(my_map, location, weight) nextLocations += utils.get_neighbors(my_map, location) utils.print_map(my_map) locations = utils.get_zero_weight_unique_locations(my_map, nextLocations) weight += 1
def step(self, action_dict): actions = [] for i in range(4): if self.agent_names[i] in action_dict: actions.append(action_dict[self.agent_names[i]]) self.stat[i][Metrics(actions[-1]).name] += 1 self.prev_actions[i].append(action_dict[self.agent_names[i]]) if list(self.prev_actions[i]) == [4, 4, 4]: self.stat[i][Metrics.TRIPLE_FREE.name] += 1 elif self.prev_actions[i][1] == 4 and self.prev_actions[i][ 2] == 4: self.stat[i][Metrics.DOUBLE_FREE.name] += 1 else: actions.append(Action.ACTION_FREE.value) if self.is_render: print( f"Action: {[constants.Action(action).name for action in actions]}" ) utils.print_map(self.prev_raw_obs) alive_agents = list(action_dict.keys()) raw_obs = self.env.step(','.join([str(action) for action in actions])) obs = utils.featurize_v2(self.agent_names, alive_agents, raw_obs, self.total_gold, self.prev_actions) rewards, win_loss = self._rewards_v3(alive_agents, raw_obs.players, raw_obs) dones = {} infos = {} self.episode_len += 1 for i, agent_name in enumerate(self.agent_names): if agent_name in alive_agents: infos[self.agent_names[i]] = {} self.stat[i][ Metrics.ENERGY.name] += raw_obs.players[i]["energy"] if raw_obs.players[i][ "status"] != constants.Status.STATUS_PLAYING.value: self.stat[i][Metrics.ENERGY.name] /= (self.episode_len + 1) infos[self.agent_names[i]]["win"] = win_loss[ self.agent_names[i]] infos[self. agent_names[i]]["gold"] = raw_obs.players[i]["score"] infos[self.agent_names[i]]["status"] = constants.Status( raw_obs.players[i]["status"]) infos[self.agent_names[i]]["metrics"] = self.stat[i] infos[self.agent_names[i]]["total_gold"] = self.total_gold dones[self.agent_names[i]] = True self.count_done += 1 dones["__all__"] = self.count_done == 4 self.prev_raw_obs = copy.deepcopy(raw_obs) if self.is_render: print(f"rewards: {rewards}") print(f"Energy ", end='') for i in range(4): print(f"({i}):{raw_obs.players[i]['energy']:5}\t", end='') print() return obs, rewards, dones, infos
# Send the request to the game environment (GAME_SOCKET_DUMMY.py) try: # Initialize environment minerEnv = MinerEnv(HOST, PORT) minerEnv.start() # Connect to the game # minerEnv.send_map_info(request) minerEnv.reset() last_3_actions = deque([4, 4, 4], maxlen=3) obs, raw_obs = minerEnv.get_state_v2( last_3_actions) ##Getting an initial state while not minerEnv.check_terminate(): try: utils.print_map(raw_obs) votes = {i: 0 for i in range(6)} best_model_act = models[0].predict(obs) # votes[best_model_act] += 1 for model in models: votes[model.predict(obs)] += 1 choosen_move = None max_count = -1 for move in votes: if votes[move] > max_count: choosen_move = move max_count = votes[move] if votes[best_model_act] == max_count: choosen_move = best_model_act