Skip to content

Instantly share code, notes, and snippets.

@Larkenx
Last active June 4, 2021 21:25
Show Gist options
  • Save Larkenx/a83d9120815bdce3cea50ea846c8d1d4 to your computer and use it in GitHub Desktop.
Save Larkenx/a83d9120815bdce3cea50ea846c8d1d4 to your computer and use it in GitHub Desktop.
a balancer for arcospheres (factorio, space exploration)
-- Signals to indiciate whether an operation should happen
-- Inversion Signals
BLUE_SIGNAL = "signal-blue" -- invert lambda, xi, epilson, pi
PINK_SIGNAL = "signal-pink" -- invert zeta, theta, gamma, omega
-- Folding Symbols
YELLOW_SIGNAL = "signal-yellow" -- fold omega, lambda
MAROON_SIGNAL = "signal-maroon" -- fold gamma, xi
ORANGE_SIGNAL = "signal-orange" -- fold xi, zeta
TEAL_SIGNAL = "signal-teal" -- -- foold lambda, theta
AQUA_SIGNAL = "signal-aqua" -- fold theta, epilson
PURPLE_SIGNAL = "signal-purple" -- fold zeta, phi
BROWN_SIGNAL = "signal-brown" -- fold phi, gamma
GREY_SIGNAL = "signal-grey" -- fold epilson, omega
ARCOSPHERE = "se-arcosphere-"
LAMBDA = ARCOSPHERE .. "a"
XI = ARCOSPHERE .. "b"
ZETA = ARCOSPHERE .. "c"
THETA = ARCOSPHERE .. "d"
EPILSON = ARCOSPHERE .. "e"
PHI = ARCOSPHERE .. "f"
GAMMA = ARCOSPHERE .. "g"
OMEGA = ARCOSPHERE .. "h"
lambdaSpheres = red[LAMBDA] == nil and 0 or red[LAMBDA]
xiSpheres = red[XI] == nil and 0 or red[XI]
zetaSpheres = red[ZETA] == nil and 0 or red[ZETA]
thetaSpheres = red[THETA] == nil and 0 or red[THETA]
epilsonSpheres = red[EPILSON] == nil and 0 or red[EPILSON]
phiSpheres = red[PHI] == nil and 0 or red[PHI]
gammaSpheres = red[GAMMA] == nil and 0 or red[GAMMA]
omegaSpheres = red[OMEGA] == nil and 0 or red[OMEGA]
foldingConstant = 5
inversionConstant = 10
function geometricMean(values)
local prod = 1
for _, v in ipairs(values) do prod = prod * v end
return (prod ^ (1 / #values))
end
function shouldFold(inputA, inputB, outputA, outputB)
return (inputA + inputB) > (outputA + outputB + foldingConstant)
end
function shouldInvertA_B_E_F()
local inputs = lambdaSpheres + xiSpheres + epilsonSpheres + phiSpheres
local outputs = zetaSpheres + thetaSpheres + gammaSpheres + omegaSpheres
return inputs > (outputs + inversionConstant)
end
function shouldInvertC_D_G_H()
local inputs = zetaSpheres + thetaSpheres + gammaSpheres + omegaSpheres
local outputs = lambdaSpheres + xiSpheres + epilsonSpheres + phiSpheres
return inputs > (outputs + inversionConstant)
end
-- Reset
out = {}
if shouldInvertA_B_E_F() then out[BLUE_SIGNAL] = 1 end
if shouldInvertC_D_G_H() then out[PINK_SIGNAL] = 1 end
if shouldFold(omegaSpheres, lambdaSpheres, xiSpheres, thetaSpheres) then
out[YELLOW_SIGNAL] = 1
end
if shouldFold(gammaSpheres, xiSpheres, zetaSpheres, lambdaSpheres) then
out[MAROON_SIGNAL] = 1
end
if shouldFold(xiSpheres, zetaSpheres, thetaSpheres, phiSpheres) then
out[ORANGE_SIGNAL] = 1
end
if shouldFold(lambdaSpheres, thetaSpheres, epilsonSpheres, zetaSpheres) then
out[TEAL_SIGNAL] = 1
end
if shouldFold(thetaSpheres, epilsonSpheres, phiSpheres, omegaSpheres) then
out[AQUA_SIGNAL] = 1
end
if shouldFold(zetaSpheres, phiSpheres, gammaSpheres, epilsonSpheres) then
out[PURPLE_SIGNAL] = 1
end
if shouldFold(phiSpheres, gammaSpheres, omegaSpheres, xiSpheres) then
out[BROWN_SIGNAL] = 1
end
if shouldFold(epilsonSpheres, omegaSpheres, lambdaSpheres, gammaSpheres) then
out[GREY_SIGNAL] = 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment