Exemplo n.º 1
0
    def update_population(self):
        # update population
        self.probe_num = self.mineral_worker_nums + self.gas_worker_nums
        self.army_nums = self.military_num()

        if type(P.Zealot()) in self.creatures_list.keys():
            self.zealot_num = self.creatures_list[type(P.Zealot())]
        else:
            self.zealot_num = 0
        if type(P.Stalker()) in self.creatures_list.keys():
            self.Stalker_num = self.creatures_list[type(P.Stalker())]
        else:
            self.Stalker_num = 0

        self.food_used = self.zealot_num * 2 + \
            self.Stalker_num * 2 + \
            self.probe_num * 1
Exemplo n.º 2
0
    def step(self, action):
        if action == ProtossAction.Build_worker.value:
            if self.mineral >= 50 and self.food_used < self.food_cap:
                self.mineral_worker_nums += 1
                self.food_used += 1
                self.mineral -= 50
        elif action == ProtossAction.Build_zealot.value:
            Zealot = P.Zealot()
            if self.fullfill_creature_condition(Zealot):
                n = self.get_build_num(Zealot)
                self.army_nums += n
                self.zealot_num += n
                self.food_used += Zealot.food_used * n
                self.mineral -= Zealot.mineral_price * n
                self.add_unit(Zealot, n)
        elif action == ProtossAction.Build_pylon.value:
            if self.mineral >= 100:
                self.building_nums += 1
                self.food_cap += 8
                self.pylon_num += 1
                self.mineral -= 100
        elif action == ProtossAction.Build_gateway.value:
            if self.mineral >= 150 and self.pylon_num >= 1:
                self.gateway_num += 1
                self.building_nums += 1
                self.mineral -= 150
        elif action == ProtossAction.Attack.value:
            if self.military_num() > 0:
                #print('order:', self.env.army[self.player_id].order)
                self.env.army[self.player_id].order = Army.Order.ATTACK
                #print('order:', self.env.army[self.player_id].order)

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

        # update mineral
        self.collected_mineral += min(self.mineral_worker_nums, 16) * 3
        if self.collected_mineral <= 10000:
            self.mineral += min(self.mineral_worker_nums, 16) * 3

        self.time_seconds += 5

        # update population
        if self.military_num() == 0:
            #print('order:', self.env.army[self.player_id].order)
            self.env.army[self.player_id].order = Army.Order.NOTHING
            #print('order:', self.env.army[self.player_id].order)
        else:
            self.army_nums = self.military_num()
            self.zealot_num = self.military_num()
            self.food_used = self.military_num(
            ) * 2 + self.mineral_worker_nums + self.gas_worker_nums
Exemplo n.º 3
0
def battle_test():
    red_agent = Protoss()
    blue_agent = Terran()
    red_agent.add_unit(P.Zealot(), 12)
    blue_agent.add_unit(T.Marine(), 1)
    blue_agent.add_building(T.Commandcenter(), 1)
    blue_agent.add_building(T.Supplydepot(), 5)
    blue_agent.add_building(T.Barracks(), 2)
    bf = BattleField(red_agent=red_agent, blue_agent=blue_agent)
    for i in range(10):
        bf.battle()
Exemplo n.º 4
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()
Exemplo n.º 5
0
    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