def wrap_actions(self, actions): """ 根据action和action_args的矩阵, 输出可以pysc2执行的Function call实例 :param actions: action和action_args的矩阵 :return: pysc2对应的action ID和pysc2可以执行的args """ # 取出action和action的参数 acts, args = actions[0], actions[1:] wrapped_actions = [] for i, act in enumerate(acts): #当前顺序i,action的ID act act_args = [] for arg_type in FUNCTIONS[act].args: #根据action的ID找到参数名称 act_arg = [DEFAULT_ARGS[arg_type.name]] #用config定义的默认参数值来初始化 if arg_type.name in self.config.act_args: act_arg = [args[self.config.arg_idx[arg_type.name]][i]] if is_spatial( arg_type.name): # spatial args, convert to coords act_arg = [ act_arg[0] % self.config.sz, act_arg[0] // self.config.sz ] # (y,x), fix for PySC2 act_args.append(act_arg) wrapped_actions.append(FunctionCall( act, act_args)) #pysc2 可以执行的是这个,原本都是数据 return wrapped_actions
def wrap_actions(self, actions): acts, args = actions[0], actions[1:] wrapped_actions = [] for i, act in enumerate(acts): # 对于batch中的每个act函数 act_args = [] for arg_type in FUNCTIONS[act].args: # 对于该动作函数的每个参数 act_arg = [DEFAULT_ARGS[arg_type.name]] # 初始化 if arg_type.name in self.config.act_args: act_arg = [args[self.config.arg_idx[arg_type.name]][i]] # 等于bacth中对应参数的第i项(第i个样本) if is_spatial(arg_type.name): # spatial args, convert to coords act_arg = [act_arg[0] % self.config.sz, act_arg[0] // self.config.sz] # (y,x), fix for PySC2 act_args.append(act_arg) wrapped_actions.append(FunctionCall(act, act_args)) return wrapped_actions
def wrap_actions(self, actions): pol_mask = [torch.zeros((self.envs.num_envs)).float().to(self.device) \ for _ in range(1 + len(ARG_TYPES))] pol_mask[0].fill_(1.0) acts, args = actions[0], actions[1:] wrapped_actions = [] for i, act in enumerate(acts): fn = TERRAN_FUNCTIONS[act] act_args = [] for arg_type in fn.args: act_arg = [args[self.config.arg_idx[arg_type.name]][i]] pol_mask[self.config.arg_idx[arg_type.name] + 1][i] = 1. if arg_type.name == 'queued': act_arg = [False] if is_spatial( arg_type.name): # spatial args, convert to coords act_arg = [ act_arg[0] % self.config.sz, act_arg[0] // self.config.sz ] act_args.append(act_arg) wrapped_actions.append(FunctionCall(fn.id, act_args)) return wrapped_actions, pol_mask