sc2ai 0.10.0 → 0.11.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4cc73bf9c7a184bba045eeda38fda3eef727073f587a2d10aaa73221a32e623
4
- data.tar.gz: 0a369e3cc2541eca0c31c9a54ee5837d1ecc468dbbef6c44294ed5446fece302
3
+ metadata.gz: 12ed47d1d8d02cf6f6b8cc90a721a6680549234091b9e59a6d26b28c176baddf
4
+ data.tar.gz: d32fa8177ced58062ce510a60923b4bd0b3808f2124c024184b4e05d1d2eea9b
5
5
  SHA512:
6
- metadata.gz: 276537ab6bd87a3bccc61664af3cffc40dd1c1d5191d14bba5ee7c22e8d23795300ea7e968db4f46dff6847e3dac50e18a2232ec2a51bdae1b9341c6f8bc96e4
7
- data.tar.gz: 6c58faf15c7eee339a9e24cbd7d945bd938cc82be86ee211bc9633127711f4b997b2b9619d83c0ce11e0b624facb4034bec83a46e9cb72e87b8f25039afc4baf
6
+ metadata.gz: 5484fa8272fa1be178882654b222691d1b7bab2c3209d29ad10643a6b43dbd99a238f5fe69f195df0066d1db58a30c3580093ac43ba16cf619993ea3853bdbb1
7
+ data.tar.gz: 509e55588fdc9c18e2011bab0c34e226123833d6daae537472076c4b21cd72950e4f4a1a94a7557040da8ca400f91775ce3fc7df4f9d66d5aa521deab69e6b7b
data/data/versions.json CHANGED
@@ -569,15 +569,13 @@
569
569
  "version": 94137
570
570
  },
571
571
  {
572
- "base-version": 95248,
573
- "data-hash": "D3BB9F619ADA87F2943384DAF437EA32",
574
- "fixed-hash": "17DA25BB12C6372C4E5944B5E4303906",
572
+ "base-version": 95841,
573
+ "data-hash": "536442325AEC578B31B2482F733396D5",
574
+ "fixed-hash": "68F2B161DFCE385FA577A21BF9BFAB0F",
575
575
  "label": "5.0.15",
576
576
  "replay-hash": "5563DC35EC51D0464DC16B56B424C9DF",
577
- "version": 95248
577
+ "version": 95841
578
578
  },
