sc2ai 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/data/sc2ai/protocol/common.proto +5 -5
  3. data/data/sc2ai/protocol/data.proto +22 -22
  4. data/data/sc2ai/protocol/debug.proto +24 -24
  5. data/data/sc2ai/protocol/error.proto +216 -215
  6. data/data/sc2ai/protocol/raw.proto +20 -20
  7. data/data/sc2ai/protocol/sc2api.proto +111 -111
  8. data/data/sc2ai/protocol/score.proto +3 -3
  9. data/data/sc2ai/protocol/spatial.proto +5 -5
  10. data/data/sc2ai/protocol/ui.proto +16 -16
  11. data/exe/sc2ai +0 -3
  12. data/lib/docker_build/Dockerfile.ruby +2 -2
  13. data/lib/sc2ai/api/data.rb +3 -3
  14. data/lib/sc2ai/connection/connection_listener.rb +3 -3
  15. data/lib/sc2ai/connection/requests.rb +31 -35
  16. data/lib/sc2ai/connection/status_listener.rb +1 -1
  17. data/lib/sc2ai/connection.rb +2 -3
  18. data/lib/sc2ai/local_play/client/configurable_options.rb +6 -7
  19. data/lib/sc2ai/local_play/client.rb +3 -3
  20. data/lib/sc2ai/local_play/match.rb +7 -2
  21. data/lib/sc2ai/paths.rb +12 -2
  22. data/lib/sc2ai/player/actions.rb +54 -35
  23. data/lib/sc2ai/player/debug.rb +21 -21
  24. data/lib/sc2ai/player/game_state.rb +11 -18
  25. data/lib/sc2ai/player/geo.rb +54 -64
  26. data/lib/sc2ai/player/units.rb +16 -16
  27. data/lib/sc2ai/player.rb +103 -41
  28. data/lib/sc2ai/ports.rb +1 -1
  29. data/lib/sc2ai/protocol/_meta_documentation.rb +265 -265
  30. data/lib/sc2ai/protocol/common_pb.rb +3865 -15
  31. data/lib/sc2ai/protocol/data_pb.rb +9109 -18
  32. data/lib/sc2ai/protocol/debug_pb.rb +10437 -26
  33. data/lib/sc2ai/protocol/error_pb.rb +1086 -10
  34. data/lib/sc2ai/protocol/extensions/ability_remapable.rb +9 -9
  35. data/lib/sc2ai/protocol/extensions/action.rb +60 -0
  36. data/lib/sc2ai/protocol/extensions/point_2_d.rb +5 -0
  37. data/lib/sc2ai/protocol/extensions/position.rb +10 -35
  38. data/lib/sc2ai/protocol/extensions/power_source.rb +3 -0
  39. data/lib/sc2ai/protocol/extensions/unit.rb +19 -35
  40. data/lib/sc2ai/protocol/query_pb.rb +5025 -17
  41. data/lib/sc2ai/protocol/raw_pb.rb +18350 -27
  42. data/lib/sc2ai/protocol/sc2api_pb.rb +48420 -93
  43. data/lib/sc2ai/protocol/score_pb.rb +5968 -12
  44. data/lib/sc2ai/protocol/spatial_pb.rb +11944 -18
  45. data/lib/sc2ai/protocol/ui_pb.rb +12927 -28
  46. data/lib/sc2ai/unit_group/action_ext.rb +0 -2
  47. data/lib/sc2ai/unit_group/filter_ext.rb +10 -9
  48. data/lib/sc2ai/unit_group/geo_ext.rb +0 -2
  49. data/lib/sc2ai/unit_group.rb +1 -1
  50. data/lib/sc2ai/version.rb +2 -3
  51. data/lib/sc2ai.rb +10 -11
  52. data/lib/templates/ladderzip/bin/ladder.tt +0 -3
  53. data/lib/templates/new/api/common.proto +6 -6
  54. data/lib/templates/new/api/data.proto +23 -20
  55. data/lib/templates/new/api/debug.proto +25 -21
  56. data/lib/templates/new/api/error.proto +217 -215
  57. data/lib/templates/new/api/query.proto +1 -1
  58. data/lib/templates/new/api/raw.proto +16 -14
  59. data/lib/templates/new/api/sc2api.proto +108 -94
  60. data/lib/templates/new/api/score.proto +4 -3
  61. data/lib/templates/new/api/spatial.proto +6 -5
  62. data/lib/templates/new/api/ui.proto +17 -14
  63. data/lib/templates/new/boot.rb.tt +1 -1
  64. data/lib/templates/new/my_bot.rb.tt +1 -1
  65. data/lib/templates/new/run_example_match.rb.tt +2 -2
  66. data/sig/sc2ai.rbs +11008 -1929
  67. metadata +25 -36
  68. data/lib/sc2ai/overrides/kernel.rb +0 -33
  69. data/sig/minaswan.rbs +0 -10323
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "sc2ai/unit_group"
4
-
5
3
  module Sc2
