Class: Checkers::AI::Engine::Base

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

Direct Known Subclasses

Alphabeta, Minmax

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree_depth = 3) ⇒ Base

Returns a new instance of Base.



9
10
11
# File 'lib/checkers/ai/engine/base.rb', line 9

def initialize(tree_depth = 3)
  @tree_depth = tree_depth
end

Instance Attribute Details

#tree_depthObject (readonly)

Returns the value of attribute tree_depth.



7
8
9
# File 'lib/checkers/ai/engine/base.rb', line 7

def tree_depth
  @tree_depth
end

Instance Method Details

#next_board(board) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/checkers/ai/engine/base.rb', line 13

def next_board(board)
  if board.jumped
    Board.generate_boards(board, :ai).first
  else
    decision_tree_root = Tree.build(board, tree_depth).root

    yield(decision_tree_root, tree_depth)

    decision_tree_root.children.max_by(&:score).board
  end
end