class Checkers::AI::Engine::Minmax
Public Instance Methods
next_board(board)
click to toggle source
Calls superclass method
Checkers::AI::Engine::Base#next_board
# File lib/checkers/ai/engine/minmax.rb, line 7 def next_board(board) super(board) { |root, tree_depth| minmax(root, tree_depth, true) } end
Private Instance Methods
minmax(node, tree_depth, maxplayer)
click to toggle source
# File lib/checkers/ai/engine/minmax.rb, line 13 def minmax(node, tree_depth, maxplayer) return node.score if tree_depth.zero? || node.children_size.zero? value = nil if maxplayer value = Float::MIN node.children.each do |child| value = max(value, minmax(child, tree_depth - 1, !maxplayer)) end else value = Float::MAX node.children.each do |child| value = min(value, minmax(child, tree_depth - 1, !maxplayer)) end end node.score = value end