Class: Astrid::Heuristics::Manhattan

Inherits:
Object
  • Object
show all
Defined in:
lib/astrid/heuristics/manhattan.rb

Instance Method Summary collapse

Constructor Details

#initialize(end_node, weight = 1) ⇒ Manhattan

Returns a new instance of Manhattan.



5
6
7
8
9
# File 'lib/astrid/heuristics/manhattan.rb', line 5

def initialize(end_node, weight=1)
  @end_x = end_node[:x]
  @end_y = end_node[:y]
  @weight = weight
end

Instance Method Details

#h(node, weight = @weight) ⇒ Object



11
12
13
# File 'lib/astrid/heuristics/manhattan.rb', line 11

def h(node, weight=@weight)
  weight * ((node[:x] - @end_x).abs + (node[:y] - @end_y).abs)
end