class Tictactoe::Ai::Tree
Constants
- MAXIMUM_SCORE
- MINIMUM_SCORE
- NEUTRAL_SCORE
Attributes
current_mark[R]
mark[R]
move[R]
state[R]
Public Class Methods
new(state, mark, current_mark = mark, move_to_arrive_here=nil)
click to toggle source
# File lib/tictactoe/ai/tree.rb, line 8 def initialize(state, mark, current_mark = mark, move_to_arrive_here=nil) @state = state @mark = mark @current_mark = current_mark @move = move_to_arrive_here end
Public Instance Methods
base_score()
click to toggle source
# File lib/tictactoe/ai/tree.rb, line 32 def base_score case state.winner when mark.value MAXIMUM_SCORE when nil NEUTRAL_SCORE else MINIMUM_SCORE end end
children()
click to toggle source
# File lib/tictactoe/ai/tree.rb, line 20 def children state.available_moves.map do |move| next_state = state.make_move(move, current_mark.value) Tree.new(next_state, mark, current_mark.next, move) end end
is_final?()
click to toggle source
# File lib/tictactoe/ai/tree.rb, line 16 def is_final? state.is_finished? end
score()
click to toggle source
# File lib/tictactoe/ai/tree.rb, line 27 def score height = state.available_moves.length + 1 base_score * height end