def step(self, obs):
        super(Overmind, self).step(obs)

        if (not self.loaded):
            self.loaded = True
            self.homeHatch = self.get_buildings(obs, units.Zerg.Hatchery)[0]
            self.model = ks.models.load_model(
                "C:\\Users\\Charlie\Models\\Conv2D-noobs - 1st Gen")
            return FUNCTIONS.move_camera(
                [const.MiniMapSize().x / 2,
                 const.MiniMapSize().y / 2])

        # If nothing to macro
        # if obs.observation.player['food_army'] < 10:
        #     function = self.macro(obs)
        #     print(function)
        #     return function

        T = Translator()

        tFeatureLayers = T.translate_feature_layers(
            T.crop_feature_layers(obs.observation.feature_screen[0],
                                  obs.observation.feature_screen,
                                  const.ScreenSize().x,
                                  const.ScreenSize().y))

        featureLayers = (np.moveaxis((np.array(tFeatureLayers)), 0,
                                     2)).reshape(-1,
                                                 const.ScreenSize().x,
                                                 const.ScreenSize().y, 12)
        prediction = self.model.predict(featureLayers)[0]
        action = translate(obs, prediction)
        print(action[0])
        for pred in prediction:
            print(pred)
        if (action[0] in obs.observation.available_actions):
            return actions.FunctionCall(action[0], action[1:])
        else:
            print("No-op, Switching to Macro:")
            function = self.macro(obs)
            print(function)
            return function
Example #2
0
    def step(self, time_step, info, act):
        #print(time_step.observation.camera_position)

        # Screen is double world units so center point would be worldSize
        self.cam_pos_offset = [
            (time_step.observation.camera_position[0] - const.WorldSize().x),
            (time_step.observation.camera_position[1] - const.WorldSize().y)
        ]
        # print(time_step.observation.camera_position)
        # print(self.cam_pos_offset)
        # print(act.arguments)
        # print(time_step.observation.camera_position - self.cam_pos_offset)
        # print (act)
        # print (self.cam_pos_offset)
        # print("\n")
        state = {
            "action": [self.extract_args(int(act.function), act.arguments)]
        }
        #print(act.function)
        #print(state["action"])
        if ("Unknown" in state["action"][0]):
            return 0
        print(state["action"])
        height_map = time_step.observation.feature_screen[0]
        #Remove all Zero lines
        height_map = height_map[~np.all(height_map == 0, axis=1)]
        #Remove all Zeros in remaining lines
        height_map = [x[x != 0] for x in height_map]

        height = 0
        width = 0
        for x in height_map:
            output = ""
            width = 0
            for i in x:
                output += str(i)
                output += ""
                width += 1
            #print(output)
            height += 1
        #print("\n")
        #print("W: {} H: {}".format(width, height))
        # print("width: ")
        # print(width)
        # print("height: ")
        # print(height)
        #print("\n")
        #return
        # print("Start")
        # print(datetime.datetime.now().time())
        #return sc_action.FUNCTIONS.move_camera([const.MiniMapSize().x / 2, const.MiniMapSize().y / 2])
        #return sc_action.FUNCTIONS.no_op()
        T = Translator()

        tFeatureLayers = T.translate_feature_layers(
            T.crop_feature_layers(time_step.observation.feature_screen[0],
                                  time_step.observation.feature_screen, width,
                                  height))

        state["feature_layers"] = tFeatureLayers
        # print("End")
        # print(datetime.datetime.now().time())
        # for y in tFeatureLayers:
        #    for x in y:
        #        output = ""
        #        for i in x:
        #            output+=str(i)
        #        print(output)
        #    print("\n")

        #[0 "height_map",
        # 1 "visibility_map",
        # 2 "creep",
        # 3 "power",
        # 4 "player_id",
        # 5 "player_relative",
        # 6 "unit_type",
        # 7 "selected",
        # 8 "unit_hit_points",
        # 9 "unit_hit_points_ratio",
        # 10"unit_energy",
        # 11"unit_energy_ratio",
        # 12"unit_shields",
        # 13"unit_shields_ratio",
        # 14"unit_density",
        # 15"unit_density_aa",
        # 16"effects"]

        return state