Class: Checkers::AI::Tree

Inherits:
Object
  • Object
show all
Defined in:
lib/checkers/ai/tree.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

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

.build(board, depth) ⇒ Object



8
9
10
# File 'lib/checkers/ai/tree.rb', line 8

def self.build(board, depth)
  Tree.new(Node.new(board, :ai, depth))
end

Instance Method Details

#depthObject



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