Updates from another location

This commit is contained in:
Benjamin Morgan 2026-06-01 18:48:19 -06:00
parent 012153e0c8
commit c474c30306

56
main.py
View file

@ -4,17 +4,21 @@ from sc2.main import run_game
from sc2.data import Race, Difficulty
from sc2.bot_ai import BotAI
from sc2.units import UnitTypeId
import math
MAX_WORKERS = 100
class MyBot(BotAI):
def __init__(self):
super().__init__()
self.sold_townhalls = 0
async def on_step(self, iteration: int):
if not self.townhalls and self.already_pending(UnitTypeId.COMMANDCENTER) == 0:
if self.can_afford(UnitTypeId.COMMANDCENTER):
await self.build(UnitTypeId.COMMANDCENTER, near=self.start_location)
else:
cmd = self.structures(UnitTypeId.COMMANDCENTER)[0]
ideal_workers = 0
all_ideal = True
for u in self.all_units:
@ -23,37 +27,65 @@ class MyBot(BotAI):
if u.ideal_harvesters != u.assigned_harvesters:
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.can_afford(UnitTypeId.SCV):
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:
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:
await self.expand_now()
for cmd in self.townhalls:
if self.structures(UnitTypeId.BARRACKS).closer_than(15, cmd).amount + self.already_pending(UnitTypeId.BARRACKS) < 2:
if self.can_afford(UnitTypeId.BARRACKS):
await self.build(UnitTypeId.BARRACKS, near=cmd)
position_towards_map_center = cmd.position.towards(self.game_info.map_center, distance=5)
await self.build(UnitTypeId.BARRACKS, near=position_towards_map_center)
for b in self.structures(UnitTypeId.BARRACKS).closer_than(10, cmd):
for b in self.structures(UnitTypeId.BARRACKS).closer_than(15, cmd):
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:
await self.build(UnitTypeId.SUPPLYDEPOT, near=cmd)
position_towards_map_center = cmd.position.towards(self.game_info.map_center, distance=10)
await self.build(UnitTypeId.SUPPLYDEPOT, near=position_towards_map_center)
for vg in self.vespene_geyser.closer_than(10, cmd):
if self.can_afford(UnitTypeId.REFINERY):
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.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:
for m in self.units(UnitTypeId.REAPER).closer_than(10, cmd):
if self.enemy_units.amount > 0:
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])
if not all_ideal:
await self.distribute_workers()
run_game(maps.get("Acropolis LE"), [
run_game(maps.get("AcropolisLE"), [
Bot(Race.Terran, MyBot()),
Computer(Race.Protoss, Difficulty.Medium)
], realtime=True)