|
|
@ -32,13 +32,17 @@ loop do
|
|
|
|
frontier.sort_by! { visited.fetch(_1) }
|
|
|
|
frontier.sort_by! { visited.fetch(_1) }
|
|
|
|
current = frontier.shift
|
|
|
|
current = frontier.shift
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nexts = []
|
|
|
|
|
|
|
|
|
|
|
|
# turn left and right
|
|
|
|
# turn left and right
|
|
|
|
nexts = [current.dir.reverse, current.dir.reverse.map { -_1 }].map {|turn|
|
|
|
|
if current.continued > 3
|
|
|
|
|
|
|
|
nexts.concat([current.dir.reverse, current.dir.reverse.map { -_1 }].map {|turn|
|
|
|
|
Node.new(current.pos.zip(turn).map { _1 + _2 }, turn, 1)
|
|
|
|
Node.new(current.pos.zip(turn).map { _1 + _2 }, turn, 1)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# keep going?
|
|
|
|
# keep going?
|
|
|
|
if current.continued < 3
|
|
|
|
if current.continued < 10
|
|
|
|
nexts << Node.new(
|
|
|
|
nexts << Node.new(
|
|
|
|
current.pos.zip(current.dir).map { _1 + _2 },
|
|
|
|
current.pos.zip(current.dir).map { _1 + _2 },
|
|
|
|
current.dir,
|
|
|
|
current.dir,
|
|
|
@ -46,7 +50,7 @@ loop do
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if found = nexts.find { _1.pos == dest }
|
|
|
|
if found = nexts.find { _1.pos == dest && (4..10).cover?(_1.continued) }
|
|
|
|
p visited.fetch(current) + map.fetch(dest)
|
|
|
|
p visited.fetch(current) + map.fetch(dest)
|
|
|
|
exit
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|