class FifteenPuzzleSolver::Node
Attributes
board[R]
depth[R]
Public Class Methods
new(parent, board, direction)
click to toggle source
# File lib/fifteen_puzzle_solver/node.rb, line 4 def initialize(parent, board, direction) @parent = parent @board = board @direction = direction @depth = (parent ? parent.depth + 1 : 0) end
Public Instance Methods
astar_function(heuristic)
click to toggle source
# File lib/fifteen_puzzle_solver/node.rb, line 21 def astar_function(heuristic) case heuristic when "manh" weight + @board.invalid_blocks_distance when "hamm" weight + @board.difference else 1 end end
path()
click to toggle source
# File lib/fifteen_puzzle_solver/node.rb, line 15 def path return "" unless @parent @parent.path + @direction end
state()
click to toggle source
# File lib/fifteen_puzzle_solver/node.rb, line 11 def state @board.state end
Private Instance Methods
weight()
click to toggle source
# File lib/fifteen_puzzle_solver/node.rb, line 34 def weight path.length end