Class: Checkers::AI::Tree
- Inherits:
-
Object
- Object
- Checkers::AI::Tree
- Defined in:
- lib/checkers/ai/tree.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #depth ⇒ Object
-
#initialize(node) ⇒ Tree
constructor
A new instance of Tree.
Constructor Details
#initialize(node) ⇒ Tree
Returns a new instance of Tree.
12 13 14 |
# File 'lib/checkers/ai/tree.rb', line 12 def initialize(node) @root = node end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
6 7 8 |
# File 'lib/checkers/ai/tree.rb', line 6 def root @root end |
Class Method Details
Instance Method Details
#depth ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/checkers/ai/tree.rb', line 16 def depth current_depth = 0 children = @root.children while children.any? current_depth += 1 children = children.first.children end current_depth end |