6
4
  # A set of action related tasks for unit groups
7
5
  class UnitGroup
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "sc2ai/unit_group"
4
3
  require "kdtree"
5
4
 
6
5
  module Sc2
@@ -118,7 +117,7 @@ module Sc2
118
117
  # structures.not.creep_tumors #=> all structures
119
118
  # structures.not.pylons #=>
120
119
  # units.not.workers # equivalent of units.army, but works too
121
- # @return [Sc2::UnitGroupNotSelector]
120
+ # @return [Sc2::UnitGroup::UnitGroupNotSelector]
122
121
  def not
123
122
  UnitGroupNotSelector.new(self)
124
123
  end
@@ -128,6 +127,8 @@ module Sc2
128
127
  class UnitGroupNotSelector < UnitGroup
129
128
  attr_accessor :parent
130
129
 
130
+ # @param unit_group [Sc2::UnitGroup]
131
+ # @return [UnitGroupNotSelector]
131
132
  def initialize(unit_group)
132
133
  @parent = unit_group
133
134
  super
@@ -150,10 +151,10 @@ module Sc2
150
151
  # Multiple values work as an "AND" filter
151
152
  # @example
152
153
  # # Single
153
- # ug.select_attribute(Api::Attribute::Structure) #=> <UnitGroup: ...>
154
+ # ug.select_attribute(Api::Attribute::STRUCTURE) #=> <UnitGroup: ...>
154
155
  # ug.select_attribute(:Structure) #=> <UnitGroup: ...>
155
156
  # # Multiple - select mechanical flying units
156
- # ug.select_attribute([:Mechanical, :Flying]) #=> <UnitGroup: ...>
157
+ # ug.select_attribute([:MECHANICAL, :FLYING]) #=> <UnitGroup: ...>
157
158
  # @param attributes [Integer, Array<Integer>] one or an array of unit Api::UnitTypeId
158
159
  # @return [UnitGroup]
159
160
  def select_attribute(attributes)
@@ -170,7 +171,7 @@ module Sc2
170
171
  # Multiple values work as an "AND" filter
171
172
  # @example
172
173
  # # Single
173
- # ug.reject_attribute(Api::Attribute::Structure) #=> <UnitGroup: ...>
174
+ # ug.reject_attribute(Api::Attribute::STRUCTURE) #=> <UnitGroup: ...>
174
175
  # ug.reject_attribute(:Structure) #=> <UnitGroup: ...>
175
176
  # # Multiple - reject mechanical flying units
176
177
  # ug.reject_attribute(:Mechanical, :Flying) #=> <UnitGroup: ...>
@@ -192,8 +193,8 @@ module Sc2
192
193
  # i.e. @bot.all_units.owned # => Units you own
193
194
  # @return [Sc2::UnitGroup] workers
194
195
  def owned
195
- cached("#{__method__}:Self") do
196
- select { |unit| unit.alliance == :Self }
196
+ cached("#{__method__}:SELF") do
197
+ select { |unit| unit.alliance == :SELF }
197
198
  end
198
199
  end
199
200
 
@@ -216,7 +217,7 @@ module Sc2
216
217
  # Selects units with attribute Structure
217
218
  # @return [Sc2::UnitGroup] structures
218
219
  def structures
219
- select_attribute(Api::Attribute::Structure)
220
+ select_attribute(Api::Attribute::STRUCTURE)
220
221
  end
221
222
 
222
223
  # Contains an array non-army types
@@ -405,7 +406,7 @@ module Sc2
405
406
  attr_accessor :use_kdtree
406
407
 
407
408
  # Builds a kdtree if not already built and returns it
408
- # @return [Kdtree]
409
+ # @return [::Kdtree]
409
410
  def kdtree
410
411
  return @kdtree unless @kdtree.nil?
411
412
  @kdtree = Kdtree.new(@units.values.each_with_index.map { |unit, index| [unit.pos.x, unit.pos.y, index] })
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "sc2ai/unit_group"
4
-
5
3
  module Sc2
6
4
  # A set geometric/map/math methods for unit group
7
5
  class UnitGroup
@@ -18,7 +18,7 @@ module Sc2
18
18
  def initialize(units = nil)
19
19
  @units = {}
20
20
  case units
21
- when Array, Google::Protobuf::RepeatedField
21
+ when Array
22
22
  units.each do |unit|
23
23
  @units[unit.tag] = unit
24
24
  end
data/lib/sc2ai/version.rb CHANGED
@@ -1,6 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Sc2
4
2
  # gem version
5
- VERSION = "0.2.0"
3
+ # @return [String]
4
+ VERSION = "0.4.0"
6
5
  end
data/lib/sc2ai.rb CHANGED
@@ -38,20 +38,16 @@ Dir.glob(File.join(__dir__, "sc2ai", "overrides", "**", "*.rb")).each do |file|
38
38
  require(file)
39
39
  end
40
40
 
41
- # Protobuf internals don't allow sharing enums in the same package,
42
- # so Blizzard under_scored some names. This throws errors when defining constants
43
- # during packing/unpacking, because they dont start capitalized, so we silence temporarily.
44
- silence_warnings do
45
- require "rumale"
46
- require_relative "sc2ai/protocol/sc2api_pb"
47
- end
41
+ require "rumale"
42
+
48
43
  # noinspection RubyMismatchedArgumentType
49
- Dir[File.join(__dir__, "sc2ai", "*.rb")].each { |file| require(file) }
50
- # The upper include can probably preload everything it needs
44
+ Dir[File.join(__dir__, "sc2ai", "protocol", "*.rb")].sort.each { |file| require(file) }
51
45
  # noinspection RubyMismatchedArgumentType
52
- Dir[File.join(__dir__, "sc2ai", "protocol", "extensions", "**", "*.rb")].each { |file| require(file) }
46
+ Dir[File.join(__dir__, "sc2ai", "protocol", "extensions", "*.rb")].sort.each { |file| require(file) }
53
47
  # noinspection RubyMismatchedArgumentType
54
- Dir[File.join(__dir__, "sc2ai", "local_play", "**", "*.rb")].each { |file| require(file) }
48
+ Dir[File.join(__dir__, "sc2ai", "*.rb")].sort.each { |file| require(file) }
49
+ # noinspection RubyMismatchedArgumentType
50
+ Dir[File.join(__dir__, "sc2ai", "local_play", "**", "*.rb")].sort.each { |file| require(file) }
55
51
 
56
52
  # Facilitates StarCraft 2 AI
57
53
  module Sc2
@@ -61,6 +57,7 @@ module Sc2
61
57
  class << self
62
58
  # Instantiate the Configuration singleton or return it.
