Class: Abstracta::Territory

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/abstracta/territory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#ageObject (readonly)

Returns the value of attribute age.



14
15
16
# File 'lib/abstracta/territory.rb', line 14

def age
  @age
end

#compassObject (readonly)

Returns the value of attribute compass.



13
14
15
# File 'lib/abstracta/territory.rb', line 13

def compass
  @compass
end

#developerObject (readonly)

Returns the value of attribute developer.



13
14
15
# File 'lib/abstracta/territory.rb', line 13

def developer
  @developer
end

#dnaObject (readonly)

Returns the value of attribute dna.



11
12
13
# File 'lib/abstracta/territory.rb', line 11

def dna
  @dna
end

#limitObject (readonly)

Returns the value of attribute limit.



15
16
17
# File 'lib/abstracta/territory.rb', line 15

def limit
  @limit
end

#occupantsObject (readonly)

Returns the value of attribute occupants.



12
13
14
# File 'lib/abstracta/territory.rb', line 12

def occupants
  @occupants
end

#periodObject (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

#growthObject



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_classObject



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_sizeObject



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

def projected_size
  (@rate.additive + size) * @rate.multiplicative 
end