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.
@@ -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::OVERLORDCOCOON])
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
@@ -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 hash containing the entries for given tag(s).
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Sc2
4
4
  # gem version
5
- VERSION = "0.0.4"
5
+ VERSION = "0.0.6"
6
6
  end
@@ -10,5 +10,5 @@ Sc2::Match.new(
10
10
  $bot,
11
11
  Sc2::Player::Computer.new(race: Api::Race::Random, difficulty: Api::Difficulty::VeryEasy)
12
12
  ],
13
- map: "Goldenaura512AIE" # Or any of the downloaded map names
13
+ map: "Goldenaura512V2AIE" # Or any of the downloaded map names
14
14
  ).run