Advertisement
Znailxxor

Thaumcraft

Jun 4th, 2015
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.94 KB | None | 0 0
  1. Aspects = {
  2.     aer = {
  3.         name = "Aer",
  4.         tier = 1
  5.     },
  6.     aqua = {
  7.         name = "Aqua",
  8.         tier = 1
  9.     },
  10.     ignis = {
  11.         name = "Ignis",
  12.         tier = 1
  13.     },
  14.     ordo = {
  15.         name = "Ordo",
  16.         tier = 1
  17.     },
  18.    
  19.     perditio = {
  20.         name = "Perditio",
  21.         tier = 1
  22.     },
  23.     terra = {
  24.         name = "Terra",
  25.         tier = 1
  26.     },
  27.     gelum = {
  28.         name = "Gelum",
  29.         tier = 2
  30.     },
  31.     lux = {
  32.         name = "Lux",
  33.         tier = 2
  34.     },
  35.     motus = {
  36.         name = "Motus",
  37.         tier = 2
  38.     },
  39.     permutatio = {
  40.         name = "Permutatio",
  41.         tier = 2
  42.     },
  43.     potentia = {
  44.         name = "Potentia",
  45.         tier = 2
  46.     },
  47.     tempestas = {
  48.         name = "Tempestas",
  49.         tier = 2
  50.     },
  51.     vacuos = {
  52.         name = "Vacuos",
  53.         tier = 2
  54.     },
  55.     venenum = {
  56.         name = "Venenum",
  57.         tier = 2
  58.     },
  59.     victus = {
  60.         name = "Victus",
  61.         tier = 2
  62.     },
  63.     vitreus = {
  64.         name = "Vitreus",
  65.         tier = 2
  66.     },
  67.     herba = {
  68.         name = "Herba",
  69.         tier = 3
  70.     },
  71.     iter = {
  72.         name = "Iter",
  73.         tier = 3
  74.     },
  75.     limus = {
  76.         name = "Limus",
  77.         tier = 3
  78.     },
  79.     metallum = {
  80.         name = "Metallum",
  81.         tier = 3
  82.     },
  83.     mortuus = {
  84.         name = "Mortuus",
  85.         tier = 3
  86.     },
  87.     sano = {
  88.         name = "Sano",
  89.         tier = 3
  90.     },
  91.     tempus = {
  92.         name = "Tempus",
  93.         tier = 3
  94.     },
  95.     vinculum = {
  96.         name = "Vinculum",
  97.         tier = 3
  98.     },
  99.     volatus = {
  100.         name = "Volatus",
  101.         tier = 3
  102.     },
  103.     bestia = {
  104.         name = "Bestia",
  105.         tier = 4
  106.     },
  107.     fames = {
  108.         name = "Fames",
  109.         tier = 4
  110.     },
  111.     praecantatio = {
  112.         name = "Praecantatio",
  113.         tier = 4
  114.     },
  115.     tenebrae = {
  116.         name = "Tenebrae",
  117.         tier = 4
  118.     },
  119.     arbor = {
  120.         name = "Arbor",
  121.         tier = 4
  122.     },
  123.     infernus = {
  124.         name = "Infernus",
  125.         tier = 5
  126.     },
  127.     auram = {
  128.         name = "Auram",
  129.         tier = 5
  130.     },
  131.     examinis = {
  132.         name = "Examinis",
  133.         tier = 5
  134.     },
  135.     spiritus = {
  136.         name = "Spiritus",
  137.         tier = 5
  138.     },
  139.     superbia = {
  140.         name = "Superbia",
  141.         tier = 5
  142.     },
  143.     vitium = {
  144.         name = "Vitium",
  145.         tier = 5
  146.     },
  147.     alienis = {
  148.         name = "Alienis",
  149.         tier = 6
  150.     },
  151.     gula = {
  152.         name = "Gula",
  153.         tier = 6
  154.     },
  155.     cognito = {
  156.         name = "Cognito",
  157.         tier = 6
  158.     },
  159.     sensus = {
  160.         name = "Sensus",
  161.         tier = 6
  162.     },
  163.     corpus = {
  164.         name = "Corpus",
  165.         tier = 7
  166.     },
  167.     desidia = {
  168.         name = "Desidia",
  169.         tier = 8
  170.     },
  171.     humanus = {
  172.         name = "Humanus",
  173.         tier = 10
  174.     },
  175.     invidia = {
  176.         name = "Invidia",
  177.         tier = 10
  178.     },
  179.     luxuria = {
  180.         name = "Luxuria",
  181.         tier = 11
  182.     },
  183.     instrumentum = {
  184.         name = "Instrumentum",
  185.         tier = 11
  186.     },
  187.     perfodio = {
  188.         name = "Perfodio",
  189.         tier = 11
  190.     },
  191.     telum = {
  192.         name = "Telum",
  193.         tier = 12
  194.     },
  195.     tutamen = {
  196.         name = "Tutamen",
  197.         tier = 12
  198.     },
  199.     messis = {
  200.         name = "Messis",
  201.         tier = 13
  202.     },
  203.     ira = {
  204.         name = "Ira",
  205.         tier = 13
  206.     },
  207.     machina = {
  208.         name = "Machina",
  209.         tier = 13
  210.     },
  211.     lucrum = {
  212.         name = "Lucrum",
  213.         tier = 14
  214.     },
  215.     pannus = {
  216.         name = "Pannus",
  217.         tier = 15
  218.     },
  219.     fabrico = {
  220.         name = "Fabrico",
  221.         tier = 21
  222.     },
  223.     meto = {
  224.         name = "Meto",
  225.         tier = 24
  226.     }
  227. }
  228.  
  229. -- Links
  230. Aspects.venenum.links = { Aspects.aqua, Aspects.perditio }
  231. Aspects.pannus.links = { Aspects.instrumentum, Aspects.bestia }
  232. Aspects.perditio.links = { Aspects.vacuos, Aspects.gelum, Aspects.venenum, Aspects.permutatio, Aspects.mortuus, Aspects.vitium, Aspects.vinculum }
  233. Aspects.humanus.links = { Aspects.bestia, Aspects.cognito, Aspects.messis, Aspects.perfodio, Aspects.instrumentum, Aspects.lucrum, Aspects.fabrico }
  234. Aspects.lux.links = { Aspects.aer, Aspects.ignis, Aspects.tenebrae }
  235. Aspects.telum.links = { Aspects.instrumentum, Aspects.ignis, Aspects.ira }
  236. Aspects.corpus.links = { Aspects.mortuus, Aspects.bestia, Aspects.luxuria }
  237. Aspects.potentia.links = { Aspects.ordo, Aspects.ignis, Aspects.praecantatio }
  238. Aspects.vacuos.links = { Aspects.aer, Aspects.perditio, Aspects.tenebrae, Aspects.alienis, Aspects.praecantatio, Aspects.fames, Aspects.superbia, Aspects.gula, Aspects.tempus }
  239. Aspects.praecantatio.links = { Aspects.vacuos, Aspects.potentia, Aspects.auram, Aspects.vitium, Aspects.infernus }
  240. Aspects.spiritus.links = { Aspects.victus, Aspects.mortuus, Aspects.cognito, Aspects.sensus, Aspects.desidia }
  241. Aspects.examinis.links = { Aspects.motus, Aspects.mortuus }
  242. Aspects.tutamen.links = { Aspects.instrumentum, Aspects.terra }
  243. Aspects.vinculum.links = { Aspects.motus, Aspects.perditio, Aspects.desidia }
  244. Aspects.superbia.links = { Aspects.volatus, Aspects.vacuos }
  245. Aspects.fames.links = { Aspects.victus, Aspects.vacuos, Aspects.lucrum, Aspects.luxuria, Aspects.gula, Aspects.invidia }
  246. Aspects.gelum.links = { Aspects.ignis, Aspects.perditio }
  247. Aspects.aer.links = { Aspects.vacuos, Aspects.lux, Aspects.tempestas, Aspects.motus, Aspects.volatus, Aspects.auram, Aspects.arbor, Aspects.sensus }
  248. Aspects.vitreus.links = { Aspects.terra, Aspects.ordo, Aspects.metallum }
  249. Aspects.limus.links = { Aspects.victus, Aspects.aqua }
  250. Aspects.vitium.links = { Aspects.praecantatio, Aspects.perditio }
  251. Aspects.tenebrae.links = { Aspects.vacuos, Aspects.lux, Aspects.alienis }
  252. Aspects.victus.links = { Aspects.aqua, Aspects.terra, Aspects.mortuus, Aspects.spiritus, Aspects.sano, Aspects.limus, Aspects.herba, Aspects.bestia, Aspects.fames }
  253. Aspects.lucrum.links = { Aspects.humanus, Aspects.fames }
  254. Aspects.ignis.links = { Aspects.lux, Aspects.gelum, Aspects.potentia, Aspects.cognito, Aspects.telum, Aspects.infernus, Aspects.ira }
  255. Aspects.tempestas.links = { Aspects.aer, Aspects.aqua }
  256. Aspects.meto.links = { Aspects.messis, Aspects.instrumentum }
  257. Aspects.sano.links = { Aspects.victus, Aspects.ordo }
  258. Aspects.messis.links = { Aspects.herba, Aspects.humanus, Aspects.meto }
  259. Aspects.iter.links = { Aspects.motus, Aspects.terra }
  260. Aspects.permutatio.links = { Aspects.perditio, Aspects.ordo }
  261. Aspects.infernus.links = { Aspects.ignis, Aspects.praecantatio }
  262. Aspects.tempus.links = { Aspects.vacuos, Aspects.ordo }
  263. Aspects.aqua.links = { Aspects.tempestas, Aspects.victus, Aspects.venenum, Aspects.limus }
  264. Aspects.motus.links = { Aspects.aer, Aspects.ordo, Aspects.volatus, Aspects.iter, Aspects.bestia, Aspects.examinis, Aspects.machina, Aspects.vinculum }
  265. Aspects.perfodio.links = { Aspects.humanus, Aspects.terra }
  266. Aspects.alienis.links = { Aspects.vacuos, Aspects.tenebrae }
  267. Aspects.metallum.links = { Aspects.terra, Aspects.vitreus }
  268. Aspects.ordo.links = { Aspects.motus, Aspects.vitreus, Aspects.potentia, Aspects.permutatio, Aspects.sano, Aspects.instrumentum, Aspects.tempus }
  269. Aspects.desidia.links = { Aspects.vinculum, Aspects.spiritus }
  270. Aspects.fabrico.links = { Aspects.humanus, Aspects.instrumentum }
  271. Aspects.cognito.links = { Aspects.ignis, Aspects.spiritus, Aspects.humanus }
  272. Aspects.terra.links = { Aspects.vitreus, Aspects.victus, Aspects.metallum, Aspects.iter, Aspects.herba, Aspects.perfodio, Aspects.tutamen }
  273. Aspects.sensus.links = { Aspects.aer, Aspects.spiritus }
  274. Aspects.ira.links = { Aspects.telum, Aspects.ignis }
  275. Aspects.bestia.links = { Aspects.motus, Aspects.victus, Aspects.corpus, Aspects.humanus, Aspects.pannus }
  276. Aspects.volatus.links = { Aspects.aer, Aspects.motus, Aspects.superbia }
  277. Aspects.instrumentum.links = { Aspects.humanus, Aspects.ordo, Aspects.meto, Aspects.telum, Aspects.tutamen, Aspects.fabrico, Aspects.pannus, Aspects.machina }
  278. Aspects.auram.links = { Aspects.praecantatio, Aspects.aer }
  279. Aspects.herba.links = { Aspects.victus, Aspects.terra, Aspects.arbor, Aspects.messis }
  280. Aspects.luxuria.links = { Aspects.corpus, Aspects.fames }
  281. Aspects.gula.links = { Aspects.fames, Aspects.vacuos }
  282. Aspects.invidia.links = { Aspects.sensus, Aspects.fames }
  283. Aspects.arbor.links = { Aspects.aer, Aspects.herba }
  284. Aspects.mortuus.links = { Aspects.victus, Aspects.perditio, Aspects.spiritus, Aspects.corpus, Aspects.examinis }
  285. Aspects.machina.links = { Aspects.motus, Aspects.instrumentum }
  286.  
  287. -- colors
  288. Aspects.venenum.colors = { text = colors.lime, background = colors.black }
  289. Aspects.pannus.colors = { text = colors.yellow, background = colors.white }
  290. Aspects.perditio.colors = { text = colors.lightGray, background = colors.gray }
  291. Aspects.humanus.colors = { text = colors.pink, background = colors.yellow }
  292. Aspects.lux.colors = { text = colors.orange, background = colors.yellow }
  293. Aspects.telum.colors = { text = colors.red, background = colors.lightGray }
  294. Aspects.corpus.colors = { text = colors.pink, background = colors.red }
  295. Aspects.potentia.colors = { text = colors.cyan, background = colors.white }
  296. Aspects.praecantatio.colors = { text = colors.pink, background = colors.magenta }
  297. Aspects.spiritus.colors = { text = colors.gray, background = colors.black }
  298. Aspects.examinis.colors = { text = colors.green, background = colors.gray }
  299. Aspects.tutamen.colors = { text = colors.cyan, background = colors.lightBlue }
  300. Aspects.vinculum.colors = { text = colors.pink, background = colors.brown }
  301. Aspects.superbia.colors = { text = colors.purple, background = colors.black }
  302. Aspects.fames.colors = { text = colors.red, background = colors.gray }
  303. Aspects.gelum.colors = { text = colors.lightBlue, background = colors.white }
  304. Aspects.aer.colors = { text = colors.white, background = colors.yellow }
  305. Aspects.vitreus.colors = { text = colors.white, background = colors.lightBlue }
  306. Aspects.limus.colors = { text = colors.lime, background = colors.yellow }
  307. Aspects.vitium.colors = { text = colors.magenta, background = colors.purple }
  308. Aspects.tenebrae.colors = { text = colors.black, background = colors.black }
  309. Aspects.victus.colors = { text = colors.magenta, background = colors.red }
  310. Aspects.lucrum.colors = { text = colors.yellow, background = colors.orange }
  311. Aspects.ignis.colors = { text = colors.yellow, background = colors.red }
  312. Aspects.tempestas.colors = { text = colors.gray, background = colors.white }
  313. Aspects.vacuos.colors = { text = colors.gray, background = colors.lightGray }
  314. Aspects.meto.colors = { text = colors.brown, background = colors.orange }
  315. Aspects.sano.colors = { text = colors.red, background = colors.magenta }
  316. Aspects.messis.colors = { text = colors.brown, background = colors.yellow }
  317. Aspects.iter.colors = { text = colors.brown, background = colors.red }
  318. Aspects.permutatio.colors = { text = colors.gray, background = colors.green }
  319. Aspects.infernus.colors = { text = colors.orange, background = colors.red }
  320. Aspects.tempus.colors = { text = colors.gray, background = colors.purple }
  321. Aspects.aqua.colors = { text = colors.lightBlue, background = colors.cyan }
  322. Aspects.motus.colors = { text = colors.white, background = colors.gray }
  323. Aspects.perfodio.colors = { text = colors.brown, background = colors.gray }
  324. Aspects.alienis.colors = { text = colors.brown, background = colors.purple }
  325. Aspects.metallum.colors = { text = colors.brown, background = colors.lightGray }
  326. Aspects.ordo.colors = { text = colors.white, background = colors.lightGray }
  327. Aspects.desidia.colors = { text = colors.black, background = colors.gray }
  328. Aspects.fabrico.colors = { text = colors.green, background = colors.lightGray }
  329. Aspects.cognito.colors = { text = colors.pink, background = colors.lightGray }
  330. Aspects.terra.colors = { text = colors.lime, background = colors.green }
  331. Aspects.sensus.colors = { text = colors.cyan, background = colors.blue }
  332. Aspects.ira.colors = { text = colors.red, background = colors.black }
  333. Aspects.bestia.colors = { text = colors.gray, background = colors.brown }
  334. Aspects.volatus.colors = { text = colors.lightGray, background = colors.white }
  335. Aspects.instrumentum.colors = { text = colors.gray, background = colors.blue }
  336. Aspects.auram.colors = { text = colors.magenta, background = colors.pink }
  337. Aspects.herba.colors = { text = colors.green, background = colors.lime }
  338. Aspects.luxuria.colors = { text = colors.white, background = colors.pink }
  339. Aspects.gula.colors = { text = colors.yellow, background = colors.brown }
  340. Aspects.invidia.colors = { text = colors.lime, background = colors.gray }
  341. Aspects.arbor.colors = { text = colors.green, background = colors.brown }
  342. Aspects.mortuus.colors = { text = colors.pink, background = colors.gray }
  343. Aspects.machina.colors = { text = colors.purple, background = colors.gray }
  344.  
  345. monitor = peripheral.find("monitor")
  346. monitor.clear()
  347. monitor.setTextScale(1)
  348. belowAspects = 1
  349. maxX, maxY = monitor.getSize()
  350. buttons = {}
  351. recursiveLim = 0
  352.  
  353. for _, v in pairs(Aspects) do
  354.     table.sort(v.links, function(a, b) return a.tier < b.tier end)
  355. end
  356.  
  357. sortedAspects = {}
  358. for _, v in pairs(Aspects) do
  359.     sortedAspects[#sortedAspects+1] = v
  360. end
  361. table.sort(sortedAspects, function(a, b) return a.tier < b.tier end)
  362.  
  363. local goDeeper
  364. goDeeper = function(carry, goal, depth)
  365.     recursiveLim = recursiveLim + 1
  366.     if recursiveLim > 100000 then
  367.         recursiveLim = 0
  368.         print("taking a while... Have a random number: "..tostring(math.random(100)))
  369.     end
  370.     local solutions = {}
  371.     local newSolutions = {}
  372.     if depth == 0 then
  373.         if carry.name == goal.name then return true, {{goal}} end
  374.     else
  375.         if depth == 1 then
  376.             if carry.name == goal.name then return true, {{goal}} end
  377.         end
  378.         for _, v in pairs(carry.links) do
  379.             result, newSolutions = goDeeper(v, goal, depth - 1)
  380.             if result == true then
  381.                 for _, solution in pairs(newSolutions) do
  382.                     solution[#solution+1] = carry
  383.                     solutions[#solutions+1] = solution
  384.                 end
  385.             end
  386.         end
  387.         if #solutions > 0 then
  388.             return true, solutions
  389.         else
  390.             return false
  391.         end
  392.     end
  393. end
  394.  
  395. function totalCost(list)
  396.     total = 0
  397.     for _, v in pairs(list) do
  398.         total = total + v.tier
  399.     end
  400.     total = total - (list[1].tier + list[#list].tier)
  401.     return total
  402. end
  403.  
  404. function findCheapest(a1, a2, iterations)
  405.     result, solutions = goDeeper(a1, a2, iterations)
  406.     if result == true then
  407.         table.sort(solutions, function(a, b) return totalCost(a) < totalCost(b) end)
  408.     end
  409.     return result, solutions
  410. end
  411.  
  412. function tryButton(x, y)
  413.     for _, button in pairs(buttons) do
  414.         if x >= button.x and x <= button.x + button.w and y == button.y then
  415.             return unpack(button.response)
  416.         end
  417.     end
  418.     return "not a button at "..tostring(x)..", "..tostring(y)
  419. end
  420.  
  421. function makeButton(x, y, w, response)
  422.     buttons[#buttons+1]  = {x = x, y = y, w = w, response = response}
  423. end
  424.  
  425. function drawButton(x, y, text, textColor, backColor)
  426.     monitor.setCursorPos(x, y)
  427.     monitor.setTextColor(textColor)
  428.     monitor.setBackgroundColor(backColor)
  429.     monitor.write(" "..text.." ")
  430.     monitor.setTextColor(colors.white)
  431.     monitor.setBackgroundColor(colors.black)
  432. end
  433.  
  434. function makeAspectButton(aspect, x, y)
  435.     drawButton(x, y, aspect.name, aspect.colors.text, aspect.colors.background)
  436.     makeButton(x, y, string.len(aspect.name) + 2, {"aspect", aspect})
  437. end
  438.  
  439. function makeAspectButtons(list, x, y)
  440.     x = x
  441.     y = y
  442.     for _, aspect in pairs(list) do
  443.         if x + string.len(aspect.name) + 2 > maxX then
  444.             x = 2
  445.             y = y + 2
  446.         end
  447.         makeAspectButton(aspect, x, y)
  448.         x = x + string.len(aspect.name) + 3
  449.     end
  450.     return x, y
  451. end
  452.  
  453. step = "prep1"
  454.  
  455. while 1 do
  456.     if step == "prep1" then
  457.         buttons = {}
  458.         currentAspect = nil
  459.         currentAspect2 = nil
  460.         monitor.clear()
  461.         _, y = makeAspectButtons(sortedAspects, 2, 2)
  462.         x = 2
  463.         y = y + 2
  464.         belowAspects = y
  465.         monitor.setCursorPos(x, y)
  466.         monitor.write("Select an aspect to start")
  467.         step = "input1"
  468.         x = 2
  469.         y = y + 2
  470.         monitor.setCursorPos(x, y)
  471.     end
  472.    
  473.     if step == "input1" then
  474.         response = nil
  475.         aspect = nil
  476.         event, _, xPos, yPos = os.pullEvent("monitor_touch")
  477.         response, aspect = tryButton(xPos, yPos)
  478.         if aspect then
  479.             currentAspect = aspect
  480.             step = "prep2"
  481.         end
  482.     end
  483.    
  484.     if step == "prep2" then
  485.         buttons = {}
  486.         currentAspect2 = nil
  487.         monitor.clear()
  488.         _, y = makeAspectButtons(sortedAspects, 2, 2)
  489.         x = 2
  490.         y = y + 2
  491.         monitor.setCursorPos(x, y)
  492.         monitor.write("Select another aspect")
  493.         x = 2
  494.         y = y + 2
  495.         monitor.setCursorPos(x, y)
  496.         monitor.write("Current selection: ")
  497.         x = 22
  498.         drawButton(x, y, currentAspect.name, currentAspect.colors.text, currentAspect.colors.background)
  499.         y = y + 2
  500.         drawButton(x, y, "Cancel", colors.red, colors.white)
  501.         makeButton(x, y, 8, {"cancel"})
  502.         step = "input2"
  503.     end
  504.    
  505.     if step == "input2" then
  506.         response = nil
  507.         aspect = nil
  508.         event, _, xPos, yPos = os.pullEvent("monitor_touch")
  509.         response, aspect = tryButton(xPos, yPos)
  510.         if aspect then
  511.             currentAspect2 = aspect
  512.             step = "prep3"
  513.         else
  514.             if response == "cancel" then
  515.                 step = "prep1"
  516.             end
  517.         end
  518.     end
  519.    
  520.     if step == "prep3" then
  521.         buttons = {}
  522.         monitor.clear()
  523.         x = 2
  524.         y = belowAspects - 2
  525.         for i = 0, 8, 1 do
  526.             drawButton(x + 4*i, y, tostring(i+1), colors.black, colors.white)
  527.             makeButton(x + 4*i, y, 3, {"number", i+1})
  528.         end
  529.         x = 2
  530.         y = y + 2
  531.         monitor.setCursorPos(x, y)
  532.         monitor.write("Select the number of aspects between the two")
  533.         x = 2
  534.         y = y + 2
  535.         monitor.setCursorPos(x, y)
  536.         monitor.write("Current selection: ")
  537.         x = 22
  538.         drawButton(x, y, currentAspect.name, currentAspect.colors.text, currentAspect.colors.background)
  539.         x = x + string.len(currentAspect.name) + 3
  540.         drawButton(x, y, currentAspect2.name, currentAspect2.colors.text, currentAspect2.colors.background)
  541.         y = y + 2
  542.         drawButton(2, y, "Cancel", colors.red, colors.white)
  543.         makeButton(2, y, 8, {"cancel"})
  544.         drawButton(11, y, "Undo", colors.yellow, colors.gray)
  545.         makeButton(11, y, 6, {"undo"})
  546.         step = "input3"
  547.     end
  548.    
  549.     if step == "input3" then
  550.         response = nil
  551.         number = nil
  552.         event, _, xPos, yPos = os.pullEvent("monitor_touch")
  553.         response, number = tryButton(xPos, yPos)
  554.         print(response)
  555.         if number then
  556.             iterations = number
  557.             step = "calc4"
  558.         elseif response == "cancel" then
  559.             step = "prep1"
  560.         elseif response == "undo" then
  561.             step = "prep2"
  562.         end
  563.     end
  564.    
  565.     if step == "calc4" then
  566.         monitor.clear()
  567.         monitor.setCursorPos(2, belowAspects)
  568.         monitor.write("Calculating...")
  569.         result, solutions = findCheapest(currentAspect, currentAspect2, iterations + 2)
  570.         if result == true then
  571.             step = "prep4"
  572.         else
  573.             step = "error4"
  574.         end
  575.     end
  576.    
  577.     if step == "error4" then
  578.         buttons = {}
  579.         monitor.clear()
  580.         x = 2
  581.         y = belowAspects - 4
  582.         monitor.setCursorPos(x, y)
  583.         monitor.write("No possible way to connect")
  584.         x = 2
  585.         y = y + 1
  586.         drawButton(x, y, currentAspect.name, currentAspect.colors.text, currentAspect.colors.background)
  587.         x = x + string.len(currentAspect.name) + 3
  588.         monitor.setCursorPos(x, y)
  589.         monitor.write("and")
  590.         x = x + 4
  591.         drawButton(x, y, currentAspect2.name, currentAspect2.colors.text, currentAspect2.colors.background)
  592.         x = 2
  593.         y = y + 1
  594.         monitor.setCursorPos(x, y)
  595.         monitor.write("in "..tostring(iterations).." or "..tostring(iterations+1).." steps.")
  596.         x = 2
  597.         y = y + 2
  598.         drawButton(2, y, "Accept", colors.green, colors.white)
  599.         makeButton(2, y, 8, {"accept"})
  600.         step = "errinput4"
  601.     end
  602.    
  603.     if step == "errinput4" then
  604.         response = nil
  605.         number = nil
  606.         event, _, xPos, yPos = os.pullEvent("monitor_touch")
  607.         response = tryButton(xPos, yPos)
  608.         print(response)
  609.         if response == "accept" then
  610.             step = "prep1"
  611.         end
  612.     end
  613.    
  614.     if step == "prep4" then
  615.         buttons = {}
  616.         monitor.clear()
  617.         x = 2
  618.         y = 2
  619.         monitor.setCursorPos(x, y)
  620.         monitor.write("Connecting ")
  621.         x = x + 11
  622.         drawButton(x, y, currentAspect.name, currentAspect.colors.text, currentAspect.colors.background)
  623.         x = x + string.len(currentAspect.name) + 3
  624.         monitor.setCursorPos(x, y)
  625.         monitor.write("to")
  626.         x = x + 3
  627.         drawButton(x, y, currentAspect2.name, currentAspect2.colors.text, currentAspect2.colors.background)
  628.         x = 2
  629.         if #solutions > 2 then
  630.             y = y + 2
  631.             monitor.setCursorPos(x, y)
  632.             monitor.write("Showing top 2 solutions:")
  633.             for i=1, 2, 1 do
  634.                 y = y + 2
  635.                 _, y = makeAspectButtons(solutions[i], x, y)
  636.                 y = y + 2
  637.                 monitor.setCursorPos(x, y)
  638.                 monitor.write("Total cost: "..tostring(totalCost(solutions[i])).." primals.")
  639.             end
  640.         else
  641.             y = y + 2
  642.             monitor.write("Showing all "..tostring(#solutions).." solution(s):")
  643.             for _, v in pairs(solutions) do
  644.                 y = y + 2
  645.                 _, y = makeAspectButtons(v, x, y)
  646.                 y = y + 2
  647.                 monitor.setCursorPos(x, y)
  648.                 monitor.write("Total cost: "..tostring(totalCost(v)).." primals.")
  649.             end
  650.         end
  651.         y = y + 4
  652.         drawButton(x, y, "Done!", colors.green, colors.white)
  653.         makeButton(x, y, 7, {"done"})
  654.        
  655.         step = "input4"
  656.     end
  657.    
  658.     if step == "input4" then
  659.         response = nil
  660.         number = nil
  661.         event, _, xPos, yPos = os.pullEvent("monitor_touch")
  662.         response = tryButton(xPos, yPos)
  663.         print(response)
  664.         if response == "done" then
  665.             step = "prep1"
  666.         end
  667.     end
  668.    
  669.    
  670. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement