sc2ai 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/data/stableid.json +424 -2562
- data/data/versions.json +8 -0
- data/lib/docker_build/Dockerfile.ruby +1 -1
- data/lib/sc2ai/api/ability_id.rb +12 -314
- data/lib/sc2ai/api/buff_id.rb +9 -16
- data/lib/sc2ai/api/data.rb +1 -1
- data/lib/sc2ai/api/tech_tree.rb +35 -0
- data/lib/sc2ai/api/tech_tree_data.rb +14 -9
- data/lib/sc2ai/api/unit_type_id.rb +6 -58
- data/lib/sc2ai/api/upgrade_id.rb +9 -9
- data/lib/sc2ai/connection/requests.rb +10 -7
- data/lib/sc2ai/data.rb +101 -0
- data/lib/sc2ai/local_play/match.rb +1 -3
- data/lib/sc2ai/player/actions.rb +8 -4
- data/lib/sc2ai/player/debug.rb +2 -3
- data/lib/sc2ai/player/game_state.rb +28 -0
- data/lib/sc2ai/player/geometry.rb +44 -39
- data/lib/sc2ai/player/previous_state.rb +1 -0
- data/lib/sc2ai/player/units.rb +25 -37
- data/lib/sc2ai/player.rb +7 -7
- data/lib/sc2ai/protocol/_meta_documentation.rb +18 -0
- data/lib/sc2ai/protocol/extensions/point_2_d.rb +1 -1
- data/lib/sc2ai/protocol/extensions/point_distance.rb +11 -0
- data/lib/sc2ai/protocol/extensions/position.rb +8 -10
- data/lib/sc2ai/protocol/extensions/unit.rb +29 -3
- data/lib/sc2ai/protocol/extensions/unit_type.rb +9 -0
- data/lib/sc2ai/unit_group/action_ext.rb +3 -3
- data/lib/sc2ai/unit_group/filter_ext.rb +22 -7
- data/lib/sc2ai/version.rb +1 -1
- data/lib/templates/new/run_example_match.rb.tt +1 -1
- data/sig/sc2ai.rbs +387 -530
- metadata +39 -21
@@ -23,8 +23,26 @@
|
|
23
23
|
# class Unit < Google::Protobuf::AbstractMessage; end;
|
24
24
|
# # Protobuf virtual class.
|
25
25
|
# class UnitTypeData < Google::Protobuf::AbstractMessage; end;
|
26
|
+
# # Protobuf virtual class.
|
27
|
+
# class AvailableAbility < Google::Protobuf::AbstractMessage; end;
|
28
|
+
# # Protobuf virtual class.
|
29
|
+
# class UnitOrder < Google::Protobuf::AbstractMessage; end;
|
30
|
+
# # Protobuf virtual class.
|
31
|
+
# class ActionRawUnitCommand < Google::Protobuf::AbstractMessage; end;
|
32
|
+
# # Protobuf virtual class.
|
33
|
+
# class ActionRawToggleAutocast < Google::Protobuf::AbstractMessage; end;
|
34
|
+
# # Protobuf virtual class.
|
35
|
+
# class ActionError < Google::Protobuf::AbstractMessage; end;
|
36
|
+
# # Protobuf virtual class.
|
37
|
+
# class ActionSpatialUnitCommand < Google::Protobuf::AbstractMessage; end;
|
38
|
+
# # Protobuf virtual class.
|
39
|
+
# class BuildItem < Google::Protobuf::AbstractMessage; end;
|
40
|
+
# # Protobuf virtual class.
|
41
|
+
# class ActionToggleAutocast < Google::Protobuf::AbstractMessage; end;
|
26
42
|
# end
|
27
43
|
|
44
|
+
|
45
|
+
|
28
46
|
# Protobuf enums ---
|
29
47
|
# Protobuf classes
|
30
48
|
# @!parse
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This class was partially generated with the help of AI.
|
2
|
+
|
3
|
+
module Api
|
4
|
+
# Adds additional functionality to message object Api::Unit
|
5
|
+
module PointDistanceExtension
|
6
|
+
end
|
7
|
+
end
|
8
|
+
Api::Point.include Api::PointDistanceExtension
|
9
|
+
Api::Point2D.include Api::PointDistanceExtension
|
10
|
+
Api::PointI.include Api::PointDistanceExtension
|
11
|
+
Api::Size2DI.include Api::PointDistanceExtension
|
@@ -84,7 +84,6 @@ module Sc2
|
|
84
84
|
# raise NoMethodError unless location == self
|
85
85
|
|
86
86
|
# Perf: Memoizing attributes which are hit hard, show gain
|
87
|
-
|
88
87
|
@y ||= send(:method_missing, :y)
|
89
88
|
end
|
90
89
|
|
@@ -97,9 +96,9 @@ module Sc2
|
|
97
96
|
|
98
97
|
# Randomly adjusts both x and y by a range of: -offset..offset
|
99
98
|
# @param offset [Float]
|
100
|
-
# @return [
|
99
|
+
# @return [Sc2::Position] new Position
|
101
100
|
def random_offset(offset)
|
102
|
-
|
101
|
+
dup.random_offset!(offset)
|
103
102
|
end
|
104
103
|
|
105
104
|
# Changes this point's x and y by the supplied offset
|
@@ -112,17 +111,16 @@ module Sc2
|
|
112
111
|
end
|
113
112
|
|
114
113
|
# Creates a new point with x and y which is offset
|
115
|
-
# @return [
|
116
|
-
def offset(x, y)
|
117
|
-
|
118
|
-
self
|
114
|
+
# @return [Sc2::Position] new Position
|
115
|
+
def offset(x = 0, y = 0)
|
116
|
+
dup.offset!(x, y)
|
119
117
|
end
|
120
118
|
|
121
119
|
# Changes this point's x and y by the supplied offset
|
122
120
|
# @return [Sc2::Position] self
|
123
|
-
def offset!(x, y)
|
124
|
-
self.x
|
125
|
-
self.y
|
121
|
+
def offset!(x = 0, y = 0)
|
122
|
+
self.x += x
|
123
|
+
self.y += y
|
126
124
|
self
|
127
125
|
end
|
128
126
|
|
@@ -227,6 +227,7 @@ module Api
|
|
227
227
|
# @param target [Api::Unit, Integer, Api::Point2D] is a unit, unit tag or a Api::Point2D
|
228
228
|
# @param queue_command [Boolean] shift+command
|
229
229
|
def attack(target:, queue_command: false)
|
230
|
+
return false if target.nil?
|
230
231
|
action(ability_id: Api::AbilityId::ATTACK, target:, queue_command:)
|
231
232
|
end
|
232
233
|
|
@@ -241,7 +242,7 @@ module Api
|
|
241
242
|
end
|
242
243
|
|
243
244
|
# Builds target unit type, i.e. issuing a build command to worker.build(...Api::UnitTypeId::BARRACKS)
|
244
|
-
# @param unit_type_id [Integer] Api::UnitTypeId the unit type
|
245
|
+
# @param unit_type_id [Integer] Api::UnitTypeId the unit type you wish to build
|
245
246
|
# @param target [Api::Point2D, Integer, nil] is a unit tag or a Api::Point2D. Nil for addons/orbital
|
246
247
|
# @param queue_command [Boolean] shift+command
|
247
248
|
def build(unit_type_id:, target: nil, queue_command: false)
|
@@ -263,7 +264,7 @@ module Api
|
|
263
264
|
end
|
264
265
|
|
265
266
|
# Research a specific upgrade
|
266
|
-
# @param upgrade_id [Integer] Api::UnitTypeId the unit type
|
267
|
+
# @param upgrade_id [Integer] Api::UnitTypeId the unit type you wish to research
|
267
268
|
# @param queue_command [Boolean] shift+command
|
268
269
|
def research(upgrade_id:, queue_command: false)
|
269
270
|
@bot.research(units: self, upgrade_id:, queue_command:)
|
@@ -359,7 +360,7 @@ module Api
|
|
359
360
|
# @param target [Api::Unit, Integer] optionally check if unit is engaged with specific target
|
360
361
|
def is_attacking?(target: nil)
|
361
362
|
is_performing_ability_on_target?(
|
362
|
-
[Api::AbilityId::ATTACK_ATTACK],
|
363
|
+
[Api::AbilityId::ATTACK_ATTACK, Api::AbilityId::ATTACK],
|
363
364
|
target:
|
364
365
|
)
|
365
366
|
end
|
@@ -421,6 +422,14 @@ module Api
|
|
421
422
|
end
|
422
423
|
end
|
423
424
|
|
425
|
+
# Returns whether this unit has an ability available
|
426
|
+
# Queries API if necessary
|
427
|
+
# @param [Integer] ability_id
|
428
|
+
# @return [Boolean]
|
429
|
+
def ability_available?(ability_id)
|
430
|
+
@bot.unit_ability_available?(unit_tag: tag, ability_id:)
|
431
|
+
end
|
432
|
+
|
424
433
|
# Checks whether a weapon can target a unit
|
425
434
|
# @param unit [Api::unit]
|
426
435
|
# @param weapon [Api::Weapon]
|
@@ -546,8 +555,25 @@ module Api
|
|
546
555
|
build(unit_type_id: unit_type_id, queue_command:)
|
547
556
|
end
|
548
557
|
|
558
|
+
# PROTOSS Convenience functions ---
|
559
|
+
|
560
|
+
# Warps in unit type at target (location or pylon)
|
561
|
+
# Only works if the source is a Warp Gate
|
562
|
+
# @param unit_type_id [Integer] Api::UnitTypeId the unit type you wish to build
|
563
|
+
# @param target [Api::Point2D] a point, which should be inside an energy source
|
564
|
+
# @param queue_command [Boolean] shift+command
|
565
|
+
def warp(unit_type_id:, target:, queue_command: false)
|
566
|
+
@bot.warp(units: self, unit_type_id:, target:, queue_command:)
|
567
|
+
end
|
568
|
+
|
549
569
|
# GENERAL Convenience functions ---
|
550
570
|
|
571
|
+
# Returns true if unit does not have orders
|
572
|
+
# @return [Boolean] whether unit is idle
|
573
|
+
def is_idle?
|
574
|
+
orders.empty?
|
575
|
+
end
|
576
|
+
|
551
577
|
# ...
|
552
578
|
|
553
579
|
private
|
@@ -26,7 +26,7 @@ module Sc2
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# Builds target unit type, i.e. issuing a build command to worker.build(...Api::UnitTypeId::BARRACKS)
|
29
|
-
# @param unit_type_id [Integer] Api::UnitTypeId the unit type
|
29
|
+
# @param unit_type_id [Integer] Api::UnitTypeId the unit type you wish to build
|
30
30
|
# @param target [Api::Point2D, Integer, nil] is a unit tag or a Api::Point2D. Nil for addons/orbital
|
31
31
|
# @param queue_command [Boolean] shift+command
|
32
32
|
def build(unit_type_id:, target: nil, queue_command: false)
|
@@ -41,10 +41,10 @@ module Sc2
|
|
41
41
|
|
42
42
|
# Warps in unit type at target (location or pylon)
|
43
43
|
# Will only have affect is this group consists of warp gates, i.e. bot.structures.warpgates
|
44
|
-
# @param unit_type_id [Integer] Api::UnitTypeId the unit type
|
44
|
+
# @param unit_type_id [Integer] Api::UnitTypeId the unit type you wish to build
|
45
45
|
# @param target [Api::Point2D] a point, which should be inside an energy source
|
46
46
|
# @param queue_command [Boolean] shift+command
|
47
|
-
def warp(unit_type_id:, target
|
47
|
+
def warp(unit_type_id:, target:, queue_command: false)
|
48
48
|
return if size.zero?
|
49
49
|
bot&.warp(units: self, unit_type_id:, target:, queue_command:)
|
50
50
|
end
|
@@ -121,13 +121,14 @@ module Sc2
|
|
121
121
|
|
122
122
|
# @private
|
123
123
|
# Does the opposite of selector and returns those values for parent
|
124
|
-
def
|
125
|
-
@parent.
|
124
|
+
def select(...)
|
125
|
+
@parent.reject(...)
|
126
126
|
end
|
127
127
|
|
128
|
+
# @private
|
128
129
|
# Does the opposite of selector and returns those values for parent
|
129
|
-
def
|
130
|
-
@parent.
|
130
|
+
def reject(...)
|
131
|
+
@parent.select(...)
|
131
132
|
end
|
132
133
|
end
|
133
134
|
|
@@ -230,14 +231,28 @@ module Sc2
|
|
230
231
|
alias_method :assimilators, :gas
|
231
232
|
|
232
233
|
# Selects only units which have finished constructing, i.o.w. build_progress == 1.0
|
233
|
-
# @return [UnitGroup]
|
234
|
+
# @return [UnitGroup] complete unit group
|
234
235
|
def completed
|
235
236
|
select(&:is_completed?)
|
236
237
|
end
|
237
238
|
|
239
|
+
# Selects only units which have finished constructing, i.o.w. build_progress != 1.0
|
240
|
+
# @return [UnitGroup] incomplete unit group
|
241
|
+
def incomplete
|
242
|
+
reject(&:is_completed?)
|
243
|
+
end
|
244
|
+
|
238
245
|
# Selects only units which do not have orders
|
239
246
|
def idle
|
240
|
-
select
|
247
|
+
select(&:is_idle?)
|
248
|
+
end
|
249
|
+
|
250
|
+
# Selects units which have this ability available\
|
251
|
+
# Queries API if necessary
|
252
|
+
# @param [Integer] ability_id
|
253
|
+
# @return [UnitGroup] units which have the ability available
|
254
|
+
def ability_available?(ability_id)
|
255
|
+
select { |unit| unit.ability_available?(ability_id) }
|
241
256
|
end
|
242
257
|
|
243
258
|
# NEUTRAL ------------------------------------------
|
@@ -340,7 +355,7 @@ module Sc2
|
|
340
355
|
# Selects pylons and warp prisms in phasing mode
|
341
356
|
# @return [Sc2::UnitGroup] pylons annd warp prisms phasing
|
342
357
|
def warpables
|
343
|
-
select_type([Api::UnitTypeId::PYLON, Api::UnitTypeId::WARPPRISMPHASING])
|
358
|
+
select_type([Api::UnitTypeId::PYLON, Api::UnitTypeId::WARPPRISMPHASING]).completed
|
344
359
|
end
|
345
360
|
|
346
361
|
# Geometric/Map ---
|
data/lib/sc2ai/version.rb
CHANGED