Driftix

Bigger reactor calibration

Jul 21st, 2025 (edited)
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 KB | None | 0 0
  1. local reactor = peripheral.wrap("BiggerReactors_Reactor_1")
  2. local sleepTime = 3
  3. local step = 20
  4. local epsilon = 0.0001
  5. local rodCount = reactor.controlRodCount()
  6. local bestRatio = 0
  7. local bestConfig = {}
  8.  
  9. -- Activer le réacteur si besoin
  10. if not reactor.active() then
  11.     reactor.setActive(true)
  12.     sleep(2)
  13. end
  14.  
  15. -- Utilitaires
  16. local function applyConfig(config)
  17.     for i = 0, rodCount - 1 do
  18.         reactor.getControlRod(i).setLevel(config[i] or 0)
  19.     end
  20. end
  21.  
  22. local function testConfig(config)
  23.     applyConfig(config)
  24.     sleep(sleepTime)
  25.     local transitioned = reactor.coolantTank().transitionedLastTick()
  26.     local burned = reactor.fuelTank().burnedLastTick()
  27.     local ratio = transitioned / (burned + epsilon)
  28.  
  29.     print("Test config: [" .. table.concat(config, ", ") .. "]")
  30.     print("  Vapeur: " .. transitioned .. " mB/t | Fuel: " .. burned .. " | Ratio: " .. ratio)
  31.  
  32.     if ratio > bestRatio then
  33.         bestRatio = ratio
  34.         bestConfig = { table.unpack(config) }
  35.     end
  36. end
  37.  
  38. -- Méthode 1 : bruteforce toutes combinaisons
  39. local function bruteForce(index, current)
  40.     if index >= rodCount then
  41.         testConfig(current)
  42.         return
  43.     end
  44.  
  45.     for level = 0, 100, step do
  46.         current[index] = level
  47.         bruteForce(index + 1, current)
  48.     end
  49. end
  50.  
  51. -- Méthode 2 : empilement progressif
  52. local function progressiveStack()
  53.     local config = {}
  54.     for i = 0, rodCount - 1 do config[i] = 0 end
  55.  
  56.     for i = 0, rodCount - 1 do
  57.         for level = 0, 100, step do
  58.             config[i] = level
  59.             testConfig(config)
  60.         end
  61.         config[i] = 100 -- verrouille la rod à 100 pour la suite
  62.     end
  63. end
  64.  
  65. -- Menu de sélection
  66. print("=== Optimiseur Bigger Reactor ===")
  67. print("1. Test complet (toutes les combinaisons)")
  68. print("2. Empilement progressif des rods")
  69. write("Choisis une méthode (1 ou 2) : ")
  70. local input = read()
  71.  
  72. if input == "1" then
  73.     print("\n▶ Lancement de l'optimisation complète...")
  74.     bruteForce(0, {})
  75. elseif input == "2" then
  76.     print("\n▶ Lancement de l'empilement progressif...")
  77.     progressiveStack()
  78. else
  79.     print("❌ Choix invalide. Fin du programme.")
  80.     return
  81. end
  82.  
  83. -- Appliquer la meilleure config
  84. print("\n✅ Meilleure configuration trouvée :")
  85. for i = 0, rodCount - 1 do
  86.     print("  Rod #" .. i .. ": " .. bestConfig[i] .. "%")
  87.     reactor.getControlRod(i).setLevel(bestConfig[i])
  88. end
  89.  
Advertisement
Add Comment
Please, Sign In to add comment