sc2ai 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -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: target, queue_command:)
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: target, queue_command: queue_command)
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
@@ -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
- def each(&block)
100
- @units.each_value(&block)
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.each {|tag, unit| puts "#{tag}: #{unit}"} #=> "12345: #<Api::Unit ...>"
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
- def each_with_tag(&block)
112
- @units.each(&block)
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 hash containing the entries for given tag(s).
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Sc2
4
4
  # gem version
5
- VERSION = "0.0.3"
5
+ VERSION = "0.0.5"
6
6
  end
@@ -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
- @step_size = 1 # Gives 22.4ms, typically compete at 2 (44.8ms) or 4 (179.2ms).
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
- enemy_start_pos = game_info.start_raw.start_locations.first
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
@@ -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