Class: Legion::Extensions::Agentic::Defense::Erosion::Helpers::ErosionEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Defense::Erosion::Helpers::ErosionEngine
- Defined in:
- lib/legion/extensions/agentic/defense/erosion/helpers/erosion_engine.rb
Instance Method Summary collapse
- #carve_channel(formation_id:, agent:, force: 0.1) ⇒ Object
- #channel_count ⇒ Object
- #create_formation(material_type:, domain:, content:, resistance: nil) ⇒ Object
- #deepest_channels(limit: 5) ⇒ Object
- #erode(formation_id:, agent:, force:) ⇒ Object
- #erosion_report ⇒ Object
- #formation_count ⇒ Object
- #get_formation(formation_id) ⇒ Object
-
#initialize ⇒ ErosionEngine
constructor
A new instance of ErosionEngine.
- #most_eroded(limit: 5) ⇒ Object
- #weather_all!(force: 0.05, agent: :wind) ⇒ Object
Constructor Details
#initialize ⇒ ErosionEngine
Returns a new instance of ErosionEngine.
10 11 12 13 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/erosion_engine.rb', line 10 def initialize @formations = {} @channels = {} end |
Instance Method Details
#carve_channel(formation_id:, agent:, force: 0.1) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/erosion_engine.rb', line 44 def carve_channel(formation_id:, agent:, force: 0.1, **) existing = find_channel(formation_id, agent) if existing existing.deepen!(force.clamp(0.0, 1.0)) existing.widen! if existing.depth >= 0.3 existing.to_h else channel = Channel.new(formation_id: formation_id, agent: agent) channel.deepen!(force.clamp(0.0, 1.0)) @channels[channel.channel_id] = channel channel.to_h end end |
#channel_count ⇒ Object
107 108 109 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/erosion_engine.rb', line 107 def channel_count @channels.size end |
#create_formation(material_type:, domain:, content:, resistance: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/erosion_engine.rb', line 15 def create_formation(material_type:, domain:, content:, resistance: nil, **) return { success: false, error: :max_formations_reached } if @formations.size >= Constants::MAX_FORMATIONS return { success: false, error: :invalid_material_type } unless Constants::MATERIAL_TYPES.include?(material_type) formation = Formation.new( material_type: material_type, domain: domain, content: content, resistance: resistance ) @formations[formation.formation_id] = formation { success: true, formation_id: formation.formation_id, formation: formation.to_h } rescue ArgumentError => e { success: false, error: e. } end |
#deepest_channels(limit: 5) ⇒ Object
69 70 71 72 73 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/erosion_engine.rb', line 69 def deepest_channels(limit: 5, **) limit = limit.clamp(1, @channels.size.positive? ? @channels.size : 1) sorted = @channels.values.sort_by { |c| -c.depth } sorted.first(limit).map(&:to_h) end |
#erode(formation_id:, agent:, force:) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/erosion_engine.rb', line 31 def erode(formation_id:, agent:, force:, **) formation = @formations[formation_id] return { success: false, error: :formation_not_found } unless formation return { success: false, error: :invalid_agent } unless Constants::EROSION_AGENTS.include?(agent) result = formation.erode!(agent, force) channel = carve_channel(formation_id: formation_id, agent: agent, force: force) { success: true, formation_id: formation_id, erosion: result, channel: channel } rescue ArgumentError => e { success: false, error: e. } end |
#erosion_report ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/erosion_engine.rb', line 81 def erosion_report(**) { success: true, total_formations: @formations.size, total_channels: @channels.size, canyons: @formations.values.count(&:canyon?), weathered: @formations.values.count(&:weathered?), pristine: @formations.values.count(&:pristine?), average_depth: average_depth, average_integrity: average_integrity, deepest_channels: deepest_channels(limit: 3), most_eroded: most_eroded(limit: 3) } end |
#formation_count ⇒ Object
103 104 105 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/erosion_engine.rb', line 103 def formation_count @formations.size end |
#get_formation(formation_id) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/erosion_engine.rb', line 96 def get_formation(formation_id) formation = @formations[formation_id] return { found: false } unless formation { found: true, formation: formation.to_h } end |
#most_eroded(limit: 5) ⇒ Object
75 76 77 78 79 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/erosion_engine.rb', line 75 def most_eroded(limit: 5, **) limit = limit.clamp(1, @formations.size.positive? ? @formations.size : 1) sorted = @formations.values.sort_by(&:erosion_depth).reverse sorted.first(limit).map(&:to_h) end |
#weather_all!(force: 0.05, agent: :wind) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/erosion_engine.rb', line 58 def weather_all!(force: 0.05, agent: :wind, **) results = @formations.map do |id, formation| erosion = formation.erode!(agent, force) ch = carve_channel(formation_id: id, agent: agent, force: force) { formation_id: id, erosion: erosion, channel: ch } end { success: true, weathered: results.size, results: results } rescue ArgumentError => e { success: false, error: e. } end |