StarCraft II Learning environment full overview (V)

gema.parreno.piqueras
3 min readOct 6, 2018

Lab : Quickstart overview of pySC2

“The task ahead is difficult, but worthwhile” Karax Protoss repeatedly selected unit quote

Configuration

You can configure all the requirements for getting started in the pysc2 official repository or in the step II of this tutorial. In this section we will test the running environment with the mini-game that we are going to train.

Run Random Agent

Open a terminal and type

$ python -m pysc2.bin.agent --map HallucinIce

You should see something like this

As you can check, there is nor learning neither strategy on this, as the agent is selecting random actions. In the pysc2 repository, you might see how a random agent works

class RandomAgent(base_agent.BaseAgent):
"""A random agent for Starcraft II pysc2."""
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)

Basically, the RandomAgent class extends from the base_agent and we define what is doing at each step ,in which defines a variable that selects randomly an available action and call it with its arguments at each step

Run Scripted Agent

Scripted agents are a set of handcrafted rules that help the agents take a strategy You can type in your console

$ python -m pysc2.bin.agent --map HallucinIce  --agent pysc2.agents.scripted_agent.HallucinIce

And should see something like this

class HallucinationArchon(base_agent.BaseAgent):
"""An agent specifically for solving the HallucinIce map with Archon Unit for Starcraft II pysc2."""
def step(self, obs):
super(HallucinationArchon, self).step(obs)
if _HAL_ARCHON in obs.observation["available_actions"]:
player_relative = obs.observation.feature_screen.player_relative
hellion_y, hellion_x = (player_relative == _PLAYER_HOSTILE).nonzero()
if not hellion_y.any():
return FUNCTIONS.no_op()
index = numpy.argmax(hellion_y)
target = [hellion_x[index], hellion_y[index]]
return FUNCTIONS.Hallucination_Archon_quick("now", target)
elif _SELECT_ARMY in obs.observation["available_actions"]:
return FUNCTIONS.select_army("select")
else:
return FUNCTIONS.no_op()

This agent creates a class in which observes if the Archon Hallucination is possible , locates the position of the enemy and calls the selection and Hallucination action.

Scripted agents might be able to execute programmed orders fast and straightforward. However, these agents are narrow , not able to execute orders outside those rules and, in the last phase, don´t learn and generalize well . In the next step we will jump into the machine learning agent

Ey!

After this step you might be able to code any scripted agent and produce a random one for the mini-games and use it as a base for benchmarking with your machine learning agent.

Let´s go straight ahead into the machine learning agent in the next step

https://medium.com/@gema.parreno.piqueras/starcraft-ii-learning-environment-full-overview-vi-ae3126aa6b35

--

--