當前位置: 首頁>>代碼示例>>Python>>正文


Python actions.FunctionCall方法代碼示例

本文整理匯總了Python中pysc2.lib.actions.FunctionCall方法的典型用法代碼示例。如果您正苦於以下問題:Python actions.FunctionCall方法的具體用法?Python actions.FunctionCall怎麽用?Python actions.FunctionCall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pysc2.lib.actions的用法示例。


在下文中一共展示了actions.FunctionCall方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_defeat_zerglings

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def test_defeat_zerglings(self):
    FLAGS(sys.argv)

    with sc2_env.SC2Env(
        "DefeatZerglingsAndBanelings",
        step_mul=self.step_mul,
        visualize=True,
        game_steps_per_episode=self.steps * self.step_mul) as env:
      obs = env.step(actions=[sc2_actions.FunctionCall(_NO_OP, [])])
      player_relative = obs[0].observation["screen"][_PLAYER_RELATIVE]

      # Break Point!!
      print(player_relative)

      agent = random_agent.RandomAgent()
      run_loop.run_loop([agent], env, self.steps)

    self.assertEqual(agent.steps, self.steps) 
開發者ID:llSourcell,項目名稱:A-Guide-to-DeepMinds-StarCraft-AI-Environment,代碼行數:20,代碼來源:scripted_test.py

