sc2ai 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/data/data.json +1 -1
- data/data/data_readable.json +238 -134
- data/data/stableid.json +2574 -404
- data/lib/sc2ai/api/ability_id.rb +319 -12
- data/lib/sc2ai/api/buff_id.rb +11 -1
- data/lib/sc2ai/api/tech_tree.rb +0 -1
- data/lib/sc2ai/api/tech_tree_data.rb +32 -28
- data/lib/sc2ai/api/unit_type_id.rb +58 -6
- data/lib/sc2ai/api/upgrade_id.rb +2 -0
- data/lib/sc2ai/cli/cli.rb +35 -33
- data/lib/sc2ai/cli/ladderzip.rb +22 -3
- data/lib/sc2ai/player/actions.rb +4 -3
- data/lib/sc2ai/player/debug.rb +50 -4
- data/lib/sc2ai/player/geometry.rb +75 -6
- data/lib/sc2ai/player/units.rb +2 -2
- data/lib/sc2ai/player.rb +7 -7
- data/lib/sc2ai/protocol/extensions/point.rb +13 -1
- data/lib/sc2ai/protocol/extensions/unit.rb +54 -7
- data/lib/sc2ai/unit_group/action_ext.rb +22 -2
- data/lib/sc2ai/unit_group.rb +22 -10
- data/lib/sc2ai/version.rb +1 -1
- data/lib/templates/new/my_bot.rb.tt +2 -3
- data/sig/sc2ai.rbs +10183 -0
- metadata +44 -72
- data/sc2ai.gemspec +0 -80
@@ -179,6 +179,26 @@ module Api
|
|
179
179
|
action(ability_id: Api::AbilityId::SMART, target:, queue_command:)
|
180
180
|
end
|
181
181
|
|
182
|
+
# Shorthand for performing action MOVE
|
183
|
+
# @param target [Api::Unit, Integer, Api::Point2D] is a unit, unit tag or a Api::Point2D
|
184
|
+
# @param queue_command [Boolean] shift+command
|
185
|
+
def move(target:, queue_command: false)
|
186
|
+
action(ability_id: Api::AbilityId::MOVE, target:, queue_command:)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Shorthand for performing action STOP
|
190
|
+
# @param queue_command [Boolean] shift+command
|
191
|
+
def stop(queue_command: false)
|
192
|
+
action(ability_id: Api::AbilityId::STOP, queue_command:)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Shorthand for performing action HOLDPOSITION
|
196
|
+
# @param queue_command [Boolean] shift+command
|
197
|
+
def hold(queue_command: false)
|
198
|
+
action(ability_id: Api::AbilityId::HOLDPOSITION, queue_command:)
|
199
|
+
end
|
200
|
+
alias_method :hold_position, :hold
|
201
|
+
|
182
202
|
# Shorthand for performing action ATTACK
|
183
203
|
# @param target [Api::Unit, Integer, Api::Point2D] is a unit, unit tag or a Api::Point2D
|
184
204
|
# @param queue_command [Boolean] shift+command
|
@@ -224,6 +244,7 @@ module Api
|
|
224
244
|
# Draws a placement outline
|
225
245
|
# @param color [Api::Color] optional api color, default white
|
226
246
|
# @return [void]
|
247
|
+
# noinspection RubyArgCount
|
227
248
|
def debug_draw_placement(color = nil)
|
228
249
|
# Slightly elevate the Z position so that the line doesn't clip into the terrain at same Z level
|
229
250
|
z_elevated = pos.z + 0.01
|
@@ -432,6 +453,12 @@ module Api
|
|
432
453
|
build_progress == 1.0 # standard:disable Lint/FloatComparison
|
433
454
|
end
|
434
455
|
|
456
|
+
# Returns true if build progress is < 100%
|
457
|
+
# @return [Boolean]
|
458
|
+
def in_progress?
|
459
|
+
!is_completed?
|
460
|
+
end
|
461
|
+
|
435
462
|
# Convenience functions ---
|
436
463
|
|
437
464
|
# TERRAN Convenience functions ---
|
@@ -444,7 +471,7 @@ module Api
|
|
444
471
|
|
445
472
|
# Returns whether the structure has a reactor add-on
|
446
473
|
# @return [Boolean] if the unit has a reactor attached
|
447
|
-
def has_reactor
|
474
|
+
def has_reactor?
|
448
475
|
Sc2::UnitGroup::TYPE_REACTOR.include?(add_on&.unit_type)
|
449
476
|
end
|
450
477
|
|
@@ -455,26 +482,46 @@ module Api
|
|
455
482
|
# # Get the actual tech-lab with #add_on
|
456
483
|
# sp.add_on.research ...
|
457
484
|
# @return [Boolean] if the unit has a tech lab attached
|
458
|
-
def has_tech_lab
|
485
|
+
def has_tech_lab?
|
459
486
|
Sc2::UnitGroup::TYPE_TECHLAB.include?(add_on&.unit_type)
|
460
487
|
end
|
461
488
|
|
462
489
|
# For Terran builds a tech lab add-on on the current structure
|
463
490
|
# @return [void]
|
464
|
-
def build_reactor
|
465
|
-
|
491
|
+
def build_reactor(queue_command: false)
|
492
|
+
unit_type_id = case unit_type
|
493
|
+
when Api::UnitTypeId::BARRACKS, Api::UnitTypeId::BARRACKSFLYING
|
494
|
+
Api::UnitTypeId::BARRACKSREACTOR
|
495
|
+
when Api::UnitTypeId::FACTORY, Api::UnitTypeId::FACTORYFLYING
|
496
|
+
Api::UnitTypeId::FACTORYREACTOR
|
497
|
+
when Api::UnitTypeId::STARPORT, Api::UnitTypeId::STARPORTFLYING
|
498
|
+
Api::UnitTypeId::STARPORTREACTOR
|
499
|
+
end
|
500
|
+
build(unit_type_id: unit_type_id, queue_command:)
|
466
501
|
end
|
467
502
|
|
468
503
|
# For Terran builds a tech lab add-on on the current structure
|
469
504
|
# @return [void]
|
470
|
-
def build_tech_lab
|
471
|
-
|
505
|
+
def build_tech_lab(queue_command: false)
|
506
|
+
unit_type_id = case unit_type
|
507
|
+
when Api::UnitTypeId::BARRACKS, Api::UnitTypeId::BARRACKSFLYING
|
508
|
+
Api::UnitTypeId::BARRACKSTECHLAB
|
509
|
+
when Api::UnitTypeId::FACTORY, Api::UnitTypeId::FACTORYFLYING
|
510
|
+
Api::UnitTypeId::FACTORYTECHLAB
|
511
|
+
when Api::UnitTypeId::STARPORT, Api::UnitTypeId::STARPORTFLYING
|
512
|
+
Api::UnitTypeId::STARPORTTECHLAB
|
513
|
+
end
|
514
|
+
build(unit_type_id: unit_type_id, queue_command:)
|
472
515
|
end
|
473
516
|
|
517
|
+
# GENERAL Convenience functions ---
|
518
|
+
|
519
|
+
# ...
|
520
|
+
|
474
521
|
private
|
475
522
|
|
476
523
|
# @private
|
477
|
-
# Reduces
|
524
|
+
# Reduces repetition in the is_*action*?(target:) methods
|
478
525
|
def is_performing_ability_on_target?(abilities, target: nil)
|
479
526
|
# Exit if not actioning the ability
|
480
527
|
return false unless is_performing_ability?(abilities)
|
@@ -46,7 +46,7 @@ module Sc2
|
|
46
46
|
# @param queue_command [Boolean] shift+command
|
47
47
|
def warp(unit_type_id:, target: nil, queue_command: false)
|
48
48
|
return if size.zero?
|
49
|
-
bot&.warp(units: self, unit_type_id:, target
|
49
|
+
bot&.warp(units: self, unit_type_id:, target:, queue_command:)
|
50
50
|
end
|
51
51
|
|
52
52
|
# Shorthand for performing action SMART (right-click)
|
@@ -56,11 +56,31 @@ module Sc2
|
|
56
56
|
action(ability_id: Api::AbilityId::SMART, target:, queue_command:)
|
57
57
|
end
|
58
58
|
|
59
|
+
# Shorthand for performing action MOVE
|
60
|
+
# @param target [Api::Unit, Integer, Api::Point2D] is a unit, unit tag or a Api::Point2D
|
61
|
+
# @param queue_command [Boolean] shift+command
|
62
|
+
def move(target:, queue_command: false)
|
63
|
+
action(ability_id: Api::AbilityId::MOVE, target:, queue_command:)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Shorthand for performing action STOP
|
67
|
+
# @param queue_command [Boolean] shift+command
|
68
|
+
def stop(queue_command: false)
|
69
|
+
action(ability_id: Api::AbilityId::STOP, queue_command:)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Shorthand for performing action HOLDPOSITION
|
73
|
+
# @param queue_command [Boolean] shift+command
|
74
|
+
def hold(queue_command: false)
|
75
|
+
action(ability_id: Api::AbilityId::HOLDPOSITION, queue_command:)
|
76
|
+
end
|
77
|
+
alias_method :hold_position, :hold
|
78
|
+
|
59
79
|
# Shorthand for performing action ATTACK
|
60
80
|
# @param target [Api::Unit, Integer, Api::Point2D] is a unit, unit tag or a Api::Point2D
|
61
81
|
# @param queue_command [Boolean] shift+command
|
62
82
|
def attack(target:, queue_command: false)
|
63
|
-
action(ability_id: Api::AbilityId::ATTACK, target
|
83
|
+
action(ability_id: Api::AbilityId::ATTACK, target:, queue_command:)
|
64
84
|
end
|
65
85
|
|
66
86
|
# Issues repair command on target
|
data/lib/sc2ai/unit_group.rb
CHANGED
@@ -89,27 +89,32 @@ module Sc2
|
|
89
89
|
@units[tags.at(index)]
|
90
90
|
end
|
91
91
|
|
92
|
+
# Meta documentation methods
|
93
|
+
# @!method first
|
94
|
+
# @return [Api::Unit]
|
95
|
+
# @!method last
|
96
|
+
# @return [Api::Unit]
|
97
|
+
|
92
98
|
# Calls the given block with each Api::Unit value
|
93
99
|
# @example
|
94
|
-
# unit_group.each {|unit| puts unit.tag } #=> 1234 ...
|
95
|
-
#
|
96
100
|
# unit_group.each do |unit|
|
97
101
|
# puts unit.tag #=> 1234 ...
|
98
102
|
# end
|
99
|
-
|
100
|
-
|
103
|
+
# @yieldparam unit [Api::Unit]
|
104
|
+
def each(&)
|
105
|
+
@units.each_value(&)
|
101
106
|
end
|
102
107
|
|
103
108
|
# Calls the given block with each key-value pair
|
104
109
|
# @return [self] a new unit group with items merged
|
105
110
|
# @example
|
106
|
-
# unit_group.
|
107
|
-
#
|
108
|
-
# unit_group.each do |tag, unit|
|
111
|
+
# unit_group.each_with_tag do |tag, unit|
|
109
112
|
# puts "#{tag}: #{unit}"} #=> "12345: #<Api::Unit ...>"
|
110
113
|
# end
|
111
|
-
|
112
|
-
|
114
|
+
# @yieldparam tag [Integer]
|
115
|
+
# @yieldparam unit [Api::Unit]
|
116
|
+
def each_with_tag(&)
|
117
|
+
@units.each(&)
|
113
118
|
self
|
114
119
|
end
|
115
120
|
|
@@ -229,12 +234,19 @@ module Sc2
|
|
229
234
|
end
|
230
235
|
|
231
236
|
# Selects a single random Unit without a parameter or an array of Units with a param, i.e. self.random(2)
|
232
|
-
# @return []
|
237
|
+
# @return [Api::Unit]
|
233
238
|
def sample(...)
|
234
239
|
@units.values.sample(...)
|
235
240
|
end
|
236
241
|
alias_method :random, :sample
|
237
242
|
|
243
|
+
# Returns the first Unit for which the block returns a truthy value
|
244
|
+
# @return [Api::Unit]
|
245
|
+
def detect(...)
|
246
|
+
@units.values.find(...)
|
247
|
+
end
|
248
|
+
alias_method :find, :detect
|
249
|
+
|
238
250
|
# def select_or(*procs)
|
239
251
|
# result = UnitGroup.new
|
240
252
|
# procs.each do |proc|
|
data/lib/sc2ai/version.rb
CHANGED
@@ -4,14 +4,13 @@ class <%= @classname %> < Sc2::Player::Bot
|
|
4
4
|
|
5
5
|
def configure
|
6
6
|
@realtime = false # Step-mode vs Bot, Realtime vs Humans
|
7
|
-
@
|
7
|
+
@step_count = 2 # 2s/22.4 = ~89.29ms step cycle time allowance
|
8
8
|
@enable_feature_layer = false; # Enables ui_ and spatial_ actions. Advanced, and has performance cost.
|
9
9
|
end
|
10
10
|
|
11
11
|
def on_step
|
12
12
|
if game_loop == 0
|
13
|
-
|
14
|
-
units.workers.attack(target: enemy_start_pos)
|
13
|
+
units.workers.attack(target: geo.enemy_start_position)
|
15
14
|
end
|
16
15
|
|
17
16
|
# If your attack fails, "good game" and exit
|