579
-
580
-
581
579
  {
582
580
  "base-version": 94137,
583
581
  "data-hash": "519EE8D06E384469C652DD58FC6016AC",
@@ -160,12 +160,12 @@ module Sc2
160
160
  end
161
161
 
162
162
  # Saves game to an in-memory bookmark.
163
- def request_quick_save
163
+ def quick_save
164
164
  send_request_for quick_save: Api::RequestQuickSave.new
165
165
  end
166
166
 
167
167
  # Loads from an in-memory bookmark.
168
- def request_quick_load
168
+ def quick_load
169
169
  send_request_for quick_load: Api::RequestQuickLoad.new
170
170
  end
171
171
 
data/lib/sc2ai/player.rb CHANGED
@@ -500,6 +500,22 @@ module Sc2
500
500
  def initialize(race:, name:)
501
501
  super(race:, name:, type: Api::PlayerType::PARTICIPANT)
502
502
  end
503
+
504
+ def play
505
+ loop do
506
+ @api.step(@step_count) unless @realtime
507
+
508
+ step_to_loop = @realtime ? game_loop + @step_count : nil
509
+ response_observation = @api.observation(game_loop: step_to_loop)
510
+ return if response_observation.nil?
511
+
512
+ # Check if match has a result and callback
513
+ on_player_result(response_observation.player_result) unless response_observation.player_result.empty?
514
+
515
+ return @result unless @result.nil?
516
+ break if @status != :IN_GAME
517
+ end
518
+ end
503
519
  end
504
520
 
505
521
  # A spectator for a Match
@@ -1,8 +1,6 @@
1
1
  module Api
2
2
  # Adds additional functionality to message object Api::PowerSource
3
3
  module PowerSourceExtension
4
- include Sc2::Position
5
-
6
4
  # Adds additional functionality to message class Api::PowerSource
7
5
  module ClassMethods
8
6
  # Shorthand for creating an instance for [x, y, z]
@@ -615,8 +615,9 @@ module Sc2
615
615
  # Builds a kdtree if not already built and returns it
616
616
  # @return [::Kdtree]
617
617
  def kdtree
618
- return @kdtree unless @kdtree.nil?
619
- @kdtree = Kdtree.new(@units.values.each_with_index.map { |unit, index| [unit.pos.x, unit.pos.y, index] })
618
+ cached("kdtree") do
619
+ Kdtree.new(@units.values.each_with_index.map { |unit, index| [unit.pos.x, unit.pos.y, index] })
620
+ end
620
621
  end
621
622
 
622
623
  # Returns an
data/lib/sc2ai/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Sc2
2
2
  # gem version
3
3
  # @return [String]
4
- VERSION = "0.10.0"
4
+ VERSION = "0.11.0"
5
5
  end
data/sig/sc2ai.rbs CHANGED
@@ -1251,6 +1251,9 @@ module Sc2
1251
1251
  CALLBACK_METHODS: untyped
1252
1252
 
1253
1253
  def initialize: (race: Integer, name: String) -> void
1254
+
1255
+ # sord omit - no YARD return type given, using untyped
1256
+ def play: () -> untyped
1254
1257
  end
1255
1258
 
1256
1259
  # A spectator for a Match
@@ -2666,11 +2669,11 @@ module Sc2
2666
2669
 
2667
2670
  # sord omit - no YARD return type given, using untyped
2668
2671
  # Saves game to an in-memory bookmark.
2669
- def request_quick_save: () -> untyped
2672
+ def quick_save: () -> untyped
2670
2673
 
2671
2674
  # sord omit - no YARD return type given, using untyped
2672
2675
  # Loads from an in-memory bookmark.
2673
- def request_quick_load: () -> untyped
2676
+ def quick_load: () -> untyped
2674
2677
 
2675
2678
  # sord omit - no YARD return type given, using untyped
2676
2679
  # Quits Sc2. Does not work on ladder.
@@ -2959,11 +2962,11 @@ module Sc2
2959
2962
 
2960
2963
  # sord omit - no YARD return type given, using untyped
2961
2964
  # Saves game to an in-memory bookmark.
2962
- def request_quick_save: () -> untyped
2965
+ def quick_save: () -> untyped
2963
2966
 
2964
2967
  # sord omit - no YARD return type given, using untyped
2965
2968
  # Loads from an in-memory bookmark.
2966
- def request_quick_load: () -> untyped
2969
+ def quick_load: () -> untyped
2967
2970
 
2968
2971
  # sord omit - no YARD return type given, using untyped
2969
2972
  # Quits Sc2. Does not work on ladder.
@@ -7179,142 +7182,6 @@ module Api
7179
7182
  # ```
7180
7183
  def self.[]: ((Float | Integer) x, (Float | Integer) y, (Float | Integer) z) -> Api::Point
7181
7184
 
7182
- # Loose equality matches on floats x and y.
7183
- # We never check z-axis, because the map is single-level.
7184
- # TODO: We should almost certainly introduce TOLERANCE here, but verify it's cost first.
7185
- #
7186
- # _@param_ `other`
7187
- def ==: (Sc2::Position other) -> bool
7188
-
7189
- # A new point representing the sum of this point and the other point.
7190
- #
7191
- # _@param_ `other` — The other point/number to add.
7192
- def add: ((Api::Point2D | Numeric) other) -> Api::Point2D
7193
-
7194
- # Returns a new point representing the difference between this point and the other point/number.
7195
- #
7196
- # _@param_ `other` — The other to subtract.
7197
- def subtract: ((Api::Point2D | Numeric) other) -> Api::Point2D
7198
-
7199
- # Returns this point multiplied by the scalar
7200
- #
7201
- # _@param_ `scalar` — The scalar to multiply by.
7202
- def multiply: (Float scalar) -> Api::Point2D
7203
-
7204
- # _@param_ `scalar` — The scalar to divide by.
7205
- #
7206
- # _@return_ — A new point representing this point divided by the scalar.
7207
- def divide: (Float scalar) -> Api::Point2D
7208
-
7209
- # Randomly adjusts both x and y by a range of: -offset..offset
7210
- #
7211
- # _@param_ `offset`
7212
- #
7213
- # _@return_ — new Position
7214
- def random_offset: (Float offset) -> Sc2::Position
7215
-
7216
- # Randomly change this point's x and y by the supplied offset.
7217
- # i.e. offset=2 can adjust x and y by any number in range -2..2
7218
- #
7219
- # _@param_ `offset`
7220
- #
7221
- # _@return_ — self
7222
- def random_offset!: (Float offset) -> Sc2::Position
7223
-
7224
- # Creates a new point with x and y which is offset
7225
- #
7226
- # _@param_ `x`
7227
- #
7228
- # _@param_ `y`
7229
- #
7230
- # _@return_ — new Position
7231
- def offset: (?(Float | Integer) x, ?(Float | Integer) y) -> Sc2::Position
7232
-
7233
- # Changes this point's x and y by the supplied offset
7234
- #
7235
- # _@param_ `x`
7236
- #
7237
- # _@param_ `y`
7238
- #
7239
- # _@return_ — self
7240
- def offset!: (?(Float | Integer) x, ?(Float | Integer) y) -> Sc2::Position
7241
-
7242
- # For vector returns the magnitude, synonymous with Math.hypot
7243
- def magnitude: () -> Float
7244
-
7245
- # The dot product of this vector and the other vector.
7246
- #
7247
- # _@param_ `other` — The other vector to calculate the dot product with.
7248
- def dot: (Api::Point2D other) -> Float
7249
-
7250
- # The cross product of this vector and the other vector.
7251
- #
7252
- # _@param_ `other` — The other vector to calculate the cross product with.
7253
- def cross_product: (Api::Point2D other) -> Float
7254
-
7255
- # The angle between this vector and the other vector, in radians.
7256
- #
7257
- # _@param_ `other` — The other vector to calculate the angle to.
7258
- def angle_to: (Api::Point2D other) -> Float
7259
-
7260
- # A new point representing the normalized version of this vector (unit length).
7261
- def normalize: () -> Api::Point2D
7262
-
7263
- # Linear interpolation between this point and another for scale
7264
- # Finds a point on a line between two points at % along the way. 0.0 returns self, 1.0 returns other, 0.5 is halfway.
7265
- #
7266
- # _@param_ `other`
7267
- #
7268
- # _@param_ `scale` — a value between 0.0..1.0
7269
- def lerp: (Sc2::Position other, Float scale) -> Api::Point2D
7270
-
7271
- # Calculates the distance between self and other
7272
- #
7273
- # _@param_ `other`
7274
- def distance_to: (Sc2::Position other) -> Float
7275
-
7276
- # The squared distance between this point and the other point.
7277
- #
7278
- # _@param_ `other` — The other point to calculate the squared distance to.
7279
- def distance_squared_to: (Api::Point2D other) -> Float
7280
-
7281
- # Distance between this point and coordinate of x and y
7282
- #
7283
- # _@param_ `x`
7284
- #
7285
- # _@param_ `y`
7286
- def distance_to_coordinate: (x: (Float | Integer), y: (Float | Integer)) -> Float
7287
-
7288
- # The distance from this point to the circle.
7289
- #
7290
- # _@param_ `center` — The center of the circle.
7291
- #
7292
- # _@param_ `radius` — The radius of the circle.
7293
- def distance_to_circle: (Api::Point2D center, Float radius) -> Float
7294
-
7295
- # Moves in direction towards other point by distance
7296
- #
7297
- # _@param_ `other` — The target point to move to.
7298
- #
7299
- # _@param_ `distance` — The distance to move.
7300
- def towards: (Api::Point2D other, Float distance) -> Api::Point2D
7301
-
7302
- # Moves in direction away from the other point by distance
7303
- #
7304
- # _@param_ `other` — The target point to move away from
7305
- #
7306
- # _@param_ `distance` — The distance to move.
7307
- def away_from: (Api::Point2D other, Float distance) -> Api::Point2D
7308
-
7309
- # Returns [x,y] array tuple
7310
- def to_axy: () -> ::Array[Float]
7311
-
7312
- # Returns [x,y] array tuple where floats are cast to ints
7313
- # Useful when trying to find the tile which something is on
7314
- def to_atile: () -> ::Array[Integer]
7315
-
7316
- def to_s: () -> String
7317
-
7318
7185
  # sord omit - no YARD type given for :pos, using untyped
7319
7186
  # optional field readers
7320
7187
  attr_accessor pos: untyped
@@ -20375,153 +20242,6 @@ module Api
20375
20242
 
20376
20243
  # Adds additional functionality to message object Api::PowerSource
20377
20244
  module PowerSourceExtension
20378
- include Sc2::Position
20379
-
20380
- # Returns self.
20381
- # If you're ever unsure if you have a Unit or Position in hand,
20382
- # this method allows safely calling `unknown_target.pos` to return a position.
20383
- #
20384
- # ```ruby
20385
- # target.pos
20386
- # ```
20387
- def pos: () -> Sc2::Position
20388
-
20389
- # Loose equality matches on floats x and y.
20390
- # We never check z-axis, because the map is single-level.
20391
- # TODO: We should almost certainly introduce TOLERANCE here, but verify it's cost first.
20392
- #
20393
- # _@param_ `other`
20394
- def ==: (Sc2::Position other) -> bool
20395
-
20396
- # A new point representing the sum of this point and the other point.
20397
- #
20398
- # _@param_ `other` — The other point/number to add.
20399
- def add: ((Api::Point2D | Numeric) other) -> Api::Point2D
20400
-
20401
- # Returns a new point representing the difference between this point and the other point/number.
20402
- #
20403
- # _@param_ `other` — The other to subtract.
20404
- def subtract: ((Api::Point2D | Numeric) other) -> Api::Point2D
20405
-
20406
- # Returns this point multiplied by the scalar
20407
- #
20408
- # _@param_ `scalar` — The scalar to multiply by.
20409
- def multiply: (Float scalar) -> Api::Point2D
20410
-
20411
- # _@param_ `scalar` — The scalar to divide by.
20412
- #
20413
- # _@return_ — A new point representing this point divided by the scalar.
20414
- def divide: (Float scalar) -> Api::Point2D
20415
-
20416
- # Randomly adjusts both x and y by a range of: -offset..offset
20417
- #
20418
- # _@param_ `offset`
20419
- #
20420
- # _@return_ — new Position
20421
- def random_offset: (Float offset) -> Sc2::Position
20422
-
20423
- # Randomly change this point's x and y by the supplied offset.
20424
- # i.e. offset=2 can adjust x and y by any number in range -2..2
20425
- #
20426
- # _@param_ `offset`
20427
- #
20428
- # _@return_ — self
20429
- def random_offset!: (Float offset) -> Sc2::Position
20430
-
20431
- # Creates a new point with x and y which is offset
20432
- #
20433
- # _@param_ `x`
20434
- #
20435
- # _@param_ `y`
20436
- #
20437
- # _@return_ — new Position
20438
- def offset: (?(Float | Integer) x, ?(Float | Integer) y) -> Sc2::Position
20439
-
20440
- # Changes this point's x and y by the supplied offset
20441
- #
20442
- # _@param_ `x`
20443
- #
20444
- # _@param_ `y`
20445
- #
20446
- # _@return_ — self
20447
- def offset!: (?(Float | Integer) x, ?(Float | Integer) y) -> Sc2::Position
20448
-
20449
- # For vector returns the magnitude, synonymous with Math.hypot
20450
- def magnitude: () -> Float
20451
-
20452
- # The dot product of this vector and the other vector.
20453
- #
20454
- # _@param_ `other` — The other vector to calculate the dot product with.
20455
- def dot: (Api::Point2D other) -> Float
20456
-
20457
- # The cross product of this vector and the other vector.
20458
- #
20459
- # _@param_ `other` — The other vector to calculate the cross product with.
20460
- def cross_product: (Api::Point2D other) -> Float
20461
-
20462
- # The angle between this vector and the other vector, in radians.
20463
- #
20464
- # _@param_ `other` — The other vector to calculate the angle to.
20465
- def angle_to: (Api::Point2D other) -> Float
20466
-
20467
- # A new point representing the normalized version of this vector (unit length).
20468
- def normalize: () -> Api::Point2D
20469
-
20470
- # Linear interpolation between this point and another for scale
20471
- # Finds a point on a line between two points at % along the way. 0.0 returns self, 1.0 returns other, 0.5 is halfway.
20472
- #
20473
- # _@param_ `other`
20474
- #
20475
- # _@param_ `scale` — a value between 0.0..1.0
20476
- def lerp: (Sc2::Position other, Float scale) -> Api::Point2D
20477
-
20478
- # Calculates the distance between self and other
20479
- #
20480
- # _@param_ `other`
20481
- def distance_to: (Sc2::Position other) -> Float
20482
-
20483
- # The squared distance between this point and the other point.
20484
- #
20485
- # _@param_ `other` — The other point to calculate the squared distance to.
20486
- def distance_squared_to: (Api::Point2D other) -> Float
20487
-
20488
- # Distance between this point and coordinate of x and y
20489
- #
20490
- # _@param_ `x`
20491
- #
20492
- # _@param_ `y`
20493
- def distance_to_coordinate: (x: (Float | Integer), y: (Float | Integer)) -> Float
20494
-
20495
- # The distance from this point to the circle.
20496
- #
20497
- # _@param_ `center` — The center of the circle.
20498
- #
20499
- # _@param_ `radius` — The radius of the circle.
20500
- def distance_to_circle: (Api::Point2D center, Float radius) -> Float
20501
-
20502
- # Moves in direction towards other point by distance
20503
- #
20504
- # _@param_ `other` — The target point to move to.
20505
- #
20506
- # _@param_ `distance` — The distance to move.
20507
- def towards: (Api::Point2D other, Float distance) -> Api::Point2D
20508
-
20509
- # Moves in direction away from the other point by distance
20510
- #
20511
- # _@param_ `other` — The target point to move away from
20512
- #
20513
- # _@param_ `distance` — The distance to move.
20514
- def away_from: (Api::Point2D other, Float distance) -> Api::Point2D
20515
-
20516
- # Returns [x,y] array tuple
20517
- def to_axy: () -> ::Array[Float]
20518
-
20519
- # Returns [x,y] array tuple where floats are cast to ints
20520
- # Useful when trying to find the tile which something is on
20521
- def to_atile: () -> ::Array[Integer]
20522
-
20523
- def to_s: () -> String
20524
-
20525
20245
  # Adds additional functionality to message class Api::PowerSource
20526
20246
  module ClassMethods
20527
20247
  # Shorthand for creating an instance for [x, y, z]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sc2ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dyson Returns
@@ -388,7 +388,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
388
388
  requirements:
389
389
  - - ">="
390
390
  - !ruby/object:Gem::Version
391
- version: 3.3.8
391
+ version: 3.4.7
392
392
  required_rubygems_version: !ruby/object:Gem::Requirement
393
393
  requirements:
394
394
  - - ">="