0
루비에서 반복에 대해 혼란스러워했습니다. 다음 코드에서 필자는 두 경로가 동일해야한다고 예상했습니다. 그러나 실제로 그들은 그렇지 않습니다. for 루프에서 경로가 변경된 것 같습니다.루비 블록 반복
내 코드에 문제가 있습니까? 덕분에
def one_step_search(dest,paths)
direction = %w(north east south west)
new_paths = []
paths.map do |path|
print "original path is: "
print_path path
curr_room = path.last
for i in 0..3
new_path = path
if !curr_room.send("exit_#{direction[i]}").nil?
next_room_tag = curr_room.send("exit_#{direction[i]}")[0]
next_room = find_room_by_tag(next_room_tag)
if !new_path.include?(next_room) # don't go back to the room visited before
new_path << next_room
new_paths << new_path
print "new path is: "
print_path path
return new_paths if dest.tag == next_room_tag
end
end
end
end
return new_paths
end