Skip to content

Commit

Permalink
feat: UnitGroup#intersection and alias #&. some_squad &= units.army
Browse files Browse the repository at this point in the history
… removes dead units.
  • Loading branch information
dysonreturns committed Mar 26, 2024
1 parent fe59140 commit e56f6b5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/sc2ai/unit_group.rb
Expand Up @@ -227,12 +227,20 @@ def except(...)
UnitGroup.new(@units.except(...))
end

# Returns a hash containing the entries for given tag(s).
# Returns a new unit group containing the entries for given tag(s).
# @return [Sc2::UnitGroup] new unit group
def slice(...)
UnitGroup.new(@units.slice(...))
end

# 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):
# @param other_unit_group [UnitGroup]
# @return [UnitGroup] new unit group
def intersection(other_unit_group)
slice(*other_unit_group.tags)
end
alias_method :&, :intersection

# Selects a single random Unit without a parameter or an array of Units with a param, i.e. self.random(2)
# @return [Api::Unit]
def sample(...)
Expand Down

0 comments on commit e56f6b5

Please sign in to comment.