Class: Legion::Extensions::Agentic::Integration::Labyrinth::Helpers::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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

#contentObject (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_levelObject (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_idObject (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_typeObject (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

#visitedObject

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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_hObject



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