Commit 6f2164d5 authored by m1ndgames's avatar m1ndgames

update

parent 3ff7fbd4
......@@ -42,8 +42,8 @@ class Ressources():
worker = self.bot.select_build_worker(vg.position)
if worker is None:
break
self.bot.do(worker.build(race_gas[self.bot.race], vg))
if not self.bot.already_pending(race_gas[self.bot.race]):
self.bot.do(worker.build(race_gas[self.bot.race], vg))
async def manageWorkers(self):
"""Creates and assigns workers"""
......
from sc2.constants import *
from sc2 import race_worker
class BanelingSpam:
"""Zerg BanelingSpam"""
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'baneling_spam'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 0
async def Run(self):
"""Runs on every GameStep"""
await self.Macro()
await self.Micro()
async def Macro(self):
"""Macro Routine"""
if self.bot.vespene <= 200:
await self.bot.ressources.createGas()
await self.bot.unitmanager.createUnit("Zergling", 100)
await self.bot.unitmanager.trainSkill("RESEARCH_ZERGLINGMETABOLICBOOST")
if self.bot.structures(UnitTypeId.LAIR).ready:
zerglings = self.bot.units(UnitTypeId.ZERGLING).ready
if zerglings.amount >= 20:
await self.bot.unitmanager.createUnit("Baneling", 10)
if self.bot.townhalls.ready.amount >= 2:
await self.bot.unitmanager.createUnit("Queen", self.bot.townhalls.ready.amount)
await self.bot.unitmanager.trainSkill("RESEARCH_CENTRIFUGALHOOKS")
await self.bot.warmanager.expand()
# Send a worker scout
if self.bot.units(race_worker[self.bot.race]).ready and not self.workerscout:
worker = self.bot.units(race_worker[self.bot.race]).ready.first
if worker:
self.workerscout = True
await self.bot.warmanager.scout(worker)
async def Micro(self):
# zergling
zerglings = self.bot.units(UnitTypeId.ZERGLING).ready
if zerglings:
for zergling in zerglings:
enemies = self.bot.enemy_units
if enemies:
closeenemies = enemies.closer_than(30, zergling)
if closeenemies:
for e in closeenemies:
if not self.bot.techtree.can_attack(zergling, e):
closeenemies.remove(e)
if not closeenemies:
break
next_enemy = closeenemies.closest_to(zergling)
if not next_enemy:
break
distance2enemy = zergling.position.distance_to(next_enemy.position)
if distance2enemy < 20:
self.bot.do(zergling.attack(next_enemy))
structures = self.bot.enemy_structures
if structures and not enemies:
closestructures = structures.closer_than(30, zergling)
if closestructures:
for e in closestructures:
if not self.bot.techtree.can_attack(zergling, e):
closestructures.remove(e)
if not closestructures:
break
next_structure = closestructures.closest_to(zergling)
if not next_structure:
break
distance2structure = zergling.position.distance_to(next_structure.position)
if distance2structure < 20:
self.bot.do(zergling.attack(next_structure))
# baneling
banelings = self.bot.units(UnitTypeId.BANELING).ready
if banelings:
for baneling in banelings:
enemies = self.bot.enemy_units
if enemies:
closeenemies = enemies.closer_than(30, baneling)
if closeenemies:
for e in closeenemies:
if not self.bot.techtree.can_attack(baneling, e):
closeenemies.remove(e)
if not closeenemies:
break
next_enemy = closeenemies.closest_to(baneling)
if not next_enemy:
break
distance2enemy = baneling.position.distance_to(next_enemy.position)
if distance2enemy < 20:
self.bot.do(baneling.attack(next_enemy))
structures = self.bot.enemy_structures
if structures and not enemies:
closestructures = structures.closer_than(30, baneling)
if closestructures:
for e in closestructures:
if not self.bot.techtree.can_attack(baneling, e):
closestructures.remove(e)
if not closestructures:
break
next_structure = closestructures.closest_to(baneling)
if not next_structure:
break
distance2structure = baneling.position.distance_to(next_structure.position)
if distance2structure < 20:
self.bot.do(baneling.attack(next_structure))
if distance2structure <= 3:
abilities = await self.bot.get_available_abilities(baneling)
if AbilityId.EXPLODE_EXPLODE in abilities:
self.bot.do(baneling(AbilityId.EXPLODE_EXPLODE))
# queen
queens = self.bot.units(UnitTypeId.QUEEN).ready
if queens:
for queen in queens:
nearhq = self.bot.townhalls.closer_than(10, queen.position)
if nearhq:
abilities = await self.bot.get_available_abilities(queen)
if AbilityId.EFFECT_INJECTLARVA in abilities:
self.bot.do(queen(AbilityId.EFFECT_INJECTLARVA, nearhq[0]))
else:
hqs = self.bot.townhalls
for hq in hqs:
nearqueen = queens.closer_than(5, hq)
if nearqueen:
hqs.remove(hq)
if hqs:
self.bot.do(queen.move(hqs[0].position))
break
from sc2.constants import *
from sc2 import race_worker
from sc2 import race_gas
class ZerglingRush:
"""Zerg ZerglingRush"""
......@@ -20,6 +20,14 @@ class ZerglingRush:
async def Macro(self):
"""Macro Routine"""
await self.bot.unitmanager.createUnit("Zergling", 100)
zerglings = self.bot.units(UnitTypeId.ZERGLING).ready
if not self.bot.structures(race_gas[self.bot.race]) and zerglings.amount >= 10:
await self.bot.ressources.createGas()
await self.bot.unitmanager.trainSkill("RESEARCH_ZERGLINGMETABOLICBOOST")
await self.bot.unitmanager.trainSkill("RESEARCH_ZERGLINGADRENALGLANDS")
if self.bot.townhalls.ready.amount >= 3:
await self.bot.unitmanager.createUnit("Queen", self.bot.townhalls.ready.amount)
......@@ -56,6 +64,33 @@ class ZerglingRush:
if distance2enemy < 20:
self.bot.do(zergling.attack(next_enemy))
nx = self.bot.townhalls.ready.closest_to(zergling)
if not nx:
break
nxdistance = zergling.position.distance_to(nx.position)
if nxdistance < 10:
break
structures = self.bot.enemy_structures
if structures and not enemies:
closestructures = structures.closer_than(30, zergling)
if closestructures:
for e in closestructures:
if not self.bot.techtree.can_attack(zergling, e):
closestructures.remove(e)
if not closestructures:
break
next_structure = closestructures.closest_to(zergling)
if not next_structure:
break
distance2structure = zergling.position.distance_to(next_structure.position)
if distance2structure < 20:
self.bot.do(zergling.attack(next_structure))
# queen
queens = self.bot.units(UnitTypeId.QUEEN).ready
if queens:
......
......@@ -17102,7 +17102,16 @@
"Biological",
"Structure"
],
"abilities": [],
"abilities": [
{
"ability": 1482,
"requirements": [
{
"building": 100
}
]
}
],
"size": 0,
"radius": 1.8125,
"accepts_addon": false,
......
......@@ -105,6 +105,15 @@ class TechTree():
if 'requirements' in ability:
return ability['requirements']
def get_skill_buildRequirement(self, skillname):
if skillname:
skillid = self.get_id_from_name(skillname)
for unit in self.unit:
for ability in unit['abilities']:
if ability['ability'] == skillid:
if 'requirements' in ability:
return ability['requirements']
def get_building_morphbuilding(self, buildingid):
if buildingid:
# ORBITALCOMMAND ID = 132
......
......@@ -10,6 +10,16 @@ class UnitManager():
"""Builds everything required for an Abiltiy"""
skillid = self.bot.techtree.get_id_from_name(skillname)
trainbuilding = self.bot.techtree.get_trainBuilding(skillname)
skillrequirements = self.bot.techtree.get_skill_buildRequirement(skillname)
if skillrequirements:
for requirement in skillrequirements:
if 'building' in requirement:
buildingid = UnitTypeId(requirement['building'])
elif 'addon' in requirement:
buildingid = UnitTypeId(requirement['addon'])
buildingname = self.bot.techtree.get_name_from_id(buildingid.value)
await self.createBuilding(buildingname, 1, self.bot.hq_location)
if not self.bot.structures(trainbuilding).exists:
buildingname = self.bot.techtree.get_name_from_id(trainbuilding.value)
await self.createBuilding(buildingname, 1, self.bot.hq_location)
......@@ -34,7 +44,6 @@ class UnitManager():
if unitcount < count:
if trainbuilding:
if self.bot.can_afford(trainunittype):
# Protoss specific
if self.bot.race_self == 'Protoss' and trainbuilding.name == 'GATEWAY':
if self.bot.structures(UnitTypeId.WARPGATE).ready:
......@@ -62,7 +71,6 @@ class UnitManager():
observersiege = self.bot.units(UnitTypeId.OBSERVERSIEGEMODE).ready
allobservers = observers | observersiege
if allobservers:
print("allobservers: " + str(allobservers.amount))
if allobservers.amount >= count:
return
......@@ -85,6 +93,7 @@ class UnitManager():
else:
trainbuildingid = trainbuilding.value
trainbuildingname = self.bot.techtree.get_name_from_id(trainbuildingid)
# Zerg specific
if trainbuildingname == "Larva":
unitid = self.bot.techtree.get_id_from_name(unitname)
......@@ -105,6 +114,31 @@ class UnitManager():
if self.bot.can_afford(unitid):
print("Training: " + str(unitname))
self.bot.do(larvas.random.train(unitid))
elif trainbuildingname == "Zergling":
zerglings = self.bot.units(UnitTypeId.ZERGLING).ready
if not zerglings:
await self.createUnit("Zergling", 1)
return
unitid = self.bot.techtree.get_id_from_name(unitname)
buildingname = None
if unitrequirement:
for requirement in unitrequirement:
if 'building' in requirement:
buildingid = UnitTypeId(requirement['building'])
elif 'addon' in requirement:
buildingid = UnitTypeId(requirement['addon'])
buildingname = self.bot.techtree.get_name_from_id(buildingid.value)
await self.createBuilding(buildingname, 1, self.bot.hq_location)
requirementbuildingid = self.bot.techtree.get_id_from_name(buildingname)
if zerglings:
if self.bot.structures(requirementbuildingid).ready.exists:
if self.bot.can_afford(unitid):
print("Training: " + str(unitname))
self.bot.do(zerglings.random.train(unitid))
else:
await self.createBuilding(trainbuildingname, 1, self.bot.hq_location)
......@@ -163,11 +197,40 @@ class UnitManager():
async def createBuilding(self, buildingname, count, position, maxrange=30, force=False):
"""Builds everything required for a Building / Builds a Building"""
buildingid = self.bot.techtree.get_id_from_name(buildingname)
buildingcount = self.bot.structures(buildingid).amount
buildingcount = self.bot.all_units(buildingid).amount
buildrequirement = self.bot.techtree.get_building_buildRequirement(buildingid)
if buildingcount < count:
if self.bot.can_afford(buildingid):
# Zerg specific
if buildingname == 'Lair':
spawningpools = self.bot.structures(UnitTypeId.SPAWNINGPOOL).ready
if not spawningpools:
await self.createBuilding("SpawningPool", 1, self.bot.hq_location)
return
hqs = self.bot.structures(UnitTypeId.HATCHERY).ready
if hqs:
hq = hqs.first
if hq:
abilities = await self.bot.get_available_abilities(hq)
if AbilityId.UPGRADETOLAIR_LAIR in abilities:
self.bot.do(hq(AbilityId.UPGRADETOLAIR_LAIR))
elif buildingname == 'Hive':
infestationpits = self.bot.structures(UnitTypeId.INFESTATIONPIT).ready
if not infestationpits:
await self.createBuilding("InfestationPit", 1, self.bot.hq_location)
return
hqs = self.bot.structures(UnitTypeId.LAIR).ready
if hqs:
hq = hqs.first
if hq:
abilities = await self.bot.get_available_abilities(hq)
if AbilityId.UPGRADETOHIVE_HIVE in abilities:
self.bot.do(hq(AbilityId.UPGRADETOHIVE_HIVE))
# Check if there is a Requirement
if buildrequirement:
for requirement in buildrequirement:
......@@ -180,6 +243,11 @@ class UnitManager():
# Zerg specific
if requirementbuildingname == 'Lair':
spawningpools = self.bot.structures(UnitTypeId.SPAWNINGPOOL).ready
if not spawningpools:
await self.createBuilding("SpawningPool", 1, self.bot.hq_location)
return
hqs = self.bot.structures(UnitTypeId.HATCHERY).ready
if hqs:
hq = hqs.first
......@@ -188,7 +256,11 @@ class UnitManager():
if AbilityId.UPGRADETOLAIR_LAIR in abilities:
self.bot.do(hq(AbilityId.UPGRADETOLAIR_LAIR))
if requirementbuildingname == 'Hive':
elif requirementbuildingname == 'Hive':
infestationpits = self.bot.structures(UnitTypeId.INFESTATIONPIT).ready
if not infestationpits:
await self.createBuilding("InfestationPit", 1, self.bot.hq_location)
return
hqs = self.bot.structures(UnitTypeId.LAIR).ready
if hqs:
hq = hqs.first
......
import random
from strategies.zerg.ZerglingRush import *
from strategies.zerg.MutaliskRush import *
from strategies.zerg.BanelingSpam import *
class ZergManager():
"""Zerg Race Manager"""
......@@ -18,10 +18,12 @@ class ZergManager():
def pickStrategy(self):
strategies = [
ZerglingRush(self.bot),
MutaliskRush(self.bot)
MutaliskRush(self.bot),
BanelingSpam(self.bot)
]
self.strategy = random.choice(strategies)
# DEBUG Overrides
# self.strategy = ZerglingRush(self.bot)
# self.strategy = MutaliskRush(self.bot)
# self.strategy = BanelingSpam(self.bot)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment