Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This code is designed to leave the reactor on all the times and maintain
- --power levels by adjusting the control rod insertion
- --return a integar ignoring any remainder
- function DIV(a,b)
- return (a - (a % b)) / b
- end
- --the total size of the buffer
- local TOTAL_MAX = 10000000
- --the amount of power we want to maintain in the buffer
- local TARGET_AMOUNT = 5000000
- --the default insertion of control rods
- local controlLevel = 50
- --Buffer zone size
- local BUFFER_SIZE = 1000000
- --connect to reactor
- local reactor = peripheral.wrap("back")
- --confirm connection
- if(not reactor.getConnected) then
- print("Not connected to Reactor")
- end
- --turn the reactor on
- if(not reactor.getActive()) then
- reactor.setActive(true)
- print("Starting Reactor")
- end
- --move control rod to defaul level
- reactor.setAllControlRodLevels(controlLevel)
- while(true) do
- --find the current amount of energy in the buffer
- local prevEnergy = reactor.getEnergyStored()
- sleep(3)
- local currentEnergy = reactor.getEnergyStored()
- if (currentEnergy > prevEnergy ) then
- local direction = 2
- local distance = (currentEnergy - prevEnergy)
- print("Greater than")
- elseif (currentEnergy < prevEnergy ) then
- local direction = 1
- local distance = (prevEnergy - currentEnergy)
- print("Less than")
- elseif (prevEnergy == currentEnergy ) then
- local direction = 0
- local distance = 0
- end
- print("prevEnergy: ", currentEnergy)
- print("currentEnergy: ", currentEnergy)
- print("Direction: ", direction)
- print("Distance: ", distance)
- --if above middle buffer
- if (currentEnergy > TARGET_AMOUNT + (BUFFER_SIZE / 2) ) then
- --if in top buffer
- if currentEnergy > (TOTAL_MAX - BUFFER_SIZE) then
- controlLevel = controlLevel + 50
- --if moving in wrong direction
- elseif direction == (2) then
- controlLevel = controlLevel + DIV(distance, 100000)
- end
- --if below middle buffer
- elseif (currentEnergy < TARGET_AMOUNT - (BUFFER_SIZE / 2) ) then
- --if in bottom buffer
- if currentEnergy < BUFFER_SIZE then
- controlLevel = controlLevel - 50
- --if moving in wrong direction
- elseif direction == (1) then
- controlLevel = controlLevel - DIV(distance, 100000)
- end
- end
- if (controlLevel < 0) then
- controlLevel = 0
- elseif (controlLevel > 100) then
- controlLevel = 100
- end
- reactor.setAllControlRodLevels(controlLevel)
- print("Control Level: %d", controlLevel)
- end
Add Comment
Please, Sign In to add comment