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()
def update_population_progress(self): for b in self.production_building_list: if not b.queue.isEmpty(): unit = b.queue.first_item() unit.progress += self.time_for_one_step if unit.progress >= unit.build_time and self.fullfill_food_condition(unit): u = b.queue.dequeue() if type(u) == type(P.Probe()): self.manage_workers() else: self.add_unit(u)
def update_population_progress(self): for b in self.production_building_list: if not b.queue.isEmpty(): unit = b.queue.first_item() unit.progress += self.time_for_one_step if self.fullfill_food_condition(unit) and ( True ): # default is unit.progress >= unit.build_time, this is represent module N_5:Production time u = b.queue.dequeue() if type(u) == type(P.Probe()): self.manage_workers() else: self.add_unit(u)
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