Commit 230a4dc9 authored by m1ndgames's avatar m1ndgames

update

parent 2a1739c5
......@@ -4,7 +4,8 @@
"Race": "Random",
"Type": "Python",
"RootPath": "./",
"FileName": "run.py"
"FileName": "run.py",
"Debug": true
}
}
}
\ No newline at end of file
......@@ -8,11 +8,13 @@ from warmanager import *
from protoss import *
from terran import *
from zerg import *
from util import *
class m1ndb0t(sc2.BotAI):
def __init__(self):
super().__init__()
self.util = Util(self)
self.techtree = TechTree(self)
self.ressources = Ressources(self)
self.gamemanager = GameManager(self)
......
......@@ -18,7 +18,7 @@ class Ressources():
async def manageSupply(self):
# Supply
if self.bot.supply_left < 7:
if self.bot.supply_left < 7 and self.bot.supply_cap != 200:
supplyposition = self.bot.hq_location.random_on_distance(random.randrange(1, 12))
await self.bot.unitmanager.createSupply(supplyposition)
......@@ -27,7 +27,11 @@ class Ressources():
# Gas
supplybuildingname = self.bot.techtree.get_supplyBuilding()
supplybuildingid = self.bot.techtree.get_id_from_name(supplybuildingname)
supplybuildingcount = self.bot.structures(UnitTypeId(supplybuildingid)).amount
if self.bot.race == Race.Zerg:
supplybuildingcount = self.bot.units(UnitTypeId(supplybuildingid)).amount
else:
supplybuildingcount = self.bot.structures(UnitTypeId(supplybuildingid)).amount
if supplybuildingcount > 0:
if self.bot.can_afford(race_gas[self.bot.race]):
......
......@@ -4,7 +4,7 @@ from sc2 import Race, Difficulty
from sc2.player import Bot, Computer
from m1ndb0t import m1ndb0t
bot = Bot(Race.Random, m1ndb0t())
bot = Bot(Race.Zerg, m1ndb0t())
# Start game
if __name__ == '__main__':
......
from sc2.constants import *
from sc2 import race_worker
class MutaliskRush:
"""Zerg MutaliskRush"""
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'mutalist_rush'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 3
async def Run(self):
"""Runs on every GameStep"""
await self.Macro()
await self.Micro()
async def Macro(self):
"""Macro Routine"""
if self.bot.vespene <= 300:
await self.bot.ressources.createGas()
await self.bot.unitmanager.createUnit("Mutalisk", 100)
if self.bot.townhalls.ready.amount >= 3:
await self.bot.unitmanager.createUnit("Queen", self.bot.townhalls.ready.amount)
if self.bot.townhalls.amount == 1:
await self.bot.warmanager.expand()
if self.bot.units(UnitTypeId.MUTALISK):
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):
# mutalisk
mutalisks = self.bot.units(UnitTypeId.MUTALISK).ready
if mutalisks:
for mutalisk in mutalisks:
enemies = self.bot.enemy_units
if enemies:
closeenemies = enemies.closer_than(30, mutalisk)
if closeenemies:
for e in closeenemies:
if not self.bot.techtree.can_attack(mutalisk, e):
closeenemies.remove(e)
if not closeenemies:
break
next_enemy = closeenemies.closest_to(mutalisk)
if not next_enemy:
break
distance2enemy = mutalisk.position.distance_to(next_enemy.position)
if distance2enemy < 20:
self.bot.do(mutalisk.attack(next_enemy))
if distance2enemy <= 3:
moveposition = mutalisk.position.towards(next_enemy.position, -1)
self.bot.do(mutalisk.move(moveposition))
nx = self.bot.townhalls.ready.closest_to(mutalisk)
if not nx:
break
nxdistance = mutalisk.position.distance_to(nx.position)
if nxdistance < 10:
break
structures = self.bot.enemy_structures
if structures and not enemies:
closestructures = structures.closer_than(30, mutalisk)
if closestructures:
for e in closestructures:
if not self.bot.techtree.can_attack(mutalisk, e):
closestructures.remove(e)
if not closestructures:
break
next_structure = closestructures.closest_to(mutalisk)
if not next_structure:
break
distance2structure = mutalisk.position.distance_to(next_structure.position)
if distance2structure < 20:
self.bot.do(mutalisk.attack(next_structure))
if distance2structure <= 3:
moveposition = mutalisk.position.towards(next_structure.position, -1)
self.bot.do(mutalisk.move(moveposition))
# 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
......@@ -16,7 +16,6 @@ class ZerglingRush:
"""Runs on every GameStep"""
await self.Macro()
await self.Micro()
await self.Buffs()
async def Macro(self):
"""Macro Routine"""
......@@ -26,6 +25,13 @@ class ZerglingRush:
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
......@@ -50,30 +56,22 @@ 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
# queen
queens = self.bot.units(UnitTypeId.QUEEN).ready
if queens:
for queen in queens:
hqs = self.bot.structures(UnitTypeId.HATCHERY)
for hq in hqs:
q = self.bot.units.filter(lambda unit: unit.type_id == UnitTypeId.QUEEN and unit.is_ready and (unit.is_idle or unit.orders[0].ability.id != AbilityId.EFFECT_INJECTLARVA))
if not q:
self.bot.do(queen.move(hq.position))
break
nearhq = self.bot.structures.closer_than(5, queen.position).filter(lambda w: w.type_id in [UnitTypeId.HATCHERY])
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)
async def Buffs(self):
return
if hqs:
self.bot.do(queen.move(hqs[0].position))
break
......@@ -5,6 +5,7 @@ from sc2.ids.ability_id import AbilityId
from sc2.ids.upgrade_id import UpgradeId
from sc2.constants import *
class TechTree():
def __init__(self, bot=None):
with open('techtree.json') as techtree_json:
......
......@@ -47,9 +47,10 @@ class UnitManager():
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
if not self.bot.util.outofbounds(placement):
if self.bot.in_placement_grid(placement):
self.bot.do(trainstructure.warp_in(trainunittype, placement))
break
else:
if self.bot.structures(trainbuilding).ready.idle:
......@@ -136,6 +137,8 @@ class UnitManager():
if supplypositionpositiondistancetoramp <= 7 and force == False:
return
if self.bot.util.outofbounds(supplyposition):
return
if not self.bot.in_placement_grid(supplyposition):
return
......@@ -174,8 +177,29 @@ class UnitManager():
if not self.bot.structures(requirementbuildingid).exists:
if not self.bot.already_pending(requirementbuildingid):
requirementbuildingname = self.bot.techtree.get_name_from_id(requirementbuildingid.value)
await self.createBuilding(requirementbuildingname, 1, self.bot.hq_location, 30)
return
# Zerg specific
if requirementbuildingname == 'Lair':
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))
if requirementbuildingname == 'Hive':
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))
else:
await self.createBuilding(requirementbuildingname, 1, self.bot.hq_location, 30)
return
# Return if there is no worker available
worker = self.bot.select_build_worker(position)
......@@ -198,6 +222,9 @@ class UnitManager():
return
randomposition = pylon.position.random_on_distance(random.randrange(1, 6))
if self.bot.util.outofbounds(randomposition):
return
# Return if its not in placement grid
if not self.bot.in_placement_grid(randomposition):
return
......
class Util():
def __init__(self, bot=None):
self.bot = bot
def outofbounds(self, pos):
if not pos:
return
raw_map = self.bot.game_info.playable_area
map_width = raw_map[2]
map_height = raw_map[3]
x = pos[0]
y = pos[1]
if (x <= 0) or (x >= map_width):
return True
elif (y <= 0) or (y >= map_height):
return True
\ No newline at end of file
import random
from strategies.zerg.ZerglingRush import *
from strategies.zerg.MutaliskRush import *
class ZergManager():
"""Zerg Race Manager"""
......@@ -15,6 +17,11 @@ class ZergManager():
def pickStrategy(self):
strategies = [
ZerglingRush(self.bot)
ZerglingRush(self.bot),
MutaliskRush(self.bot)
]
self.strategy = random.choice(strategies)
# DEBUG Overrides
# self.strategy = ZerglingRush(self.bot)
# self.strategy = MutaliskRush(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