63
59
  # Remember that the instance has attribute readers so that we can access the configured values
60
+ # @return [Sc2::Configuration]
64
61
  def config
65
62
  @config ||= Configuration.new
66
63
  yield @config if block_given?
@@ -81,6 +78,8 @@ module Sc2
81
78
 
82
79
  @logger = Logger.new($stdout)
83
80
  @logger.level = :debug
81
+ @logger.datetime_format = "%H:%M:%S.%6N"
82
+
84
83
  @logger
85
84
  end
86
85
 
@@ -15,9 +15,6 @@ export RUBY_GC_HEAP_INIT_SIZE_160_SLOTS=18000
15
15
  export RUBY_GC_HEAP_INIT_SIZE_320_SLOTS=2000
16
16
  export RUBY_GC_HEAP_INIT_SIZE_640_SLOTS=1000
17
17
 
18
- # Maxime <3
19
- export RUBY_YJIT_ENABLE=true
20
-
21
18
  export AIARENA=true
22
19
  sc2ai ladderconfig
23
20
  exec sc2ai laddermatch "$@" 1>&2
@@ -1,5 +1,5 @@
1
1
 
2
- syntax = "proto2";
2
+ syntax = "proto3";
3
3
 
4
4
  package Api;
5
5
 
@@ -49,11 +49,11 @@ message Size2DI {
49
49
  }
50
50
 
51
51
  enum Race {
52
- NoRace = 0;
53
- Terran = 1;
54
- Zerg = 2;
55
- Protoss = 3;
56
- Random = 4;
52
+ NO_RACE = 0;
53
+ TERRAN = 1;
54
+ ZERG = 2;
55
+ PROTOSS = 3;
56
+ RANDOM = 4;
57
57
  }
58
58
 
59
59
 
@@ -1,5 +1,5 @@
1
1
 
2
- syntax = "proto2";
2
+ syntax = "proto3";
3
3
 
4
4
  package Api;
5
5
 
