Updates from another location
This commit is contained in:
parent
012153e0c8
commit
c474c30306
1 changed files with 49 additions and 17 deletions
66
main.py
66
main.py
|
|
@ -4,17 +4,21 @@ from sc2.main import run_game
|
||||||
from sc2.data import Race, Difficulty
|
from sc2.data import Race, Difficulty
|
||||||
from sc2.bot_ai import BotAI
|
from sc2.bot_ai import BotAI
|
||||||
from sc2.units import UnitTypeId
|
from sc2.units import UnitTypeId
|
||||||
|
import math
|
||||||
|
|
||||||
|
MAX_WORKERS = 100
|
||||||
|
|
||||||
class MyBot(BotAI):
|
class MyBot(BotAI):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.sold_townhalls = 0
|
||||||
|
|
||||||
async def on_step(self, iteration: int):
|
async def on_step(self, iteration: int):
|
||||||
if not self.townhalls and self.already_pending(UnitTypeId.COMMANDCENTER) == 0:
|
if not self.townhalls and self.already_pending(UnitTypeId.COMMANDCENTER) == 0:
|
||||||
if self.can_afford(UnitTypeId.COMMANDCENTER):
|
if self.can_afford(UnitTypeId.COMMANDCENTER):
|
||||||
await self.build(UnitTypeId.COMMANDCENTER, near=self.start_location)
|
await self.build(UnitTypeId.COMMANDCENTER, near=self.start_location)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
cmd = self.structures(UnitTypeId.COMMANDCENTER)[0]
|
|
||||||
|
|
||||||
ideal_workers = 0
|
ideal_workers = 0
|
||||||
all_ideal = True
|
all_ideal = True
|
||||||
for u in self.all_units:
|
for u in self.all_units:
|
||||||
|
|
@ -23,37 +27,65 @@ class MyBot(BotAI):
|
||||||
if u.ideal_harvesters != u.assigned_harvesters:
|
if u.ideal_harvesters != u.assigned_harvesters:
|
||||||
all_ideal = False
|
all_ideal = False
|
||||||
|
|
||||||
|
ideal_workers = min(MAX_WORKERS, ideal_workers)
|
||||||
|
|
||||||
|
# if ideal_workers == MAX_WORKERS:
|
||||||
|
# sell_cmd = self.structures(UnitTypeId.COMMANDCENTER).closest_to(self.start_location)
|
||||||
|
# for s in (self.structures - self.structures(UnitTypeId.SUPPLYDEPOT)).closer_than(15, sell_cmd):
|
||||||
|
# s.
|
||||||
|
|
||||||
|
cmd = self.structures(UnitTypeId.COMMANDCENTER)[0]
|
||||||
|
|
||||||
if self.workers.amount + self.already_pending(UnitTypeId.SCV) < ideal_workers:
|
if self.workers.amount + self.already_pending(UnitTypeId.SCV) < ideal_workers:
|
||||||
if self.can_afford(UnitTypeId.SCV):
|
if self.can_afford(UnitTypeId.SCV):
|
||||||
self.train(UnitTypeId.SCV, closest_to=cmd)
|
self.train(UnitTypeId.SCV, closest_to=cmd)
|
||||||
elif not self.can_feed(UnitTypeId.SCV) and self.can_afford(UnitTypeId.SUPPLYDEPOT) and self.already_pending(UnitTypeId.SUPPLYDEPOT) == 0:
|
elif not self.can_feed(UnitTypeId.SCV) and self.can_afford(UnitTypeId.SUPPLYDEPOT) and self.already_pending(UnitTypeId.SUPPLYDEPOT) == 0:
|
||||||
await self.build(UnitTypeId.SUPPLYDEPOT, near=cmd)
|
position_towards_map_center = cmd.position.towards(self.game_info.map_center, distance=5)
|
||||||
|
await self.build(UnitTypeId.SUPPLYDEPOT, near=position_towards_map_center)
|
||||||
|
|
||||||
if self.structures(UnitTypeId.BARRACKS).closer_than(10, cmd).amount + self.already_pending(UnitTypeId.BARRACKS) < 2:
|
if self.can_afford(UnitTypeId.COMMANDCENTER) and self.already_pending(UnitTypeId.COMMANDCENTER) == 0 and ideal_workers < MAX_WORKERS:
|
||||||
if self.can_afford(UnitTypeId.BARRACKS):
|
await self.expand_now()
|
||||||
await self.build(UnitTypeId.BARRACKS, near=cmd)
|
|
||||||
|
|
||||||
for b in self.structures(UnitTypeId.BARRACKS).closer_than(10, cmd):
|
for cmd in self.townhalls:
|
||||||
if b.is_idle:
|
if self.structures(UnitTypeId.BARRACKS).closer_than(15, cmd).amount + self.already_pending(UnitTypeId.BARRACKS) < 2:
|
||||||
if self.can_afford(UnitTypeId.REAPER):
|
if self.can_afford(UnitTypeId.BARRACKS):
|
||||||
self.train(UnitTypeId.REAPER, closest_to=cmd)
|
position_towards_map_center = cmd.position.towards(self.game_info.map_center, distance=5)
|
||||||
elif not self.can_feed(UnitTypeId.REAPER) and self.can_afford(UnitTypeId.SUPPLYDEPOT) and self.already_pending(UnitTypeId.SUPPLYDEPOT) == 0:
|
await self.build(UnitTypeId.BARRACKS, near=position_towards_map_center)
|
||||||
await self.build(UnitTypeId.SUPPLYDEPOT, near=cmd)
|
|
||||||
|
|
||||||
for vg in self.vespene_geyser.closer_than(10, cmd):
|
for b in self.structures(UnitTypeId.BARRACKS).closer_than(15, cmd):
|
||||||
if self.can_afford(UnitTypeId.REFINERY):
|
if b.is_idle:
|
||||||
|
if self.can_afford(UnitTypeId.REAPER):
|
||||||
|
self.train(UnitTypeId.REAPER, closest_to=cmd)
|
||||||
|
elif not self.can_feed(UnitTypeId.REAPER) and self.can_afford(UnitTypeId.SUPPLYDEPOT) and self.already_pending(UnitTypeId.SUPPLYDEPOT) == 0:
|
||||||
|
position_towards_map_center = cmd.position.towards(self.game_info.map_center, distance=10)
|
||||||
|
await self.build(UnitTypeId.SUPPLYDEPOT, near=position_towards_map_center)
|
||||||
|
|
||||||
|
if self.can_afford(UnitTypeId.REFINERY) and self.already_pending(UnitTypeId.REFINERY) == 0 and self.vespene_geyser.closer_than(10, cmd).amount > 0:
|
||||||
|
vg = self.vespene_geyser.closer_than(10, cmd)[0]
|
||||||
drone = self.workers.closest_to(vg)
|
drone = self.workers.closest_to(vg)
|
||||||
drone.build_gas(vg)
|
drone.build_gas(vg)
|
||||||
|
|
||||||
if self.units(UnitTypeId.REAPER).closer_than(10, cmd).amount > 0 and self.units(UnitTypeId.REAPER).closer_than(10, cmd).amount % 10 == 0:
|
if self.enemy_units.amount > 0:
|
||||||
for m in self.units(UnitTypeId.REAPER).closer_than(10, cmd):
|
target = self.enemy_units.closest_to(self.start_location)
|
||||||
|
rally = self.units(UnitTypeId.REAPER).closest_to(target)
|
||||||
|
if self.units(UnitTypeId.REAPER).closer_than(10, rally).amount > self.enemy_units.amount:
|
||||||
|
for m in self.units(UnitTypeId.REAPER):
|
||||||
|
m.attack(target)
|
||||||
|
else:
|
||||||
|
for m in self.units(UnitTypeId.REAPER):
|
||||||
|
m.move(rally)
|
||||||
|
elif len(self.blips) > 0:
|
||||||
|
for m in self.units(UnitTypeId.REAPER):
|
||||||
|
m.attack(sorted(self.blips, key=lambda x: math.dist(x.position, self.start_location))[0])
|
||||||
|
elif self.units(UnitTypeId.REAPER).amount > 0 and self.units(UnitTypeId.REAPER).amount % 10 == 0:
|
||||||
|
for m in self.units(UnitTypeId.REAPER):
|
||||||
m.attack(self.enemy_start_locations[0])
|
m.attack(self.enemy_start_locations[0])
|
||||||
|
|
||||||
if not all_ideal:
|
if not all_ideal:
|
||||||
await self.distribute_workers()
|
await self.distribute_workers()
|
||||||
|
|
||||||
|
|
||||||
run_game(maps.get("Acropolis LE"), [
|
run_game(maps.get("AcropolisLE"), [
|
||||||
Bot(Race.Terran, MyBot()),
|
Bot(Race.Terran, MyBot()),
|
||||||
Computer(Race.Protoss, Difficulty.Medium)
|
Computer(Race.Protoss, Difficulty.Medium)
|
||||||
], realtime=True)
|
], realtime=True)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue