sc2ai 0.0.4 → 0.0.6
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/docker_build/Dockerfile.ruby +1 -1
- data/lib/sc2ai/api/data.rb +159 -2
- data/lib/sc2ai/api/tech_tree.rb +22 -0
- data/lib/sc2ai/api/tech_tree_data.rb +19 -8
- data/lib/sc2ai/connection/requests.rb +26 -11
- data/lib/sc2ai/connection.rb +1 -1
- data/lib/sc2ai/local_play/client_manager.rb +9 -1
- data/lib/sc2ai/player/actions.rb +17 -0
- data/lib/sc2ai/player/debug.rb +1 -0
- data/lib/sc2ai/player/game_state.rb +8 -5
- data/lib/sc2ai/player/geometry.rb +100 -16
- data/lib/sc2ai/player/previous_state.rb +3 -3
- data/lib/sc2ai/player/units.rb +116 -6
- data/lib/sc2ai/player.rb +3 -1
- data/lib/sc2ai/protocol/_meta_documentation.rb +2 -0
- data/lib/sc2ai/protocol/extensions/ability_remapable.rb +22 -0
- data/lib/sc2ai/protocol/extensions/point.rb +3 -1
- data/lib/sc2ai/protocol/extensions/point_2_d.rb +6 -0
- data/lib/sc2ai/protocol/extensions/position.rb +41 -4
- data/lib/sc2ai/protocol/extensions/unit.rb +35 -3
- data/lib/sc2ai/protocol/extensions/unit_type_data.rb +20 -0
- data/lib/sc2ai/unit_group/action_ext.rb +9 -0
- data/lib/sc2ai/unit_group/filter_ext.rb +18 -1
- data/lib/sc2ai/unit_group/geo_ext.rb +28 -0
- data/lib/sc2ai/unit_group.rb +12 -1
- data/lib/sc2ai/version.rb +1 -1
- data/lib/templates/new/run_example_match.rb.tt +1 -1
- data/sig/sc2ai.rbs +498 -87
- metadata +26 -23
@@ -49,6 +49,15 @@ module Sc2
|
|
49
49
|
bot&.warp(units: self, unit_type_id:, target:, queue_command:)
|
50
50
|
end
|
51
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:)
|
59
|
+
end
|
60
|
+
|
52
61
|
# Shorthand for performing action SMART (right-click)
|
53
62
|
# @param target [Api::Unit, Integer, Api::Point2D] is a unit, unit tag or a Api::Point2D
|
54
63
|
# @param queue_command [Boolean] shift+command
|
@@ -229,6 +229,17 @@ 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
|
+
|
238
|
+
# Selects only units which do not have orders
|
239
|
+
def idle
|
240
|
+
select { |unit| unit.orders.empty? }
|
241
|
+
end
|
242
|
+
|
232
243
|
# NEUTRAL ------------------------------------------
|
233
244
|
|
234
245
|
# Selects mineral fields
|
@@ -284,7 +295,13 @@ module Sc2
|
|
284
295
|
# Selects overlords
|
285
296
|
# @return [Sc2::UnitGroup]
|
286
297
|
def overlords
|
287
|
-
select_type([Api::UnitTypeId::OVERLORD, Api::UnitTypeId::
|
298
|
+
select_type([Api::UnitTypeId::OVERLORD, Api::UnitTypeId::OVERLORDTRANSPORT, Api::UnitTypeId::TRANSPORTOVERLORDCOCOON])
|
299
|
+
end
|
300
|
+
|
301
|
+
# Selects overseers
|
302
|
+
# @return [Sc2::UnitGroup]
|
303
|
+
def overseers
|
304
|
+
select_type([Api::UnitTypeId::OVERLORDCOCOON, Api::UnitTypeId::OVERSEER, Api::UnitTypeId::OVERSEERSIEGEMODE])
|
288
305
|
end
|
289
306
|
|
290
307
|
# Selects creep tumors (all)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sc2ai/unit_group"
|
4
|
+
|
5
|
+
module Sc2
|
6
|
+
# A set geometric/map/math methods for unit group
|
7
|
+
class UnitGroup
|
8
|
+
# Returns the center (average) position of all units or nil if the group is empty.
|
9
|
+
# Outliers effect this point
|
10
|
+
# @return [Api::Point2D, nil]
|
11
|
+
def pos_centroid
|
12
|
+
return nil if size == 0
|
13
|
+
size = @units.size
|
14
|
+
sum_x = 0.0
|
15
|
+
sum_y = 0.0
|
16
|
+
i = 0
|
17
|
+
|
18
|
+
while i < size
|
19
|
+
unit = at(i)
|
20
|
+
sum_x += unit.pos.x.to_f
|
21
|
+
sum_y += unit.pos.y.to_f
|
22
|
+
i += 1
|
23
|
+
end
|
24
|
+
|
25
|
+
Api::Point2D[sum_x / size.to_f, sum_y / size.to_f]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/sc2ai/unit_group.rb
CHANGED
@@ -182,6 +182,8 @@ module Sc2
|
|
182
182
|
UnitGroup.new(@units.reject { |tag, _unit| other_unit_group.units.has_key?(tag) })
|
183
183
|
end
|
184
184
|
|
185
|
+
alias_method :-, :subtract
|
186
|
+
|
185
187
|
# Merges unit_group with our units and returns a new unit group
|
186
188
|
# @return [Sc2::UnitGroup] a new unit group with items merged
|
187
189
|
def merge(unit_group)
|
@@ -227,12 +229,20 @@ module Sc2
|
|
227
229
|
UnitGroup.new(@units.except(...))
|
228
230
|
end
|
229
231
|
|
230
|
-
# Returns a
|
232
|
+
# Returns a new unit group containing the entries for given tag(s).
|
231
233
|
# @return [Sc2::UnitGroup] new unit group
|
232
234
|
def slice(...)
|
233
235
|
UnitGroup.new(@units.slice(...))
|
234
236
|
end
|
235
237
|
|
238
|
+
# 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):
|
239
|
+
# @param other_unit_group [UnitGroup]
|
240
|
+
# @return [UnitGroup] new unit group
|
241
|
+
def intersection(other_unit_group)
|
242
|
+
slice(*other_unit_group.tags)
|
243
|
+
end
|
244
|
+
alias_method :&, :intersection
|
245
|
+
|
236
246
|
# Selects a single random Unit without a parameter or an array of Units with a param, i.e. self.random(2)
|
237
247
|
# @return [Api::Unit]
|
238
248
|
def sample(...)
|
@@ -287,3 +297,4 @@ end
|
|
287
297
|
|
288
298
|
require_relative "unit_group/action_ext"
|
289
299
|
require_relative "unit_group/filter_ext"
|
300
|
+
require_relative "unit_group/geo_ext"
|
data/lib/sc2ai/version.rb
CHANGED