├── .DS_Store ├── Agents ├── .DS_Store ├── DQN_Agent.py ├── DQN_Agent_LSTM.py ├── README.md ├── q_learning_agent.py ├── scripted_agent.py └── sentry_defense.py ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── Images ├── 2C01EB1027814BB7FF16A15272E1B2DEF9FDEEC3.jpg ├── Captura de pantalla 2017-09-03 a las 12.05.18.png ├── Captura de pantalla 2017-09-08 a las 17.05.07.png ├── Captura de pantalla 2017-09-08 a las 17.48.55.png ├── Captura de pantalla 2017-09-17 a las 12.58.11.png ├── Captura de pantalla 2017-09-17 a las 12.58.45.png ├── Captura de pantalla 2017-09-17 a las 13.09.44.png ├── Captura de pantalla 2017-09-18 a las 20.14.14.png ├── Captura de pantalla 2018-01-02 a las 14.51.09.png ├── Captura de pantalla 2018-08-13 a las 15.43.15.png ├── ForceField.png ├── ForceField2.png ├── HallucinIce.gif ├── HallucinIce.png ├── HallucinIceV2.png ├── README.md ├── Reward shaping.png ├── ScoreUpdateVariables.png ├── a0031372f617b683f02fe0ae163419ca-sc2-battlechest-product.jpg ├── change Marines.png ├── change marine.png ├── change sentry.png ├── change_units.png ├── change_units_new.png ├── new_init.png ├── print_screen_1.png ├── trigger.png └── zerling change.png ├── LICENSE ├── README.md ├── RL └── README.md ├── Replays ├── DefeatRoaches_2017-09-08-13-59-49.SC2Replay └── README.md ├── SentryDefense.SC2Map ├── _config.yml ├── docs ├── README.md ├── SentryUnit.md ├── Terran │ └── Terran_mini_games.md └── _config.yml ├── new_minigames ├── .DS_Store ├── BlueMoon │ ├── Images │ │ ├── First_Tech_Core_Protoss.png │ │ ├── Protoss.jpg │ │ └── README.MD │ ├── README.md │ └── bluemoon.SC2Map ├── FlowerFields │ ├── FlowerFields.SC2Map │ └── README.md ├── HallucinIceSMAC │ ├── HallucinIce.SC2Map │ └── README.md ├── MicroPrism │ └── README.MD ├── RedWaves │ ├── README.md │ └── redwaves.SC2Map ├── SentryDefense │ ├── README.md │ └── SentryDefense.SC2Map ├── SentryForceField │ ├── ForceField.SC2Map │ ├── README.md │ └── scripted_agent.py ├── SentryHallucination │ ├── HallucinIce.SC2Map │ ├── README.md │ └── scripted_agent.py └── TheRightPath │ ├── README.md │ └── TheRightPath.SC2Map ├── requirements.txt └── zip ├── README.md └── mini-games.zip /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/.DS_Store -------------------------------------------------------------------------------- /Agents/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Agents/.DS_Store -------------------------------------------------------------------------------- /Agents/DQN_Agent.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import sys 3 | import random 4 | 5 | from keras.models import Sequential 6 | from keras.layers import Dense, Flatten, Conv2D, Activation, MaxPooling2D 7 | from keras.optimizers import Adam, Adamax, Nadam 8 | from keras.backend import set_image_dim_ordering 9 | from absl import flags 10 | 11 | from pysc2.env import sc2_env, environment 12 | from pysc2.lib import actions 13 | from pysc2.lib import features 14 | 15 | from rl.memory import SequentialMemory 16 | from rl.policy import LinearAnnealedPolicy, EpsGreedyQPolicy 17 | from rl.core import Processor 18 | from rl.callbacks import FileLogger, ModelIntervalCheckpoint 19 | from rl.agents.dqn import DQNAgent 20 | from rl.agents.sarsa import SARSAAgent 21 | 22 | ## Actions from pySC2 API ( Move, attack, select , hallucination actions ) 23 | 24 | _PLAYER_RELATIVE = features.SCREEN_FEATURES.player_relative.index 25 | _PLAYER_FRIENDLY = 1 26 | _PLAYER_NEUTRAL = 3 # beacon/minerals 27 | _PLAYER_HOSTILE = 4 28 | _NO_OP = actions.FUNCTIONS.no_op.id 29 | _MOVE_SCREEN = actions.FUNCTIONS.Move_screen.id 30 | _ATTACK_SCREEN = actions.FUNCTIONS.Attack_screen.id 31 | _SELECT_ARMY = actions.FUNCTIONS.select_army.id 32 | _NOT_QUEUED = [0] 33 | _SELECT_ALL = [0] 34 | _HAL_ADEPT = actions.FUNCTIONS.Hallucination_Adept_quick.id 35 | _HAL_ARCHON = actions.FUNCTIONS.Hallucination_Archon_quick.id 36 | 37 | ## Size of the screen and length of the window 38 | 39 | _SIZE = 64 40 | _WINDOW_LENGTH = 1 41 | 42 | ## Load and save weights for training 43 | 44 | LOAD_MODEL = False #True si ya está creado para entrenar el modelo 45 | SAVE_MODEL = True 46 | 47 | ## global variable 48 | 49 | episode_reward = 0 50 | 51 | ## Configure Flags for executing model from console 52 | 53 | FLAGS = flags.FLAGS 54 | flags.DEFINE_string("mini-game", "HalucinIce", "Name of the minigame") 55 | flags.DEFINE_string("algorithm", "deepq", "RL algorithm to use") 56 | 57 | ## Processor 58 | # A processor acts as a relationship between an Agent and the Env . 59 | # useful if the agent has different requirements with respect to the form of the observations, actions, and rewards of environment 60 | # How many frames will be an obs ? 61 | 62 | class SC2Proc(Processor): 63 | def process_observation(self, observation): 64 | """Process the observation as obtained from the environment for use an agent and returns it""" 65 | obs = observation[0].observation["feature_screen"][_PLAYER_RELATIVE] # Read the features from the screen . This will change with pix2pix 66 | return np.expand_dims(obs, axis=2) 67 | 68 | def process_state_batch(self, batch): 69 | """Processes an entire batch of states and returns it""" 70 | return batch[0] 71 | 72 | def process_reward(self, reward): 73 | """Processes the reward as obtained from the environment for use in an agent and returns it """ 74 | reward = 0 75 | return reward 76 | 77 | 78 | ## Define the environment 79 | 80 | 81 | class Environment(sc2_env.SC2Env): 82 | """Starcraft II enviromnet. Implementation details in lib/features.py""" 83 | 84 | def step(self, action): 85 | """Apply actions, step the world forward, and return observations""" 86 | global episode_reward # global variable defined previously 87 | 88 | action = actions_to_choose( 89 | action) # Actions of Hallucination and movement Make a function that selects among hallucination functions 90 | obs = super(Environment, self).step( 91 | [actions.FunctionCall(_NO_OP, [])]) ## change the action for Hallucination or attack ? 92 | # The method calls an observation that moves the screen 93 | observation = obs 94 | r = obs[0].reward 95 | done = obs[0].step_type == environment.StepType.LAST # Episode_over 96 | episode_reward += r 97 | 98 | return observation, r, done, {} # Return observation, reward, and episode_over 99 | 100 | def reset(self): 101 | # reset the environment 102 | global episode_reward 103 | episode_reward = 0 104 | super(Environment, self).reset() 105 | 106 | return super(Environment, self).step([actions.FunctionCall(_SELECT_ARMY, [_SELECT_ALL])]) 107 | 108 | 109 | def actions_to_choose(action): 110 | hall = [_HAL_ADEPT, _HAL_ARCHON] 111 | action = actions.FunctionCall(random.choice(hall), [_NOT_QUEUED]) 112 | return action 113 | 114 | 115 | ## Agent architecture using keras rl 116 | 117 | 118 | ### Model 119 | # Agents representation of the environment. ( How the agent thinks the environment works) 120 | 121 | #### 1. 256 , 127, 256 are the channels- depth of the first layer, one can be colour, edges) 122 | #### 2. Kernel size is the size of the matrix it will be use to make the convolution ( impair size is better) 123 | #### 3. strides are the translation that kernel size will be making 124 | #### 4. The Neural net architecture is CONV2D-RELU-MAXPOOL-FLATTEN+FULLYCONNECTED 125 | 126 | def neural_network_model(input, actions): 127 | model = Sequential() 128 | model.add(Conv2D(256, kernel_size=(5, 5), input_shape=input)) 129 | model.add(Activation('relu')) 130 | 131 | model.add(MaxPooling2D(pool_size=(2, 2), strides=None, padding='valid', data_format=None)) 132 | model.add(Flatten()) 133 | model.add(Dense(actions)) # This means fully connected ? 134 | model.add(Activation('softmax')) 135 | 136 | model.compile(loss="categorical_crossentropy", 137 | optimizer="adam", 138 | metrics=["accuracy"]) 139 | 140 | return model 141 | 142 | 143 | def training_game(): 144 | env = Environment(map_name="HallucinIce", visualize=True, game_steps_per_episode=150, agent_interface_format=features.AgentInterfaceFormat( 145 | feature_dimensions=features.Dimensions(screen=64, minimap=32) 146 | )) 147 | 148 | input_shape = (_SIZE, _SIZE, 1) 149 | nb_actions = _SIZE * _SIZE # Should this be an integer 150 | 151 | model = neural_network_model(input_shape, nb_actions) 152 | # memory : how many subsequent observations should be provided to the network? 153 | memory = SequentialMemory(limit=5000, window_length=_WINDOW_LENGTH) 154 | 155 | processor = SC2Proc() 156 | 157 | ### Policy 158 | # Agent´s behaviour function. How the agent pick actions 159 | # LinearAnnealedPolicy is a wrapper that transforms the policy into a linear incremental linear solution . Then why im not see LAP with other than not greedy ? 160 | # EpsGreedyQPolicy is a way of selecting random actions with uniform distributions from a set of actions . Select an action that can give max or min rewards 161 | # BolztmanQPolicy . Assumption that it follows a Boltzman distribution. gives the probability that a system will be in a certain state as a function of that state´s energy?? 162 | 163 | policy = LinearAnnealedPolicy(EpsGreedyQPolicy(), attr="eps", value_max=1, value_min=0.7, value_test=.0, 164 | nb_steps=1e6) 165 | # policy = (BoltzmanQPolicy( tau=1., clip= (-500,500)) #clip defined in between -500 / 500 166 | 167 | 168 | ### Agent 169 | # Double Q-learning ( combines Q-Learning with a deep Neural Network ) 170 | # Q Learning -- Bellman equation 171 | 172 | dqn = DQNAgent(model=model, nb_actions=nb_actions, memory=memory, 173 | nb_steps_warmup=500, target_model_update=1e-2, policy=policy, 174 | batch_size=150, processor=processor) 175 | 176 | dqn.compile(Adam(lr=.001), metrics=["mae"]) 177 | 178 | 179 | ## Save the parameters and upload them when needed 180 | 181 | name = "HallucinIce" 182 | w_file = "dqn_{}_weights.h5f".format(name) 183 | check_w_file = "train_w" + name + "_weights.h5f" 184 | 185 | if SAVE_MODEL: 186 | check_w_file = "train_w" + name + "_weights_{step}.h5f" 187 | 188 | log_file = "training_w_{}_log.json".format(name) 189 | callbacks = [ModelIntervalCheckpoint(check_w_file, interval=1000)] 190 | callbacks += [FileLogger(log_file, interval=100)] 191 | 192 | if LOAD_MODEL: 193 | dqn.load_weights(w_file) 194 | 195 | dqn.fit(env, callbacks=callbacks, nb_steps=1e7, action_repetition=2, 196 | log_interval=1e4, verbose=2) 197 | 198 | dqn.save_weights(w_file, overwrite=True) 199 | dqn.test(env, action_repetition=2, nb_episodes=30, visualize=False) 200 | 201 | if __name__ == '__main__': 202 | FLAGS(sys.argv) 203 | training_game() 204 | 205 | -------------------------------------------------------------------------------- /Agents/DQN_Agent_LSTM.py: -------------------------------------------------------------------------------- 1 | #SC2-pySC2 agent for HallucinIce mini-game 2 | #@SoyGema 3 | #Thanks to @DavSuCar 4 | 5 | 6 | import numpy as np 7 | import sys 8 | import random 9 | import time 10 | 11 | from keras.models import Sequential 12 | from keras.layers import Dense, Flatten, Conv2D, Activation, MaxPooling2D, TimeDistributed, LSTM, Reshape 13 | from keras.optimizers import Adam, Adamax, Nadam 14 | from keras.backend import set_image_dim_ordering 15 | from absl import flags 16 | 17 | from pysc2.env import sc2_env 18 | from pysc2.env import environment as pysc2environment 19 | from pysc2.lib import actions 20 | from pysc2.lib import features 21 | 22 | from rl.memory import SequentialMemory 23 | from rl.policy import LinearAnnealedPolicy, EpsGreedyQPolicy 24 | from rl.core import Processor 25 | from rl.callbacks import FileLogger, ModelIntervalCheckpoint 26 | from rl.agents.dqn import DQNAgent 27 | # from rl.agents.sarsa import SARSAAgent 28 | 29 | # Actions from pySC2 API 30 | 31 | FUNCTIONS = actions.FUNCTIONS 32 | _PLAYER_RELATIVE = features.SCREEN_FEATURES.player_relative.index 33 | _PLAYER_FRIENDLY = 1 34 | _PLAYER_NEUTRAL = 3 35 | _PLAYER_HOSTILE = 4 36 | _NO_OP = FUNCTIONS.no_op.id 37 | _MOVE_SCREEN = FUNCTIONS.Move_screen.id 38 | _ATTACK_SCREEN = FUNCTIONS.Attack_screen.id 39 | _SELECT_ARMY = FUNCTIONS.select_army.id 40 | _NOT_QUEUED = [0] 41 | _SELECT_ALL = [0] 42 | _HAL_ADEPT = FUNCTIONS.Hallucination_Adept_quick.id 43 | _HAL_ARCHON = FUNCTIONS.Hallucination_Archon_quick.id 44 | _HAL_COL = FUNCTIONS.Hallucination_Colossus_quick.id 45 | _HAL_DISRUP = FUNCTIONS.Hallucination_Disruptor_quick.id 46 | _HAL_HIGTEM = FUNCTIONS.Hallucination_HighTemplar_quick.id 47 | _HAL_IMN = FUNCTIONS.Hallucination_Immortal_quick.id 48 | _HAL_PHOENIX = FUNCTIONS.Hallucination_Phoenix_quick.id 49 | _HAL_STALKER = FUNCTIONS.Hallucination_Stalker_quick.id 50 | _HAL_VOIDRAID = FUNCTIONS.Hallucination_VoidRay_quick.id 51 | _HAL_ZEALOT = FUNCTIONS.Hallucination_Zealot_quick.id 52 | _FORCE_FIELD = FUNCTIONS.Effect_ForceField_screen.id 53 | _GUARD_FIELD = FUNCTIONS.Effect_GuardianShield_quick.id 54 | 55 | # Size of the screen and length of the window 56 | 57 | _WINDOW_LENGTH = 1 58 | 59 | # Load and save weights for training 60 | 61 | LOAD_MODEL = False # True if the training process is already created 62 | SAVE_MODEL = True 63 | 64 | # Configure Flags for executing model from console: 65 | 66 | FLAGS = flags.FLAGS 67 | flags.DEFINE_string("mini_game", "HallucinIce", "Name of the minigame.") 68 | flags.DEFINE_integer("screen_size", "64", "Resolution for screen actions.") 69 | flags.DEFINE_integer("minimap_size", "32", "Resolution for minimap actions.") 70 | # flags.DEFINE_string("algorithm", "deepq", "RL algorithm to use") 71 | flags.DEFINE_bool("verbose", False, "Intended to help a programmer read actions taken in real-time.") 72 | flags.DEFINE_float("pause", 0.0, "Seconds to pause between consecutive actions. Intended to help a programmer observe the effect of an action taken in real-time.") 73 | flags.DEFINE_bool("visualize", True, "Visualize game") 74 | flags.DEFINE_integer("steps_per_ep", 150, "steps per episode.") 75 | FLAGS(sys.argv) 76 | 77 | # Processor 78 | 79 | class SC2Proc(Processor): 80 | def process_observation(self, observation): 81 | """Process the observation as obtained from the environment for use an agent and returns it""" 82 | obs = observation[0].observation["feature_screen"][_PLAYER_RELATIVE] 83 | return np.expand_dims(obs, axis=2) 84 | 85 | def process_state_batch(self, batch): 86 | """Processes an entire batch of states and returns it""" 87 | batch = np.swapaxes(batch, 0, 1) 88 | return batch[0] 89 | 90 | # Define the environment 91 | 92 | class Environment(sc2_env.SC2Env): 93 | """Starcraft II environmet. Implementation details in lib/features.py""" 94 | 95 | def __init__(self): 96 | # Creates common pysc2 objects required for running of agent. 97 | agent_interface_format=features.AgentInterfaceFormat( 98 | feature_dimensions=features.Dimensions(screen=FLAGS.screen_size, minimap=FLAGS.minimap_size)) 99 | feats = features.Features(agent_interface_format) 100 | action_spec = feats.action_spec() 101 | super().__init__(map_name=FLAGS.mini_game, 102 | visualize=FLAGS.visualize, 103 | game_steps_per_episode=FLAGS.steps_per_ep, 104 | agent_interface_format=agent_interface_format) 105 | # Save variables which can help in debugging or better unds-ing pysc2: 106 | self.observation_spec = self.observation_spec() 107 | self.agent_interface_format = agent_interface_format 108 | self.feats = feats 109 | self.action_spec = action_spec 110 | # Initialize variables: 111 | self.episode_reward = 0 112 | self.observation_cur = None 113 | 114 | def step(self, action): 115 | """Apply actions, step the world forward, and return observations""" 116 | if FLAGS.verbose: 117 | print('{} AVAILABLE ACTIONS.'.format(len(self.observation_cur.available_actions))) 118 | # Uncomment to print individual available actions. 119 | # for a in observation_cur.available_actions: 120 | # print(actions.FUNCTIONS[a]) 121 | 122 | chosen_func_id = np.random.choice(self.observation_cur.available_actions) 123 | 124 | if FLAGS.verbose: 125 | chosen_action = actions.FUNCTIONS[chosen_func_id] 126 | print('Chosen action: ', chosen_func_id, '~~', chosen_action) 127 | 128 | # Uncomment to print "template" args of chosen action: 129 | # allargs = self.action_spec.functions[chosen_func_id].args 130 | # for arg in allargs: 131 | # print(arg); print('arg sizes ', arg.sizes) 132 | 133 | chosen_args = [[np.random.randint(0, size) for size in arg.sizes] for arg in self.action_spec.functions[chosen_func_id].args] 134 | 135 | if FLAGS.verbose: 136 | print('Chosen args: ', chosen_args) 137 | 138 | action = actions.FunctionCall(chosen_func_id, chosen_args) 139 | obs = super(Environment, self).step([action]) 140 | self.observation_cur = obs[0].observation 141 | r = obs[0].reward 142 | done = obs[0].step_type == pysc2environment.StepType.LAST 143 | self.episode_reward += r 144 | time.sleep(FLAGS.pause) 145 | return obs, r, done, {} 146 | 147 | def reset(self): 148 | obs = super(Environment, self).reset() 149 | self.observation_cur = obs[0].observation 150 | self.episode_reward = 0 151 | return obs 152 | 153 | def actions_to_choose(): 154 | hall = [_HAL_ADEPT, _HAL_ARCHON, _HAL_COL, _HAL_DISRUP, 155 | _HAL_HIGTEM, _HAL_IMN, _HAL_PHOENIX, _HAL_STALKER, 156 | _HAL_VOIDRAID, _HAL_ZEALOT, _FORCE_FIELD, _GUARD_FIELD] 157 | action = actions.FunctionCall(_HAL_ADEPT, [_NOT_QUEUED]) 158 | print(action) 159 | return action 160 | 161 | # TO-DO : Define actions_to_choose based on SC2 sentry unit 162 | 163 | # Agent architecture using keras rl 164 | 165 | def neural_network_model(input, actions): 166 | model = Sequential() 167 | # Define CNN model 168 | print(input) 169 | model.add(Conv2D(256, kernel_size=(5, 5), input_shape=input)) 170 | model.add(MaxPooling2D(pool_size=(2, 2), strides=None, padding='valid', data_format=None)) 171 | model.add(Flatten()) 172 | 173 | model.add(Dense(256, activation='relu')) 174 | model.add(Reshape((1, 256))) 175 | 176 | model.add(LSTM(256)) 177 | model.add(Dense(actions, activation='softmax')) 178 | model.summary() 179 | model.compile(loss="categorical_crossentropy", 180 | optimizer="adam", 181 | metrics=["accuracy"]) 182 | 183 | return model 184 | 185 | 186 | def training_game(): 187 | env = Environment() 188 | 189 | input_shape = (FLAGS.screen_size, FLAGS.screen_size, 1) 190 | nb_actions = 12 # Number of actions 191 | 192 | model = neural_network_model(input_shape, nb_actions) 193 | memory = SequentialMemory(limit=5000, window_length=_WINDOW_LENGTH) 194 | 195 | processor = SC2Proc() 196 | 197 | # Policy 198 | 199 | policy = LinearAnnealedPolicy(EpsGreedyQPolicy(), attr="eps", value_max=1, value_min=0.7, value_test=.0, nb_steps=1e6) 200 | 201 | # Agent 202 | 203 | dqn = DQNAgent(model=model, 204 | nb_actions=nb_actions, 205 | memory=memory, 206 | enable_double_dqn=False, 207 | nb_steps_warmup=500, 208 | # nb_steps_warmup=1, 209 | target_model_update=1e-2, 210 | policy=policy, 211 | batch_size=150, 212 | processor=processor) 213 | 214 | dqn.compile(Adam(lr=.001), metrics=["mae"]) 215 | 216 | # Tensorboard callback 217 | 218 | callbacks = keras.callbacks.TensorBoard(log_dir='./Graph', histogram_freq=0, 219 | write_graph=True, write_images=False) 220 | 221 | 222 | # Save the parameters and upload them when needed 223 | 224 | name = FLAGS.mini_game 225 | w_file = "dqn_{}_weights.h5f".format(name) 226 | check_w_file = "train_w" + name + "_weights.h5f" 227 | 228 | if SAVE_MODEL: 229 | check_w_file = "train_w" + name + "_weights_{step}.h5f" 230 | 231 | log_file = "training_w_{}_log.json".format(name) 232 | 233 | if LOAD_MODEL: 234 | dqn.load_weights(w_file) 235 | 236 | dqn.fit(env, callbacks=callbacks, nb_steps=1e7, action_repetition=2, 237 | log_interval=1e4, verbose=2) 238 | 239 | dqn.save_weights(w_file, overwrite=True) 240 | dqn.test(env, action_repetition=2, nb_episodes=30, visualize=False) 241 | 242 | 243 | if __name__ == '__main__': 244 | print('FLAGS:') 245 | for k in FLAGS._flags(): 246 | print(k, FLAGS[k].value) 247 | print('-'*20) 248 | training_game() 249 | -------------------------------------------------------------------------------- /Agents/README.md: -------------------------------------------------------------------------------- 1 | # Sentry Agent mini-game Map exploration 2 | 3 | This part of the repository aims to post several agents regarding functions of sentry unit. 4 | SentryDefense.py --contains all the actions for sentrydefense unit 5 | scripted_agent.py --contains tests for Forcefield Starcraft 2 map 6 | 7 | ### Sentry unit scripted bot running 8 | 9 | --Clone the repo 10 | 11 | --Put ForceField.sc2 map into your minigames map folder 12 | 13 | --Go to pysc2/maps/mini_games.py and add ForceField map to the array map 14 | 15 | --In the /pysc2/agents/ folder type 16 | 17 | ``` 18 | $ python3 -m pysc2.bin.agent --agent scripted_agent.SentryForceField --map ForceField 19 | ``` 20 | ### About the agents 21 | 22 | -- scripted_gent.py --- > scripted -Tested- 23 | 24 | -- q_learning_agent.py --- > learning agent - Tested - 25 | 26 | -- DQN_Agent.py --- > learning agent - Tested - 27 | 28 | -- DQN_Agent_LSTM.py --- > learning agent - Tested - Architecture bellow 29 | 30 | After executing file, type in console : 31 | 32 | ``` 33 | $ tensorboard --logdir path/Graph --host localhost --port 8088 34 | ``` 35 |  36 | 37 | 38 | ### Debugging and testing 39 | 40 | 41 | #### Print available actions 42 | 43 | Will print the id of the available actions in a list 44 | 45 | action_no = actions.FunctionCall(_NO_OP, []) 46 | obs_no = super(Environment, self).step([action_no]) 47 | actions_available = obs_no[0].observation.available_actions 48 | print(actions_available) 49 | -------------------------------------------------------------------------------- /Agents/q_learning_agent.py: -------------------------------------------------------------------------------- 1 | # Q-learning agent for HallucinIce. 2 | # The goal for the agent is to discover wich combination of Hallucination will be better to defeat Terran 3 | # Kudos to Steven Brown and to MorvanZhou 4 | 5 | import random 6 | import math 7 | 8 | import numpy as np 9 | import pandas as pd 10 | 11 | from pysc2.agents import base_agent 12 | from pysc2.lib import actions 13 | from pysc2.lib import features 14 | 15 | # Features 16 | _PLAYER_RELATIVE = features.SCREEN_FEATURES.player_relative.index 17 | _PLAYER_FRIENDLY = 1 18 | _PLAYER_HOSTILE = 4 19 | _UNIT_TYPE = features.SCREEN_FEATURES.unit_type.index 20 | _PLAYER_ID = features.SCREEN_FEATURES.player_id.index 21 | _PLAYER_SELF = 1 22 | 23 | # Functions 24 | _NO_OP = actions.FUNCTIONS.no_op.id 25 | _SELECT_POINT = actions.FUNCTIONS.select_point.id 26 | _MOVE_SCREEN = actions.FUNCTIONS.Move_screen.id 27 | _ATTACK_SCREEN = actions.FUNCTIONS.Attack_screen.id 28 | _SELECT_ARMY = actions.FUNCTIONS.select_army.id # Attack_minimap.id 29 | 30 | # Parameters 31 | _NOT_QUEUED = [0] 32 | _SELECT_ALL = [0] 33 | 34 | # Unit IDs 35 | PROTOSS_SENTRY = 77 36 | TERRAN_HELLION = 53 37 | 38 | # Define the actions 39 | ACTION_DO_NOTHING = 'donothing' 40 | ACTION_SELECT_SENTRY = 'selectsentry' 41 | ACTION_HAL_ADEPT = 'adept' 42 | ACTION_HAL_ARCHON = 'archon' 43 | ACTION_HAL_COL = 'colosus' 44 | ACTION_HAL_DISRUP = 'disruptor' 45 | ACTION_HAL_HIGTEM = 'higtem' 46 | ACTION_HAL_IMN = 'imortal' 47 | ACTION_HAL_PHOENIX = 'phoenix' 48 | ACTION_HAL_STALKER = 'stalker' 49 | ACTION_HAL_VOIDRAID = 'voidraid' 50 | ACTION_HAL_ZEALOT = 'zealot' 51 | ACTION_ATTACK = 'attack' 52 | 53 | # Define the call to the API of the Hallucination function 54 | _HAL_ADEPT = actions.FUNCTIONS.Hallucination_Adept_quick.id 55 | _HAL_ARCHON = actions.FUNCTIONS.Hallucination_Archon_quick.id 56 | _HAL_COL = actions.FUNCTIONS.Hallucination_Colossus_quick.id 57 | _HAL_DISRUP = actions.FUNCTIONS.Hallucination_Disruptor_quick.id 58 | _HAL_HIGTEM = actions.FUNCTIONS.Hallucination_HighTemplar_quick.id 59 | _HAL_IMN = actions.FUNCTIONS.Hallucination_Immortal_quick.id 60 | _HAL_PHOENIX = actions.FUNCTIONS.Hallucination_Phoenix_quick.id 61 | _HAL_STALKER = actions.FUNCTIONS.Hallucination_Stalker_quick.id 62 | _HAL_VOIDRAID = actions.FUNCTIONS.Hallucination_VoidRay_quick.id 63 | _HAL_ZEALOT = actions.FUNCTIONS.Hallucination_Zealot_quick.id 64 | _FORCE_FIELD = actions.FUNCTIONS.Effect_ForceField_screen.id 65 | _GUARD_FIELD = actions.FUNCTIONS.Effect_GuardianShield_quick.id 66 | 67 | 68 | print(_HAL_ARCHON) 69 | 70 | smart_actions = [ 71 | ACTION_DO_NOTHING, 72 | ACTION_HAL_ADEPT, 73 | ACTION_HAL_ARCHON, 74 | ACTION_HAL_COL, 75 | ACTION_HAL_DISRUP, 76 | ACTION_HAL_HIGTEM, 77 | ACTION_HAL_IMN, 78 | ACTION_HAL_PHOENIX, 79 | ACTION_HAL_STALKER, 80 | ACTION_HAL_VOIDRAID, 81 | ACTION_HAL_ZEALOT, 82 | ACTION_ATTACK, 83 | ] 84 | 85 | KILL_UNIT_REWARD = 0.5 86 | 87 | 88 | class QLearningTable: 89 | def __init__(self, actions, learning_rate=0.01, reward_decay=0.9, e_greedy=0.9): 90 | self.actions = actions # a list? 91 | self.lr = learning_rate 92 | self.gamma = reward_decay 93 | self.epsilon = e_greedy 94 | self.q_table = pd.DataFrame(columns=self.actions, dtype=np.float64) 95 | 96 | def choose_action(self, observation): 97 | self.check_state_exist(observation) 98 | 99 | if np.random.uniform() < self.epsilon: 100 | # choose the best action from q-table 101 | state_action = self.q_table.ix[observation, :] 102 | 103 | # some actions have the same value 104 | state_action = state_action.reindex(np.random.permutation(state_action.index)) 105 | 106 | action = state_action.idxmax() 107 | else: 108 | # choose random action 109 | action = np.random.choice(self.actions) 110 | 111 | return action 112 | 113 | # Q-learning implementation 114 | 115 | def learn(self, s, a, r, s_): 116 | self.check_state_exist(s_) 117 | self.check_state_exist(s) 118 | 119 | # Make q-table and select max value 120 | 121 | q_predict = self.q_table.ix[s, a] 122 | q_target = r + self.gamma * self.q_table.ix[s_, :].max() 123 | 124 | # update 125 | 126 | self.q_table.ix[s, a] += self.lr * (q_target - q_predict) 127 | 128 | def check_state_exist(self, state): 129 | if state not in self.q_table.index: 130 | self.q_table = self.q_table.append( 131 | pd.Series([0] * len(self.actions), index=self.q_table.columns, name=state)) 132 | 133 | 134 | class SmartAgent(base_agent.BaseAgent): 135 | def __init__(self): 136 | super(SmartAgent, self).__init__() # For fix trouble with undefined properties 137 | self.qlearn = QLearningTable(actions=list(range(len(smart_actions)))) 138 | 139 | self.previous_killed_unit_score = 0 140 | self.previous_action = None 141 | self.previous_state = None 142 | 143 | # Compare step from scripted agent with learning agent 144 | 145 | def step(self, obs): 146 | super(SmartAgent, self).step(obs) 147 | 148 | def _xy_locs(mask): 149 | """Mask should be a set of bools from comparison with a feature layer""" 150 | y, x = mask.nonzero() 151 | return list(zip(x, y)) 152 | 153 | PLAYER_RELATIVE = obs.observation.feature_screen.player_relative 154 | player_ = _xy_locs(PLAYER_RELATIVE == _PLAYER_SELF) 155 | if not player_: 156 | return _NO_OP 157 | # player_center = numpy.mean(player_, axis=0).round() 158 | else: 159 | return actions.FUNCTIONS.select_army("select") 160 | 161 | 162 | ##unit_type = obs.observation['screen'][_UNIT_TYPE] is this here or inside fork ? 163 | 164 | sentry_y, sentry_x = (unit_type == PROTOSS_SENTRY).nonzero() 165 | n_sentry_count = 1 if sentry_y.any() else 0 166 | 167 | enemy_y, enemy_x = (unit_type == TERRAN_HELLION).nonzero() 168 | n_enemies_count = 1 if enemy_y.any() else 0 169 | 170 | current_state = [ 171 | n_sentry_count, 172 | hallucinations_count, # how does this method work? 173 | n_enemies_count, 174 | army_supply, # this comma exists? 175 | ] 176 | 177 | if self.previous_action is not None: 178 | reward = 0 179 | 180 | if killed_unit_score > self.previous_killed_score: 181 | reward += KILL_UNIT_REWARD 182 | 183 | self.qlearn.learn(str(self.previous_state), self.previous_action, reward, str(current_state)) 184 | 185 | rl_action = self.qlearn.choose_action(str(current_state)) 186 | smart_action = Smart_actions[rl_action] 187 | 188 | self.previous_killed_unit_score = killed_unit_score 189 | self.previous_state = current_state 190 | self.previous_action = rl_action 191 | 192 | if smart_action == ACTION_DO_NOTHING: 193 | return actions.FunctionCall(_NO_OP, []) 194 | 195 | elif smart_action == ACTION_SELECT_SENTRY: 196 | unit_type = obs.observation['screen'][_UNIT_TYPE] 197 | unit_y, unit_x = (unit_type == _SENTRY).nonzero() 198 | 199 | if unit_y.any(): 200 | i = random.randint(o, len(unit_y) - 1) 201 | target = [unit_x[i], unit_y[i]] 202 | 203 | return actions.FunctionCall(_SELECT_POINT, [_NOT_QUEUED, target]) 204 | 205 | elif smart_action == ACTION_HAL_ARCHON: 206 | if _HAL_ARCHON in obs.observation["available_actions"]: 207 | return actions.FunctionCall(_HAL_ARCHON, [_NOT_QUEUED]) 208 | 209 | elif smart_action == ACTION_HAL_ADEPT: 210 | if _HAL_ADEPT in obs.observation["available_actions"]: 211 | return actions.FunctionCall(_HAL_ADEPT, [_NOT_QUEUED]) 212 | 213 | elif smart_action == ACTION_HAL_COL: 214 | if _HAL_COL in obs.observation["available_actions"]: 215 | return actions.FunctionCall(_HAL_ADEPT, [_NOT_QUEUED]) 216 | 217 | elif smart_action == ACTION_HAL_DISRUP: 218 | if _HAL_DISRUP in obs.observation["available_actions"]: 219 | return actions.FunctionCall(_HAL_ADEPT, [_NOT_QUEUED]) 220 | 221 | elif smart_action == ACTION_HIGTEM: 222 | if _HAL_HIGTEM in obs.observation["available_actions"]: 223 | return actions.FunctionCall(_HAL_ADEPT, [_NOT_QUEUED]) 224 | 225 | elif smart_action == ACTION_PHOENIX: 226 | if _HAL_PHOENIX in obs.observation["available_actions"]: 227 | return actions.FunctionCall(_HAL_ADEPT, [_NOT_QUEUED]) 228 | 229 | elif smart_action == ACTION_STALKER: 230 | if _HAL_STALKER in obs.observation["available_actions"]: 231 | return actions.FunctionCall(_HAL_ADEPT, [_NOT_QUEUED]) 232 | 233 | elif smart_action == ACTION_ATTACK: 234 | if _ATTACK_MINIMAP in obs.obsservation["available_actions"]: 235 | if self.base_top_left: 236 | return actions.FunctionCall(_ATTACK_MINIMAP, [_NOT_QUEUED], [77, 53]) 237 | 238 | return actions.FunctionCall(_ATTACK_MINIMAP, [_NOT_QUEUED], [77, 53]) 239 | 240 | return actions.FunctionCall(_NO_OP, []) 241 | -------------------------------------------------------------------------------- /Agents/scripted_agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS-IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # Special thanks to : jmathison 15 | # thebunny 16 | # AleKahpwn 17 | 18 | from __future__ import absolute_import 19 | from __future__ import division 20 | from __future__ import print_function 21 | 22 | import numpy 23 | import random 24 | 25 | from pysc2.agents import base_agent 26 | from pysc2.lib import actions 27 | from pysc2.lib import features 28 | 29 | 30 | FUNCTIONS = actions.FUNCTIONS 31 | _PLAYER_RELATIVE = features.SCREEN_FEATURES.player_relative.index 32 | _PLAYER_FRIENDLY = 1 33 | _PLAYER_NEUTRAL = 3 # beacon/minerals 34 | _PLAYER_HOSTILE = 4 35 | _NO_OP = FUNCTIONS.no_op.id 36 | _MOVE_SCREEN = FUNCTIONS.Move_screen.id 37 | _ATTACK_SCREEN = FUNCTIONS.Attack_screen.id 38 | _SELECT_ARMY = FUNCTIONS.select_army.id 39 | _NOT_QUEUED = [0] 40 | _SELECT_ALL = [0] 41 | _HAL_ADEPT = FUNCTIONS.Hallucination_Adept_quick.id 42 | _HAL_ARCHON = FUNCTIONS.Hallucination_Archon_quick.id 43 | _HAL_COL = FUNCTIONS.Hallucination_Colossus_quick.id 44 | _HAL_DISRUP = FUNCTIONS.Hallucination_Disruptor_quick.id 45 | _HAL_HIGTEM = FUNCTIONS.Hallucination_HighTemplar_quick.id 46 | _HAL_IMN = FUNCTIONS.Hallucination_Immortal_quick.id 47 | _HAL_PHOENIX = FUNCTIONS.Hallucination_Phoenix_quick.id 48 | _HAL_STALKER = FUNCTIONS.Hallucination_Stalker_quick.id 49 | _HAL_VOIDRAID = FUNCTIONS.Hallucination_VoidRay_quick.id 50 | _HAL_ZEALOT = FUNCTIONS.Hallucination_Zealot_quick.id 51 | _FORCE_FIELD = FUNCTIONS.Effect_ForceField_screen.id 52 | _GUARD_FIELD = FUNCTIONS.Effect_GuardianShield_quick.id 53 | 54 | class SentryForceField(base_agent.BaseAgent): 55 | """An agent specifically for solving the ForceField map.""" 56 | 57 | def step(self, obs): 58 | super(SentryForceField, self).step(obs) 59 | if _FORCE_FIELD in obs.observation["available_actions"]: 60 | player_relative = obs.observation.feature_screen.player_relative 61 | hydralisk_y, hydralisk_x = (player_relative == _PLAYER_HOSTILE).nonzero() 62 | if not hydralisk_y.any(): 63 | return FUNCTIONS.no_op() 64 | index = numpy.argmax(hydralisk_y) 65 | target = [hydralisk_x[index], hydralisk_y[index]] 66 | return FUNCTIONS.Effect_ForceField_screen("now", target) 67 | elif _SELECT_ARMY in obs.observation["available_actions"]: 68 | return FUNCTIONS.select_army("select") 69 | else: 70 | return FUNCTIONS.no_op() 71 | 72 | Hallucinations_list = [_HAL_ADEPT, _HAL_ARCHON, _HAL_DISRUP, _HAL_HIGTEM, _HAL_IMN, _HAL_PHOENIX, _HAL_STALKER, _HAL_VOIDRAID, _HAL_ZEALOT] 73 | 74 | 75 | 76 | class HallucinationArchon(base_agent.BaseAgent): 77 | """An agent specifically for solving the HallucinIce map with Archon Unit.""" 78 | 79 | def step(self, obs): 80 | super(HallucinationArchon, self).step(obs) 81 | if _HAL_ARCHON in obs.observation["available_actions"]: 82 | player_relative = obs.observation["feature_screen"][_PLAYER_RELATIVE] 83 | hellion_y, hellion_x = (player_relative == _PLAYER_HOSTILE).nonzero() 84 | if not hellion_y.any(): 85 | return actions.FunctionCall(_NO_OP, []) 86 | index = numpy.argmax(hellion_y) 87 | target = [hellion_x[index], hellion_y[index]] 88 | return actions.FunctionCall(_HAL_ARCHON, [_NOT_QUEUED]) 89 | elif _SELECT_ARMY in obs.observation["available_actions"]: 90 | return actions.FunctionCall(_SELECT_ARMY, [_SELECT_ALL]) 91 | else: 92 | return actions.FunctionCall(_NO_OP, []) 93 | 94 | 95 | Hallucinations = [_HAL_ADEPT, _HAL_ARCHON, _HAL_DISRUP, _HAL_HIGTEM, _HAL_IMN, _HAL_PHOENIX, _HAL_STALKER, _HAL_VOIDRAID, _HAL_ZEALOT] 96 | 97 | class Hallucination(base_agent.BaseAgent): 98 | """An agent specifically for solving the HallucinIce map with Random Hallucination.""" 99 | 100 | def step(self, obs): 101 | test = random.randrange(0, len(Hallucinations_list) - 1) 102 | super(Hallucination, self).step(obs) 103 | 104 | score_general = obs.observation["score_cumulative"][0] 105 | value_units = obs.observation["score_cumulative"][3] 106 | kill_value_units = obs.observation["score_cumulative"][5] 107 | 108 | print("score general is ", score_general) 109 | print("value units is ", value_units) 110 | print("kill value units is", kill_value_units) 111 | 112 | if Hallucinations_list[test] in obs.observation["available_actions"]: 113 | player_relative = obs.observation["feature_screen"][_PLAYER_RELATIVE] 114 | hellion_y, hellion_x = (player_relative == _PLAYER_HOSTILE).nonzero() 115 | if not hellion_y.any(): 116 | return actions.FunctionCall(_NO_OP, []) 117 | index = numpy.argmax(hellion_y) 118 | target = [hellion_x[index], hellion_y[index]] 119 | print(random.randrange(0, len(Hallucinations_list))) 120 | 121 | return actions.FunctionCall(Hallucinations_list[test], [_NOT_QUEUED]) 122 | elif _SELECT_ARMY in obs.observation["available_actions"]: 123 | return FUNCTIONS.select_army("select") 124 | else: 125 | return FUNCTIONS.no_op() 126 | 127 | 128 | class StalkerControl(base_agent.BaseAgent): 129 | """An agent specifically for solving the DefeatZealotsMap map without Blink but with micro """ 130 | 131 | base_top_left = None 132 | 133 | def transformLocation(self, x, x_distance, y, y_distance): 134 | if not self.base_top_left: 135 | return [x - x_distance, y - y_distance]= 136 | return [x + x_distance, y + y_distance] 137 | 138 | 139 | def step(self, obs): 140 | super(StalkerControl, self).step(obs) 141 | if _______ in obs.observation["available_actions"]: 142 | player_relative = obs.observation["feature_screen"][_PLAYER_RELATIVE] 143 | zealot_y, zealot_x = (player_relative == _PLAYER_HOSTILE).nonzero() 144 | if not zealot_y.any(): 145 | return actions.FunctionCall(_NO_OP, []) 146 | index = numpy.argmax(zealot_y) 147 | target = [zealot_x[index], zealot_y[index]] 148 | return actions.FunctionCall(_________, [_NOT_QUEUED]) 149 | elif _SELECT_ARMY in obs.observation["available_actions"]: 150 | return actions.FunctionCall(_SELECT_ARMY, [_SELECT_ALL]) 151 | else: 152 | return actions.FunctionCall(_NO_OP, []) 153 | -------------------------------------------------------------------------------- /Agents/sentry_defense.py: -------------------------------------------------------------------------------- 1 | 2 | from __future__ import absolute_import 3 | from __future__ import division 4 | from __future__ import print_function 5 | 6 | import numpy 7 | from pysc2.agents import base_agent 8 | from pysc2.lib import features 9 | from pysc2.lib import actions 10 | 11 | _PLAYER_RELATIVE = features.SCREEN_FEATURES.player_relative.index 12 | _PLAYER_FRIENDLY = 1 13 | _PLAYER_HOSTILE = 4 14 | _NO_OP = actions.FUNCTIONS.no_op.id 15 | _MOVE_SCREEN = actions.FUNCTIONS.Move_screen.id 16 | _ATTACK_SCREEN = actions.FUNCTIONS.Attack_screen.id 17 | _SELECT_ARMY = actions.FUNCTIONS.select_army.id 18 | _NOT_QUEUED = [0] 19 | _SELECT_ALL = [0] 20 | _FORCE_FIELD = actions.FUNCTIONS.Effect_ForceField_screen.id 21 | 22 | class SentryForceField(base_agent.BaseAgent): 23 | """An agent specifically for solving the ForceField map.""" 24 | 25 | def step(self, obs): 26 | super(SentryForceField, self).step(obs) 27 | if _FORCE_FIELD in obs.observation["available_actions"]: 28 | player_relative = obs.observation["screen"][_PLAYER_RELATIVE] 29 | hydralisk_y, hydralisk_x = (player_relative == _PLAYER_HOSTILE).nonzero() 30 | if not hydralisk_y.any(): 31 | return actions.FunctionCall(_NO_OP, []) 32 | index = numpy.argmax(hydralisk_y) 33 | target = [hydralisk_x[index], hydralisk_y[index]] 34 | return actions.FunctionCall(_FORCE_FIELD, [_NOT_QUEUED, target]) 35 | elif _SELECT_ARMY in obs.observation["available_actions"]: 36 | return actions.FunctionCall(_SELECT_ARMY, [_SELECT_ALL]) 37 | else: 38 | return actions.FunctionCall(_NO_OP, []) 39 | 40 | 41 | 42 | class Sentry(): 43 | '''Defines how the sentry SC2 unit works''' 44 | 45 | 46 | def Force_Field(sentry): 47 | '''Function related with Force Field creation''' 48 | _FORCE_FIELD = actions.FUNCTIONS.Effect_ForceField_screen.id 49 | 50 | 51 | def Guardian_Shield(sentry): 52 | '''Function related with Shield creation''' 53 | _GUARD_FIELD = actions.FUNCTIONS.Effect_GuardianShield_quick.id 54 | 55 | def Hallucinations(sentry): 56 | '''Functions related with Hallucination''' 57 | 58 | _HAL_ADEPT = actions.FUNCTIONS.Hallucination_Adept_quick.id 59 | _HAL_ARCHON = actions.FUNCTIONS.Hallucination_Archon_quick.id 60 | _HAL_COL = actions.FUNCTIONS.Hallucination_Colossus_quick.id 61 | _HAL_DISRUP = actions.FUNCTIONS.Hallucination_Disruptor_quick.id 62 | _HAL_HIGTEM = actions.FUNCTIONS.Hallucination_HighTemplar_quick.id 63 | _HAL_IMN = actions.FUNCTIONS.Hallucination_Immortal_quick.id 64 | _HAL_PHOENIX = actions.FUNCTIONS.Hallucination_Phoenix_quick.id 65 | _HAL_STALKER = actions.FUNCTIONS.Hallucination_Stalker_quick.id 66 | _HAL_VOIDRAID = actions.FUNCTIONS.Hallucination_VoidRay_quick.id 67 | _HAL_ZEALOT = actions.FUNCTIONS.Hallucination_Zealot_quick.id 68 | return actions.FunctionCall(actions.FUNCTIONS.no_op.id, []) 69 | 70 | def Standard_Functions(sentry): 71 | '''Standard Functions related with movements and exploration ''' 72 | _NOOP = actions.FUNCTIONS.no_op.id 73 | _SELECT_POINT = actions.FUNCTIONS.select_point.id 74 | return actions.FunctionCall(actions.FUNCTIONS.no_op.id, []) 75 | 76 | 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | This is an open contributing project 3 | Significant accepted pull request are given authory to any contributions following Apache license and will be noted and named 4 | in any given talk or project citation. 5 | 6 | This project is searching for : 7 | 8 | * Starcraft2 hardcore players and map creators for interviews, creation and feedback. 9 | 10 | * Software developers that can help within agent programming 11 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Issue Template description 2 | =========== 3 | 4 | Context 5 | ------------ 6 | 7 | Describe the context you are working on, it can include : 8 | * op sistem / machine 9 | * level of experience with this library 10 | * Starcraft 2 map designer or agent developer experience 11 | 12 | Problem 13 | ------------ 14 | 15 | Describe the problem you finded with this repo, as this might include : 16 | * what is the goal you want to achieve 17 | * if you didn´t find suitable documentation 18 | 19 | Issue resolution 20 | ------------ 21 | 22 | Please note that you might be asked for some questions in order to solve the issue 23 | 24 | -------------------------------------------------------------------------------- /Images/2C01EB1027814BB7FF16A15272E1B2DEF9FDEEC3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/2C01EB1027814BB7FF16A15272E1B2DEF9FDEEC3.jpg -------------------------------------------------------------------------------- /Images/Captura de pantalla 2017-09-03 a las 12.05.18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/Captura de pantalla 2017-09-03 a las 12.05.18.png -------------------------------------------------------------------------------- /Images/Captura de pantalla 2017-09-08 a las 17.05.07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/Captura de pantalla 2017-09-08 a las 17.05.07.png -------------------------------------------------------------------------------- /Images/Captura de pantalla 2017-09-08 a las 17.48.55.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/Captura de pantalla 2017-09-08 a las 17.48.55.png -------------------------------------------------------------------------------- /Images/Captura de pantalla 2017-09-17 a las 12.58.11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/Captura de pantalla 2017-09-17 a las 12.58.11.png -------------------------------------------------------------------------------- /Images/Captura de pantalla 2017-09-17 a las 12.58.45.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/Captura de pantalla 2017-09-17 a las 12.58.45.png -------------------------------------------------------------------------------- /Images/Captura de pantalla 2017-09-17 a las 13.09.44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/Captura de pantalla 2017-09-17 a las 13.09.44.png -------------------------------------------------------------------------------- /Images/Captura de pantalla 2017-09-18 a las 20.14.14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/Captura de pantalla 2017-09-18 a las 20.14.14.png -------------------------------------------------------------------------------- /Images/Captura de pantalla 2018-01-02 a las 14.51.09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/Captura de pantalla 2018-01-02 a las 14.51.09.png -------------------------------------------------------------------------------- /Images/Captura de pantalla 2018-08-13 a las 15.43.15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/Captura de pantalla 2018-08-13 a las 15.43.15.png -------------------------------------------------------------------------------- /Images/ForceField.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/ForceField.png -------------------------------------------------------------------------------- /Images/ForceField2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/ForceField2.png -------------------------------------------------------------------------------- /Images/HallucinIce.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/HallucinIce.gif -------------------------------------------------------------------------------- /Images/HallucinIce.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/HallucinIce.png -------------------------------------------------------------------------------- /Images/HallucinIceV2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/HallucinIceV2.png -------------------------------------------------------------------------------- /Images/README.md: -------------------------------------------------------------------------------- 1 | Images coming for executing sc2py library 2 | -------------------------------------------------------------------------------- /Images/Reward shaping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/Reward shaping.png -------------------------------------------------------------------------------- /Images/ScoreUpdateVariables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/ScoreUpdateVariables.png -------------------------------------------------------------------------------- /Images/a0031372f617b683f02fe0ae163419ca-sc2-battlechest-product.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/a0031372f617b683f02fe0ae163419ca-sc2-battlechest-product.jpg -------------------------------------------------------------------------------- /Images/change Marines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/change Marines.png -------------------------------------------------------------------------------- /Images/change marine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/change marine.png -------------------------------------------------------------------------------- /Images/change sentry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/change sentry.png -------------------------------------------------------------------------------- /Images/change_units.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/change_units.png -------------------------------------------------------------------------------- /Images/change_units_new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/change_units_new.png -------------------------------------------------------------------------------- /Images/new_init.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/new_init.png -------------------------------------------------------------------------------- /Images/print_screen_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/print_screen_1.png -------------------------------------------------------------------------------- /Images/trigger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/trigger.png -------------------------------------------------------------------------------- /Images/zerling change.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Images/zerling change.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [](https://github.com/SoyGema/Startcraft_pysc2_minigames/blob/master/LICENSE) 3 | [](https://github.com/SoyGema/Startcraft_pysc2_minigames/issues) 4 | [](https://github.com/SoyGema/Startcraft_pysc2_minigames/stargazers) 5 | [](https://github.com/SoyGema/Startcraft_pysc2_minigames/network) 6 | [](https://twitter.com/intent/tweet?text=Pysc2_mini-games_by_@SoyGema:&url=https%3A%2F%2Fgithub.com%2FSoyGema%2FStartcraft_pysc2_minigames) 7 | 8 | # Startcraft PySC2 mini-games and agents 9 | This repository aims to serve as a guide for open source contributing in minigame pysc2 library for Starcraft II 10 | For minigame instalation for execution you should go to [the official repository](https://github.com/deepmind/pysc2) and install requirements 11 | 12 | ## Direct Links 13 | Please, if you want to reach directly mini-games click to the following [link](https://github.com/SoyGema/Startcraft_pysc2_minigames/blob/master/zip/mini-games.zip) 14 | 15 | ## Minigame task description 16 | Minigames come as a controled environments that might be useful to exploit game features in SC2. General purpose learning system for Startcraft 2 can be a daunting task. So there is a logical option in splitting this tasks into minitask in orther to advance in research . Mini-games focus on different elements of Starcraft II Gameplay . 17 | 18 | To investigate elements of the game in isolation, and to provide further fine-grained steps towards playing the full game, Deepmind has built several mini-games. These are focused scenarios on small maps that have been constructed with the purpose of testing a subset of actions and/or game mechanics with a clear reward structure. Unlike the full game where the reward is just win/lose/tie, the reward structure for mini-games can reward particular behaviours (as defined in a corresponding .SC2Map file). 19 | 20 | ## Minigame introduction and Repo information 21 | Before creating a minigame, I encourage you to run the alredy developed ones to see wich task are subdivided into each minigame as the reward function could be important due to the behaviour that leads to learning . The minigame title gives us a description of the goal 22 | You might find in this repo new maps created for investigate in explotation-exploration dilema and some programming about the functions of different units . 23 | 24 | ## SentryDefense , ForceField , HallucinIce and FlowerFields Projects 25 | 26 | In this repo, besides information about current minigames, you will find my own minigames development . 27 | In projects section you can know more about the state of the art and in docs and new_minigames folder you can find the map. 28 | In SentryDefense, a arrowhead TerranVSProtoss Melee is proposed . 29 | In ForceField,an imbalanced situation between Sentry and Zerg units forces sentry to use forcefield, adding terrain disposition. 30 | 31 | 1.- [SentryDefense](https://github.com/SoyGema/Startcraft_pysc2_minigames/tree/master/new_minigames/SentryDefense): Protoss VS Terran Melee. 32 | 33 | 2.- [ForceField](https://github.com/SoyGema/Startcraft_pysc2_minigames/tree/master/new_minigames/SentryForceField): Learn about Sentry forcefield function. 34 | 35 | 3.- [HallucinIce](https://github.com/SoyGema/Startcraft_pysc2_minigames/tree/master/new_minigames/SentryHallucination): Learn how to play with hallucination. 36 | 37 | 4.- [FlowerFields](https://github.com/SoyGema/Startcraft_pysc2_minigames/tree/master/new_minigames/FlowerFields): Defeat protoss photon cannon . 38 | 39 | 5.-[TheRightPath](https://github.com/SoyGema/Startcraft_pysc2_minigames/tree/master/new_minigames/TheRightPath): Move to beacon finding the optimal route collecting minerals and avoiding mines . 40 | 41 | 6.-[RedWaves](https://github.com/SoyGema/Startcraft_pysc2_minigames/tree/master/new_minigames/RedWaves): Choose your race and defend against waves of zerg attacks . 42 | 43 | 7.-[BlueMoon](https://github.com/SoyGema/Startcraft_pysc2_minigames/tree/master/new_minigames/BlueMoon): Choose unit development to defend against protoss development . (under construction) 44 | 45 | 8.-[MicroPrism](https://github.com/SoyGema/Startcraft_pysc2_minigames/tree/master/new_minigames/MicroPrism): Learn how to use Warp Prism in a protoss versus protoss stalker melee 46 | 47 | ## Agents 48 | Regarding scripted agent, there is a python file with several developments. Scriptedagent.py is focused on HallucinIce map in which makes Archon Hallucination. Besides there is another class that put all hallucination actions on a list and the agent chooses randomly in between those actions . 49 | 50 | Q-Learning and DQN agents are provided for HallucinIce minigame with the new PySC2 release 51 | 52 | An A3C trained agent has been tested with several minigames, reaching some of them a local optima . 53 | Please, report problems in issues if you currently find problems . 54 | 55 | ## How to run mini-games in your environment 56 | 57 | 1. Download or clone the repository, or download all minigames clicking here 58 | 59 | 2. Place the .SC2 files into /Applications/StarCraft II/Maps/mini_games/ -sometimes the Map folder might not exist. If so, please create it- 60 | 61 | 3. Go to pysc2\maps\mini_games.py and add to mini-games array the following mini-games names 62 | 63 | ```python 64 | mini_games = [ ## This mini-games names should alredy been in your list 65 | "BuildMarines", # 900s 66 | "CollectMineralsAndGas", # 420s 67 | "CollectMineralShards", # 120s 68 | "DefeatRoaches", # 120s 69 | "DefeatZerglingsAndBanelings", # 120s 70 | "FindAndDefeatZerglings", # 180s 71 | "MoveToBeacon", # 120s ##Now you add this few lines 72 | "SentryDefense", # 120s 73 | "ForceField", # 30s 74 | "HallucinIce", # 30s 75 | "FlowerFields", # 60s 76 | "TheRightPath", # 300s 77 | "RedWaves", # 180s 78 | "BlueMoon", # 60s 79 | "MicroPrism", # 45s 80 | ] 81 | ``` 82 | 4. In your console, you can type the mini-game map name 83 | 84 | ```console 85 | my-computer:~ me$ python -m pysc2.bin.agent --map FlowerFields 86 | ``` 87 | 88 | 89 | #### Tutorial 90 | Find an ongoing tutorial about how to create your own mini-game [here](https://github.com/SoyGema/Startcraft_pysc2_minigames/tree/master/docs) 91 | 92 | #### Other repository 93 | With features with map placement [here](https://github.com/ttinies/sc2gameMapRepo) 94 | 95 | 96 | 97 | 'Making a reward function isn’t that difficult. The difficulty comes when you try to design a reward function that encourages the behaviors you want while still being learnable.' 98 | -Deep Reinforcement Learning Doesn´t work yet , Alex Irpan [post](https://www.alexirpan.com/2018/02/14/rl-hard.html)- 99 | -------------------------------------------------------------------------------- /RL/README.md: -------------------------------------------------------------------------------- 1 | Notes and references about reinforcement learning for pySC2 2 | 3 | -------------------------------------------------------------------------------- /Replays/DefeatRoaches_2017-09-08-13-59-49.SC2Replay: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/Replays/DefeatRoaches_2017-09-08-13-59-49.SC2Replay -------------------------------------------------------------------------------- /Replays/README.md: -------------------------------------------------------------------------------- 1 | Replays for DefeatRoaches 2 | -------------------------------------------------------------------------------- /SentryDefense.SC2Map: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoyGema/Startcraft_pysc2_minigames/dc0ece73a98cc3419757df1ee39d3fbea07270b1/SentryDefense.SC2Map -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Startcraft Pysc2 Deepmind mini games creation 4 | This file aims to serve as a guide for opensource contributing in minigame pysc2 library for Artificial Intelligence reserach. In this document we will execute and change the map 'DefeatRoaches' for a 'DefeatWhatever' or some minor changes you could do in the StarCraft II editor for designing our own mini-battle 5 | 6 | For minigame instalation for execution you should go to the  and install requirements 7 | 8 | ## Mini game task description 9 | Mini games come as a controled environments that might be useful to exploit game features in SC2. General purpose learning system for Startcraft 2 can be a daunting task. So there is a logical option in splitting this tasks into minitask in orther to advance in research . 10 | To investigate elements of the game in isolation, and to provide further fine-grained steps towards playing the full game, Deepmind has built several mini-games. These are focused scenarios on small maps that have been constructed with the purpose of testing a subset of actions and/or game mechanics with a clear reward structure. Unlike the full game where the reward is just win/lose/tie, the reward structure for mini-games can reward particular behaviours (as defined in a corresponding .SC2Map file). 11 | 12 | ## Mini game introduction 13 | Before creating a minigame, I encourage you to run the alredy developed ones to see wich task are subdivided into each minigame as the design could be important . The minigame title gives us a description of the goal 14 | Find bellow the exploration of DefeatRoaches mini-game map 15 | 16 | ## From DefeatRoaches to Defeat'Whatever' 17 | 18 | #### Description 19 | 20 | A map with 9 Marines and a group of 4 Roaches on opposite sides. Rewards are earned by using the Marines to defeat Roaches, with optimal combat strategy requiring the Marines to perform focus fire on the Roaches. Whenever all 4 Roaches have been defeated, a new group of 4 Roaches is spawned and the player is awarded 5 additional Marines at full health, with all other surviving Marines retaining their existing health (no restore). Whenever new units are spawned, all unit positions are reset to opposite sides of the map. 21 | 22 | #### Initial State ---------> Transformation UNIT CHANGE 23 | 24 | * 9 Marines in a vertical line at a random side of the map (preselected) -------> 9 sentry 25 | * 4 Roaches in a vertical line at the opposite side of the map from the -------> 4 zerlings 26 | Marines 27 | 28 | #### Rewards --------------> Transformation REWARD SHAPPING 29 | 30 | * Roach defeated: +10 ---------> Zerlings defeated : +5 31 | * Marine defeated: -1 ---------> Sentry defeated : -5 32 | 33 | #### End Conditions 34 | 35 | * Time elapsed 36 | * All Marines defeated ---------> Sentry 37 | 38 | #### Time Limit. ------------> Transformation TIME LIMIT 39 | 40 | * 120 seconds 41 | 42 |  43 | 44 | This is a human interpretable view of the game on the left, and coloured versions of the feature layers on the right. Find in top left described the actions 45 | *a-Attack 46 | *d-Stop 47 | *m-Move 48 | *p-MovePatrol 49 | *t-MoveHoldPosition 50 | Green circles are used to define player1(terran) and red circles correspond to player2(roaches) 51 | This abstraction might be useful for CNN training 52 | 53 | 54 | ## 1. Defeat Roaches Test Map 55 | 56 | Two different type of agents have been executed in this minimap. As a matter of results, you can find bellow listed the difference in between them 57 | 58 | #### Experiment 1 59 | 60 | DefeatRoaches minigame map random agent 61 | 62 | ```shell 63 | $ python3 -m pysc2.bin.agent --map DefeatRoaches 64 | ``` 65 | 66 |