Class: SearchTree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/chess_openings/search_tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Node

Returns a new instance of Node.



128
129
130
131
# File 'lib/chess_openings/search_tree.rb', line 128

def initialize(value)
  @value = value
  @nodes = {}
end

Instance Attribute Details

#nodesObject

Returns the value of attribute nodes.



126
127
128
# File 'lib/chess_openings/search_tree.rb', line 126

def nodes
  @nodes
end

#valueObject

Returns the value of attribute value.



126
127
128
# File 'lib/chess_openings/search_tree.rb', line 126

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/chess_openings/search_tree.rb', line 149

def ==(other)
  return false if self.size != other.size || @value != other.value
  @nodes.keys.each do |key|
    return false unless other.keys.include?(key)
  end

  @nodes.keys.each do |key|
    return false if @nodes[key] != other.nodes[key]
  end

  true
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/chess_openings/search_tree.rb', line 145

def include?(key)
  @nodes.keys.include?(key)
end

#is_leaf?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/chess_openings/search_tree.rb', line 133

def is_leaf?
  @nodes.empty?
end

#keysObject



141
142
143
# File 'lib/chess_openings/search_tree.rb', line 141

def keys
  @nodes.keys
end

#sizeObject



137
138
139
# File 'lib/chess_openings/search_tree.rb', line 137

def size
  @nodes.size
end