Class: Legion::Extensions::Agentic::Integration::Labyrinth::Helpers::Node
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Integration::Labyrinth::Helpers::Node
- Defined in:
- lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb
Instance Attribute Summary collapse
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#danger_level ⇒ Object
readonly
Returns the value of attribute danger_level.
-
#node_id ⇒ Object
readonly
Returns the value of attribute node_id.
-
#node_type ⇒ Object
readonly
Returns the value of attribute node_type.
-
#visited ⇒ Object
Returns the value of attribute visited.
Instance Method Summary collapse
- #connect!(other_id) ⇒ Object
- #dangerous? ⇒ Boolean
- #dead_end? ⇒ Boolean
- #disconnect!(other_id) ⇒ Object
-
#initialize(node_id:, node_type:, content: nil, danger_level: Constants::DEFAULT_DANGER_LEVEL) ⇒ Node
constructor
A new instance of Node.
- #junction? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(node_id:, node_type:, content: nil, danger_level: Constants::DEFAULT_DANGER_LEVEL) ⇒ Node
Returns a new instance of Node.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 13 def initialize(node_id:, node_type:, content: nil, danger_level: Constants::DEFAULT_DANGER_LEVEL) unless Constants::NODE_TYPES.include?(node_type) raise ArgumentError, "unknown node_type: #{node_type.inspect}; must be one of #{Constants::NODE_TYPES.inspect}" end @node_id = node_id @node_type = node_type @content = content @connections = [] @visited = false @danger_level = danger_level.clamp(0.0, 1.0) end |
Instance Attribute Details
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 10 def connections @connections end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 10 def content @content end |
#danger_level ⇒ Object (readonly)
Returns the value of attribute danger_level.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 10 def danger_level @danger_level end |
#node_id ⇒ Object (readonly)
Returns the value of attribute node_id.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 10 def node_id @node_id end |
#node_type ⇒ Object (readonly)
Returns the value of attribute node_type.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 10 def node_type @node_type end |
#visited ⇒ Object
Returns the value of attribute visited.
11 12 13 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 11 def visited @visited end |
Instance Method Details
#connect!(other_id) ⇒ Object
26 27 28 29 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 26 def connect!(other_id) @connections << other_id unless @connections.include?(other_id) self end |
#dangerous? ⇒ Boolean
44 45 46 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 44 def dangerous? @node_type == :minotaur_lair || @danger_level >= 0.5 end |
#dead_end? ⇒ Boolean
36 37 38 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 36 def dead_end? @node_type == :dead_end || (@connections.empty? && @node_type != :entrance && @node_type != :exit) end |
#disconnect!(other_id) ⇒ Object
31 32 33 34 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 31 def disconnect!(other_id) @connections.delete(other_id) self end |
#junction? ⇒ Boolean
40 41 42 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 40 def junction? @node_type == :junction || @connections.size >= 3 end |
#to_h ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb', line 48 def to_h { node_id: @node_id, node_type: @node_type, content: @content, connections: @connections.dup, visited: @visited, danger_level: @danger_level } end |