Skip to content

Commit 9c60adc

Browse files
author
Reynald Pader
committed
Fix state parameters being passed
1 parent 1620f16 commit 9c60adc

File tree

7 files changed

+39
-39
lines changed

7 files changed

+39
-39
lines changed

examples/terran_marine_rush_build_order.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sc2.state_conditions.conditions import all_of, supply_at_least, minerals_at_least, unit_count
88

99

10-
def first_barracks(bot, state):
10+
def first_barracks(bot):
1111
return bot.units(UnitTypeId.BARRACKS).first
1212

1313

@@ -38,9 +38,9 @@ def __init__(self):
3838
self.attack = False
3939
self.build_order = BuildOrder(self, build_order, worker_count=16)
4040

41-
async def on_step(self, state, iteration):
41+
async def on_step(self, iteration):
4242
await self.distribute_workers()
43-
await self.build_order.execute_build(state)
43+
await self.build_order.execute_build()
4444

4545
if self.units(UnitTypeId.MARINE).amount >= 15 or self.attack:
4646
self.attack = True

examples/threebase_voidray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sc2.player import Bot, Computer
88

99
class ThreebaseVoidrayBot(sc2.BotAI):
10-
def select_target(self, state):
10+
def select_target(self):
1111
if self.known_enemy_structures.exists:
1212
return random.choice(self.known_enemy_structures)
1313

examples/zerg_rush_build_order.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def research(building, upgrade):
12-
async def research_spec(bot,state):
12+
async def research_spec(bot):
1313
sp = bot.units(building).ready
1414
if sp.exists and bot.can_afford(upgrade) and not bot.already_pending(upgrade):
1515
await bot.do(sp.first(upgrade))
@@ -37,7 +37,7 @@ def __init__(self):
3737

3838
self.build_order = BuildOrder(self, build_order, worker_count=35)
3939

40-
async def on_step(self, state, iteration):
40+
async def on_step(self, iteration):
4141
await self.distribute_workers()
4242

4343
if self.vespene >= 100:
@@ -46,7 +46,7 @@ async def on_step(self, state, iteration):
4646
await self.do(sp.first(AbilityId.ZERGLINGMOVEMENTSPEED))
4747
self.mboost_started = True
4848

49-
await self.build_order.execute_build(state)
49+
await self.build_order.execute_build()
5050

5151
for queen in self.units(UnitTypeId.QUEEN).idle:
5252
if queen.energy >= 25: # Hard coded, since this is not (yet) available

sc2/bot_ai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def already_pending(self, unit_type):
250250
return sum([o.ability == ability for w in self.workers for o in w.orders])
251251
elif any(egg.orders[0].ability == ability for egg in self.units(EGG)):
252252
return sum([egg.orders[0].ability == ability for egg in self.units(EGG)])
253-
return
253+
return 0
254254

255255
async def build(self, building, near, max_distance=20, unit=None, random_alternative=True, placement_step=2):
256256
if isinstance(near, Unit):

sc2/build_orders/build_order.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ def __init__(self, bot, build, worker_count=0, auto_add_supply=True):
1010
self.worker_count = worker_count
1111
self.auto_add_supply = auto_add_supply
1212

13-
async def execute_build(self, state):
13+
async def execute_build(self):
1414
bot = self.bot
1515
if bot.supply_left <= ((bot.supply_cap+50) / 50) and not bot.already_pending(bot.supply_type) \
1616
and self.auto_add_supply:
17-
return await add_supply().execute(bot, state)
17+
return await add_supply().execute(bot)
1818

1919
for index, item in enumerate(self.build):
2020
condition, command = item
2121
condition = item[0] if item[0] else always_true
22-
if condition(bot, state) and not command.is_done:
23-
e = await command.execute(bot, state)
22+
if condition(bot) and not command.is_done:
23+
e = await command.execute(bot)
2424
if command.is_done:
2525
return e
2626
else:
@@ -30,12 +30,12 @@ async def execute_build(self, state):
3030

3131
if e == ActionResult.NotEnoughFood and self.auto_add_supply \
3232
and not bot.already_pending(bot.supply_type):
33-
return await add_supply().execute(bot, state)
33+
return await add_supply().execute(bot)
3434
continue
3535

3636
if bot.workers.amount < self.worker_count:
3737
if bot.race == Race.Zerg:
38-
return await morph(race_worker[Race.Zerg]).execute(bot, state)
38+
return await morph(race_worker[Race.Zerg]).execute(bot)
3939
else:
40-
return await train_unit(race_worker[bot.race], race_townhalls[self.bot.race]).execute(bot, state)
40+
return await train_unit(race_worker[bot.race], race_townhalls[self.bot.race]).execute(bot)
4141
return None

sc2/build_orders/commands.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def __init__(self, action, repeatable=False, priority=False):
99
self.is_repeatable = repeatable
1010
self.is_priority = priority
1111

12-
async def execute(self, bot, state):
13-
e = await self.action(bot, state)
12+
async def execute(self, bot):
13+
e = await self.action(bot)
1414
if not e and not self.is_repeatable:
1515
self.is_done = True
1616

@@ -23,7 +23,7 @@ def allow_repeat(self):
2323

