Class: Abstracta::TerritoryDeveloper

Inherits:
Developer
  • Object
show all
Defined in:
lib/abstracta/developer.rb

Instance Method Summary collapse

Methods inherited from Developer

#initialize, #step, #tick

Constructor Details

This class inherits a constructor from Abstracta::Developer

Instance Method Details

#collectionObject



35
# File 'lib/abstracta/developer.rb', line 35

def collection; territory.occupants end

#develop(targets: adjacent) ⇒ Object



37
38
39
40
# File 'lib/abstracta/developer.rb', line 37

def develop(targets: adjacent)
  grow(targets) if growth_indicated?
  cull!
end

#grow(targets, n = growth) ⇒ Object



48
49
50
# File 'lib/abstracta/developer.rb', line 48

def grow(targets, n=growth)
  targets.sample(n).map(&method(:occupy!))
end

#growth_indicated?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/abstracta/developer.rb', line 42

def growth_indicated?
  in_cycle = age % territory.period == 0
  under_bound = size <= territory.limit
  in_cycle && under_bound
end

#territoryObject



34
# File 'lib/abstracta/developer.rb', line 34

def territory; @entity end