Class: Tictactoe::Ai::ABNegamax

Inherits:
Object
  • Object
show all
Defined in:
lib/tictactoe/ai/ab_negamax.rb

Constant Summary collapse

COLOR_SELF =
1
COLOR_OPPONENT =
-1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(depth_limit, depth_reached_score) ⇒ ABNegamax



7
8
9
10
# File 'lib/tictactoe/ai/ab_negamax.rb', line 7

def initialize(depth_limit, depth_reached_score)
  @depth_limit = depth_limit
  @depth_reached_score = depth_reached_score
end

Instance Attribute Details

#depth_limitObject (readonly)

Returns the value of attribute depth_limit.



12
13
14
# File 'lib/tictactoe/ai/ab_negamax.rb', line 12

def depth_limit
  @depth_limit
end

#depth_reached_scoreObject (readonly)

Returns the value of attribute depth_reached_score.



12
13
14
# File 'lib/tictactoe/ai/ab_negamax.rb', line 12

def depth_reached_score
  @depth_reached_score
end

Instance Method Details

#best_nodes(tree) ⇒ Object



18
19
20
# File 'lib/tictactoe/ai/ab_negamax.rb', line 18

def best_nodes(tree)
  negamax(tree)[:nodes]
end

#score(tree) ⇒ Object



14
15
16
# File 'lib/tictactoe/ai/ab_negamax.rb', line 14

def score(tree)
  negamax(tree)[:score]
end