Commit 32132a5b authored by m1ndgames's avatar m1ndgames

update

parent 53830d49
......@@ -19,8 +19,6 @@ class GameManager():
self.bot.race_enemy = None
self.bot.enemy_id = None
self.bot.worker = None
self.bot.townhall = None
self.bot.gasbuilding = None
# Locations
self.bot.hq_location = None # 1st townhall
......@@ -103,17 +101,6 @@ class GameManager():
if not self.bot.worker:
self.bot.worker = self.bot.techtree.get_id_from_name(self.bot.workers.first.name)
if not self.bot.townhall:
self.bot.townhall = self.bot.techtree.get_id_from_name(self.bot.townhalls.first.name)
if not self.bot.gasbuilding:
gasbuildingid = None
if self.bot.race_self == 'Protoss':
gasbuildingid = self.bot.techtree.get_id_from_name('Assimilator')
if self.bot.race_self == 'Terran':
gasbuildingid = self.bot.techtree.get_id_from_name('Refinery')
if self.bot.race_self == 'Zerg':
gasbuildingid = self.bot.techtree.get_id_from_name('Extractor')
self.bot.gasbuilding = UnitTypeId(gasbuildingid)
if self.bot.race_self == 'Protoss':
self.bot.townhalls = self.bot.structures(UnitTypeId.NEXUS)
......@@ -160,13 +147,13 @@ class GameManager():
async def set_positions(self):
# HQ
if not self.bot.hq_location:
self.bot.hq_location = self.bot.structures(self.bot.townhall).ready.first.position
self.bot.hq_location = self.bot.townhalls.ready.first.position
print("Location: HQ = " + str(self.bot.hq_location))
# Ramp
if not self.bot.ramp_location:
pos = self.bot.main_base_ramp.barracks_in_middle
nx = self.bot.structures(self.bot.townhall).ready.first.position
nx = self.bot.townhalls.ready.first.position
p = pos.towards(nx, 4)
self.bot.ramp_location = p
print("Location: Ramp = " + str(self.bot.ramp_location))
......@@ -181,7 +168,7 @@ class GameManager():
if not self.bot.proxy_location:
if self.bot.known_enemy_structures:
target = self.bot.known_enemy_structures.first.position
nx = self.bot.structures(self.bot.townhall).ready.first.position
nx = self.bot.townhalls.ready.first.position
self.bot.proxy_location = target.towards(nx.position, random.randrange(40, 50))
print("Location: Proxy Pylon = " + str(self.bot.proxy_location))
......
import random
from strategies.protoss.StalkerRush import *
from strategies.protoss.ZealotRush import *
class ProtossManager():
"""Protoss Race Manager"""
......@@ -14,4 +15,12 @@ class ProtossManager():
await self.strategy.Run()
def pickStrategy(self):
self.strategy = StalkerRush(self.bot)
strategies = [
ZealotRush(self.bot),
StalkerRush(self.bot)
]
self.strategy = random.choice(strategies)
# DEBUG Overrides
#self.strategy = StalkerRush(self.bot)
self.strategy = ZealotRush(self.bot)
from sc2 import race_gas
from sc2.ids.unit_typeid import UnitTypeId
from sc2.ids.ability_id import AbilityId
from sc2.constants import *
......@@ -28,21 +30,21 @@ class Ressources():
supplybuildingcount = self.bot.structures(UnitTypeId(supplybuildingid)).amount
if supplybuildingcount > 0:
if self.bot.can_afford(self.bot.gasbuilding):
for hq in self.bot.structures(self.bot.townhall).ready:
if self.bot.can_afford(race_gas[self.bot.race]):
for hq in self.bot.townhalls.ready:
vgs = self.bot.vespene_geyser.closer_than(15, hq.position)
for vg in vgs:
if not self.bot.structures.filter(lambda unit: unit.type_id == self.bot.gasbuilding and unit.distance_to(vg) < 1):
if not self.bot.structures.filter(lambda unit: unit.type_id == race_gas[self.bot.race] and unit.distance_to(vg) < 1):
worker = self.bot.select_build_worker(vg.position)
if worker is None:
break
self.bot.do(worker.build(self.bot.gasbuilding, vg))
self.bot.do(worker.build(race_gas[self.bot.race], vg))
async def manageWorkers(self):
"""Creates and assigns workers"""
# Distribute idle workers
randomhq = self.bot.structures(self.bot.townhall).ready
randomhq = self.bot.townhalls.ready
if randomhq:
randomhqpos = randomhq.random.position
for lazy in self.bot.workers.idle:
......@@ -57,7 +59,7 @@ class Ressources():
# Assign workers to minerals
self.assigned_harvesters = 0
for hq in self.bot.units(self.bot.townhall).ready:
for hq in self.bot.townhalls.ready:
self.assigned_harvesters = hq.assigned_harvesters + self.assigned_harvesters
if hq.assigned_harvesters > hq.ideal_harvesters:
......@@ -68,15 +70,15 @@ class Ressources():
harvesters_pool.extend(harvesters.random_group_of(toomuch))
if harvesters_pool:
for harvester in harvesters_pool:
for checkhq in self.bot.structures(self.bot.townhall).ready:
for checkhq in self.bot.townhalls.ready:
if checkhq.assigned_harvesters < checkhq.ideal_harvesters:
mineral = self.bot.mineral_field.closest_to(checkhq)
self.bot.do(harvester.gather(mineral))
# Assign workers to assimilators
if self.assigned_harvesters >= 5:
if self.bot.structures(self.bot.gasbuilding).ready.exists:
for gasstation in self.bot.structures(self.bot.gasbuilding):
if self.bot.gas_buildings.ready.exists:
for gasstation in self.bot.gas_buildings:
workers = self.bot.units(self.bot.worker)
assigned = gasstation.assigned_harvesters
ideal = gasstation.ideal_harvesters
......@@ -96,19 +98,18 @@ class Ressources():
# Build Workers
self.bot.neededworkers = 0
workerscount = self.bot.units(self.bot.worker).amount
assimilators = self.bot.structures(self.bot.gasbuilding)
for a in assimilators:
for a in self.bot.gas_buildings:
self.bot.neededworkers = self.bot.neededworkers + a.ideal_harvesters
self.maxworkers = self.maxworkers + 3
for h in self.bot.structures(self.bot.townhall).ready:
for h in self.bot.townhalls.ready:
self.bot.neededworkers = self.bot.neededworkers + h.ideal_harvesters
self.maxworkers = self.maxworkers + 16
if (workerscount >= self.maxworkers) or (workerscount >= self.bot.neededworkers):
return
for hq in self.bot.structures(self.bot.townhall).ready:
for hq in self.bot.townhalls.ready:
if hq.is_idle and self.bot.can_afford(self.bot.worker):
self.bot.do(hq.train(self.bot.worker))
return
\ No newline at end of file
......@@ -17,5 +17,5 @@ if __name__ == '__main__':
print("Starting local game...")
sc2.run_game(sc2.maps.get("AutomatonLE"), [
bot,
Computer(Race.Random, Difficulty.Easy)
Computer(Race.Random, Difficulty.Medium)
], realtime=False)
......@@ -8,10 +8,20 @@ class StalkerRush:
self.ramp_supply_built = False
self.coreboosted = None
self.workerscout = None
self.strategy = 'stalker_rush'
self.bot.strategy = 'stalker_rush'
async def Run(self):
"""Runs on every GameStep"""
if int(self.bot.time) <= 360:
self.bot.attack_count = 5
self.bot.retreat_count = 1
elif int(self.bot.time) > 360:
self.bot.attack_count = 10
self.bot.retreat_count = 3
elif int(self.bot.time) >= 600:
self.bot.attack_count = 15
self.bot.retreat_count = 5
await self.Macro()
await self.Buffs()
await self.Micro()
......@@ -28,12 +38,12 @@ class StalkerRush:
if self.bot.structures(UnitTypeId.GATEWAY) or self.bot.structures(UnitTypeId.WARPGATE):
await self.bot.ressources.createGas()
await self.bot.unitmanager.createUnit("Stalker", 50)
await self.bot.unitmanager.trainSkill("RESEARCH_WARPGATE")
if self.bot.units(UnitTypeId.CYBERNETICSCORE):
await self.bot.unitmanager.createBuilding("Gateway", 2, self.bot.hq_location, 15)
if self.bot.structures(UnitTypeId.CYBERNETICSCORE):
await self.bot.unitmanager.createBuilding("Gateway", 3, self.bot.hq_location, 15)
await self.bot.unitmanager.createUnit("Stalker", 50)
if self.bot.units(UnitTypeId.STALKER):
await self.bot.unitmanager.trainSkill("RESEARCH_BLINK")
......@@ -48,9 +58,9 @@ class StalkerRush:
if (self.bot.units(self.bot.worker).ready.amount / 1.1) >= self.bot.neededworkers:
await self.bot.warmanager.expand()
if int(self.bot.time) >= 300 and self.bot.units(self.bot.townhall).amount == 1:
if int(self.bot.time) >= 300 and self.bot.townhalls.amount == 1:
await self.bot.warmanager.expand()
if int(self.bot.time) >= 600 and self.bot.units(self.bot.townhall).amount <= 3:
if int(self.bot.time) >= 600 and self.bot.townhalls.amount <= 3:
await self.bot.warmanager.expand()
async def Micro(self):
......@@ -90,7 +100,7 @@ class StalkerRush:
if not blinkposition:
break
if stalker.position != next_enemy.position:
if self.bot.in_pathing_grid(blinkposition) and self.bot.is_visible(blinkposition) or (blinkposition == stalker.position):
if self.bot.in_pathing_grid(blinkposition) or (blinkposition == stalker.position):
self.bot.do(stalker(AbilityId.EFFECT_BLINK_STALKER, blinkposition))
elif distance2enemy < 2:
break
......
from sc2.constants import *
class ZealotRush:
"""Protoss ZealotRush"""
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'zealot_rush'
async def Run(self):
"""Runs on every GameStep"""
if int(self.bot.time) <= 300:
self.bot.attack_count = 1
self.bot.retreat_count = 0
elif int(self.bot.time) >= 300:
self.bot.attack_count = 1
self.bot.retreat_count = 0
elif int(self.bot.time) >= 600:
self.bot.attack_count = 1
self.bot.retreat_count = 0
await self.Macro()
await self.Micro()
async def Macro(self):
"""Macro Routine"""
if self.bot.townhalls.amount <= 2:
await self.bot.unitmanager.createBuilding("Gateway", 3, self.bot.hq_location, 15)
if self.bot.townhalls.amount >= 3:
await self.bot.unitmanager.createBuilding("Gateway", 6, self.bot.hq_location, 15)
await self.bot.unitmanager.createUnit("Zealot", 50)
# Send a worker scout
if self.bot.units(self.bot.worker).ready and not self.workerscout:
worker = self.bot.units(self.bot.worker).ready.first
if worker:
self.workerscout = True
await self.bot.warmanager.scout(worker)
# Check if expansion is needed
if (self.bot.units(self.bot.worker).ready.amount / 1.1) >= self.bot.neededworkers:
await self.bot.warmanager.expand()
if int(self.bot.time) >= 300 and self.bot.townhalls.amount == 1:
await self.bot.warmanager.expand()
if int(self.bot.time) >= 600 and self.bot.townhalls.amount <= 3:
await self.bot.warmanager.expand()
async def Micro(self):
"""Micro Routine"""
# Zealot Micro
zealots = self.bot.units(UnitTypeId.ZEALOT).ready
if zealots:
ground_enemies = self.bot.enemy_units.not_flying
if ground_enemies:
for zealot in zealots:
near_enemies = ground_enemies.closer_than(30, zealot)
if near_enemies:
next_enemy = near_enemies.closest_to(zealot)
distance2enemy = zealot.distance_to(next_enemy)
if distance2enemy < 20:
self.bot.do(zealot.attack(next_enemy))
......@@ -44,13 +44,12 @@ class UnitManager():
if AbilityId.WARPGATETRAIN_STALKER in abilities:
pylon = self.bot.structures(UnitTypeId.PYLON).closest_to(trainstructure)
pos = pylon.position.to2.random_on_distance(4)
if pos:
possible_positions = {pos + Point2((x, y)) for x in range(-5, 6) for y in range(-5, 6)}
better_positions = pos.sort_by_distance(possible_positions)
for placement in better_positions:
if placement:
if self.bot.in_placement_grid(placement) and self.bot.is_visible(placement):
self.bot.do(trainstructure.warp_in(trainunittype, placement))
possible_positions = {pos + Point2((x, y)) for x in range(-5, 6) for y in range(-5, 6)}
better_positions = pos.sort_by_distance(possible_positions)
for placement in better_positions:
if self.bot.in_placement_grid(placement):
self.bot.do(trainstructure.warp_in(trainunittype, placement))
break
else:
if self.bot.structures(trainbuilding).ready.idle:
......@@ -114,9 +113,8 @@ class UnitManager():
if not p:
return
if self.bot.structures(self.bot.gasbuilding).exists:
gasbuildings = self.bot.structures(self.bot.gasbuilding)
nextgas = gasbuildings.closest_to(supplyposition)
if self.bot.gas_buildings.exists:
nextgas = self.bot.gas_buildings.closest_to(supplyposition)
gas_distance2buildplace = nextgas.position.distance_to(supplyposition)
if gas_distance2buildplace <= 7 and force is False:
return
......@@ -164,7 +162,7 @@ class UnitManager():
pylons = self.bot.units(UnitTypeId.PYLON).ready
if pylons:
for pylon in pylons:
for hq in self.bot.structures(self.bot.townhall):
for hq in self.bot.townhalls:
# Make sure we dont build at a Proxy Pylon
if pylon.position.distance_to(hq.position) >= 25:
return
......@@ -192,23 +190,22 @@ class UnitManager():
if randompositiondistancetoramp <= 7 and force == False:
return
# Make sure its not build close to mineras
# Make sure its not build close to minerals
nextmineral = self.bot.mineral_field.closest_to(randomposition)
mineral_distance2buildplace = nextmineral.position.distance_to(randomposition)
if mineral_distance2buildplace <= 7:
return
# Make sure its not build close to gas
if self.bot.structures(self.bot.gasbuilding).exists:
gasbuildings = self.bot.structures(self.bot.gasbuilding)
nextgas = gasbuildings.closest_to(randomposition)
if self.bot.gas_buildings.exists:
nextgas = self.bot.gas_buildings.closest_to(randomposition)
gas_distance2buildplace = nextgas.position.distance_to(randomposition)
if gas_distance2buildplace <= 7:
return
# Protoss specific
if self.bot.race_self == 'Protoss':
# Make sure Buildings a created in psyionic matrix
# Make sure Buildings a created in psyonic matrix
if not self.bot.state.psionic_matrix.covers(randomposition):
return
......
from sc2 import race_townhalls
from sc2.client import *
from sc2 import Result
from sc2.constants import *
import random
......@@ -10,8 +12,8 @@ class WarManager():
self.commanderunit = None
self.commanderposition = False
self.commandertarget = None
self.attack_count = 0
self.retreat_count = 3
self.bot.attack_count = 0
self.bot.retreat_count = 0
self.startcounter = False
self.fightstarted = False
self.move2ramp = False
......@@ -41,13 +43,6 @@ class WarManager():
await self.defendroutine()
await self.counterworkerrush()
if int(self.bot.time) <= 300:
self.attack_count = 5
elif int(self.bot.time) >= 300:
self.attack_count = 10
elif int(self.bot.time) >= 600:
self.attack_count = 15
if self.bot.iteration & 2 == 0:
await self.estimate()
await self.estimate_status()
......@@ -55,7 +50,7 @@ class WarManager():
if self.bot.showstatus:
if int(self.bot.time) & 2 == 0:
self.bot.gamemanager.clearscreen()
print("My Army: " + str(self.my_armypower) + "/" + str(self.attack_count))
print("My Army: " + str(self.my_armypower) + "/" + str(self.bot.attack_count))
print("My Army (-30s): " + str(self.my_armypower_older))
print("My Status: " + self.my_status)
print("My Status (-30s): " + self.my_status_older)
......@@ -65,6 +60,13 @@ class WarManager():
print("Enemy Status: " + self.enemy_status)
print("Enemy Status (-30s): " + self.enemy_status_older)
#TODO: Make this work?!
async def savewinningstrategie(self):
if Result:
print("Result: " + str(Result))
#await self.bot.gamemanager.savedata("[strategy]\n")
#await self.bot.gamemanager.savedata(self.bot.strategy + "\n")
async def estimate(self):
"""Estimates the army value"""
if int(self.bot.time) & 1 == 0:
......@@ -86,9 +88,8 @@ class WarManager():
async def estimate_status(self):
"""Estimates the status"""
hqlist = self.bot.structures(self.bot.townhall)
hqpositions = []
for n in hqlist:
for n in self.bot.townhalls:
hqpositions.append(n.position)
enemies = self.bot.enemy_units.not_structure.filter(lambda w: w.type_id not in [UnitTypeId.PROBE] and w.type_id not in [UnitTypeId.SCV] and w.type_id not in [UnitTypeId.DRONE])
......@@ -120,11 +121,11 @@ class WarManager():
if self.bot.time >= 300:
if (self.enemy_status_older == 'Attack' and self.enemy_status == 'Unknown') and (self.my_status != 'Attack' and self.my_armypower >= 8):
self.startcounter = True
elif self.my_armypower <= self.retreat_count:
elif self.my_armypower <= self.bot.retreat_count:
self.startcounter = False
async def check_retreat(self):
if self.my_armypower <= self.enemy_armypower:
if (self.my_armypower < self.enemy_armypower) or (self.my_armypower <= self.bot.retreat_count):
self.my_status = 'Retreat'
fighters = self.bot.units.ready.filter(
lambda w: w.type_id not in [UnitTypeId.PROBE] and w.type_id not in [
......@@ -169,7 +170,7 @@ class WarManager():
UnitTypeId.OBSERVER] and w.type_id not in [UnitTypeId.WARPPRISM] and w.type_id not in [
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [UnitTypeId.DARKTEMPLAR] and w.type_id not in [UnitTypeId.SENTRY] and w.type_id not in [UnitTypeId.OBSERVERSIEGEMODE])
if (fighters.amount > self.attack_count) or self.startcounter:
if (fighters.amount >= self.bot.attack_count) or self.startcounter:
self.fightstarted = True
else:
self.fightstarted = False
......@@ -275,7 +276,7 @@ class WarManager():
else:
self.commandertarget = None
ramp = self.bot.main_base_ramp.top_center
hq = self.bot.structures(self.bot.townhall).first
hq = self.bot.townhalls.first
p = ramp.position.towards(hq.position, 1)
distance = fighter.position.distance_to(p)
if distance < 2:
......@@ -313,21 +314,29 @@ class WarManager():
return
async def expand(self):
if self.bot.already_pending(self.bot.townhall):
townhall = None
if self.bot.race_self == 'Protoss':
townhall = UnitTypeId.NEXUS
elif self.bot.race_self == 'Terran':
townhall = UnitTypeId.COMMANDCENTER
elif self.bot.race_self == 'Zerg':
townhall = UnitTypeId.HATCHERY
if self.bot.already_pending(townhall):
self.bot.expansion = False
return
if self.bot.can_afford(self.bot.townhall):
if self.bot.can_afford(townhall):
location = await self.bot.get_next_expansion()
if location:
self.bot.expansion = True
await self.bot.build(self.bot.townhall, location)
await self.bot.build(townhall, location)
async def scout(self, unit=False, corners=False, force=False):
"""Scouts for the enemy"""
if self.bot.enemy_structures and not force:
scout = self.bot.units.find_by_tag(self.bot.scout_tag)
if scout:
self.bot.do(scout.move(self.bot.structures(self.bot.townhall).first.position))
self.bot.do(scout.move(self.bot.townhalls.first.position))
self.bot.scout_tag = None
return
else:
......
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