Commit 24ee2f64 authored by m1ndgames's avatar m1ndgames

update

parent 9d840f15
......@@ -79,8 +79,8 @@ async def join_ladder_game(host, port, players, realtime, portconfig, save_repla
result = await sc2.main._play_game(players[0], client, realtime, portconfig, step_time_limit, game_time_limit)
if save_replay_as is not None:
await client.save_replay(save_replay_as)
await client.leave()
await client.quit()
#await client.leave()
#await client.quit()
except ConnectionAlreadyClosed:
logging.error(f"Connection was closed before the game ended")
return None
......
......@@ -2,6 +2,7 @@ from sc2.client import *
import random
import os
import configparser
from pathlib import Path
class GameManager():
def __init__(self, bot=None):
......@@ -39,6 +40,7 @@ class GameManager():
self.attacktime = None
self.bot.data_attacktime = None
self.bot.data_attackunits = None
self.bot.data_race_strategy = None
self.bot.not_squadunit = []
self.bot.not_commanderunit = []
......@@ -48,23 +50,6 @@ class GameManager():
else:
_ = os.system('clear')
async def dataAttacktime(self):
"""Checks when 1st attack is made and writes to datafile"""
if not self.attacktime:
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:
datafile = "./data/" + str(self.bot.opponent_id) + ".db"
......@@ -75,8 +60,15 @@ class GameManager():
async def readdata(self, id):
botdata = configparser.ConfigParser()
botdata.read("./data/" + id + ".db")
self.bot.data_attacktime = int(botdata['attack']['time'])
self.bot.data_attackunits = botdata['attack']['units']
if botdata:
if botdata.has_section("Enemy"):
if botdata.has_option("Enemy", "attacktime"):
self.bot.data_attacktime = botdata.get('Enemy', 'attacktime')
if botdata.has_option("Enemy", "units"):
self.bot.data_attackunits = botdata.get('Enemy', 'units')
if botdata.has_section(str(self.bot.race_self)):
if botdata.has_option(str(self.bot.race_self), "strategy"):
self.bot.data_race_strategy = botdata.get(str(self.bot.race_self), 'strategy')
async def startGame(self):
if not self.bot.real_time and self.bot.last_game_loop == self.bot.state.game_loop:
......@@ -94,6 +86,19 @@ class GameManager():
await self.set_positions()
await self.mapbounds()
if self.bot.opponent_id:
datafile = "./data/" + str(self.bot.opponent_id) + ".db"
if not os.path.isfile(datafile):
Path("./data/" + str(self.bot.opponent_id) + ".db").touch()
botdata = configparser.ConfigParser()
botdata.read("./data/" + str(self.bot.opponent_id) + ".db")
botdata.add_section('Terran')
botdata.add_section('Protoss')
botdata.add_section('Zerg')
botdata.add_section('Enemy')
with open(datafile, 'w') as dbfile:
botdata.write(dbfile)
async def setExpansion(self):
self.bot.next_expansion = await self.bot.get_next_expansion()
......
......@@ -77,4 +77,4 @@ class m1ndb0t(sc2.BotAI):
await self.client._send_debug()
async def on_end(self, game_result):
await self.warmanager.savewinningstrategy()
await self.warmanager.savewinningstrategy(game_result)
......@@ -9,26 +9,34 @@ class ProtossManager():
"""Protoss Race Manager"""
def __init__(self, bot=None):
self.bot = bot
self.strategy = None
self.bot.strategy = None
self.bot.current_strategy = None
async def Run(self):
if self.bot.iteration == 1:
self.bot.not_squadunit.append(race_worker[self.bot.race])
self.bot.not_commanderunit.append(race_worker[self.bot.race])
if not self.strategy:
if not self.bot.strategy:
self.pickStrategy()
else:
await self.strategy.Run()
await self.bot.strategy.Run()
def pickStrategy(self):
strategies = [
ZealotRush(self.bot),
StalkerRush(self.bot),
SkyToss(self.bot),
DarkTemplar(self.bot)
]
self.strategy = random.choice(strategies)
strategies = {
'ZealotRush': ZealotRush(self.bot),
'StalkerRush': StalkerRush(self.bot),
'SkyToss': SkyToss(self.bot),
'DarkTemplar': DarkTemplar(self.bot)
}
if self.bot.data_race_strategy in strategies:
self.bot.strategy = strategies[self.bot.data_race_strategy]
print("Using strategy: " + str(self.bot.strategy))
else:
print("No Data - Picking random strategy")
self.bot.strategy = random.choice(list(strategies.values()))
print("Using strategy:" + str(self.bot.strategy))
# DEBUG Overrides
# self.strategy = StalkerRush(self.bot)
......
......@@ -18,11 +18,12 @@ class Ressources():
async def manageSupply(self):
# Supply
if self.bot.supply_left < 7 and self.bot.supply_cap != 200:
hq = random.choice(self.bot.townhalls).position
if hq:
supplyposition = hq.random_on_distance(random.randrange(1, 12))
if supplyposition:
await self.bot.unitmanager.createSupply(supplyposition)
if self.bot.townhalls:
hq = random.choice(self.bot.townhalls).position
if hq:
supplyposition = hq.random_on_distance(random.randrange(1, 12))
if supplyposition:
await self.bot.unitmanager.createSupply(supplyposition)
async def createGas(self):
# Gas
......@@ -36,17 +37,18 @@ class Ressources():
if supplybuildingcount > 0:
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 == race_gas[self.bot.race] and unit.distance_to(vg) < 1):
worker = self.bot.select_build_worker(vg.position)
if worker is None:
break
if worker.tag == self.bot.scout_tag:
break
if not self.bot.already_pending(race_gas[self.bot.race]):
self.bot.do(worker.build(race_gas[self.bot.race], vg))
if self.bot.townhalls.ready:
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 == race_gas[self.bot.race] and unit.distance_to(vg) < 1):
worker = self.bot.select_build_worker(vg.position)
if worker is None:
break
if worker.tag == self.bot.scout_tag:
break
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"""
......
......@@ -7,13 +7,17 @@ class DarkTemplar:
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'DarkTemplar'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.squadsize = 0
self.bot.attack_count = 0
self.bot.retreat_count = 0
async def Run(self):
"""Runs on every GameStep"""
self.bot.current_strategy = 'DarkTemplar'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 0
await self.Macro()
await self.Micro()
await self.Buffs()
......@@ -126,7 +130,7 @@ class DarkTemplar:
if self.ramp_supply_built:
depot_placement_positions = self.bot.main_base_ramp.corner_depots | {self.bot.main_base_ramp.depot_in_middle}
depots = self.bot.units(UnitTypeId.PHOTONCANNON)
depots = self.bot.structures(UnitTypeId.PHOTONCANNON)
if depots:
depot_placement_positions = {d for d in depot_placement_positions if depots.closest_distance_to(d) > 3}
......
......@@ -8,14 +8,19 @@ class SkyToss:
self.bot = bot
self.ramp_supply_built = False
self.workerscout = None
self.bot.strategy = 'SkyToss'
self.bot.squadsize = 6
self.bot.squadsize = 0
self.bot.attack_count = 0
self.bot.retreat_count = 0
async def Run(self):
"""Runs on every GameStep"""
if self.bot.iteration == 1:
self.bot.not_squadunit.extend([UnitTypeId.ADEPT, UnitTypeId.INTERCEPTOR])
self.bot.not_commanderunit.extend([UnitTypeId.ADEPT, UnitTypeId.MOTHERSHIP, UnitTypeId.INTERCEPTOR])
self.bot.current_strategy = 'SkyToss'
self.bot.squadsize = 10
self.bot.attack_count = 1
self.bot.retreat_count = 0
if int(self.bot.time) <= 360:
self.bot.attack_count = 5
......@@ -209,7 +214,7 @@ class SkyToss:
if self.ramp_supply_built:
depot_placement_positions = self.bot.main_base_ramp.corner_depots | {self.bot.main_base_ramp.depot_in_middle}
depots = self.bot.units(UnitTypeId.PHOTONCANNON)
depots = self.bot.structures(UnitTypeId.PHOTONCANNON)
if depots:
depot_placement_positions = {d for d in depot_placement_positions if depots.closest_distance_to(d) > 3}
......
......@@ -11,13 +11,18 @@ class StalkerRush:
self.ramp_supply_built = False
self.coreboosted = None
self.workerscout = None
self.bot.strategy = 'StalkerRush'
self.bot.squadsize = 5
self.bot.squadsize = 0
self.bot.attack_count = 0
self.bot.retreat_count = 0
async def Run(self):
"""Runs on every GameStep"""
if self.bot.iteration == 1:
self.bot.not_commanderunit.append(UnitTypeId.SENTRY)
self.bot.current_strategy = 'StalkerRush'
self.bot.squadsize = 10
self.bot.attack_count = 1
self.bot.retreat_count = 0
if int(self.bot.time) <= 360:
self.bot.attack_count = 5
......@@ -226,7 +231,7 @@ class StalkerRush:
if self.ramp_supply_built:
depot_placement_positions = self.bot.main_base_ramp.corner_depots | {self.bot.main_base_ramp.depot_in_middle}
depots = self.bot.units(UnitTypeId.PHOTONCANNON)
depots = self.bot.structures(UnitTypeId.PHOTONCANNON)
if depots:
depot_placement_positions = {d for d in depot_placement_positions if depots.closest_distance_to(d) > 3}
......
......@@ -7,13 +7,17 @@ class ZealotRush:
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'ZealotRush'
self.bot.squadsize = 10
self.bot.attack_count = 1
self.bot.squadsize = 0
self.bot.attack_count = 0
self.bot.retreat_count = 0
async def Run(self):
"""Runs on every GameStep"""
self.bot.current_strategy = 'ZealotRush'
self.bot.squadsize = 10
self.bot.attack_count = 1
self.bot.retreat_count = 0
await self.Macro()
await self.Micro()
......@@ -50,12 +54,17 @@ class ZealotRush:
# Zealot Micro
zealots = self.bot.units(UnitTypeId.ZEALOT).ready
if zealots:
ground_enemies = self.bot.all_enemies.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))
for zealot in zealots:
enemies = self.bot.enemy_units
if enemies:
closeenemies = enemies.closer_than(30, zealot)
if closeenemies:
for e in closeenemies:
if not self.bot.techtree.can_attack(zealot, e) or not e.can_be_attacked or e.name == 'Larva':
closeenemies.remove(e)
if closeenemies:
next_enemy = closeenemies.closest_to(zealot)
distance2enemy = zealot.distance_to(next_enemy)
if distance2enemy < 20:
self.bot.do(zealot.attack(next_enemy))
......@@ -8,13 +8,17 @@ class MarineRush:
self.bot = bot
self.ramp_supply_built = False
self.workerscout = None
self.bot.strategy = 'MarineRush'
self.bot.squadsize = 10
self.bot.squadsize = 0
self.bot.attack_count = 0
self.bot.retreat_count = 0
async def Run(self):
"""Runs on every GameStep"""
self.bot.attack_count = 1
self.bot.retreat_count = 0
self.bot.attack_count = 10
self.bot.retreat_count = 2
self.bot.current_strategy = 'MarineRush'
self.bot.squadsize = 10
await self.Macro()
await self.Micro()
await self.Buffs()
......@@ -35,20 +39,13 @@ class MarineRush:
await self.bot.unitmanager.createBuilding("Barracks", barrackscount, self.bot.hq_location, 15)
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)
# Check if expansion is needed
if (self.bot.units(race_worker[self.bot.race]).ready.amount / 1.1) >= self.bot.neededworkers:
await self.bot.warmanager.expand()
if int(self.bot.time) >= 300 and self.bot.townhalls.amount == 1:
if int(self.bot.time) >= 180 and self.bot.townhalls.amount == 1:
await self.bot.warmanager.expand()
if int(self.bot.time) >= 600 and self.bot.townhalls.amount <= 3:
if int(self.bot.time) >= 360 and self.bot.townhalls.amount <= 3:
await self.bot.warmanager.expand()
async def Micro(self):
......@@ -115,22 +112,22 @@ class MarineRush:
async def Buffs(self):
# Supply Depots
# Raise depos when enemies are nearby
for depo in self.bot.units(UnitTypeId.SUPPLYDEPOT).ready:
for depo in self.bot.structures(UnitTypeId.SUPPLYDEPOT).ready:
for unit in self.bot.enemy_units.not_structure:
if unit.position.to2.distance_to(depo.position.to2) < 15:
break
else:
await self.bot.do(depo(AbilityId.MORPH_SUPPLYDEPOT_LOWER))
self.bot.do(depo(AbilityId.MORPH_SUPPLYDEPOT_LOWER))
# Lower depos when no enemies are nearby
for depo in self.bot.units(UnitTypeId.SUPPLYDEPOTLOWERED).ready:
for depo in self.bot.structures(UnitTypeId.SUPPLYDEPOTLOWERED).ready:
for unit in self.bot.enemy_units.not_structure:
if unit.position.to2.distance_to(depo.position.to2) < 10:
await self.bot.do(depo(AbilityId.MORPH_SUPPLYDEPOT_RAISE))
self.bot.do(depo(AbilityId.MORPH_SUPPLYDEPOT_RAISE))
break
# Scanner Sweep
for hq in self.bot.townhalls.ready:
for hq in self.bot.structures(UnitTypeId.ORBITALCOMMAND).ready.idle:
abilities = await self.bot.get_available_abilities(hq)
if AbilityId.SCANNERSWEEP_SCAN in abilities:
self.bot.do(hq(AbilityId.SCANNERSWEEP_SCAN, self.bot.enemy_start_locations[0]))
......@@ -139,7 +136,7 @@ class MarineRush:
async def createWall(self):
depot_placement_positions = self.bot.main_base_ramp.corner_depots | {self.bot.main_base_ramp.depot_in_middle}
depots = self.bot.units(UnitTypeId.SUPPLYDEPOT) | self.bot.units(UnitTypeId.SUPPLYDEPOTLOWERED)
depots = self.bot.structures(UnitTypeId.SUPPLYDEPOT) | self.bot.structures(UnitTypeId.SUPPLYDEPOTLOWERED)
if depots:
depot_placement_positions = {d for d in depot_placement_positions if depots.closest_distance_to(d) > 1}
......
......@@ -7,9 +7,8 @@ class BanelingSpam:
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'BanelingSpam'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.squadsize = 0
self.bot.attack_count = 0
self.bot.retreat_count = 0
async def Run(self):
......@@ -17,6 +16,10 @@ class BanelingSpam:
if self.bot.iteration == 1:
self.bot.not_squadunit.append(UnitTypeId.QUEEN)
self.bot.not_commanderunit.append(UnitTypeId.QUEEN)
self.bot.current_strategy = 'BanelingSpam'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 0
await self.Macro()
await self.Micro()
......
......@@ -7,16 +7,19 @@ class MutaliskRush:
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'MutaliskRush'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 3
self.bot.squadsize = 0
self.bot.attack_count = 0
self.bot.retreat_count = 0
async def Run(self):
"""Runs on every GameStep"""
if self.bot.iteration == 1:
self.bot.not_squadunit.append(UnitTypeId.QUEEN)
self.bot.not_commanderunit.append(UnitTypeId.QUEEN)
self.bot.current_strategy = 'MutaliskRush'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 3
await self.Macro()
await self.Micro()
......
......@@ -7,9 +7,8 @@ class ZerglingRush:
def __init__(self, bot=None):
self.bot = bot
self.workerscout = None
self.bot.strategy = 'ZerglingRush'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.squadsize = 0
self.bot.attack_count = 0
self.bot.retreat_count = 0
async def Run(self):
......@@ -18,6 +17,11 @@ class ZerglingRush:
self.bot.not_squadunit.append(UnitTypeId.QUEEN)
self.bot.not_commanderunit.append(UnitTypeId.QUEEN)
self.bot.current_strategy = 'ZerglingRush'
self.bot.squadsize = 10
self.bot.attack_count = 10
self.bot.retreat_count = 0
await self.Macro()
await self.Micro()
......
......@@ -5,20 +5,28 @@ class TerranManager():
"""Protoss Race Manager"""
def __init__(self, bot=None):
self.bot = bot
self.strategy = None
self.bot.strategy = None
self.bot.current_strategy = None
async def Run(self):
if self.bot.iteration == 1:
self.bot.not_squadunit.append(race_worker[self.bot.race])
self.bot.not_commanderunit.append(race_worker[self.bot.race])
if not self.strategy:
if not self.bot.strategy:
self.pickStrategy()
else:
await self.strategy.Run()
await self.bot.strategy.Run()
def pickStrategy(self):
strategies = [
MarineRush(self.bot)
]
self.strategy = random.choice(strategies)
strategies = {
'MarineRush': MarineRush(self.bot)
}
if self.bot.data_race_strategy in strategies:
self.bot.strategy = strategies[self.bot.data_race_strategy]
print("Using strategy: " + str(self.bot.strategy))
else:
print("No Data - Picking random strategy")
self.bot.strategy = random.choice(list(strategies.values()))
print("Using strategy:" + str(self.bot.strategy))
from sc2 import race_townhalls
from sc2.client import *
from sc2 import race_worker
from sc2 import Result
import sc2
from sc2.constants import *
import random
import os
import configparser
class WarManager():
def __init__(self, bot=None):
......@@ -27,6 +27,7 @@ class WarManager():
self.my_status_older = None
self.my_status = None
self.startcounter = None
self.attacktime = None
self.enemy_armypower_older = None
self.enemy_armypower = None
......@@ -37,6 +38,12 @@ class WarManager():
self.mineral_worker = None
async def Run(self):
self.bot.all_enemies = []
self.bot.all_enemies = self.bot.all_enemies + self.bot.enemy_units
self.bot.all_enemies = self.bot.all_enemies + self.bot.enemy_structures
await self.saveAttacktime()
if self.bot.iteration & 2 == 0:
await self.estimate()
await self.estimate_status()
......@@ -46,12 +53,9 @@ class WarManager():
await self.commanderroutine()
await self.fightroutine()
await self.counterworkerrush()
await self.countercannonrush()
await self.defendroutine()
self.bot.all_enemies = []
self.bot.all_enemies = self.bot.all_enemies + self.bot.enemy_units
self.bot.all_enemies = self.bot.all_enemies + self.bot.enemy_structures
if self.bot.showstatus:
if int(self.bot.time) & 2 == 0:
self.bot.gamemanager.clearscreen()
......@@ -65,11 +69,49 @@ class WarManager():
print("Enemy Status: " + self.enemy_status)
print("Enemy Status (-30s): " + self.enemy_status_older)
async def saveAttacktime(self):
"""Checks when 1st attack is made and writes to datafile"""
if not self.attacktime:
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
if self.bot.opponent_id:
datafile = "./data/" + str(self.bot.opponent_id) + ".db"
botdata = configparser.ConfigParser()
botdata.read(datafile)
if botdata.has_section("Enemy"):
botdata.set("Enemy", 'attacktime', str(self.attacktime))
botdata.set("Enemy", 'units', str(closeenemies))
with open(datafile, 'w') as dbfile:
botdata.write(dbfile)
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")
if not result:
return
if self.bot.opponent_id:
if result == Result.Defeat:
if self.bot.data_race_strategy:
datafile = "./data/" + str(self.bot.opponent_id) + ".db"
botdata = configparser.ConfigParser()
botdata.read(datafile)
if botdata.has_section(str(self.bot.race_self)):
print("We lost - Removing strategy " + str(self.bot.data_race_strategy))
botdata.remove_option(str(self.bot.race_self), 'strategy')
with open(datafile, 'w') as dbfile:
botdata.write(dbfile)
elif result == Result.Victory:
datafile = "./data/" + str(self.bot.opponent_id) + ".db"
botdata = configparser.ConfigParser()
botdata.read(datafile)
if botdata.has_section(str(self.bot.race_self)):
print("We won - Saving strategy " + str(self.bot.data_race_strategy))
botdata.set(str(self.bot.race_self), 'strategy', self.bot.current_strategy)
with open(datafile, 'w') as dbfile:
botdata.write(dbfile)
async def estimate(self):
"""Estimates the army value"""
......@@ -141,11 +183,64 @@ class WarManager():
if distance2ramp >= 5:
self.bot.do(fighter.move(self.bot.ramp_location))
async def counterworkerrush(self):
async def writeenemydata(self):
if self.bot.opponent_id:
if self.bot.enemy_units:
cannonrush = self.bot.enemy_structures.closer_than(35, self.bot.hq_location).filter(lambda w: w.type_id in [UnitTypeId.PHOTONCANNON])
if cannonrush:
datafile = "./data/" + str(self.bot.opponent_id) + ".db"
botdata = configparser.ConfigParser()
botdata.read(datafile)
if botdata.has_section("Enemy"):
botdata.set("Enemy", 'cannonrush', "True")
with open(datafile, 'w') as dbfile:
botdata.write(dbfile)
async def countercannonrush(self):
"""Detects Probe rushes - Stupidly"""
fighters = self.bot.units.filter(lambda w: w.type_id not in [race_worker[self.bot.race]])
if self.bot.enemy_units.not_structure:
enemyprobes = self.bot.enemy_units.not_structure.closer_than(30, self.bot.hq_location).filter(lambda w: w.type_id in [UnitTypeId.PROBE])
if enemyprobes.amount >= 2 and not fighters:
if not self.bot.workers.ready or fighters.amount >= 3:
return
if self.bot.all_enemies:
for enemy in self.bot.all_enemies:
distance2hq = enemy.position.distance_to(self.bot.hq_location)
if distance2hq <= 30 and ((enemy.name == 'Pylon') or (enemy.name == 'PhotonCannon')):
if self.bot.opponent_id:
datafile = "./data/" + str(self.bot.opponent_id) + ".db"
botdata = configparser.ConfigParser()
botdata.read(datafile)
if botdata.has_section("Enemy"):
if botdata.has_option("Enemy", "cannonrush"):
return
else:
botdata.set("Enemy", 'cannonrush', "True")
with open(datafile, 'w') as dbfile:
botdata.write(dbfile)
self.workercount = 0
for worker in self.bot.workers:
if self.workercount <= 1:
self.bot.do(worker.attack(enemy))
self.workercount = self.workercount + 1
break
async def counterworkerrush(self):
fighters = self.bot.units.filter(lambda w: w.type_id not in {race_worker[self.bot.race], UnitTypeId.LARVA, UnitTypeId.OVERLORD, UnitTypeId.EGG})
if self.bot.enemy_units:
enemyworker = self.bot.enemy_units.closer_than(30, self.bot.hq_location).filter(lambda w: w.type_id in [UnitTypeId.PROBE] or w.type_id in [UnitTypeId.SCV] or w.type_id in [UnitTypeId.DRONE])
if enemyworker.amount >= 2 and not fighters:
if self.bot.opponent_id:
datafile = "./data/" + str(self.bot.opponent_id) + ".db"
botdata = configparser.ConfigParser()
botdata.read(datafile)
if botdata.has_section("Enemy"):
if not botdata.has_option("Enemy", "workerrush"):
botdata.set("Enemy", 'workerrush', "True")
with open(datafile, 'w') as dbfile:
botdata.write(dbfile)
counterworkers = self.bot.units(race_worker[self.bot.race]).ready
mw = self.bot.units.find_by_tag(self.mineral_worker)
if counterworkers:
......@@ -158,7 +253,7 @@ class WarManager():
for counterworker in counterworkers:
distance2hq = counterworker.position.distance_to(self.bot.hq_location)
if distance2hq <= 30:
next_enemy = enemyprobes.closest_to(counterworker)
next_enemy = enemyworker.closest_to(counterworker.position)
self.bot.do(counterworker.attack(next_enemy))
for worker in self.bot.units(race_worker[self.bot.race]).ready:
......@@ -217,6 +312,9 @@ class WarManager():
UnitTypeId.WARPPRISMPHASING] and w.type_id not in [UnitTypeId.OBSERVERSIEGEMODE] and