本文整理汇总了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)
示例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
示例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, {}
示例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, [])
示例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
示例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)
示例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])
示例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])
示例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)
示例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))
示例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, [])
示例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)
示例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, [])
示例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, [])
示例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, [])