Exemple #1
0
    def update_buildings(self):
        self.building_nums = self.building_num()

        if type(P.Pylon()) in self.building_list.keys():
            self.pylon_num = self.building_list[type(P.Pylon())]
        else:
            self.pylon_num = 0

        if type(P.Gateway()) in self.building_list.keys():
            self.gateway_num = self.building_list[type(P.Gateway())]
        else:
            self.gateway_num = 0

        if type(P.Assimilator()) in self.building_list.keys():
            self.Assimilator_num = self.building_list[type(P.Assimilator())]
        else:
            self.Assimilator_num = 0

        if type(P.CyberneticsCore()) in self.building_list.keys():
            self.CyberneticsCore_num = self.building_list[type(
                P.CyberneticsCore())]
        else:
            self.CyberneticsCore_num = 0

        self.food_cup = self.pylon_num * 8 + \
            self.Nexus_num * 15
Exemple #2
0
    def step(self, action):
        if action == ProtossAction.Build_probe.value:
            Probe = P.Probe()
            if self.fullfill_creature_condition(Probe):
                self.caclulate_resources(Probe)
                self.build_from_nexus(Probe)

        elif action == ProtossAction.Build_zealot.value:
            Zealot = P.Zealot()
            if self.fullfill_creature_condition(Zealot):
                self.caclulate_resources(Zealot)
                #self.add_unit(Zealot, 1)
                self.build_from_gateway(Zealot)

        elif action == ProtossAction.Build_Stalker.value:
            Stalker = P.Stalker()
            if self.fullfill_creature_condition(Stalker):
                self.caclulate_resources(Stalker)
                #self.add_unit(Stalker, 1)
                self.build_from_gateway(Stalker)

        elif action == ProtossAction.Build_pylon.value:
            Pylon = P.Pylon()
            if self.fullfill_building_condition(Pylon):
                self.caclulate_resources(Pylon)
                self.init_building(Pylon)

        elif action == ProtossAction.Build_gateway.value:
            Gateway = P.Gateway()
            if self.fullfill_building_condition(Gateway):
                self.caclulate_resources(Gateway)
                self.init_building(Gateway)

        elif action == ProtossAction.Build_Assimilator.value:
            Assimilator = P.Assimilator()
            if self.fullfill_building_condition(Assimilator):
                self.caclulate_resources(Assimilator)
                self.init_building(Assimilator)

        elif action == ProtossAction.Build_CyberneticsCore.value:
            CyberneticsCore = P.CyberneticsCore()
            if self.fullfill_building_condition(CyberneticsCore):
                self.caclulate_resources(CyberneticsCore)
                self.init_building(CyberneticsCore)

        elif action == ProtossAction.Attack.value:
            if self.military_num() > 0:
                self.env.army[self.player_id].order = Army.Order.ATTACK

        elif action == ProtossAction.Retreat.value:
            if self.military_num() > 0:
                self.env.army[self.player_id].order = Army.Order.DEFEND

        self.update()
Exemple #3
0
    def get_empty_gateway(self):
        min_produce_len = 5
        min_building = None

        for b in self.production_building_list:
            if type(b) == type(P.Gateway()):
                produce_len = b.queue.size()
                if produce_len < min_produce_len:
                    min_produce_len = produce_len
                    min_building = b

        return min_building
Exemple #4
0
    def get_empty_gateway(self):
        min_produce_len = MIN_PRODUCE_LEN  # default is 5, this is represent module N_6:Production queue
        min_building = None

        for b in self.production_building_list:
            if type(b) == type(P.Gateway()):
                produce_len = b.queue.size()
                if produce_len < min_produce_len:
                    min_produce_len = produce_len
                    min_building = b

        return min_building
    def calculate_features(self):
        state = self.obs
        myunits = state.units[state.player_id]

        self.mineral_worker_nums = 0
        self.gas_worker_nums = 0

        self.spent_mineral = 0
        self.spent_gas = 0

        self.probe_num = 0
        self.zealot_num = 0
        self.Stalker_num = 0
        self.army_nums = 0

        self.gateway_num = 0
        self.pylon_num = 0
        self.Assimilator_num = 0
        self.CyberneticsCore_num = 0

        for unit in myunits:
            if unit.type == T.Protoss_Probe:
                self.spent_mineral += P.Probe().mineral_price
                if unit.completed:
                    self.probe_num += 1
                    if unit.gathering_minerals:
                        self.mineral_worker_nums += 1
                    if unit.gathering_gas:
                        self.gas_worker_nums += 1
            if unit.type == T.Protoss_Zealot:
                self.spent_mineral += P.Zealot().mineral_price
                if unit.completed:
                    if unit.visible:
                        self.zealot_num += 1
                        self.army_nums += 1
                    else:
                        print('find invisible Zealot')
            if unit.type == T.Protoss_Dragoon:
                self.spent_mineral += P.Stalker().mineral_price
                self.spent_gas += P.Stalker().gas_price
                if unit.completed:
                    if unit.visible:
                        self.Stalker_num += 1
                        self.army_nums += 1
                    else:
                        print('find invisible Dragoon')
            if unit.type == T.Protoss_Pylon:
                self.spent_mineral += P.Pylon().mineral_price
                if unit.completed:
                    self.pylon_num += 1
            if unit.type == T.Protoss_Gateway:
                self.spent_mineral += P.Gateway().mineral_price
                if unit.completed:
                    self.gateway_num += 1
            if unit.type == T.Protoss_Assimilator:
                self.spent_mineral += P.Assimilator().mineral_price
                if unit.completed:
                    self.Assimilator_num += 1
            if unit.type == T.Protoss_Cybernetics_Core:
                self.spent_mineral += P.CyberneticsCore().mineral_price
                if unit.completed:
                    self.CyberneticsCore_num += 1

        self.mineral = state.frame.resources[state.player_id].ore
        self.gas = state.frame.resources[state.player_id].gas
        self.food_used = state.frame.resources[state.player_id].used_psi
        self.food_cup = state.frame.resources[state.player_id].total_psi