Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Build order support #18

Open
wants to merge 82 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
824bdef
Add inline condition to prevent converting of 'None' to string for no…
Jan 26, 2018
9ea30f7
Merge branch 'master' into playable
Jan 26, 2018
cf0483c
Initial implementation of build order support
Jan 26, 2018
d6e168d
Merge branch 'master' into build-order-support
reypader Jan 26, 2018
c8c0d5e
Move build order related files to its own submodule
reypader Jan 26, 2018
5c80134
Move can_afford conditions into the actions of the build order
reypader Jan 26, 2018
96ff76e
Add `expand` build order action
reypader Jan 26, 2018
4ba7ac6
Wrap cwd expression in parentheses
reypader Jan 26, 2018
13e8bcd
Merge remote-tracking branch 'remotes/upstream/master'
reypader Jan 26, 2018
f45d613
Add return resource command to units
reypader Jan 26, 2018
cb6ff95
Initialize geysers for each step
reypader Jan 26, 2018
9096d22
Conver `expansion_locations` to a dict of Point2D: Mineral Fields
reypader Jan 26, 2018
2fd008b
Implement distribution of workers
reypader Jan 26, 2018
79655e0
Add sample script to showcase worker distribution in action
reypader Jan 26, 2018
2ecb34b
Change `BotAI.already_pending` to return integers to allow counting
reypader Jan 27, 2018
f01042e
Add support for morhping instead of training for Zerg
reypader Jan 27, 2018
e68e686
rename unit_count arguments
reypader Jan 27, 2018
63505df
Introduce Intent class and make worker creation a parameter
reypader Jan 27, 2018
156fcad
Allow build order actions to be executed indefinitely as long as it's…
reypader Jan 27, 2018
f69a91d
Add supply, geyser, townhall, and worker type properties to BotAI
Jan 28, 2018
3c1beec
Move state conditions into separate submodule
Jan 28, 2018
c05f930
Add auto-add-supply feature to build order
Jan 28, 2018
78cf389
Partial fix for #8 - already_pending returns count instead of boolean
Jan 28, 2018
a919b05
Move commands into a different submodule for clear separation.
Jan 28, 2018
a34faa9
Wrap the response of `BotAI.can_afford` to return a wrapper
Jan 28, 2018
c81dffe
Add `action_result` property to CanAffordWrapper
Jan 28, 2018
95c3f62
Merge branch 'worker-distribution' into build-order-support
Jan 28, 2018
b0d7a64
Merge branch 'can_afford-wrapper' into build-order-support
Jan 28, 2018
0aadf21
Convert get_owned_expansions to owned_expansions property
Jan 28, 2018
ea1545d
Merge branch 'worker-distribution' into build-order-support
Jan 28, 2018
28850b2
Add support for rich mineral fields
Jan 28, 2018
e45bea9
Merge branch 'worker-distribution' into build-order-support
Jan 28, 2018
e0e89c9
Utilize `can_afford` wrapper
Jan 28, 2018
bd5a716
Allow prioritization of build order actions
Jan 28, 2018
5a59654
Adjust priority of build commands in build orders
Jan 28, 2018
ffb3ea8
Assign idle workers to gather before distribution
Jan 28, 2018
3fc94f6
Merge branch 'worker-distribution' into build-order-support
Jan 28, 2018
4da9af8
Optimize mineral field selection during transfer
Jan 28, 2018
1c29052
Merge branch 'worker-distribution' into build-order-support
Jan 28, 2018
63cf2af
Add unit count conditions
Jan 28, 2018
329ce67
Tweak sample scripts
Jan 28, 2018
495ace3
Queue gather command when transferring workers with resource
Jan 28, 2018
85c0581
Merge branch 'worker-distribution' into build-order-support
Jan 29, 2018
a519808
Add terran build order sample - marine rush
Jan 29, 2018
c9e8f01
Make auto-adding supply to be done when there's at least 1 supply lef…
Jan 30, 2018
e37848c
Rename commands to avoid confusion with core SC2 methods
Jan 30, 2018
e5518ac
Use the installed StarCraft 2 stableid.json for ids
Jan 30, 2018
8f705ab
Update header in id files
Jan 30, 2018
b2778d1
Use abilities with index 0
Jan 30, 2018
8be993c
Add support for getting the available abilities of a unit
Jan 30, 2018
1ac55cd
Merge branch 'can-cast-support' into build-order-support
Jan 30, 2018
e988a5f
Merge branch 'use-stableid-json' into build-order-support
Jan 30, 2018
983e52c
remove PyCharm files
Jan 30, 2018
2324062
Manually add SMART ability
Jan 30, 2018
5a64a3d
Convert usage of enums to new enum names
Jan 30, 2018
6eb9c0e
Merge branch 'use-stableid-json' into build-order-support
Jan 30, 2018
fe048c1
Tweak naming extraction to use friendly name whenever possible
Jan 30, 2018
9f0407e
Revert to using globals in examples
Jan 31, 2018
7c4f654
Adjust variable naming in zerg_rush.py
Jan 31, 2018
bea5073
Revert to using globals but add assertion for duplicate enums
Jan 31, 2018
41eaed4
Revert to some global usage in examples
Jan 31, 2018
dd1a85a
Merge remote-tracking branch 'upstream/master' into worker-distribution
Jan 31, 2018
910d2e9
Remove usage of state parameter in sample
Jan 31, 2018
e3159cc
Merge remote-tracking branch 'upstream/master' into can-cast-support
Jan 31, 2018
9471626
Merge remote-tracking branch 'upstream/master' into use-stableid-json
Jan 31, 2018
f199af1
Merge branch 'master' of github.com:Dentosal/python-sc2
Feb 1, 2018
071be7f
Merge branch 'can-cast-support'
Feb 1, 2018
0d90df9
Merge branch 'already-pending-enhancement'
Feb 1, 2018
e98cd55
Merge branch 'worker-distribution'
Feb 1, 2018
ebcf1ff
Merge branch 'use-stableid-json'
Feb 1, 2018
ad9d314
Ignore pycharm files
Feb 1, 2018
1620f16
Merge branch 'master' into build-order-support
Feb 1, 2018
9c60adc
Fix state parameters being passed
Feb 1, 2018
902b877
Update example for chronoboost cast
Feb 1, 2018
a8ceab2
Fix enum names changed from new ID generation script
Feb 1, 2018
d3d4ec9
Implement warpgate support using find_placement and available_abilities
Feb 1, 2018
e75cb65
Merge branch 'warpgate-support' into build-order-support
Feb 1, 2018
c0ba90f
Merge remote-tracking branch 'upstream/master' into use-stableid-json
Feb 1, 2018
32b422a
Rever BotAI find placement default step to 2
Feb 1, 2018
1726531
Remove local path in generated files
Feb 1, 2018
ae55f67
Merge branch 'use-stableid-json' into build-order-support
Feb 1, 2018
c5f2b26
Merge branch 'master' of github.com:Dentosal/python-sc2 into build-or…
Feb 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move can_afford conditions into the actions of the build order
To be concise, only the condition must be checked to decide whether
the action would be done. Checking `can_afford` is the responsibility of the action.
  • Loading branch information
