Skip to content

Commit

Permalink
adding the wrapper and others
Browse files Browse the repository at this point in the history
  • Loading branch information
junkilee committed Apr 1, 2019
1 parent 3e499a4 commit 03c09c2
Show file tree
Hide file tree
Showing 17 changed files with 580 additions and 212 deletions.
2 changes: 2 additions & 0 deletions .idea/starcraft-ai.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ Install pysc2
- http://github.com/junkilee/pysc2
- `pip install -e .`

## Install docker
Install docker
-------------
- Installation instructions for Ubuntu
- https://docs.docker.com/install/linux/docker-ce/ubuntu/
- Post installation setup
- https://docs.docker.com/install/linux/linux-postinstall/
- Nvidia-docker setup
- https://github.com/NVIDIA/nvidia-docker
Empty file added sc2ai/envs/actions.py
Empty file.
49 changes: 0 additions & 49 deletions sc2ai/envs/minigame.py

This file was deleted.

5 changes: 5 additions & 0 deletions sc2ai/envs/minigames/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from sc2ai.envs.minigames.collect_minerals_and_gas import CollectMineralAndGasEnv
from sc2ai.envs.minigames.defeat_zerglings import DefeatZerglingsEnv
from sc2ai.envs.minigames.move_to_beacon import MoveToBeaconEnv

__all__ = ["CollectMineralAndGasEnv", "DefeatZerglingsEnv", "MoveToBeaconEnv"]
4 changes: 2 additions & 2 deletions sc2ai/envs/minigames/collect_minerals_and_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from gym import spaces
from pysc2.lib import actions, features

from ..minigame import MiniGameEnv
from ..sc2env import MiniGameEnv

class DefeatZerglingsEnv(MiniGameEnv):
class CollectMineralAndGasEnv(MiniGameEnv):
"""
"""
Expand Down
5 changes: 4 additions & 1 deletion sc2ai/envs/minigames/defeat_zerglings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
from gym import spaces
from pysc2.lib import actions, features

from ..minigame import MiniGameEnv
from ..sc2env import MiniGameEnv

class DefeatZerglingsEnv(MiniGameEnv):
"""
"""
def __init__(self, **kwargs):
super().__init__(**kwargs)

Expand Down
8 changes: 5 additions & 3 deletions sc2ai/envs/minigames/move_to_beacon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from gym import spaces
from pysc2.lib import actions, features

from ..minigame import MiniGameEnv
from ..sc2env import MiniGameEnv

class MoveToBeaconDiscreteEnv(MiniGameEnv):
class MoveToBeaconEnv(MiniGameEnv):
"""
"""
def __init__(self, **kwargs):
super().__init__(**kwargs)


def _process_reward(self, reward, raw_obs):
raise NotImplementedError
Expand Down
73 changes: 71 additions & 2 deletions sc2ai/envs/sc2env.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,35 @@

from .game_info import default_env_options
from .game_info import ActionIDs
import sc2ai.envs.minigames as minigames

import numpy as np

from baselines import logger

MAP_ENV_MAPPINGS = {
"DefeatZerglings": minigames.DefeatZerglingsEnv,
"CollectMineralAndGas": minigames.DefeatCollectMinardAndGasEnv,
"MoveToBeacon": minigames.MoveToBeaconEnv
}

def make_sc2env(**kwargs):
"""
Args:
**kwargs:
Returns:
"""
cls = None
if kwargs["map"] is not in MAP_ENV_MAPPINGS:
raise Exception("The map is unknown and not registered.")
else
cls = MAP_ENV_MAPPINGS[kwargs["map"]]

return gym.make(cls(**kwargs))

class SC2Env(gym.Env):
"""A gym wrapper for PySC2's Starcraft II environment.
Expand Down Expand Up @@ -136,7 +160,7 @@ def step(self, action):
logging.info("Keyboard Interruption.")
return None, 0, True, {}
except Exception:
logger.exception("An unexpected exception occured.")
logging.exception("An unexpected exception occured.")
return None, 0, True, {}
self._available_actions = obs.observation['available_actions']
reward = obs.reward
Expand All @@ -155,4 +179,49 @@ def action_space(self):

@property
def observation_space(self):
raise self.observation_space
raise self.observation_space


class MiniGameEnv(SC2Env):
"""Providing a wrapper for minigames. Mainly supports preprocessing of both reward and observation.
Args:
map_name:
**kwargs:
"""
def __init__(self, map_name, **kwargs):
assert isinstance(map_name, str)
super().__init__(map_name, **kwargs)

def _reset(self):
obs = super()._reset()
return _process_observation(self, obs)

def _step(self, action):
raw_obs, reward, done, info = super()._step(self, action)
reward = self._process_reward(reward, raw_obs)
obs = self._process_observation(raw_obs)
return obs, reward, done, info

def _process_reward(self, reward, raw_obs):
raise NotImplementedError

def _process_observation(self, raw_obs):
raise NotImplementedError

class MultiStepMiniGameEnv(SC2Env):
"""
Instead of taking one action per step, it handles a list of consecutive actions.
"""
def __init__(self, **kwargs):
super().__init__(**kwargs)

def _step(self, actions):
total_reward = 0
for action in actions:
raw_obs, reward, done, info = super().__step(self, action)
total_reward += self._process_reward(reward, raw_obs)
if done:
break
obs = self._process_observation(raw_obs)
return obs, total_reward, done, info
File renamed without changes.
146 changes: 0 additions & 146 deletions sc2ai/policies/bl_fully_conv_lstm.py

This file was deleted.

Loading

0 comments on commit 03c09c2

Please sign in to comment.