simplify bootstrap
@@ -6,56 +6,37 @@ from sc2.main import run_game
from sc2.player import Bot, Computer
from loguru import logger
+ME = 1
+PC = 2
+
class FightBot(BotAI):
def __init__(self):
super().__init__()
- self.control_received = False
+ self.enemy_location = None
self.fight_started = False
async def on_step(self, iteration):
# retrieve control by enabling enemy control and showing whole map
if iteration == 0:
- # we need this one for `self.enemy_units` to "see" all units on the map
await self._client.debug_show_map()
- # this one will allow us to do something like: `self.enemy_units.first.attack(self._game_info.map_center)`
await self._client.debug_control_enemy()
- # wait till control retrieved
- if iteration > 0 and self.enemy_units and not self.control_received:
- # prepare my side
- me = 1
-
- cc = self.townhalls.first
- p = cc.position.towards(self.game_info.map_center, 4)
- # create supply
- await self._client.debug_create_unit([[UnitTypeId.SUPPLYDEPOT, 1, p, me]])
- # destroy command center
- await self._client.debug_kill_unit([cc.tag])
- # destroy all workers
- await self._client.debug_kill_unit([w.tag for w in self.workers])
-
- # create marines
- await self._client.debug_create_unit([[UnitTypeId.MARINE, 4, p, me]])
-
- # prepare opponent side
- pc = 2
- cc = self.enemy_structures.first
- p = cc.position.towards(self.game_info.map_center, 4)
- # create supply
- await self._client.debug_create_unit([[UnitTypeId.SUPPLYDEPOT, 1, p, pc]])
- # destroy command center
- await self._client.debug_kill_unit([cc.tag])
- # destroy all workers
- await self._client.debug_kill_unit([w.tag for w in self.enemy_units(UnitTypeId.SCV)])
- # create marines
- await self._client.debug_create_unit([[UnitTypeId.MARINE, 4, p, pc]])
- logger.info("control received")
- # await self.chat_send("control received")
- self.control_received = True
+ # wait till control retrieved, destroy all starting units, recreate the world
+ if iteration > 0 and self.enemy_units and not self.enemy_location:
+ self.enemy_location = self.enemy_structures(UnitTypeId.COMMANDCENTER).first.position.closest(self.enemy_start_locations)
+ await self._client.debug_kill_unit([u.tag for u in self.units + self.structures + self.enemy_units + self.enemy_structures])
+ await self._client.debug_create_unit([
+ [UnitTypeId.SUPPLYDEPOT, 1, self.enemy_location, PC],
+ [UnitTypeId.MARINE, 4, self.enemy_location.towards(self.start_location, 8), PC]
+ ])
+ await self._client.debug_create_unit([
+ [UnitTypeId.SUPPLYDEPOT, 1, self.start_location, ME],
+ [UnitTypeId.MARINE, 4, self.start_location.towards(self.enemy_location, 8), ME]
+ ])
# note: we should wait till workers will be destroyed
- if not self.fight_started and self.control_received and self.enemy_units and not self.enemy_units(UnitTypeId.SCV) and not self.units(UnitTypeId.SCV):
+ if not self.fight_started and self.enemy_location and not self.enemy_units(UnitTypeId.SCV) and not self.units(UnitTypeId.SCV):
# start fight
for u in self.enemy_units:
u.attack(self.structures.first.position)
