I'm trying to make a flood-fill that asks for user input starting from the top right corner of a randomly generated array filled with numbers 1-6 that are represented by 'colours'. I added the oldColor/newColor feature just now and I get error message and I'm not exactly sure why. Other then that, the algorithm keeps going on asking for input without printing what the new flood-fill looks like in each step.
def floodfill(array_1, row, column, colours, oldColor, newColor)
#colours is an array of the 6 colours i'm going to be using
boxHeight = array_1.length
boxWeight = array_1[0].length
oldColor = array_1
#puts oldColor
print "> "
newColor = gets.chomp.downcase
if array_1[row][column] != oldColor
return
if newColor == "r"
newColor = colours[:red]
array_1[row][column] = newColor
floodfill(array_1, row + 1, column, colours, newColor) # right
floodfill(array_1, row - 1, column, colours, newColor) # left
floodfill(array_1, row, column + 1, colours, newColor) # down
floodfill(array_1, row, column - 1, colours, newColor)# up
print_it
else
puts "didnt get that"
array_1.each do |row|
row.each do |c|
print c
end
puts
end
end
end
end
floodfill(array_1,14,9,colours,0,0)
I cant directly post images, but here is what my output currently looks like and then the failure message https://i.stack.imgur.com/BzdVB.jpg