Class: Abstracta::Territory
- Inherits:
-
Object
- Object
- Abstracta::Territory
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/abstracta/territory.rb
Instance Attribute Summary collapse
-
#age ⇒ Object
readonly
Returns the value of attribute age.
-
#compass ⇒ Object
readonly
Returns the value of attribute compass.
-
#developer ⇒ Object
readonly
Returns the value of attribute developer.
-
#dna ⇒ Object
readonly
Returns the value of attribute dna.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#occupants ⇒ Object
readonly
Returns the value of attribute occupants.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
Instance Method Summary collapse
- #age! ⇒ Object
- #cull! ⇒ Object
- #growth ⇒ Object
-
#initialize(locations = [[0,0]], genome = Genome.default) ⇒ Territory
constructor
A new instance of Territory.
- #occupant_at(point) ⇒ Object
- #occupant_class ⇒ Object
- #occupy!(target) ⇒ Object
- #projected_size ⇒ Object
Constructor Details
#initialize(locations = [[0,0]], genome = Genome.default) ⇒ Territory
Returns a new instance of Territory.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/abstracta/territory.rb', line 17 def initialize(locations=[[0,0]],genome=Genome.default) @compass = Compass.default @occupants = locations.map(&method(:occupant_at)) @dna = genome.tap do |my| @period = my.growth.cycle @rate = my.growth.rate @limit = my.growth.limit @max_age = my.age_bound end @age = 0 @developer = TerritoryDeveloper.new(self) end |
Instance Attribute Details
#age ⇒ Object (readonly)
Returns the value of attribute age.
14 15 16 |
# File 'lib/abstracta/territory.rb', line 14 def age @age end |
#compass ⇒ Object (readonly)
Returns the value of attribute compass.
13 14 15 |
# File 'lib/abstracta/territory.rb', line 13 def compass @compass end |
#developer ⇒ Object (readonly)
Returns the value of attribute developer.
13 14 15 |
# File 'lib/abstracta/territory.rb', line 13 def developer @developer end |
#dna ⇒ Object (readonly)
Returns the value of attribute dna.
11 12 13 |
# File 'lib/abstracta/territory.rb', line 11 def dna @dna end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
15 16 17 |
# File 'lib/abstracta/territory.rb', line 15 def limit @limit end |
#occupants ⇒ Object (readonly)
Returns the value of attribute occupants.
12 13 14 |
# File 'lib/abstracta/territory.rb', line 12 def occupants @occupants end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
15 16 17 |
# File 'lib/abstracta/territory.rb', line 15 def period @period end |
Instance Method Details
#age! ⇒ Object
33 34 35 |
# File 'lib/abstracta/territory.rb', line 33 def age! @age = @age + 1 end |
#cull! ⇒ Object
57 58 59 60 61 |
# File 'lib/abstracta/territory.rb', line 57 def cull! @occupants.reject! do |occupant| occupant.age >= @max_age end end |
#growth ⇒ Object
41 42 43 |
# File 'lib/abstracta/territory.rb', line 41 def growth projected_size - size end |
#occupant_at(point) ⇒ Object
49 50 51 |
# File 'lib/abstracta/territory.rb', line 49 def occupant_at(point) occupant_class.new([point.x, point.y]) end |
#occupant_class ⇒ Object
45 46 47 |
# File 'lib/abstracta/territory.rb', line 45 def occupant_class Occupant end |
#occupy!(target) ⇒ Object
53 54 55 |
# File 'lib/abstracta/territory.rb', line 53 def occupy!(target) @occupants << occupant_at(target) end |
#projected_size ⇒ Object
37 38 39 |
# File 'lib/abstracta/territory.rb', line 37 def projected_size (@rate.additive + size) * @rate.multiplicative end |