示例2: actions_to_pysc2

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def actions_to_pysc2(actions, size):
  """Convert agent action representation to FunctionCall representation."""
  height, width = size
  fn_id, arg_ids = actions
  actions_list = []
  for n in range(fn_id.shape[0]):
    a_0 = fn_id[n]
    a_l = []
    for arg_type in FUNCTIONS._func_list[a_0].args:
      arg_id = arg_ids[arg_type][n]
      if is_spatial_action[arg_type]:
        arg = [arg_id % width, arg_id // height]
      else:
        arg = [arg_id]
      a_l.append(arg)
    action = FunctionCall(a_0, a_l)
    actions_list.append(action)
  return actions_list 
開發者ID:simonmeister,項目名稱:pysc2-rl-agents,代碼行數:20,代碼來源:runner.py

示例3: _safe_step

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def _safe_step(self, action):
        self._num_step += 1
        if action[0] not in self.available_actions:
            logger.warning("Attempted unavailable action: %s", action)
            action = [_NO_OP]
        try:
            obs = self._env.step([actions.FunctionCall(action[0], action[1:])])[0]
        except KeyboardInterrupt:
            logger.info("Interrupted. Quitting...")
            return None, 0, True, {}
        except Exception:
            logger.exception("An unexpected error occurred while applying action to environment.")
            return None, 0, True, {}
        self.available_actions = obs.observation['available_actions']
        reward = obs.reward
        self._episode_reward += reward
        self._total_reward += reward
        return obs, reward, obs.step_type == StepType.LAST, {} 
開發者ID:islamelnabarawy,項目名稱:sc2gym,代碼行數:20,代碼來源:sc2_game.py

示例4: step

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def step(self, obs):
        super(SparseAgent, self).step(obs)
        
        unit_type = obs.observation['screen'][_UNIT_TYPE]

        if obs.first():
            player_y, player_x = (obs.observation['minimap'][_PLAYER_RELATIVE] == _PLAYER_SELF).nonzero()
            self.base_top_left = 1 if player_y.any() and player_y.mean() <= 31 else 0
        
            self.cc_y, self.cc_x = (unit_type == _TERRAN_COMMANDCENTER).nonzero()

        cc_y, cc_x = (unit_type == _TERRAN_COMMANDCENTER).nonzero()
        cc_count = 1 if cc_y.any() else 0
        
        depot_y, depot_x = (unit_type == _TERRAN_SUPPLY_DEPOT).nonzero()
        supply_depot_count = int(round(len(depot_y) / 69))

        barracks_y, barracks_x = (unit_type == _TERRAN_BARRACKS).nonzero()
        barracks_count = int(round(len(barracks_y) / 137))
            
        return actions.FunctionCall(_NO_OP, []) 
開發者ID:skjb,項目名稱:pysc2-tutorial,代碼行數:23,代碼來源:sparse_agent_step3.py

示例5: actions_to_choose

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def actions_to_choose(action):
    hall = [_HAL_ADEPT, _HAL_ARCHON]
    action = actions.FunctionCall(random.choice(hall), [_NOT_QUEUED])
    return action


## Agent architecture using keras rl


### Model
# Agents representation of the environment. ( How the agent thinks the environment works)

#### 1. 256 , 127, 256 are the channels- depth of the first layer, one can be colour, edges)
#### 2. Kernel size is the size of the matrix it will be use to make the convolution ( impair size is better)
#### 3. strides are the translation that kernel size will be making
#### 4. The Neural net architecture is CONV2D-RELU-MAXPOOL-FLATTEN+FULLYCONNECTED 
開發者ID:SoyGema,項目名稱:Startcraft_pysc2_minigames,代碼行數:18,代碼來源:DQN_Agent.py

示例6: test_defeat_zerglings

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def test_defeat_zerglings(self):
    agent_format = sc2_env.AgentInterfaceFormat(
      feature_dimensions=sc2_env.Dimensions(
        screen=(32,32),
        minimap=(32,32),
      )
    )
    with sc2_env.SC2Env(
        map_name="DefeatZerglingsAndBanelings",
        step_mul=self.step_mul,
        visualize=True,
        agent_interface_format=[agent_format],
        game_steps_per_episode=self.steps * self.step_mul) as env:
      obs = env.step(actions=[sc2_actions.FunctionCall(_NO_OP, [])])
      player_relative = obs[0].observation["feature_screen"][_PLAYER_RELATIVE]

      # Break Point!!
      print(player_relative)

      agent = random_agent.RandomAgent()
      run_loop.run_loop([agent], env, self.steps)

    self.assertEqual(agent.steps, self.steps) 
開發者ID:chris-chris,項目名稱:pysc2-examples,代碼行數:25,代碼來源:scripted_test.py

示例7: step

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def step(self, obs):
    super(CollectMineralShards2, self).step(obs)
    if _MOVE_SCREEN in obs.observation["available_actions"]:
      player_relative = obs.observation["screen"][_PLAYER_RELATIVE]
      neutral_y, neutral_x = (
        player_relative == _PLAYER_NEUTRAL).nonzero()
      player_y, player_x = (
        player_relative == _PLAYER_FRIENDLY).nonzero()
      if not neutral_y.any() or not player_y.any():
        return actions.FunctionCall(_NO_OP, [])
      player = [int(player_x.mean()), int(player_y.mean())]
      closest, min_dist = None, None
      for p in zip(neutral_x, neutral_y):
        dist = numpy.linalg.norm(numpy.array(player) - numpy.array(p))
        if not min_dist or dist < min_dist:
          closest, min_dist = p, dist
      return actions.FunctionCall(_MOVE_SCREEN, [_NOT_QUEUED, closest])
    else:
      return actions.FunctionCall(_SELECT_ARMY, [_SELECT_ALL]) 
開發者ID:chris-chris,項目名稱:pysc2-examples,代碼行數:21,代碼來源:scripted_agent.py

示例8: _take_action

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def _take_action(self, action):
        if self.use_full_action_space:
            action_identifier = action[0]
            action_arguments = action[1:]
            action = actions.FunctionCall(action_identifier, action_arguments)
        else:
            coord = np.array(action[0:2])
            noop = False
            coord = coord.round()
            coord = np.clip(coord, 0, SCREEN_SIZE - 1)
            self.last_action_idx = coord

            if noop:
                action = actions.FunctionCall(_NOOP, [])
            else:
                action = actions.FunctionCall(_MOVE_SCREEN, [_NOT_QUEUED, coord])

        self.last_result = self.env.step(actions=[action]) 
開發者ID:NervanaSystems,項目名稱:coach,代碼行數:20,代碼來源:starcraft2_environment.py

示例9: gen_random_function_call

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def gen_random_function_call(self, action_spec, func_id):
    args = [[numpy.random.randint(0, size) for size in arg.sizes]  # pylint: disable=g-complex-comprehension
            for arg in action_spec.functions[func_id].args]
    return actions.FunctionCall(func_id, args) 
開發者ID:deepmind,項目名稱:pysc2,代碼行數:6,代碼來源:features_test.py

示例10: testCanDeepcopyNumpyFunctionCall

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def testCanDeepcopyNumpyFunctionCall(self):
    arguments = [numpy.float32] * len(actions.Arguments._fields)
    dtypes = actions.FunctionCall(
        function=numpy.float32,
        arguments=actions.Arguments(*arguments))
    self.assertEqual(dtypes, copy.deepcopy(dtypes)) 
開發者ID:deepmind,項目名稱:pysc2,代碼行數:8,代碼來源:features_test.py

示例11: step

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def step(self, obs):
    self.steps += 1
    self.reward += obs.reward
    return actions.FunctionCall(actions.FUNCTIONS.no_op.id, []) 
開發者ID:deepmind,項目名稱:pysc2,代碼行數:6,代碼來源:base_agent.py

示例12: step

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def step(self, obs):
    super(RandomAgent, self).step(obs)
    function_id = numpy.random.choice(obs.observation.available_actions)
    args = [[numpy.random.randint(0, size) for size in arg.sizes]
            for arg in self.action_spec.functions[function_id].args]
    return actions.FunctionCall(function_id, args) 
開發者ID:deepmind,項目名稱:pysc2,代碼行數:8,代碼來源:random_agent.py

示例13: step

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def step(self, obs):
        super(SimpleAgent, self).step(obs)
        return actions.FunctionCall(actions.FUNCTIONS.no_op.id, []) 
開發者ID:skjb,項目名稱:pysc2-tutorial,代碼行數:5,代碼來源:simple_agent_step1.py

示例14: step

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def step(self, obs):
        super(SimpleAgent, self).step(obs)
        
        time.sleep(0.5)
        
        if self.base_top_left is None:
            player_y, player_x = (obs.observation["minimap"][_PLAYER_RELATIVE] == _PLAYER_SELF).nonzero()
            self.base_top_left = player_y.mean() <= 31
            
        if not self.supply_depot_built:
            if not self.scv_selected:
                unit_type = obs.observation["screen"][_UNIT_TYPE]
                unit_y, unit_x = (unit_type == _TERRAN_SCV).nonzero()
                
                target = [unit_x[0], unit_y[0]]
                
                self.scv_selected = True
                
                return actions.FunctionCall(_SELECT_POINT, [_NOT_QUEUED, target])
            elif _BUILD_SUPPLYDEPOT in obs.observation["available_actions"]:
                unit_type = obs.observation["screen"][_UNIT_TYPE]
                unit_y, unit_x = (unit_type == _TERRAN_COMMANDCENTER).nonzero()
                
                target = self.transformLocation(int(unit_x.mean()), 0, int(unit_y.mean()), 20)
                
                self.supply_depot_built = True
                
                return actions.FunctionCall(_BUILD_SUPPLYDEPOT, [_NOT_QUEUED, target])

        return actions.FunctionCall(_NOOP, []) 
開發者ID:skjb,項目名稱:pysc2-tutorial,代碼行數:32,代碼來源:simple_agent_step2a.py

示例15: step

# 需要導入模塊: from pysc2.lib import actions [as 別名]
# 或者: from pysc2.lib.actions import FunctionCall [as 別名]
def step(self, obs):
        super(SimpleAgent, self).step(obs)
        
        time.sleep(0.5)
        
        if self.base_top_left is None:
            player_y, player_x = (obs.observation["minimap"][_PLAYER_RELATIVE] == _PLAYER_SELF).nonzero()
            self.base_top_left = player_y.mean() <= 31
            
        if not self.supply_depot_built:
            if not self.scv_selected:
                unit_type = obs.observation["screen"][_UNIT_TYPE]
                unit_y, unit_x = (unit_type == _TERRAN_SCV).nonzero()
                
                target = [unit_x[0], unit_y[0]]
                
                self.scv_selected = True
                
                return actions.FunctionCall(_SELECT_POINT, [_NOT_QUEUED, target])
            elif _BUILD_SUPPLYDEPOT in obs.observation["available_actions"]:
                unit_type = obs.observation["screen"][_UNIT_TYPE]
                unit_y, unit_x = (unit_type == _TERRAN_COMMANDCENTER).nonzero()
                
                target = self.transformLocation(int(unit_x.mean()), 0, int(unit_y.mean()), 20)
                
                self.supply_depot_built = True
                
                return actions.FunctionCall(_BUILD_SUPPLYDEPOT, [_NOT_QUEUED, target])
        elif not self.barracks_built and _BUILD_BARRACKS in obs.observation["available_actions"]:
            unit_type = obs.observation["screen"][_UNIT_TYPE]
            unit_y, unit_x = (unit_type == _TERRAN_COMMANDCENTER).nonzero()
            
            target = self.transformLocation(int(unit_x.mean()), 20, int(unit_y.mean()), 0)
            
            self.barracks_built = True
            
            return actions.FunctionCall(_BUILD_BARRACKS, [_NOT_QUEUED, target])

        return actions.FunctionCall(_NOOP, []) 
開發者ID:skjb,項目名稱:pysc2-tutorial,代碼行數:41,代碼來源:simple_agent_step2.py


注:本文中的pysc2.lib.actions.FunctionCall方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。