예제 #1
0
 def test_print_enviorment(self):
     value = 82 * 82
     list = []
     for i in range(value):
         list.append(random.randint(0, 1))
     assert len(list) == value
     BuildFacade.print_enviroment(self, list)
예제 #2
0
 def test_build_model(self):
     n_list = np.full((82, 82), 0)
     for i in range(41, 44):
         for j in range(41, 44):
             n_list[i][j] = 345
     list = BuildModelLocations.set_building_location(self, n_list)
     n_list = BuildFacade.build_model(self, list)
     assert len(list) == 3
     for list_value in n_list:
         assert len(n_list[list_value]) == 3
예제 #3
0
 def test_the_flatte_uneven_length(self):
     list = [[1, 2], [1, 2, 3]]
     n_list = BuildFacade.flatten_values(self, list)
     assert n_list == [1, 2, 1, 2, 3]
     print("Value did change")
예제 #4
0
 def test_flatten_uneven_length(self):
     list = [[1, 2, 3], [1, 2]]
     n_list = BuildFacade.flatten_values(self, list)
     assert n_list == [1, 2, 3, 1, 2]
     print("The list is the flatten")
예제 #5
0
 def test_method_if_list_if_the_method_is_one(self):
     list = [[1], [1]]
     n_list = BuildFacade.flatten_values(self, list)
     assert n_list == [1, 1]
     print("The list is of same size ")
예제 #6
0
 def test_method_to_be_empty(self):
     list = [[], []]
     n_list = BuildFacade.flatten_values(self, list)
     assert n_list == []
     print("The value for the list is an empty list")
예제 #7
0
 def test_check_value_of_map_to_be_single(self):
     list = [[1, 3, 4], [2, 3, 5]]
     n_list = BuildFacade.flatten_values(self, list)
     assert n_list == [1, 3, 4, 2, 3, 5]
     print("The value was then flattend")
예제 #8
0
 def test_stacked_value(self):
     list = [1]
     n_list = BuildFacade.stacked_enviorment(self, list)
     assert len(list) == 4
    def step(self, obs, epsilon, episode):
        super(AiBot, self).step(obs)
        self.epsilon = epsilon
        self.episode = episode

        # first step
        if obs.first():
            # Räknaren resettas inte mellan games/episoder. Vet ej om detta är en bra lösning.
            self.steps = 0
            start_y, start_x = (obs.observation.feature_minimap.player_relative
                                == features.PlayerRelative.SELF).nonzero()
            xmean = start_x.mean()
            ymean = start_y.mean()

            self.base_location = (xmean, ymean)

            if xmean <= 31 and ymean <= 31:
                self.start_top = True
                self.attack_coordinates = Coordinates.START_LOCATIONS[1]
                self.base_location = Coordinates.START_LOCATIONS[0]
            else:
                self.start_top = False
                self.attack_coordinates = Coordinates.START_LOCATIONS[0]
                self.base_location = Coordinates.START_LOCATIONS[1]

            self.game_state = State(self)

        HelperClass.find_the_camera_postion(self, obs)

        if HelperClass.check_building_at_position(
                self, obs,
                Buildsingelton().get_location()):
            HelperClass.move_camera_to_base_location(self, obs)
            self.build_States = BuildFacade.set_up(self, obs,
                                                   self.base_location)

            self.build_state_reward = self.build_States[0][0]
            self.build_state = self.build_States[0][1]
            Buildsingelton().set_location(self.build_state)

            self.action_state = self.build_States[0][2]

            self.old_score = self.build_States[1]

            self.build_state = self.build_States[2]
            self.build_space = len(self.build_state)

            #self.build_network = BuildNetwork(self.build_state_reward,self.build_state, self.action_state, epsilon)

            #BuildNetwork.predict_neural_network(self.build_network, self.build_States)

        self.build_location = Buildsingelton().get_location()

        action = [actions.FUNCTIONS.no_op()]

        if self.reqSteps == 0 or self.reqSteps == -1:
            self.earlier_action = self.next_action
            self.next_action = Selector.selector(self, obs)

        if self.next_action == "updateState":
            self.game_state.update_state(self, obs)
            action = ActionSingleton().get_action()

        if self.next_action == "expand":
            BuildOrdersController.build_expand(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_scv":  # build scv
            UnitBuildOrdersController.build_scv(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "distribute_scv":  # Har inte gjort någon controller än
            if self.reqSteps == 0:
                self.DistributeSCVInstance = DistributeSCV()
            self.DistributeSCVInstance.distribute_scv(self, obs,
                                                      self.base_location)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_supply_depot":  # build supply depot
            BuildOrdersController.build_supply_depot(self, obs,
                                                     self.build_location)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_barracks":
            BuildOrdersController.build_barracks(self, obs,
                                                 self.build_location)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_refinery":
            BuildOrdersController.build_refinery(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "return_scv":
            BuildOrdersController.return_scv(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_marine":
            UnitBuildOrdersController.train_marines(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_marauder":
            UnitBuildOrdersController.train_marauder(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_reaper":
            UnitBuildOrdersController.train_reaper(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_hellion":
            UnitBuildOrdersController.train_hellion(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_medivac":
            UnitBuildOrdersController.train_medivac(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_viking":
            UnitBuildOrdersController.train_viking(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "army_count":
            ArmyControlController.count_army(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "attack":
            ArmyControlController.attack(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_factory":
            BuildOrdersController.build_factory(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_starport":
            BuildOrdersController.build_starport(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "build_tech_lab_barracks":
            BuildOrdersController.build_tech_lab_barracks(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "retreat":
            ArmyControlController.retreat(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "scout":
            ArmyControlController.scout(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "transform_vikings_to_ground":
            ArmyControlController.transform_vikings_to_ground(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "transform_vikings_to_air":
            ArmyControlController.transform_vikings_to_air(self, obs)
            action = ActionSingleton().get_action()

        elif self.next_action == "no_op":
            HelperClass.no_op(self, obs)
            action = ActionSingleton().get_action()

        return action[0]