Class: Checkers::AI::Engine::Base
- Inherits:
-
Object
- Object
- Checkers::AI::Engine::Base
- Defined in:
- lib/checkers/ai/engine/base.rb
Instance Attribute Summary collapse
-
#tree_depth ⇒ Object
readonly
Returns the value of attribute tree_depth.
Instance Method Summary collapse
-
#initialize(tree_depth = 3) ⇒ Base
constructor
A new instance of Base.
- #next_board(board) ⇒ Object
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_depth ⇒ Object (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 |