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

Big Reactors Material Calculator

Started by Hydrotronics, 22 December 2015 - 09:20 PM
Hydrotronics #1
Posted 22 December 2015 - 10:20 PM
I have been working on a program for calculating the materials you require for a big reactors reactor. the code is here.

the problem is, it gives off crazy numbers, many times more than you actually need. for an example, it thinks you need 61 or something yellorium when only you need 16. Could you explain why this occours?
Bomb Bloke #2
Posted 22 December 2015 - 11:31 PM
Beats me as to whether this is your only problem, but looking up casings, one craft makes four. You should hence reduce your casing count before calculating their total cost:

case = math.ceil(case / 4)
Hydrotronics #3
Posted 23 December 2015 - 10:23 AM
Ok, I shall try that when I'm on the computer!
Hydrotronics #4
Posted 23 December 2015 - 01:13 PM
ok, that managed to make it slightly closer to what it is meant to do. I only need 18 yellorium for a 3x3x3 and it gives 20. so it is much closer than 61 :P/>
Dragon53535 #5
Posted 23 December 2015 - 01:46 PM
I'll just ask this question. Can you give me an example usage: filename arg1 arg2 arg3 etc. and an example output as well as the calculations per item? It helps to know exactly what you want, need, and don't have.
Edited on 23 December 2015 - 12:48 PM
Hydrotronics #6
Posted 23 December 2015 - 01:49 PM
well, you can look at the code, which i put in the main question

and the format is: reactor X Y Z Turbine? Computer? Redstone?
example input:
reactor 3 3 3 false false false

Output:

Yellorium: 20
Iron: 73
Graphite: 72
Redstone: 6
Gold: 0
Planks: 11
Cobble: 4

Should Be:
Yellorium: 18
Iron: 47
Graphite: 45
Redstone: 7
Gold: 0
Planks: 11
Cobble: 4
Edited on 23 December 2015 - 12:54 PM
Dragon53535 #7
Posted 23 December 2015 - 01:50 PM
xyz as in scale? Size in blocks of it from a corner basically?

Also, the calculations aren't easy to understand exactly from it is in.

Nevermind, I wasn't looking far enough, I think I got it, although the case parts, i'm a bit confused about.


Got your error, although I don't know the fix, but from what I can see, the parts of the walls where intersections occur such as the wall corner of xy and zy, aren't being properly added together. They're duplicating that one small bit.
Edited on 23 December 2015 - 12:54 PM
Hydrotronics #8
Posted 23 December 2015 - 01:54 PM
what bit of the case parts are you confused about?
Dragon53535 #9
Posted 23 December 2015 - 01:57 PM
I'll just make a new post about this since you replied.

Let's say I have two walls, 10 high, and 5 wide.

Now these walls are perpendicular to each other, and share a corner. So we have a total of 90 blocks.

The problem is, that I KNOW we have 90 blocks, and the calculations you would do would total 100 blocks. (10 * 5 + 10 *5)
Problem is that corner we share, it's 10 blocks, that BOTH WALLS have.


XZ = X * Z
XY = (X - 2) * Y --# Since X will lose a part when connected to the XZ on either side
YZ = (Z - 2 ) * (Y - 2)
I believe this SHOULD fix it. It's an annoying thing when you think about it, but I'm pretty sure it's your problem.
Edited on 23 December 2015 - 01:02 PM
Hydrotronics #10
Posted 23 December 2015 - 02:05 PM
ok… and then we refer to the vertical edges as (Y - 2) * 4?

so it'd look like this:

XZ = X * Z
XY = (X - 2) * Y
ZY = (Z - 2) * Y
Yedge = (Y - 2) * 4
Edited on 23 December 2015 - 01:09 PM
Dragon53535 #11
Posted 23 December 2015 - 02:07 PM
I'm not sure why you would want to refer to the edges at all? The calculations keep them in for casings. You just have to math.ceil( case / 4) for the casings calculations still.
Hydrotronics #12
Posted 23 December 2015 - 02:11 PM
well, i did it anyway and it came out with the correct yellorium count

but the Iron and Graphite count is still too high
Dragon53535 #13
Posted 23 December 2015 - 02:13 PM
Add some extra print statements after each of the calculation loops, conrods, fuelrods, case, etc. and find out which one makes the count incorrect.
Hydrotronics #14
Posted 23 December 2015 - 02:16 PM
i shall
Hydrotronics #15
Posted 23 December 2015 - 02:24 PM
ok, i did that and there is a strange thing happening…
when i read the case's output, it was completely fine! then when i read the output of the program, it had added on another 20! the other calculations for the accesory ports didn't start as expected, so idk what is going on…

I think i found the issue, when it calculates the access ports and the controller and the power tap, it adds another 17 iron and 16 graphite. Yet i believe that is the amount required…
I have a series of structures showing me the crafting recipies of the componants required, the picture is admitidly upside down, but that shouldn't affect the count
Edited on 23 December 2015 - 01:32 PM
Dragon53535 #16
Posted 23 December 2015 - 02:35 PM
Can you order those for us? Or at least say which ones are for what item that is needed?

Besides the chest and piston (2nd, 3rd) ones
Edited on 23 December 2015 - 01:36 PM
Hydrotronics #17
Posted 23 December 2015 - 02:41 PM
ok, from left to right.

