Class: Legion::Extensions::Agentic::Defense::Quicksilver::Helpers::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb

Constant Summary collapse

DEPTH_CHANGE =
0.05
TENSION_DECREASE =
0.1
TENSION_INCREASE =
0.05

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(surface_type:, depth: 0.5, surface_tension: Constants::SURFACE_TENSION) ⇒ Pool

Returns a new instance of Pool.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 18

def initialize(surface_type:, depth: 0.5, surface_tension: Constants::SURFACE_TENSION)
  raise ArgumentError, "invalid surface_type: #{surface_type}" unless Constants::SURFACE_TYPES.include?(surface_type)

  @id              = SecureRandom.uuid
  @surface_type    = surface_type
  @depth           = depth.clamp(0.0, 1.0)
  @droplet_ids     = []
  @surface_tension = surface_tension.clamp(0.0, 1.0)
  @created_at      = Time.now.utc
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 12

def created_at
  @created_at
end

#depthObject (readonly)

Returns the value of attribute depth.



12
13
14
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 12

def depth
  @depth
end

#droplet_idsObject (readonly)

Returns the value of attribute droplet_ids.



12
13
14
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 12

def droplet_ids
  @droplet_ids
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 12

def id
  @id
end

#surface_tensionObject (readonly)

Returns the value of attribute surface_tension.



12
13
14
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 12

def surface_tension
  @surface_tension
end

#surface_typeObject (readonly)

Returns the value of attribute surface_type.



12
13
14
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 12

def surface_type
  @surface_type
end

Instance Method Details

#add_droplet(droplet_id) ⇒ Object



29
30
31
32
33
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 29

def add_droplet(droplet_id)
  @droplet_ids << droplet_id unless @droplet_ids.include?(droplet_id)
  @depth = (@depth + DEPTH_CHANGE).clamp(0.0, 1.0).round(10)
  self
end

#agitate!Object



41
42
43
44
45
46
47
48
49
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 41

def agitate!
  @surface_tension = (@surface_tension - TENSION_DECREASE).clamp(0.0, 1.0).round(10)
  released = []
  @droplet_ids.each do |did|
    released << did if rand > @surface_tension
  end
  released.each { |did| remove_droplet(did) }
  released
end

#reflective?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 56

def reflective?
  @depth >= 0.7 && @surface_tension >= 0.5
end

#remove_droplet(droplet_id) ⇒ Object



35
36
37
38
39
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 35

def remove_droplet(droplet_id)
  @droplet_ids.delete(droplet_id)
  @depth = (@depth - DEPTH_CHANGE).clamp(0.0, 1.0).round(10)
  self
end

#settle!Object



51
52
53
54
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 51

def settle!
  @surface_tension = (@surface_tension + TENSION_INCREASE).clamp(0.0, 1.0).round(10)
  self
end

#shallow?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 60

def shallow?
  @depth < 0.2
end

#to_hObject



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/pool.rb', line 64

def to_h
  {
    id:              @id,
    surface_type:    @surface_type,
    depth:           @depth.round(10),
    droplet_ids:     @droplet_ids.dup,
    droplet_count:   @droplet_ids.size,
    surface_tension: @surface_tension.round(10),
    reflective:      reflective?,
    shallow:         shallow?,
    created_at:      @created_at
  }
end