sc2ai 0.0.3 → 0.0.5
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 +31 -28
- data/lib/sc2ai/api/data.rb +162 -2
- data/lib/sc2ai/api/tech_tree.rb +22 -0
- data/lib/sc2ai/api/tech_tree_data.rb +19 -8
- data/lib/sc2ai/connection.rb +1 -1
- data/lib/sc2ai/local_play/client_manager.rb +9 -1
- data/lib/sc2ai/player/actions.rb +21 -3
- data/lib/sc2ai/player/debug.rb +51 -4
- data/lib/sc2ai/player/geometry.rb +80 -5
- data/lib/sc2ai/player/previous_state.rb +2 -2
- data/lib/sc2ai/player/units.rb +77 -8
- data/lib/sc2ai/player.rb +7 -7
- data/lib/sc2ai/protocol/_meta_documentation.rb +2 -0
- data/lib/sc2ai/protocol/extensions/point.rb +13 -1
- data/lib/sc2ai/protocol/extensions/point_2_d.rb +6 -0
- data/lib/sc2ai/protocol/extensions/unit.rb +64 -10
- data/lib/sc2ai/protocol/extensions/unit_type_data.rb +20 -0
- data/lib/sc2ai/unit_group/action_ext.rb +31 -2
- data/lib/sc2ai/unit_group/filter_ext.rb +6 -0
- data/lib/sc2ai/unit_group.rb +31 -11
- data/lib/sc2ai/version.rb +1 -1
- data/lib/templates/new/my_bot.rb.tt +2 -3
- data/lib/templates/new/run_example_match.rb.tt +1 -1
- data/sig/sc2ai.rbs +10382 -0
- metadata +43 -69
@@ -46,7 +46,16 @@ 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
|
+
end
|
51
|
+
|
52
|
+
# Research a specific upgrade at one of these structures
|
53
|
+
# @param upgrade_id [Integer] Api::UpgradeId to research
|
54
|
+
# @param queue_command [Boolean] shift+command
|
55
|
+
def research(upgrade_id:, queue_command: false)
|
56
|
+
return if size.zero?
|
57
|
+
|
58
|
+
bot&.research(units: self, upgrade_id:, queue_command:)
|
50
59
|
end
|
51
60
|
|
52
61
|
# Shorthand for performing action SMART (right-click)
|
@@ -56,11 +65,31 @@ module Sc2
|
|
56
65
|
action(ability_id: Api::AbilityId::SMART, target:, queue_command:)
|
57
66
|
end
|
58
67
|
|
68
|
+
# Shorthand for performing action MOVE
|
69
|
+
# @param target [Api::Unit, Integer, Api::Point2D] is a unit, unit tag or a Api::Point2D
|
70
|
+
# @param queue_command [Boolean] shift+command
|
71
|
+
def move(target:, queue_command: false)
|
72
|
+
action(ability_id: Api::AbilityId::MOVE, target:, queue_command:)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Shorthand for performing action STOP
|
76
|
+
# @param queue_command [Boolean] shift+command
|
77
|
+
def stop(queue_command: false)
|
78
|
+
action(ability_id: Api::AbilityId::STOP, queue_command:)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Shorthand for performing action HOLDPOSITION
|
82
|
+
# @param queue_command [Boolean] shift+command
|
83
|
+
def hold(queue_command: false)
|
84
|
+
action(ability_id: Api::AbilityId::HOLDPOSITION, queue_command:)
|
85
|
+
end
|
86
|
+
alias_method :hold_position, :hold
|
87
|
+
|
59
88
|
# Shorthand for performing action ATTACK
|
60
89
|
# @param target [Api::Unit, Integer, Api::Point2D] is a unit, unit tag or a Api::Point2D
|
61
90
|
# @param queue_command [Boolean] shift+command
|
62
91
|
def attack(target:, queue_command: false)
|
63
|
-
action(ability_id: Api::AbilityId::ATTACK, target
|
92
|
+
action(ability_id: Api::AbilityId::ATTACK, target:, queue_command:)
|
64
93
|
end
|
65
94
|
|
66
95
|
# Issues repair command on target
|
@@ -229,6 +229,12 @@ module Sc2
|
|
229
229
|
alias_method :extractors, :gas
|
230
230
|
alias_method :assimilators, :gas
|
231
231
|
|
232
|
+
# Selects only units which have finished constructing, i.o.w. build_progress == 1.0
|
233
|
+
# @return [UnitGroup] gas structures
|
234
|
+
def completed
|
235
|
+
select(&:is_completed?)
|
236
|
+
end
|
237
|
+
|
232
238
|
# NEUTRAL ------------------------------------------
|
233
239
|
|
234
240
|
# Selects mineral fields
|
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
|
|
@@ -222,19 +227,34 @@ module Sc2
|
|
222
227
|
UnitGroup.new(@units.except(...))
|
223
228
|
end
|
224
229
|
|
225
|
-
# Returns a
|
230
|
+
# Returns a new unit group containing the entries for given tag(s).
|
226
231
|
# @return [Sc2::UnitGroup] new unit group
|
227
232
|
def slice(...)
|
228
233
|
UnitGroup.new(@units.slice(...))
|
229
234
|
end
|
230
235
|
|
236
|
+
# Returns a new unit group containing each element found both in self and in all of the given other_arrays; duplicates are omitted; items are compared using eql? (items must also implement hash correctly):
|
237
|
+
# @param other_unit_group [UnitGroup]
|
238
|
+
# @return [UnitGroup] new unit group
|
239
|
+
def intersection(other_unit_group)
|
240
|
+
slice(*other_unit_group.tags)
|
241
|
+
end
|
242
|
+
alias_method :&, :intersection
|
243
|
+
|
231
244
|
# Selects a single random Unit without a parameter or an array of Units with a param, i.e. self.random(2)
|
232
|
-
# @return []
|
245
|
+
# @return [Api::Unit]
|
233
246
|
def sample(...)
|
234
247
|
@units.values.sample(...)
|
235
248
|
end
|
236
249
|
alias_method :random, :sample
|
237
250
|
|
251
|
+
# Returns the first Unit for which the block returns a truthy value
|
252
|
+
# @return [Api::Unit]
|
253
|
+
def detect(...)
|
254
|
+
@units.values.find(...)
|
255
|
+
end
|
256
|
+
alias_method :find, :detect
|
257
|
+
|
238
258
|
# def select_or(*procs)
|
239
259
|
# result = UnitGroup.new
|
240
260
|
# 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
|