This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Connor_13_'s profile picture

Fuel Intake Max?

Started by Connor_13_, 08 February 2013 - 04:09 PM
Connor_13_ #1
Posted 08 February 2013 - 05:09 PM
I have a turtle program that calculates the amount of fuel needed for a specific amount of mining. I was testing it and to dig out a 20x20x20 cube it needed 102 coal to fuel it…. It said that this value was out of bounds? is there a way to allow the turtle to intake this much? or is it impossible?
theoriginalbit #2
Posted 08 February 2013 - 05:15 PM
Can we please see your code? Seems like it could be a problem somewhere else. What version of CC are you using?

If your using ComputerCraft 1.481 then
the maximum fuel level is 2^32 which is quite a lot of fuel… 4294967296, which is 53687091.2 pieces of coal…

Also 20*20*20 = 8000 meaning a maximum 100 pieces of coal, so your calculations are off… and to get 101 required to move back to original position..
Connor_13_ #3
Posted 08 February 2013 - 05:36 PM
The most current version with Tekkit Lite.

Ill give you my code. The different sections are labeled. Hopefully well enough.

An additional question i have is, when there is a pig/ entity in front of the turtle, the turtle.attack method does not seem to work… Idk Why.

Spoiler

function test2()
print("WARNING: Entitys and falling gravel and sand will change course of Turtle.")
print(" ")
print(" ")
--Length/Width
print("Lenth/ Width must be an even number.")
print("Lenth/ Width:")
x = tonumber(read())
print(" ")
--Height
print("Height can be any number.")
print("Height:")
y = tonumber(read())
print(" ")
i = 0
j = 0
k = 0
l = 0
m = 0
n = 0
o = 0
p = 0
q = 0
--fuels and values
sticks = { name = "Sticks", value = 5 }
woodenTools = { name = "Wooden Tools", value = 10 }
scrap = { name = "Scrap", value = 15 }
woodBlocks = { name = "Wood Blocks", value = 15 }
mushroomBlocks = { name = "Mushroom Blocks", value = 15 }
woodenScaffolding = { name = "Wooden Scaffolding", value = 15 }
coal = { name = "Coal", value = 80 }
charcoal = { name = "Charcoal", value = 80 }
peat = { name = "Peat", value = 80 }
blazeRod = { name = "Blaze Rod", value = 120 }
coalCoke = { name = "Coal Coke", value = 320 }
biofuelCan = { name = "Biofuel Can", value = 520 }
lava = { name = "Lava", value = 1000 }
coalfuelCan = { name = "Coalfuel Can", value = 1520 }
--if square root of lenth * width is less than or greater than something, give that as recommended fuel.
--fix error here
--maybe use x squared and compare to fuel instead x and square root of fuel.
if x^2 <= sticks.value then
  recomendedFuel = "Sticks"
  fuel = sticks.value
end
if (sticks.value <= x^2) and (x^2 <= woodenTools.value) then
  recomendedFuel = "Wooden Tools"
  fuel = woodenTools.value
end
if (woodenTools.value <= x^2) and (x^2 <= scrap.value) then
  recomendedFuel = "Scrap, Wood Blocks, Mushroom Blocks, Wooden Scaffolding"
  fuel = scrap.value
end
if (scrap.value <= x^2) and (x^2 <= coal.value) then
  recomendedFuel = "Coal/ Charcoal, Peat"
  fuel = coal.value
end
if (coal.value <= x^2) and (x^2 <= blazeRod.value) then
  recomendedFuel = "Blaze Rod"
  fuel = blazeRod.value
end
if (blazeRod.value <= x^2) and (x^2 <= coalCoke.value) then
  recomendedFuel = "Coal Coke"
  fuel = coalCoke.value
end
if (coalCoke.value <= x^2) and (x^2 <= biofuelCan.value) then
  recomendedFuel = "Biofuel Can"
  fuel = biofuelCan.value
end
if (biofuelCan.value <= x^2) and (x^2 <= lava.value) then
  recomendedFuel = "Lava"
  fuel = lava.value
end
if (lava.value <= x^2) and (x^2 <= coalfuelCan.value) then
  recomendedFuel = "Coalfuel Can"
  fuel = coalfuelCan.value
end
--Equations: for a 4x4x4 cube
--Top = x^2 + (x - 1)
--Normal Layer = (x^2 - x) + 1
--Bottom = x^2
--Finish/Return(even depth) = x + x
moves = (((x^2)+(x - 1))+((y - 1)*(((x^2) - x) + 1)) + (x^2) + (x + x))
print("Expected total number of moves:")
print(moves)
print(" ")
print("Recomended fuel:")
print(recomendedFuel)
print(" ")
print("Use this fuel? Type 'Yes'")
print("Use custom? Type 'Other'")
fuelSelection = read()
print(" ")
if fuelSelection == "Yes" then
  print("Estimated number of fuel needed:")
  --total number divided by the number fuel can move
  fuelNeeded = moves / fuel
  print(fuelNeeded)
  print("Make sure to add 1 to amount of fuel")
  print("This will ensure completion.")
  print(" ")