2424

2525
def expand(prioritize=False, repeatable=True):
26-
async def do_expand(bot, state):
26+
async def do_expand(bot):
2727
building = bot.basic_townhall_type
2828
can_afford = bot.can_afford(building)
2929
if can_afford:
@@ -35,7 +35,7 @@ async def do_expand(bot, state):
3535

3636

3737
def train_unit(unit, on_building, prioritize=False, repeatable=False):
38-
async def do_train(bot, state):
38+
async def do_train(bot):
3939
buildings = bot.units(on_building).ready.noqueue
4040
if buildings.exists:
4141
selected = buildings.first
@@ -52,7 +52,7 @@ async def do_train(bot, state):
5252

5353

5454
def morph(unit, prioritize=False, repeatable=False):
55-
async def do_morph(bot, state):
55+
async def do_morph(bot):
5656
larvae = bot.units(UnitTypeId.LARVA)
5757
if larvae.exists:
5858
selected = larvae.first
@@ -69,7 +69,7 @@ async def do_morph(bot, state):
6969

7070

7171
def construct(building, placement=None, prioritize=True, repeatable=False):
72-
async def do_build(bot, state):
72+
async def do_build(bot):
7373

7474
if not placement:
7575
location = bot.townhalls.first.position.towards(bot.game_info.map_center, 5)
@@ -87,28 +87,28 @@ async def do_build(bot, state):
8787

8888

8989
def add_supply(prioritize=True, repeatable=False):
90-
async def supply_spec(bot, state):
90+
async def supply_spec(bot):
9191
can_afford = bot.can_afford(bot.supply_type)
9292
if can_afford:
9393
if bot.race == Race.Zerg:
94-
return await morph(bot.supply_type).execute(bot, state)
94+
return await morph(bot.supply_type).execute(bot)
9595
else:
96-
return await construct(bot.supply_type).execute(bot, state)
96+
return await construct(bot.supply_type).execute(bot)
9797
else:
9898
return can_afford.action_result
9999

100100
return Command(supply_spec, priority=prioritize, repeatable=repeatable)
101101

102102

103103
def add_gas(prioritize=True, repeatable=False):
104-
async def do_add_gas(bot, state):
104+
async def do_add_gas(bot):
105105
can_afford = bot.can_afford(bot.geyser_type)
106106
if not can_afford:
107107
return can_afford.action_result
108108

109109
owned_expansions = bot.owned_expansions
110110
for location, th in owned_expansions.items():
111-
vgs = state.vespene_geyser.closer_than(20.0, th)
111+
vgs = bot.state.vespene_geyser.closer_than(20.0, th)
112112
for vg in vgs:
113113
worker = bot.select_build_worker(vg.position)
114114
if worker is None:

sc2/state_conditions/conditions.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
def all_of(*args):
2-
def condition(bot, state):
3-
return all(map(lambda a: a(bot, state), args))
2+
def condition(bot):
3+
return all(map(lambda a: a(bot), args))
44

55
return condition
66

77

88
def any_of(*args):
9-
def condition(bot, state):
10-
return all(any(lambda a: a(bot, state), args))
9+
def condition(bot):
10+
return all(any(lambda a: a(bot), args))
1111

1212
return condition
1313

1414

15-
def always_true(bot, state):
15+
def always_true(bot):
1616
return True
1717

1818

1919
def supply_at_least(s):
20-
def condition(bot, state):
20+
def condition(bot):
2121
return bot.supply_used >= s
2222

2323
return condition
2424

2525

2626
def gas_at_least(s):
27-
def condition(bot, state):
27+
def condition(bot):
2828
return bot.vespene >= s
2929

3030
return condition
3131

3232

3333
def gas_less_than(s):
34-
def condition(bot, state):
34+
def condition(bot):
3535
return bot.vespene < s
3636

3737
return condition
3838

3939

4040
def minerals_at_least(s):
41-
def condition(bot, state):
41+
def condition(bot):
4242
return bot.minerals >= s
4343

4444
return condition
4545

4646

4747
def minerals_less_than(s):
48-
def condition(bot, state):
48+
def condition(bot):
4949
return bot.minerals < s
5050

5151
return condition
5252

5353

5454
def unit_count(unit, n, include_pending=False):
55-
def condition(bot, state):
55+
def condition(bot):
5656
actual_amount = bot.units(unit).amount
5757
if include_pending:
5858
actual_amount += bot.already_pending(unit)
@@ -62,7 +62,7 @@ def condition(bot, state):
6262

6363

6464
def unit_count_at_least(unit, n, include_pending=False):
65-
def condition(bot, state):
65+
def condition(bot):
6666
actual_amount = bot.units(unit).amount
6767
if include_pending:
6868
actual_amount += bot.already_pending(unit)
@@ -72,7 +72,7 @@ def condition(bot, state):
7272

7373

7474
def unit_count_less_than(unit, n, include_pending=False):
75-
def condition(bot, state):
75+
def condition(bot):
7676
actual_amount = bot.units(unit).amount
7777
if include_pending:
7878
actual_amount += bot.already_pending(unit)

0 commit comments

Comments
 (0)