Commit 93e20488 authored by m1ndgames's avatar m1ndgames

update

parent 6f2164d5
......@@ -48,18 +48,19 @@ class GameManager():
async def dataAttacktime(self):
"""Checks when 1st attack is made and writes to datafile"""
if not self.attacktime:
enemies = self.bot.enemy_units.not_structure.closer_than(20, self.bot.main_base_ramp.top_center.position).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])
enemyproxy = self.bot.enemy_units.structure.closer_than(30, self.bot.main_base_ramp.top_center.position)
if enemies or enemyproxy:
self.attacktime = self.bot.time
print("Got attacked at " + str(self.attacktime))
await self.savedata("[attack]\n")
await self.savedata("time=" + str(int(self.attacktime)) + "\n")
attackers = []
for enemy in enemies:
attackers.append(enemy.name + ",")
await self.savedata("units=" + str(attackers) + "\n")
enemies = self.bot.enemy_units
if enemies:
closeenemies = enemies.closer_than(20, self.bot.main_base_ramp.top_center.position).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])
if closeenemies:
self.attacktime = self.bot.time
print("Got attacked at " + str(self.attacktime))
await self.savedata("[attack]\n")
await self.savedata("time=" + str(int(self.attacktime)) + "\n")
attackers = []
for enemy in closeenemies:
attackers.append(enemy.name + ",")
await self.savedata("units=" + str(attackers) + "\n")
async def savedata(self, data):
if self.bot.opponent_id:
......
......@@ -69,5 +69,5 @@ class m1ndb0t(sc2.BotAI):
self.do(unit.attack(target))
return
async def on_end(self):
async def on_end(self, game_result):
await self.warmanager.savewinningstrategy()
......@@ -7,7 +7,7 @@ class DarkTemplar:
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'dark_templar'
self.bot.strategy = 'DarkTemplar'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 0
......
......@@ -8,7 +8,7 @@ class SkyToss:
self.bot = bot
self.ramp_supply_built = False
self.workerscout = None
self.bot.strategy = 'sky_toss'
self.bot.strategy = 'SkyToss'
self.bot.squadsize = 10
async def Run(self):
......@@ -65,7 +65,7 @@ class SkyToss:
if closeenemies:
for e in closeenemies:
if not self.bot.techtree.can_attack(adept, e):
if not self.bot.techtree.can_attack(adept, e) or not e.can_be_attacked:
closeenemies.remove(e)
if not closeenemies:
......
......@@ -9,7 +9,7 @@ class StalkerRush:
self.ramp_supply_built = False
self.coreboosted = None
self.workerscout = None
self.bot.strategy = 'stalker_rush'
self.bot.strategy = 'StalkerRush'
self.bot.squadsize = 5
async def Run(self):
......
......@@ -7,7 +7,7 @@ class ZealotRush:
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'zealot_rush'
self.bot.strategy = 'ZealotRush'
self.bot.squadsize = 10
self.bot.attack_count = 1
self.bot.retreat_count = 0
......
from sc2.constants import *
from sc2 import race_worker
from sc2 import race_gas
class MarineRush:
"""Terran MarineRush"""
......@@ -8,7 +8,7 @@ class MarineRush:
self.bot = bot
self.ramp_supply_built = False
self.workerscout = None
self.bot.strategy = 'marine_rush'
self.bot.strategy = 'MarineRush'
self.bot.squadsize = 10
async def Run(self):
......@@ -21,22 +21,26 @@ class MarineRush:
async def Macro(self):
"""Macro Routine"""
#await self.bot.ressources.createGas()
#if not self.bot.structures(race_gas[self.bot.race]):
# await self.bot.ressources.createGas()
# await self.bot.unitmanager.createUnit("Medivac", 3)
await self.createWall()
await self.bot.unitmanager.trainSkill("SCANNERSWEEP_SCAN")
barrackscount = self.bot.townhalls.amount * 4
barrackscount = self.bot.townhalls.amount * 3
if barrackscount == 0:
barrackscount = 1
await self.bot.unitmanager.createBuilding("Barracks", barrackscount, self.bot.hq_location, 15)
await self.bot.unitmanager.createUnit("Marine", 50)
#await self.bot.unitmanager.createUnit("Medivac", 3)
await self.bot.unitmanager.createUnit("Marine", 100)
# 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)
#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)
# Check if expansion is needed
if (self.bot.units(race_worker[self.bot.race]).ready.amount / 1.1) >= self.bot.neededworkers:
......@@ -49,7 +53,7 @@ class MarineRush:
async def Micro(self):
"""Micro Routine"""
# Marine
# marine
marines = self.bot.units(UnitTypeId.MARINE).ready
if marines:
for marine in marines:
......@@ -58,62 +62,55 @@ class MarineRush:
closeenemies = enemies.closer_than(30, marine)
if closeenemies:
next_enemy = closeenemies.closest_to(marine)
if not next_enemy:
break
distance2enemy = marine.position.distance_to(next_enemy.position)
if distance2enemy < 20:
self.bot.do(marine.attack(next_enemy))
nx = self.bot.townhalls.ready.closest_to(marine)
if not nx:
break
nxdistance = marine.position.distance_to(nx.position)
if nxdistance < 10:
break
if distance2enemy < self.bot.techtree.get_unit_weaponrange(UnitTypeId.MARINE):
if (next_enemy.name != 'Probe') or (next_enemy.name != 'SCV') or (
next_enemy.name != 'Drone'):
if distance2enemy < 2:
break
else:
moveposition = marine.position.towards(next_enemy.position, -1)
if not moveposition or not self.bot.in_pathing_grid(moveposition):
break
self.bot.do(marine.move(moveposition))
for e in closeenemies:
if not self.bot.techtree.can_attack(marine, e) or not e.can_be_attacked or e.name == 'Larva':
closeenemies.remove(e)
if closeenemies:
next_enemy = closeenemies.closest_to(marine)
if next_enemy:
distance2enemy = marine.position.distance_to(next_enemy.position)
if distance2enemy < self.bot.techtree.get_unit_weaponrange(UnitTypeId.MARINE):
if (next_enemy.name != 'Probe') or (next_enemy.name != 'SCV') or (
next_enemy.name != 'Drone'):
if distance2enemy < 2:
break
else:
moveposition = marine.position.towards(next_enemy.position, -1)
if not moveposition or not self.bot.in_pathing_grid(moveposition):
break
self.bot.do(marine.move(moveposition))
if distance2enemy < 20:
self.bot.do(marine.attack(next_enemy))
structures = self.bot.enemy_structures
if structures and not enemies:
closestructures = structures.closer_than(30, marine)
if closestructures:
for e in closestructures:
if not self.bot.techtree.can_attack(marine, e) or not e.can_be_attacked:
closestructures.remove(e)
if closestructures:
next_structure = closestructures.closest_to(marine)
if next_structure:
distance2structure = marine.position.distance_to(next_structure.position)
if distance2structure < 20:
self.bot.do(marine.attack(next_structure))
# medivac
medivacs = self.bot.units(UnitTypeId.MEDIVAC).ready
marines = self.bot.units(UnitTypeId.MARINE).ready
if medivacs:
for medivac in medivacs:
enemies = self.bot.enemy_units
if enemies:
closeenemies = enemies.closer_than(30, medivac)
if closeenemies:
next_enemy = closeenemies.closest_to(medivac)
if not next_enemy:
break
distance2enemy = medivac.position.distance_to(next_enemy.position)
if distance2enemy < 20:
self.bot.do(medivac.attack(next_enemy))
nx = self.bot.townhalls.ready.closest_to(medivac)
if not nx:
break
nxdistance = medivac.position.distance_to(nx.position)
if nxdistance < 10:
break
if distance2enemy <= 8:
if (next_enemy.name != 'Probe') or (next_enemy.name != 'SCV') or (next_enemy.name != 'Drone'):
moveposition = medivac.position.towards(next_enemy.position, -1)
self.bot.do(medivac.move(moveposition))
if marines:
if self.bot.commanderposition:
distance2commander = medivac.position.distance_to(self.bot.commanderposition)
if distance2commander >= 5:
self.bot.do(medivac.move(self.bot.commanderposition))
async def Buffs(self):
# Supply Depots
......
......@@ -7,7 +7,7 @@ class BanelingSpam:
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'baneling_spam'
self.bot.strategy = 'BanelingSpam'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 0
......@@ -54,7 +54,7 @@ class BanelingSpam:
if closeenemies:
for e in closeenemies:
if not self.bot.techtree.can_attack(zergling, e):
if not self.bot.techtree.can_attack(zergling, e) or not e.can_be_attacked:
closeenemies.remove(e)
if not closeenemies:
......@@ -73,7 +73,7 @@ class BanelingSpam:
if closestructures:
for e in closestructures:
if not self.bot.techtree.can_attack(zergling, e):
if not self.bot.techtree.can_attack(zergling, e) or not e.can_be_attacked:
closestructures.remove(e)
if not closestructures:
......@@ -96,7 +96,7 @@ class BanelingSpam:
if closeenemies:
for e in closeenemies:
if not self.bot.techtree.can_attack(baneling, e):
if not self.bot.techtree.can_attack(baneling, e) or not e.can_be_attacked:
closeenemies.remove(e)
if not closeenemies:
......@@ -115,7 +115,7 @@ class BanelingSpam:
if closestructures:
for e in closestructures:
if not self.bot.techtree.can_attack(baneling, e):
if not self.bot.techtree.can_attack(baneling, e) or not e.can_be_attacked:
closestructures.remove(e)
if not closestructures:
......
......@@ -7,7 +7,7 @@ class MutaliskRush:
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'mutalist_rush'
self.bot.strategy = 'MutaliskRush'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 3
......@@ -44,57 +44,54 @@ class MutaliskRush:
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))
if self.bot.commandertarget:
if mutalisk.position.distance_to(self.bot.commandertarget.position) <= 10 and mutalisk.tag != self.bot.commander:
self.bot.do(mutalisk.attack(self.bot.commandertarget))
else:
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) or not e.can_be_attacked:
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))
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) or not e.can_be_attacked:
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
......
......@@ -7,7 +7,7 @@ class ZerglingRush:
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'zergling_rush'
self.bot.strategy = 'ZerglingRush'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 0
......@@ -51,7 +51,7 @@ class ZerglingRush:
if closeenemies:
for e in closeenemies:
if not self.bot.techtree.can_attack(zergling, e):
if not self.bot.techtree.can_attack(zergling, e) or not e.can_be_attacked:
closeenemies.remove(e)
if not closeenemies:
......@@ -64,22 +64,14 @@ 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)
for s in closestructures:
if not self.bot.techtree.can_attack(zergling, s):
closestructures.remove(s)
if not closestructures:
break
......
This diff is collapsed.
......@@ -10,10 +10,10 @@ class WarManager():
def __init__(self, bot=None):
self.bot = bot
self.commander = False
self.commanderunit = None
self.commanderposition = False
self.commandertarget = None
self.bot.commander = False
self.bot.commanderunit = None
self.bot.commanderposition = False
self.bot.commandertarget = None
self.bot.attack_count = 0
self.bot.retreat_count = 0
self.startcounter = False
......@@ -60,8 +60,8 @@ class WarManager():
print("Enemy Status: " + self.enemy_status)
print("Enemy Status (-30s): " + self.enemy_status_older)
async def savewinningstrategy(self):
print("Result: " + self.client.game_result)
async def savewinningstrategy(self, result):
print("Result: " + str(result))
#if Result == Result.Win:
# await self.bot.gamemanager.savedata("[strategy]\n")
# await self.bot.gamemanager.savedata(str(self.bot.strategy) + "\n")
......@@ -129,7 +129,7 @@ class WarManager():
fighters = self.bot.units.ready.filter(
lambda w: w.type_id not in [UnitTypeId.PROBE] and w.type_id not in [
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.OBSERVERSIEGEMODE] and w.type_id not in [UnitTypeId.SCV] and w.type_id not in [UnitTypeId.DRONE] and w.type_id not in [UnitTypeId.OVERLORD] and w.type_id not in [UnitTypeId.QUEEN] and w.type_id not in [UnitTypeId.LARVA])
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [UnitTypeId.OBSERVERSIEGEMODE] and w.type_id not in [UnitTypeId.SCV] and w.type_id not in [UnitTypeId.DRONE] and w.type_id not in [UnitTypeId.OVERLORD] and w.type_id not in [UnitTypeId.QUEEN] and w.type_id not in [UnitTypeId.LARVA] and w.type_id not in [UnitTypeId.MEDIVAC])
for fighter in fighters:
distance2ramp = fighter.position.distance_to(self.bot.ramp_location)
......@@ -166,7 +166,7 @@ class WarManager():
fighters = self.bot.units.ready.filter(
lambda w: w.type_id not in [race_worker[self.bot.race]] and w.type_id not in [
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.SENTRY] and w.type_id not in [UnitTypeId.OBSERVERSIEGEMODE] and w.type_id not in [UnitTypeId.OVERLORD] and w.type_id not in [UnitTypeId.QUEEN])
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [UnitTypeId.SENTRY] and w.type_id not in [UnitTypeId.OBSERVERSIEGEMODE] and w.type_id not in [UnitTypeId.OVERLORD] and w.type_id not in [UnitTypeId.QUEEN] and w.type_id not in [UnitTypeId.MEDIVAC])
if (fighters.amount >= self.bot.attack_count) or self.startcounter:
self.fightstarted = True
......@@ -174,19 +174,19 @@ class WarManager():
self.fightstarted = False
if fighters:
if not self.commander:
if not self.bot.commander:
possiblecommanders = sorted(fighters, key=lambda i: i.distance_to(self.bot.enemy_start_locations[0]), reverse=False)
self.commander = possiblecommanders[0].tag
self.bot.commander = possiblecommanders[0].tag
else:
for fighter in fighters:
if fighter.tag == self.commander:
if fighter.tag == self.bot.commander:
#await self.bot._client.debug_text("C", fighter.position) # DEBUG
self.commanderunit = fighter
self.commanderposition = fighter.position
self.bot.commanderunit = fighter
self.bot.commanderposition = fighter.position
return
self.commanderunit = None
self.commander = False
self.commandertarget = None
self.bot.commanderunit = None
self.bot.commander = False
self.bot.commandertarget = None
return
async def defendroutine(self):
......@@ -211,7 +211,7 @@ class WarManager():
fighters = self.bot.units.ready.filter(
lambda w: w.type_id not in [race_worker[self.bot.race]] and w.type_id not in [
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.OBSERVERSIEGEMODE] and w.type_id not in [UnitTypeId.OVERLORD] and w.type_id not in [UnitTypeId.LARVA])
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [UnitTypeId.OBSERVERSIEGEMODE] and w.type_id not in [UnitTypeId.OVERLORD] and w.type_id not in [UnitTypeId.LARVA]and w.type_id not in [UnitTypeId.MEDIVAC])
for fighter in fighters:
unit_enemies = self.bot.enemy_units.closer_than(30, hq)
......@@ -226,19 +226,19 @@ class WarManager():
async def fightroutine(self):
"""The main Attack and Movement Routine"""
if not self.commander or not self.commanderunit or not self.commanderposition:
if not self.bot.commander or not self.bot.commanderunit or not self.bot.commanderposition:
return
fighters = self.bot.units.ready.filter(
lambda w: w.type_id not in [race_worker[self.bot.race]] and w.type_id not in [
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.OVERLORD] and w.type_id not in [UnitTypeId.QUEEN] and w.type_id not in [UnitTypeId.LARVA])
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [UnitTypeId.OVERLORD] and w.type_id not in [UnitTypeId.QUEEN] and w.type_id not in [UnitTypeId.LARVA] and w.type_id not in [UnitTypeId.MEDIVAC])
if fighters:
for fighter in fighters:
# Commander Action
if fighter.tag == self.commander:
if fighter.tag == self.bot.commander:
if not self.fightstarted:
d = random.randint(0, 4)
......@@ -274,7 +274,7 @@ class WarManager():
squad = self.bot.units.ready.filter(
lambda w: w.type_id not in [race_worker[self.bot.race]] and w.type_id not in [
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.QUEEN] and w.type_id not in [UnitTypeId.LARVA]).closer_than(10, fighter)
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [UnitTypeId.QUEEN] and w.type_id not in [UnitTypeId.LARVA] and w.type_id not in [UnitTypeId.MEDIVAC]).closer_than(10, fighter)
if squad.amount < self.bot.squadsize:
self.bot.do(fighter.move(fighter.position))
......@@ -282,11 +282,11 @@ class WarManager():
if target:
self.bot.do(fighter.attack(target.position))
self.commanderposition = target.position
self.commandertarget = target.position
self.bot.commanderposition = target.position
self.bot.commandertarget = target
break
else:
self.commandertarget = None
self.bot.commandertarget = None
ramp = self.bot.main_base_ramp.top_center
hq = self.bot.townhalls.first
p = ramp.position.towards(hq.position, 1)
......@@ -294,27 +294,27 @@ class WarManager():
if distance < 2:
break
self.bot.do(fighter.attack(p))
self.commanderposition = p
self.bot.commanderposition = p
break
# Fighter Action
elif fighter.tag != self.commander:
elif fighter.tag != self.bot.commander:
await self.moveroutine(fighter)
async def moveroutine(self, fighterunit):
"""Orders the given unit to move next to the Commander"""
if self.commanderunit:
distance = fighterunit.position.distance_to(self.commanderposition)
if self.bot.commanderunit:
distance = fighterunit.position.distance_to(self.bot.commanderposition)
if distance < 3:
return
target = self.commandertarget
target = self.bot.commandertarget
if not target:
pos = self.commanderposition.towards(fighterunit.position, random.randrange(1, 3))
pos = self.bot.commanderposition.towards(fighterunit.position, random.randrange(1, 3))
if not self.bot.in_pathing_grid(pos):
return
else:
pos = self.commanderposition.towards(target, random.randrange(3, 10))
pos = self.bot.commanderposition.towards(target.position, random.randrange(3, 10))
if not self.bot.in_pathing_grid(pos):
return
......
......@@ -15,6 +15,9 @@ class ZergManager():
else:
await self.strategy.Run()
def setStrategy(self, strategy):
self.strategy = strategy
def pickStrategy(self):
strategies = [
ZerglingRush(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