end
--finish this somehow
--convert input to number? assign fuels a number?
--convert fuel variables (coal = 80 etc)
--give each fuel variable an additional string value so that when string is inputed, fuel variable can be used
--give one variable a number and string value.
--check stack overflow
if fuelSelection == "Other" then
  --Fuels.  does not show all of them
  print("Fuels and movement allowed low to high")
  print(" ")
  print("-Sticks: 5")
  print("-Wooden Tools: 10")
  print("-Scrap, Wood Blocks, Mushroom Blocks, Wooden Scaffolding: 15")
  print("-Coal/Charcoal, Peat: 80")
  print("-Blaze Rod: 120")
  print("-Coal Coke: 320")
  print("-Biofuel Can: 520")
  print("-Lava: 1000")
  print("-Coalfuel Can: 1520")
  print(" ")
  print("Estimated number of moves:")
  print(moves)
  print("Enter fuel type:")
  fuelType = read()
  if fuelType == sticks.name then
   fuel = sticks.value
  end
  if fuelType == woodenTools.name then
   fuel = woodenTools.value
  end
  if fuelType == scrap.name then
   fuel = scrap.value
  end
  if fuelType == woodBlocks.name then
   fuel = woodBlocks.value
  end
  if fuelType == mushroomBlocks.name then
   fuel = mushroomBlocks.value
  end
  if fuelType == woodenScaffolding.name then
   fuel = woodenScaffolding.value
  end
  if fuelType == coal.name then
   fuel = coal.value
  end
  if fuelType == charcoal.name then
   fuel = charcoal.value
  end
  if fuelType == peat.name then
   fuel = peat.value
  end
  if fuelType == blazeRod.name then
   fuel = blazeRod.value
  end
  if fuelType == coalCoke.name then
   fuel = coalCoke.value
  end
  if fuelType == biofuelCan.name then
   fuel = biofuelCan.value
  end
  if fuelType == lava.name then
   fuel = lava.value
  end
  if fuelType == coalfuelCan.name then
   fuel = coalfuelCan.value
  end
  print("Estimated number of fuel needed:")
  --total number divided by the number fuel can move
  fuelNeeded = moves / fuel
  print(fuelNeeded)
  print("Make sure to add 1 to amount of fuel.")
  print("This will ensure completion.")
  print(" ")
end
--Pause program
--Resume program when 'yes' is typed
print("Type 'Yes' to continue")
continue = read()
if continue == "Yes" then
--START MINING--
--START MINING--
--First Horizontal row
turtle.refuel(fuelNeeded + 1)
while i < x do
  turtle.digUp()
  while turtle.detectUp() do
   turtle.digUp()
   turtle.attackUp()
  end
  turtle.dig()
  while turtle.detect() do
   turtle.dig()
   turtle.attack()
  end
  turtle.forward()
  i = i + 1
end
i = 0
turtle.turnRight()
turtle.digUp()
while turtle.detectUp() do
  turtle.digUp()  
  turtle.attackUp()
end
turtle.dig()
while turtle.detect() do
  turtle.dig()
  turtle.attack()
