From cd23340c1c0f0631bd199c04db8c91957612eb47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=89=E1=85=A9=E1=86=BC=E1=84=92=E1=85=A9=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=AB?= Date: Thu, 4 Jan 2018 15:36:16 +0900 Subject: [PATCH] fix xy_per_marine #1 --- {defeat_zerglings => common}/common.py | 0 common/vec_env/subproc_vec_env.py | 20 +++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) rename {defeat_zerglings => common}/common.py (100%) diff --git a/defeat_zerglings/common.py b/common/common.py similarity index 100% rename from defeat_zerglings/common.py rename to common/common.py diff --git a/common/vec_env/subproc_vec_env.py b/common/vec_env/subproc_vec_env.py index 258d177..c740803 100644 --- a/common/vec_env/subproc_vec_env.py +++ b/common/vec_env/subproc_vec_env.py @@ -8,7 +8,7 @@ _PLAYER_RELATIVE = features.SCREEN_FEATURES.player_relative.index _SELECTED = features.SCREEN_FEATURES.selected.index -from defeat_zerglings import common +from common import common def worker(remote, map_name, i): @@ -21,6 +21,7 @@ def worker(remote, map_name, i): available_actions = None result = None group_list = [] + xy_per_marine = {} while True: cmd, data = remote.recv() if cmd == 'step': @@ -38,12 +39,12 @@ def worker(remote, map_name, i): action1 = data[0][0] action2 = data[0][1] func = actions.FUNCTIONS[action1[0]] - #print("agent(",i," ) action : ", action1, " func : ", func) + # print("agent(",i," ) action : ", action1, " func : ", func) func = actions.FUNCTIONS[action2[0]] #print("agent(",i," ) action : ", action2, " func : ", func, "xy :", action2[1][1]) x, y = action2[1][1] move = True - if (x == 0 and y == 0): + if (x == -1 and y == -1): move = False result = env.step(actions=[action1]) reward += result[0].reward @@ -64,6 +65,7 @@ def worker(remote, map_name, i): # extra = np.zeros((1, 32, 32)) control_groups = result[0].observation["control_groups"] army_count = env._obs[0].observation.player_common.army_count + # extra[0,0,0] = army_count # for id, group in enumerate(control_groups): # control_group_id = id @@ -90,6 +92,18 @@ def worker(remote, map_name, i): # reward = result[0].reward # done = result[0].step_type == environment.StepType.LAST info = result[0].observation["available_actions"] + + group_id = action1[1][1][0] + # print("group_id:", group_id) + + player_y, player_x = (result[0].observation["screen"][_SELECTED] == 1).nonzero() + + if (len(player_x) > 0): + if (group_id == 1): + xy_per_marine["1"] = [int(player_x.mean()), int(player_y.mean())] + else: + xy_per_marine["0"] = [int(player_x.mean()), int(player_y.mean())] + remote.send((ob, reward, done, info, army_count, control_groups, selected, xy_per_marine)) elif cmd == 'reset':