[2023][ruby][17.2]

main
Alpha Chen 11 months ago
parent 51c91ab2f2
commit 6f332e48d1
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -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

Loading…
Cancel
Save