Class: Checkers::AI::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(board, player, depth = 0) ⇒ Node

Returns a new instance of Node.



9
10
11
12
13
14
# File 'lib/checkers/ai/node.rb', line 9

def initialize(board, player, depth = 0)
  @board = board
  @player = player
  @score = board.calculate_score(player: player)
  @children = generate_children(depth)
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



6
7
8
# File 'lib/checkers/ai/node.rb', line 6

def board
  @board
end

#childrenObject (readonly)

Returns the value of attribute children.



6
7
8
# File 'lib/checkers/ai/node.rb', line 6

def children
  @children
end

#playerObject (readonly)

Returns the value of attribute player.



6
7
8
# File 'lib/checkers/ai/node.rb', line 6

def player
  @player
end

#scoreObject

Returns the value of attribute score.



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

def score
  @score
end

Instance Method Details

#children_sizeObject



16
17
18
# File 'lib/checkers/ai/node.rb', line 16

def children_size
  @children.size
end