Class: Legion::Extensions::Agentic::Learning::Chrysalis::Helpers::Cocoon

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb

Constant Summary collapse

TEMP_ADJUST =
0.05
HUMID_ADJUST =
0.05

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment:, temperature: 0.5, humidity: 0.5) ⇒ Cocoon

Returns a new instance of Cocoon.



17
18
19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 17

def initialize(environment:, temperature: 0.5, humidity: 0.5, **)
  @id            = SecureRandom.uuid
  @environment   = environment.to_s
  @temperature   = temperature.to_f.clamp(0.0, 1.0)
  @humidity      = humidity.to_f.clamp(0.0, 1.0)
  @chrysalis_ids = []
  @created_at    = Time.now.utc
end

Instance Attribute Details

#chrysalis_idsObject (readonly)

Returns the value of attribute chrysalis_ids.



12
13
14
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 12

def chrysalis_ids
  @chrysalis_ids
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 12

def created_at
  @created_at
end

#environmentObject (readonly)

Returns the value of attribute environment.



12
13
14
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 12

def environment
  @environment
end

#humidityObject (readonly)

Returns the value of attribute humidity.



12
13
14
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 12

def humidity
  @humidity
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 12

def id
  @id
end

#temperatureObject (readonly)

Returns the value of attribute temperature.



12
13
14
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 12

def temperature
  @temperature
end

Instance Method Details

#cool!Object



40
41
42
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 40

def cool!
  @temperature = (@temperature - TEMP_ADJUST).clamp(0.0, 1.0).round(10)
end

#dry!Object



48
49
50
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 48

def dry!
  @humidity = (@humidity - HUMID_ADJUST).clamp(0.0, 1.0).round(10)
end

#expose(chrysalis_id) ⇒ Object



31
32
33
34
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 31

def expose(chrysalis_id)
  @chrysalis_ids.delete(chrysalis_id)
  true
end

#growth_modifierObject



60
61
62
63
64
65
66
67
68
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 60

def growth_modifier
  if ideal?
    0.1
  elsif hostile?
    -0.05
  else
    0.0
  end
end

#hostile?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 56

def hostile?
  @temperature > 0.9 || @humidity < 0.1
end

#ideal?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 52

def ideal?
  @temperature.between?(0.4, 0.7) && @humidity.between?(0.4, 0.7)
end

#moisten!Object



44
45
46
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 44

def moisten!
  @humidity = (@humidity + HUMID_ADJUST).clamp(0.0, 1.0).round(10)
end

#shelter(chrysalis_id) ⇒ Object



26
27
28
29
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 26

def shelter(chrysalis_id)
  @chrysalis_ids << chrysalis_id unless @chrysalis_ids.include?(chrysalis_id)
  true
end

#to_hObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 70

def to_h
  {
    id:              @id,
    environment:     @environment,
    temperature:     @temperature,
    humidity:        @humidity,
    chrysalis_ids:   @chrysalis_ids.dup,
    ideal:           ideal?,
    hostile:         hostile?,
    growth_modifier: growth_modifier,
    created_at:      @created_at
  }
end

#warm!Object



36
37
38
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 36

def warm!
  @temperature = (@temperature + TEMP_ADJUST).clamp(0.0, 1.0).round(10)
end