M
Michael Lesniak
Hello,
I'm playing a bit with informed search algorithm, esp. A* and sliding
puzzles. For the heuristic I chose the manhattan distance, at the
moment implemented like
def manhattan
sum = 0
size = @puzzle.size
size.times do |y|
size.times do |x|
num = @puzzle.get x, y
l, m = @goal.number num
sum += (x - l).abs + (y - m).abs
end
end
sum
end
@puzzle simulates a Sliding puzzle, e.g. shuffling, generating possible
children, etc...
@puzzle.get x, y
returns the tile at position x, y
@goal.number num
returns the position of the tile in the desired state
Is there any better -- "faster" -- way of doing this?
Thanks for the help
Michael
I'm playing a bit with informed search algorithm, esp. A* and sliding
puzzles. For the heuristic I chose the manhattan distance, at the
moment implemented like
def manhattan
sum = 0
size = @puzzle.size
size.times do |y|
size.times do |x|
num = @puzzle.get x, y
l, m = @goal.number num
sum += (x - l).abs + (y - m).abs
end
end
sum
end
@puzzle simulates a Sliding puzzle, e.g. shuffling, generating possible
children, etc...
@puzzle.get x, y
returns the tile at position x, y
@goal.number num
returns the position of the tile in the desired state
Is there any better -- "faster" -- way of doing this?
Thanks for the help
Michael