Skip to content

Commit

Permalink
Merge pull request #25 from dysonreturns/unit-group-find
Browse files Browse the repository at this point in the history
feat: adding ug #find and #detect with forced sigs
  • Loading branch information
dysonreturns committed Mar 19, 2024
2 parents 6e2aed7 + 465183a commit ef86bfb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/sc2ai/unit_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ def initialize(units = nil)
def_delegator :@units, :to_hash # Returns {UnitGroup#units}
def_delegator :@units, :to_proc # Returns a proc that maps a given key to its value.Returns a proc that maps a given key to its value.

# Methods which return unit
# @!macro [attach] def_delegators
# @!method $2
# Forwards to hash of #units.
# @see Hash#$2
# @return [Api::Unit]
def_delegator :@units, :find # Returns an element selected by the block.
def_delegator :@units, :detect # Returns an element selected by the block.

# Gets the Unit at an index
# @return [Api::Unit]
def at(index)
Expand Down
21 changes: 19 additions & 2 deletions sig/sc2ai.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,13 @@ module Sc2
# _@param_ `length` — how many cells to merge, i.e. 3 for finding 3x3 placement
def divide_grid: (Numo::Bit input_grid, Integer length) -> untyped

# Returns own 2d start position as set by initial camera
# This differs from position of first base structure
def start_position: () -> Api::Point2D

# Returns the enemy 2d start position
def enemy_start_position: () -> Api::Point2D

# Gets expos and surrounding minerals
# The index is a build location for an expo and the value is a UnitGroup, which has minerals and geysers
#
Expand All @@ -1916,8 +1923,8 @@ module Sc2
# ```
def expansion_points: () -> ::Array[Api::Point2D]

# sord warn - "Hash<Api::Point2D]" does not appear to be a type
# Returns a slice of #expansions where a base hasn't been built yet
# The has index is a build position and the value is a UnitGroup of resources for the base
#
# _@return_ — Location => UnitGroup of resources (minerals+geysers)
#
Expand All @@ -1928,7 +1935,7 @@ module Sc2
# puts expansions_unoccupied[expo_pos].minerals # or expansions[expo_pos]... => UnitGroup
# puts expansions_unoccupied[expo_pos].geysers # or expansions[expo_pos]... => UnitGroup
# ```
def expansions_unoccupied: () -> (SORD_ERROR_HashApiPoint2D | UnitGroup)
def expansions_unoccupied: () -> ::Hash[Api::Point2D, UnitGroup]

# Gets minerals for a base or base position
#
Expand Down Expand Up @@ -3194,6 +3201,16 @@ module Sc2
# _@see_ `Hash#to_proc`
def to_proc: () -> untyped

# Forwards to hash of #units.
#
# _@see_ `Hash#find`
def find: () -> Api::Unit

# Forwards to hash of #units.
#
# _@see_ `Hash#detect`
def detect: () -> Api::Unit

# sord omit - no YARD type given for "index", using untyped
# Gets the Unit at an index
def at: (untyped index) -> Api::Unit
Expand Down

0 comments on commit ef86bfb

Please sign in to comment.