end
turtle.forward()
turtle.turnRight()
--Vertical w/ horizondal 
while m < y + 1 do
  --Horizontal remainder
  while j < (x / 2) - 1 do
   while k < x - 1 do
    turtle.digUp()
    while turtle.detectUp() do
	 turtle.digUp()
	 turtle.attackUp()
    end
    turtle.dig()
    while turtle.detect() do
	 turtle.dig()
	 turtle.attack()
    end
    turtle.forward()
    k = k + 1
   end
   turtle.turnLeft()
   turtle.digUp()
   while turtle.detectUp() do
    turtle.digUp()
    turtle.attackUp()
   end
   turtle.dig()
   while turtle.detect() do
    turtle.dig()
    turtle.attack()
   end
   turtle.forward()
   turtle.turnLeft()
   while l < x - 1 do
    turtle.digUp()
    while turtle.detectUp() do
	 turtle.digUp()
	 turtle.attackUp()
    end
    turtle.dig()
    while turtle.detect() do
	 turtle.dig()
	 turtle.attack()
    end
    turtle.forward()
    l = l + 1
   end
   turtle.turnRight()
   turtle.digUp()
   while turtle.detectUp() do
    turtle.digUp()
    turtle.attackUp()
   end
   turtle.dig()
   while turtle.detect() do
    turtle.dig()
    turtle.attack()
   end
   turtle.forward()
   turtle.turnRight()
   j = j + 1
   k = 0
   l = 0
  end 
  j = 0
  --finishes the last row above the first layer then restarts the process.
  if m == 0 then
   while q < x - 1 do
    turtle.digUp()
    while turtle.detectUp() do
	 turtle.digUp()
	 turtle.attackUp()
    end
    turtle.dig()
    while turtle.detect() do
	 turtle.dig()
	 turtle.attack()
    end
    turtle.forward()
    turtle.digUp()
    q = q + 1
   end
   q = 0
   while q < x - 1 do
    turtle.turnRight()
    turtle.turnRight()
    while turtle.detect() do
	 turtle.dig()
	 turtle.attack()
    end
    turtle.forward()
    q = q + 1
   end
   turtle.turnRight()
   turtle.turnRight()
   q = 0
  end
  --Vertical.  moves turtle down and starts the first row.
  if m < y then
   turtle.digDown()
   while turtle.detectDown() do
    turtle.attackDown()
   end
   turtle.down()
   while n < x - 1 do
    turtle.digUp()
    while turtle.detectUp() do
	 turtle.digUp()
	 turtle.attackUp()
    end
    turtle.dig()
    while turtle.detect() do
	 turtle.dig()
	 turtle.attack()
    end
    turtle.forward()
    n = n + 1
   end
   n = 0
   turtle.turnRight()
   turtle.digUp()
   while turtle.detectUp() do
    turtle.digUp()
    turtle.attackUp()
   end
   turtle.dig()
   while turtle.detect() do
    turtle.dig()
    turtle.attack()
   end
   turtle.forward()
   turtle.turnRight()
  end
  --finishs last row on bottom
  if m == y then
   if y % 2 == 0 then
    while p < x - 1 do
	 turtle.dig()
	 while turtle.detect() do
	  turtle.dig()
	  turtle.attack()
	 end
	 turtle.forward()
	 p = p + 1
    end
   else
    while p < x - 1 do
	 turtle.dig()
	 while turtle.detectUp() do
	  turtle.digUp()
	  turtle.attackUp()
	 end
	 turtle.forward()
	 p = p + 1
    end
   end
  end
  m = m + 1
end
--tests for even / odd numbered depths
--then makes turtle return to starting position
if y % 2 == 0 then
  --odd?
  while o < y do
   turtle.up()
   o = o + 1
  end
  o = 0
  turtle.turnRight()
  while o < x - 1 do
   while turtle.detect() do
    turtle.dig()
    turtle.attack()
   end
   turtle.forward()
   o = o + 1
  end
  turtle.turnLeft()
  turtle.forward()
else
  --odd
  while o < y do
   turtle.up()
   o = o + 1
  end
  o = 0
  turtle.turnRight()
  turtle.turnRight()
  while o < x do
   while turtle.detect() do
    turtle.dig()
    turtle.attack()
   end
   turtle.forward()
   o = o + 1
  end
end
end
print(" ")
print("Done")
end

Sorry if it is WAY too long
Orwell #4
Posted 08 February 2013 - 05:44 PM
Well, it can't pull more items from an item stack than 64… So even if 'fuelNeeded' is greater than 64, you'll need to divide that number over the stacks that contain fuel. A basic way of doing this:

local fuelNeeded = 101 -- or as calculated in your code

for i=1,16 do
  if fuelNeeded <= 0 then break end
  turtle.select(i)
  if turtle.refuel( math.min(fuelNeeded, 64) ) then
	fuelNeeded = fuelNeeded - math.min(fuelNeeded, 64)
  end
end

if fuelNeeded > 0 then
  -- needs more fuel!
end

You can adapt this to your more sophisticated way of choosing items to refuel with. :)/>
Connor_13_ #5
Posted 08 February 2013 - 06:29 PM
Ok thanks for the code! But could you explain what it does? What each part does i mean. I'm pretty new to Lua and im still learning.

Edit: just now looking at it now I understand it a little better and I think I know what it is doing. But a little explanation will confirm what I think.
ChunLing #6
Posted 08 February 2013 - 07:32 PM
It goes through all your slots, trying to use them as fuel, and assumes that they are full stacks of coal if they are usable as fuel…which isn't the most reliable way to do this. I mean, it counts a log or a sapling as if it was a full stack of coal, which it isn't (even a bucket of lava isn't a full stack of coal).

I think that you should use the calculated move value and getFuelLevel() in a simpler loop that only checked slots you're willing to use as fuel (Like, for large excavations some people use chests to dump extra material for later collection…the above code would burn the chests as fuel and assume that they were coal, so you'd have lost all your chests and you wouldn't have enough fuel).