Posted 29 April 2014 - 05:11 AM
Hi all, I'm working on a pretty handy turtle program that I hope will be useful to people, but I'm having a hard time figuring out the most efficient way to go about something.
Basically, I want the turtles inventory to evenly distribute items between slots. Say if you have an iron ingot in slots 2, 3 and 5, and any number of ingots in any of those slots, I'd like to be able to distribute them evenly between all the slots already containing iron ingots. Round robin fashion, basically how the Auto crafting tables would do it.
I have some code already that creates a 2D array of which slots contain items the same as other slots, here:
So in my example with the iron ingots above, the array would contain:
[2][3], [2][5], [3][2], [3][5], [5][2], [5][3] would all be 1, everything else = 0.
Can anyone think of an efficient way of doing this? :)/>
Basically, I want the turtles inventory to evenly distribute items between slots. Say if you have an iron ingot in slots 2, 3 and 5, and any number of ingots in any of those slots, I'd like to be able to distribute them evenly between all the slots already containing iron ingots. Round robin fashion, basically how the Auto crafting tables would do it.
I have some code already that creates a 2D array of which slots contain items the same as other slots, here:
for i=1,3 do
if turtle.getItemCount(i) > 0 then
numItems[i] = turtle.getItemCount(i)
for k=1,3 do
turtle.select(i)
if turtle.compareTo(k) == true and i ~= k then
sameItems[i][k] = 1
else
sameItems[i][k] = 0
end
end
for k=5,7 do
turtle.select(i)
if turtle.compareTo(k) == true and i ~= k then
sameItems[i][k] = 1
else
sameItems[i][k] = 0
end
end
for k=9,11 do
turtle.select(i)
if turtle.compareTo(k) == true and i ~= k then
sameItems[i][k] = 1
else
sameItems[i][k] = 0
end
end
end
end
for i=5,6 do
if turtle.getItemCount(i) > 0 then
numItems[i] = turtle.getItemCount(i)
for k=1,3 do
turtle.select(i)
if turtle.compareTo(k) == true and i ~= k then
sameItems[i][k] = 1
else
sameItems[i][k] = 0
end
end
for k=5,7 do
turtle.select(i)
if turtle.compareTo(k) == true and i ~= k then
sameItems[i][k] = 1
else
sameItems[i][k] = 0
end
end
for k=9,11 do
turtle.select(i)
if turtle.compareTo(k) == true and i ~= k then
sameItems[i][k] = 1
else
sameItems[i][k] = 0
end
end
end
end
for i=9,11 do
if turtle.getItemCount(i) > 0 then
numItems[i] = turtle.getItemCount(i)
for k=1,3 do
turtle.select(i)
if turtle.compareTo(k) == true and i ~= k then
sameItems[i][k] = 1
else
sameItems[i][k] = 0
end
end
for k=5,7 do
turtle.select(i)
if turtle.compareTo(k) == true and i ~= k then
sameItems[i][k] = 1
else
sameItems[i][k] = 0
end
end
for k=9,11 do
turtle.select(i)
if turtle.compareTo(k) == true and i ~= k then
sameItems[i][k] = 1
else
sameItems[i][k] = 0
end
end
end
end
So in my example with the iron ingots above, the array would contain:
[2][3], [2][5], [3][2], [3][5], [5][2], [5][3] would all be 1, everything else = 0.
Can anyone think of an efficient way of doing this? :)/>