@@ -19,11 +19,12 @@ message AbilityData {
19
19
  optional uint32 remaps_to_ability_id = 7; // This ability id may be represented by the given more generic id.
20
20
 
21
21
  enum Target {
22
- None = 1; // Does not require a target.
23
- Point = 2; // Requires a target position.
24
- Unit = 3; // Requires a unit to target. Given by position using feature layers.
25
- PointOrUnit = 4; // Requires either a target point or target unit.
26
- PointOrNone = 5; // Requires either a target point or no target. (eg. building add-ons)
22
+ ENUM_TARGET_UNSET = 0; // PROTO3 COMPAT
23
+ NONE = 1; // DOES NOT REQUIRE A TARGET.
24
+ POINT = 2; // REQUIRES A TARGET POSITION.
25
+ UNIT = 3; // REQUIRES A UNIT TO TARGET. GIVEN BY POSITION USING FEATURE LAYERS.
26
+ POINT_OR_UNIT = 4; // REQUIRES EITHER A TARGET POINT OR TARGET UNIT.
27
+ POINT_OR_NONE = 5; // REQUIRES EITHER A TARGET POINT OR NO TARGET. (EG. BUILDING ADD_ONS)
27
28
  }
28
29
 
29
30
  optional bool available = 8; // If true, the ability may be used by this set of mods/map.
@@ -37,17 +38,18 @@ message AbilityData {
37
38
  }
38
39
 
39
40
  enum Attribute {
40
- Light = 1;
41
- Armored = 2;
42
- Biological = 3;
43
- Mechanical = 4;
44
- Robotic = 5;
45
- Psionic = 6;
46
- Massive = 7;
47
- Structure = 8;
48
- Hover = 9;
49
- Heroic = 10;
50
- Summoned = 11;
41
+ ENUM_ATTRIBUTE_UNSET = 0; // PROTO3 COMPAT
42
+ LIGHT = 1;
43
+ ARMORED = 2;
44
+ BIOLOGICAL = 3;
45
+ MECHANICAL = 4;
46
+ ROBOTIC = 5;
47
+ PSIONIC = 6;
48
+ MASSIVE = 7;
49
+ STRUCTURE = 8;
50
+ HOVER = 9;
51
+ HEROIC = 10;
52
+ SUMMONED = 11;
51
53
  }
52
54
 
53
55
  message DamageBonus {
@@ -57,9 +59,10 @@ message DamageBonus {
57
59
 
58
60
  message Weapon {
59
61
  enum TargetType {
60
- Ground = 1;
61
- Air = 2;
62
- Any = 3;
62
+ ENUM_TARGET_TYPE_UNSET = 0; // PROTO3 COMPAT
63
+ GROUND = 1;
64
+ AIR = 2;
65
+ ANY = 3;
63
66
  }
64
67
  optional TargetType type = 1;
65
68
  optional float damage = 2;
@@ -1,5 +1,5 @@
1
1
 
2
- syntax = "proto2";
2
+ syntax = "proto3";
3
3
 
4
4
  package Api;
5
5
 
@@ -67,18 +67,19 @@ message DebugSphere {
67
67
  }
68
68
 
69
69
  enum DebugGameState {
70
- show_map = 1;
71
- control_enemy = 2;
72
- food = 3;
73
- free = 4;
74
- all_resources = 5;
75
- god = 6;
76
- minerals = 7;
77
- gas = 8;
78
- cooldown = 9;
79
- tech_tree = 10;
80
- upgrade = 11;
81
- fast_build = 12;
70
+ ENUM_DEBUG_GAME_STATE_UNSET = 0; // PROTO3 COMPAT
71
+ SHOW_MAP = 1;
72
+ CONTROL_ENEMY = 2;
73
+ FOOD = 3;
74
+ FREE = 4;
75
+ ALL_RESOURCES = 5;
76
+ GOD = 6;
77
+ MINERALS = 7;
78
+ GAS = 8;
79
+ COOLDOWNS = 9;
80
+ TECH_TREE = 10;
81
+ UPGRADE = 11;
82
+ FAST_BUILD = 12;
82
83
  }
83
84
 
84
85
  message DebugCreateUnit {
@@ -94,9 +95,10 @@ message DebugKillUnit {
94
95
 
95
96
  message DebugTestProcess {
96
97
  enum Test {
97
- hang = 1;
98
- crash = 2;
99
- exit = 3;
98
+ ENUM_TEST_UNSET = 0; // PROTO3 COMPAT
99
+ HANG = 1;
100
+ CRASH = 2;
101
+ EXIT = 3;
100
102
  }
101
103
  optional Test test = 1;
102
104
  optional int32 delay_ms = 2;
@@ -108,17 +110,19 @@ message DebugSetScore {
108
110
 
109
111
  message DebugEndGame {
110
112
  enum EndResult {
111
- Surrender = 1; // Default if nothing is set. The current player admits defeat.
112
- DeclareVictory = 2;
113
+ ENUM_END_RESULT_UNSET = 0; // PROTO3 COMPAT
114
+ SURRENDER = 1; // DEFAULT IF NOTHING IS SET. THE CURRENT PLAYER ADMITS DEFEAT.
115
+ DECLARE_VICTORY = 2;
113
116
  }
114
117
  optional EndResult end_result = 1;
115
118
  }
116
119
 
117
120
  message DebugSetUnitValue {
118
121
  enum UnitValue {
119
- Energy = 1;
120
- Life = 2;
121
- Shields = 3;
122
+ ENUM_UNIT_VALUE_UNSET = 0; // PROTO3 COMPAT
123
+ ENERGY = 1;
124
+ LIFE = 2;
125
+ SHIELDS = 3;
122
126
  }
123
127
  optional UnitValue unit_value = 1;
124
128
  optional float value = 2;