reactor access port (need two of those)
chest,
piston
control rod
power tap
controller
casing (10 crafts for 3x3x3)
fuel rod
Edited on 23 December 2015 - 01:41 PM
Dragon53535 #18
Posted 23 December 2015 - 02:46 PM
Okay, so let's work backwards, rather than forwards on this. I'm assuming that the casing is a base part of just about everything else, blocks are used in space of dust/ingots/diamond/coal. and ofc normal blocks are as they should be. Out of all of these, except the casing, chest, and piston, is there any other items that are part of another's crafting recipe?
Hydrotronics #19
Posted 23 December 2015 - 03:07 PM
nope, there is no other item which is in another crafting recipie
Edited on 23 December 2015 - 02:21 PM
Dragon53535 #20
Posted 23 December 2015 - 03:31 PM
Okay, this is gonna be a long post-ish full of calculations for each thing in order of full items down to the casings and others.


--#Variable declarations
local wood,coal,yellorium,iron,diamond,gold,cobble,redstone = 0,0,0,0,0,0,0,0
--#This is just setting all the items values to 0 on one line (slightly more efficient)
local args = {...}

local casings,fuelRods,chests,pistons,ports,controllers,controlRods,taps,turbines = 0,0,0,0,0,0,0,0,0

--#Setting up the amounts for our final products.
Okay, we've set our default amounts. Now let's calculate.


local x,y,z = args[1],args[2],args[3]
--#xyz are set


--#Time for the walls
local floorRoof = x * y
--#The dimensions of our roof and floor.
local leftRight = (y-2) * z
--#Looking from the front, the dimensions of the walls on the left and right
local frontBack = (x-2) * (z-2)
--#Front wall, and back wall.

casings = casings + (2 * leftRight) + (2 * frontBack) + (2 * floorRoof)
In mathematics, x and y are usually used for the base dimensions of a 2d object (roof and floor) and the height in a 3d object is z.

I'm gonna keep writing the rest, but I'll just submit this here for now.
Hydrotronics #21
Posted 23 December 2015 - 03:36 PM
ok
Dragon53535 #22
Posted 23 December 2015 - 03:41 PM
I'm gonna ask another couple questions while I type up the rest.

The fuel rods and control rods, they're gonna be a cross in the center of the top correct? Middle one is control, and the 4 around it are fuel right?

Which blocks are being made for the different arguments? turbine computer and redstone.
Hydrotronics #23
Posted 23 December 2015 - 03:58 PM
i dont know what you mean by cross in the center of the top?
Dragon53535 #24
Posted 23 December 2015 - 04:15 PM
I'll just ask for you to explain how the rods need to be put in, and the rest of the earlier question.
Edited on 23 December 2015 - 03:15 PM
Hydrotronics #25
Posted 23 December 2015 - 04:19 PM
lol ok. so the control rods must be ontop of every pillar of fuel rods. the best pattern i found was a checkerboard pattern, with coolant in between. in a 3x3x3 reactor, there is no space for coolant, and doesn't require it anyway. you need two access ports, one for input and one for output. you need a controller and a power tap. 21 cases to make the frame for the reactor (3x3x3)
Dragon53535 #26
Posted 23 December 2015 - 04:37 PM
Got it, so the fuel rods are just internal pillars of size 1x1x(z-2), with multitude of

for i = 1,x-2 do
  for j = 1, y-2 do
	if ( i % 2 == 1 and j % 2 == 1) or (i % 2 == 0 and j % 2 == 0) then
	  rods = rods + 1
	end
  end
end

This loop will calculate the checkerboard pattern, and add one for each spot. Starting in the corner, and for when we're at an even row, and even column, then we want a rod there ([2,2],[2,4]) and when we're at an odd row and odd column ([1,1],[1,3]) we also want a rod there. This should setup the amount of rods we want and need.


--#Our arguments
if args[4] == "true" then
  turbines = turbines + 1
end
if args[5] == "true" then
  controllers = controllers + 1
end
if args[6] == "true" then
  taps = taps + 1
end

ports = 2 --#Since you need 2 ports, i'm assuming this is constant.
casings = casings + (4 * ports)
chests = chests + (1 * ports)
pistons = pistons + (1 * ports)
--#This is the port crafting recipe.


--#Chest crafting
wood = wood + (8 * chests)

--#Piston Crafting
wood = wood + (3 * pistons)
iron = iron + (1 * pistons)
cobble = cobble + (4 * pistons)
redstone = redstone + (1 * pistons)


--#Controller crafting
casings = casings + (4 * controllers)
yellorium = yellorium + (2 * controllers)
diamonds = diamond + (1 * controllers)
redstone = redstone + (1 * controllers)

--#Casing crafting
casings = math.ceil(casings / 4) --#Since yield is 4 per craft
iron = iron + (4 * casings)
yellorium = yellorium + (1 * casings)
coal = coal + (4 * casings)


This is what I've pretty much got right now, and it's some of the calculations, I will tell you, the args part, is probably wrong.
The rest of the calculations, I'll leave up to you, but leave everything above what it's requirements are. (In other words, if it uses casings, put it above the casings calculation)


I actually could probably setup a function to auto calculates the costs based on the item. but it would be decently difficult.
Edited on 23 December 2015 - 03:38 PM