reypader committed Jan 26, 2018
commit 5c80134dd147a9f4e00b4fee3673e453c0f70272
17 changes: 12 additions & 5 deletions sc2/build_orders/build_order.py
Original file line number Diff line number Diff line change
@@ -12,25 +12,26 @@ async def execute_build(self, state):
if index > self.next_execution:
return None

condition, intent = item
action, intended_unit = intent
condition, action = item
condition = item[0] if item[0] else always_true
if condition(self.bot, state) and self.bot.can_afford(intended_unit):
if condition(self.bot, state):
print("Executing build order index {}".format(index))
self.next_execution = index + 1
print("Next build order index {}".format(self.next_execution))
return await action(self.bot, state)


def train(unit, on_building):
async def train_spec(bot, state):
buildings = bot.units(on_building).ready.noqueue
if buildings.exists:
if buildings.exists and bot.can_afford(unit):
selected = buildings.first
print("Training {}".format(unit))
return await bot.do(selected.train(unit))
else:
return None

return train_spec, unit
return train_spec


def build(building, around_building=None, placement=None):
@@ -44,4 +45,10 @@ async def build_spec(bot, state):
location = around.position.towards(bot.game_info.map_center, 5)
else:
location = placement
if bot.can_afford(building):
print("Building {}".format(building))
return await bot.build(building, near=location)
else:
return None

return build_spec